Question
STM32F4 How to repeatedly enable/disable CHx and CHxN outputs
Posted on January 30, 2015 at 09:52
I would like to repeatedly enable/disable TIM1 CH1 and CH1x outputs. Here is my code.
static u8 step = 1;
switch(step)
{
case 1:
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
step = 2;
break;
case 2:
TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);
TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
step=1;
break;
}
This part of code is called every 50ms. The duty cycle for CH1 is set to be 50%. What I expected to see is 50ms waveform with PWM output followed by 50ms disabled state output. However, the code didn't work as expected and both CH1 and CH1x continuously output without any disabled status. Would anyone please suggest how to realize the waveform I expected?