现用STM32 TIM8做两路PWM调制输出,TIM_CounterMode_CenterAligned1模式,通道1为TIM_OCMode_PWM1,通道3为TIM_OCMode_PWM2模式,在主程序调试OK,但用TIM1比较中断进调制,用调试模式,写CCR1,CCR3寄存器后再读出来,发现是对的,可PC6,PC8脚脉宽却没有更新,而是要在15ms左右后才能更新,调试几天没找出问题,求帮忙!
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_DeInit(TIM8);
TIM_TimeBaseStructure.TIM_Period=PWMCycle-1;
TIM_TimeBaseStructure.TIM_Prescaler=2-1;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_CenterAligned1;
TIM_TimeBaseInit(TIM8,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputState_Disable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse=PWMDutyCycle;
TIM_OCInitStructure.TIM_OutputState=ENABLE;
TIM_OC1Init(TIM8,&TIM_OCInitStructure);
TIM_ForcedOC3Config(TIM8, TIM_ForcedAction_InActive);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_Pulse=PWMCycle-PWMDutyCycle;
TIM_OC3Init(TIM8,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM8, TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM8, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM8, ENABLE);
TIM_CtrlPWMOutputs(TIM8,DISABLE);
TIM_Cmd(TIM8,DISABLE); |