本帖最后由 苦尽甘来 于 2016-6-3 15:13 编辑
使用STM8S单片机的TIM1输出带死区控制的PWM,CH1,CH1N的波形如下(PWM.JPG),蓝 {MOD}是CH1,黄 {MOD}是CH1N;CH1的波形不正常。
CH2和CH2N(123.pang)的波形如下,波形正常 是想要的波形。
代码:
TIM1_DeInit();
TIM1_TimeBaseInit(79, TIM1_COUNTERMODE_UP, 9, 0); // 10 配置 预分频,计数模式,周期,重装值
TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_ENABLE,
5, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCNIDLESTATE_SET);
TIM1_OC2Init(TIM1_OCMODE_PWM1, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_ENABLE, 5,
TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_LOW, TIM1_OCIDLESTATE_RESET,
TIM1_OCNIDLESTATE_SET);
TIM1_OC1PolarityConfig(TIM1_OCPOLARITY_LOW);
TIM1_OC1NPolarityConfig(TIM1_OCNPOLARITY_LOW);
TIM1_OC2PolarityConfig(TIM1_OCPOLARITY_HIGH);
TIM1_OC2NPolarityConfig(TIM1_OCNPOLARITY_LOW);
TIM1_CCxCmd(TIM1_CHANNEL_1|TIM1_CHANNEL_2,ENABLE); //设置CCxE,OCxREF 被定向到OCx或者OCxN.
TIM1_CCxNCmd(TIM1_CHANNEL_1|TIM1_CHANNEL_2,ENABLE);
TIM1_CCPreloadControl(ENABLE);
TIM1_OC1PreloadConfig(ENABLE);
TIM1_PrescalerConfig(7, TIM1_PSCRELOADMODE_IMMEDIATE); //
TIM1_BDTRConfig(TIM1_OSSISTATE_ENABLE, TIM1_LOCKLEVEL_OFF, 3, TIM1_BREAK_DISABLE, TIM1_BREAKPOLARITY_LOW, TIM1_AUTOMATICOUTPUT_ENABLE);
TIM1_SetAutoreload(0x0A);
TIM1_ARRPreloadConfig(ENABLE);
TIM1_Cmd(ENABLE);
TIM1_CtrlPWMOutputs(ENABLE);
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>