Skip to main content
PCu1
Senior
January 14, 2021
Question

PWM Timer and GPIO level

  • January 14, 2021
  • 3 replies
  • 1558 views

Hello,

I'm using a STM32F091 with TIM2 configured in PWM mode.(and CH1-CH2 connected to an output)

After some hundreads of milliseconds, I have to stop the PWM by setting CCRx at 0. And reenable later.

So far so good.

But to improve my working, I would to know when the level of the GPIO is really at 0, preferably by polling.

I tried a lot of tests but I can get what I expect.

Thx

This topic has been closed for replies.

3 replies

TDK
Super User
January 14, 2021

The current state of the GPIO pin is always in GPIO->IDR, unless it's in analog mode.

"If you feel a post has answered your question, please click ""Accept as Solution""."
PCu1
PCu1Author
Senior
January 14, 2021

Thank you for the tips

PCu1
PCu1Author
Senior
January 14, 2021

I think I found a solution:

Activate in the setup the event:

LL_TIM_EnableUpdateEvent(TIM2);

Then in the code:

LL_TIM_OC_SetCompareCH1(TIM2, 0); //stop PWM

LL_TIM_ClearFlag_UPDATE(TIM2);

while(LL_TIM_IsActiveFlag_UPDATE(TIM2) == 0);

At this point, the output level is at 0 and at the end of period.

Piranha
Principal III
January 16, 2021

Probably you can solve it in a more robust and an easier way.

https://community.st.com/s/question/0D53W00000FyMIHSA3/how-to-clear-output-compare-timer-pin-set-to-mode-active-level-on-match

Also advanced timers can force output channels to a defined inactive level when channels are disabled. Read the AN4013 section 4.1.

PCu1
PCu1Author
Senior
January 16, 2021

Ok I will Check.

May be this solution avoid to spend processor time by polling while(LL_TIM_IsActiveFlag_UPDATE(TIM2) == 0);