芯片为STM8S105K4,初始化让OC1,OC2互补端输出PWM,OC3端输出PWM,现在的现象是互补端都无PWM输出,OC3输出端有PWM,求高手来帮解决。代码如下
void init_PWM(void)
{
TIM1_DeInit();
TIM1->CR1&=~60;
TIM1_TimeBaseInit(0x0000, TIM1_COUNTERMODE_UP,TIME_PERIOD, 0x00);
TIM1_OC1Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_ENABLE, 800, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_OC2Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_ENABLE, 800, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_OC3Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_DISABLE, 800, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_RESET, TIM1_OCNIDLESTATE_RESET);
TIM1_OC1PreloadConfig(ENABLE);
TIM1_OC2PreloadConfig(ENABLE);
TIM1_OC3PreloadConfig(ENABLE);
TIM1_BDTRConfig(TIM1_OSSISTATE_ENABLE, TIM1_LOCKLEVEL_OFF, DEAD_TIME, TIM1_BREAK_DISABLE, TIM1_BREAKPOLARITY_HIGH, TIM1_AUTOMATICOUTPUT_ENABLE); //死区配置
TIM1_CCPreloadControl(ENABLE); //比较捕获预装载,用于互补方式
TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE); //选择更新中断
TIM1_Cmd(ENABLE); //启用定时器
TIM1_CtrlPWMOutputs(ENABLE); //输出使能
} |