Skip to main content
b.a.
Associate III
May 23, 2023 11:08 AM UTC
Solved

How to temporarily disable timer outputs on STM32G071

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?

This topic has been closed for replies.
KnarfB
KnarfBBest answer
Super User
May 24, 2023 8:30 PM UTC

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

6 replies

KnarfB
KnarfBBest answer
Super User
May 24, 2023 8:30 PM UTC

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 9:29 AM UTC

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

Thank you very much!

works also when Timer is in OC mode

Associate
Jan 4, 2024 4:47 PM UTC

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

S.Ma
Principal
May 25, 2023 5:24 AM UTC

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

b.a.
b.a.Author
Associate III
May 25, 2023 5:43 AM UTC

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