stm32 TIM3 工作于PWM1,向上计数,软件仿真中:中断函数里更改CCR1的值,然后再软件设置UG位产生更新,将CCR1的值更新到影子寄存器,发现CNT清零了,但是为什么CCR1影子寄存器的值没有被更新啊?谢谢了 void TM3_PWM_Config(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; //比较捕获模式初始化 //基本的初始化 TIM_TimeBaseStructure.TIM_Prescaler=0; //PSC预分频 不分频72MHZ TIM_TimeBaseStructure.TIM_Period=900; //自动重载寄存器 0到999 1000次一个周期 TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式 TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1 ; //不分频 见TIMx_CR1寄存器位9 位8 TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1 ; TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse=CCR1_Val; //设定比较值 TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High; TIM_OC1Init(TIM3,&TIM_OCInitStructure); //初始化了通道1 TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable); TIM_ITConfig(TIM3,TIM_IT_CC1,ENABLE); //使能匹配中断 //使能TM3重载寄存器ARR TIM_ARRPreloadConfig(TIM3,ENABLE); //使能TM3 TIM_Cmd(TIM3,ENABLE); } void TIM3_IRQHandler(void) { if(TIM_GetITStatus(TIM3,TIM_IT_CC1)==SET) { TIM_ClearITPendingBit(TIM3,TIM_IT_CC1); //软件清0 CCR1_Val++; TIM_SetCompare1(TIM3,CCR1_Val); TIM_ClearFlag(TIM3,TIM_FLAG_Update); TIM_GenerateEvent(TIM3,TIM_EventSource_Update); if(CCR1_Val==998) CCR1_Val=500; } } |