cancel
Showing results for 
Search instead for 
Did you mean: 

How to disable PWM output properly?

JJohn.3
Associate II

Hello,

My timer PWM channel is connected directly to a mosfet driver. By using

TIM_Cmd(TIM2, DISABLE);

it puts the output at high level. I tried to use TIM_DeInit(TIM2); but it generates an additional pulse in the output ( I count the each PWM pulse in interrupt and I disable timer in the interrupt routine). So I need to know what is the best way to disable a timer to put it at low level while it is disabled.

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

You can set a PWM channel to a fixed oputput level using the OCM (Output compare mode) bits of the capture/compare mode register, see reference manual. Don't know how that maps to your library.

View solution in original post

4 REPLIES 4
KnarfB
Principal III

You can set a PWM channel to a fixed oputput level using the OCM (Output compare mode) bits of the capture/compare mode register, see reference manual. Don't know how that maps to your library.

JJohn.3
Associate II

Thank you for your comment. I think I've done your comment with SPL library ( TIMOCStruct.TIM_OCPolarity to TIM_OCPolarity_Low and even TIM_OCPolarity_High) but nothing works. I changed CCMR1 to TIM_ForcedAction_Active(0x0050) it works fine but I see an additional pulse in the output(before the last pulse I changed the CCMR1 to 0x0050)

0693W000007Dca6QAC.jpg 

Depends on when you change the bits?

Another solution may be to change the given CCRx to 0 or maximum (depending on which PWM mode you are using), while using CCRx preload. This should transition cleanly, whenever written, although the result is delayed one timer cycle.

JW