Skip to main content
Lukasz Przenioslo
Associate III
Mar 29, 2019 12:47 PM UTC
Solved

Turn on PWM for n cycles?

Hello there,

I was wondering either it is possible (with STM32L4) to turn on a PWM channel for a certain amount of cycles or for a certain amount of time? Ideally, without any interrupts during this period or at the end.

I am trying to figure out a way to re-trigger an external watchdog supervisor without breaking the MCU from sleep mode. For example, lets say the wdg device has to be retriggered every 500 ms and I would like to sleep the MCU for 2 seconds. With this functionality, I would configure the peripheral to do 4 cycles (assuming 500 ms period) or to work for 2 secs (any period less than 500 ms is ok).

Turning the pwm peripheral without any timeout could cause a deadlock in the application.

In case this is not possible, I thought of using an external multivibrator, that would make the additional line toggle for me while I am asleep... But its a bit too much.

I would appreciate all help.

This topic has been closed for replies.
S.Ma
S.MaBest answer
Principal
Mar 29, 2019 1:10 PM UTC

Check low power timer, otherwise for a burst of pulses I would think to use advanced timer repetition counter, or use timer output compare fed by dma from a table of compare values, detecting the dma tranfer complete being the event.

7 replies

S.Ma
Principal
Mar 29, 2019 1:00 PM UTC

MCU sleep means clock stop mode?

Lukasz Przenioslo
Associate III
Mar 29, 2019 1:04 PM UTC

I believe not. The other timer (TIM3) I am using for 3 channels PWM generation without the global interrupt turned on is working all the time.

S.Ma
S.MaBest answer
Principal
Mar 29, 2019 1:10 PM UTC

Check low power timer, otherwise for a burst of pulses I would think to use advanced timer repetition counter, or use timer output compare fed by dma from a table of compare values, detecting the dma tranfer complete being the event.

Lukasz Przenioslo
Associate III
Mar 29, 2019 1:11 PM UTC

This seems reasonable, will check it out. Thanks.

S.Ma
Principal
Mar 29, 2019 1:18 PM UTC

Let us know later which solution you used and what made you choose. Thanks.

Lukasz Przenioslo
Associate III
Mar 29, 2019 1:46 PM UTC

Its seems like LPTIM1/2 One-pulse mode is exactly what I need (If I understood the functionality correctly). If I set LSI as clock source (32k) and set the prescaler to 32, it would give me 1 ms time base. So in order to make a 1500 ms pulse I would do:

HAL_LPTIM_OnePulse_Start(lptim_handle, 1500, 0);

I dont have the scope with me, so will be able to test it later only. Thanks for the hint.