Skip to main content
b.a.
Associate III
May 23, 2023
Solved

How to temporarily disable timer outputs on STM32G071

  • May 23, 2023
  • 2 replies
  • 5692 views

In my application I have TIM1 configured to output a configurable frequency - which works well.

Now I want to add support for pausing the timer and the outputs should then go to inactive state( = low).

But whatever I try with MOE, OSSI, CC2E, CC2NE bits, both outputs on channel 2 remain high.

Am I misinterpreting table 116 on page 604 of the ref.manual?

Best answer by KnarfB

Suppose TIM1 CH2 and CH2N are running in PWM1 mode.

Set TIM1->BDTR |= TIM_BDTR_OSSI; // The timer maintains its control over the output.

OIS2 and OIS2N should have the levels you want (0==low)

Put the outputs in idle state (low) by generaing a break event:

TIM1->EGR |= TIM_EGR_BG;

Back to PWM output: TIM1->BDTR |= TIM_BDTR_MOE;

Note that this sequence does not completely reset/restart the timer.

hth

KnarfB

2 replies

KnarfB
KnarfBBest answer
Super User
May 24, 2023

Suppose TIM1 CH2 and CH2N are running in PWM1 mode.

Set TIM1->BDTR |= TIM_BDTR_OSSI; // The timer maintains its control over the output.

OIS2 and OIS2N should have the levels you want (0==low)

Put the outputs in idle state (low) by generaing a break event:

TIM1->EGR |= TIM_EGR_BG;

Back to PWM output: TIM1->BDTR |= TIM_BDTR_MOE;

Note that this sequence does not completely reset/restart the timer.

hth

KnarfB

b.a.
b.a.Author
Associate III
May 25, 2023

generating the break event was the part that I was missing!

Thank you very much!

works also when Timer is in OC mode

Associate
January 4, 2024

Hello B.a can you please share your code if possible

S.Ma
Principal
May 25, 2023

One alternative is to stop time by disabling the timer clock...

b.a.
b.a.Author
Associate III
May 25, 2023

wouldn't that just leave the outputs in the state they last had?