现在用TIM8产生两路180°波形,配置为TIM_CounterMode_CenterAligned1,通道一为TIM_OCMode_PWM1,通道三为TIM_OCMode_PWM2,原初步调试在主程序脉宽能实时调制,现放在TIM1比较中断中进脉宽调制,却怎么也要到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); |