cancel
Showing results for 
Search instead for 
Did you mean: 

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.

1 ACCEPTED SOLUTION

Accepted Solutions
S.Ma
Principal

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.

View solution in original post

7 REPLIES 7
S.Ma
Principal

MCU sleep means clock stop mode?

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
Principal

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.

This seems reasonable, will check it out. Thanks.

S.Ma
Principal

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

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.

Hi,

I have checked the LPTIM functionality with scope. It works as its supposed to. Bellow an 850 ms pulse is being generated with:

    HAL_LPTIM_OnePulse_Start(lptim_handle, 850, 0);

32k LSI as LPTIM1 source with /32 divider.

0690X0000089I9kQAE.png