cancel
Showing results for 
Search instead for 
Did you mean: 

PWM Timer and GPIO level

PCu1
Senior

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

5 REPLIES 5
TDK
Guru

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
Senior

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.

Thank you for the tips

Piranha
Chief II

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.

Ok I will Check.

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