2021-01-14 03:27 AM
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
2021-01-14 05:32 AM
The current state of the GPIO pin is always in GPIO->IDR, unless it's in analog mode.
2021-01-14 05:39 AM
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.
2021-01-14 11:28 AM
Thank you for the tips
2021-01-16 04:36 AM
Probably you can solve it in a more robust and an easier way.
Also advanced timers can force output channels to a defined inactive level when channels are disabled. Read the AN4013 section 4.1.
2021-01-16 05:01 AM
Ok I will Check.
May be this solution avoid to spend processor time by polling while(LL_TIM_IsActiveFlag_UPDATE(TIM2) == 0);