新手上路
- 积分
- 29
- 金钱
- 29
- 注册时间
- 2016-4-28
- 在线时间
- 6 小时
|
1金钱
本帖最后由 苦尽甘来 于 2016-6-3 15:15 编辑
使用STM8S 的TIM1输出PWM CH1和CH1N的波形如下图,不正常为啥CH1(蓝色)的波形不正常? 其他3个通道都正常。
CH2和CH2N的波形如下,很正常
代码:
TIM1_DeInit();
TIM1_TimeBaseInit(79, TIM1_COUNTERMODE_UP, 9, 0); // 10 配置 预分频,计数模式,周期,重装值
TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_DISABLE, TIM1_OUTPUTNSTATE_ENABLE, //初始化OC1
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, //初始化OC2
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);
|
-
-
|