打印
[STM32F1]

STM32 PWM比较寄存器值已改,实测PC6,PC8脉宽没更新

[复制链接]
746|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
estelle08|  楼主 | 2015-12-10 19:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
现在用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);
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

14

帖子

0

粉丝