Skip to main content
JJohn.3
Associate III
February 2, 2021
Solved

How to disable PWM output properly?

  • February 2, 2021
  • 3 replies
  • 3569 views

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.

This topic has been closed for replies.
Best answer by KnarfB

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.

3 replies

KnarfB
KnarfBBest answer
Super User
February 2, 2021

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
JJohn.3Author
Associate III
February 2, 2021

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 

KnarfB
Super User
February 2, 2021

Depends on when you change the bits?

waclawek.jan
Super User
February 5, 2021

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