cancel
Showing results for 
Search instead for 
Did you mean: 

LPTIM repetition counter not work

clee.10
Associate III

Hi ,

I am trying to use lptim on NUCLEOL412RB.

I want to use lptim repetition counter to fire a interrupt which period is 5 secs.

My lptim clock source is 32k LSI.

Here is my config:

hlptim1.Instance = LPTIM1;
hlptim1.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
hlptim1.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
hlptim1.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
hlptim1.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
hlptim1.Init.UpdateMode = LPTIM_UPDATE_ENDOFPERIOD;
hlptim1.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
hlptim1.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
hlptim1.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
hlptim1.Init.RepetitionCounter = 5;
 
/* Enable LPTIM */
HAL_LPTIM_TimeOut_Start_IT(&hlptim1, 0, 32767);

By this config I always get 1 sec timeout, not 5 secs. Can any one tell me what's going on?

Thanks a lot.

5 REPLIES 5
TDK
Guru

Next time please include the chip you're using in the post. There are a lot of chip families out there.

An update event is generated when the counter reaches 0. This repeats 5 times, but the update event occurs each time.

Use LPTIM_PRESCALER_DIV8 or higher so you don't need any repetitions.

If you feel a post has answered your question, please click "Accept as Solution".
clee.10
Associate III

Hi TDK,

Thanks for your fast reply.

My platform is NUCLEOL412RB (sorry for my less information).

Actually I want to make longer timeout (maybe one hour). Even I change freq DIV to 128.

The timeout will be 128 * 65535 / 32768 = 256 secs. //HAL_LPTIM_TimeOut_Start_IT(&hlptim1, 0, 65535);

Therefore, I think change freq DIV is not enough.

TDK
Guru

Are you actually calling HAL_LPTIM_Init in your code? The code you posted doesn't call it.

I'd try this example and see if it works for you.

https://github.com/STMicroelectronics/STM32CubeL4/blob/d00623f229d09f3a1be050bdb0606b8870fa5d1c/Projects/NUCLEO-L412RB-P/Examples/LPTIM/LPTIM_RepetitionCounter/Src/main.c

Not also you want repetition of 4 to get a 5 sec delay. repetition of 0 gives a 1sec delay.

It's also possible you're catching the ARR match event and incorrectly interpreting that as an UPDATE event.

If you feel a post has answered your question, please click "Accept as Solution".

> It's also possible you're catching the ARR match event and incorrectly interpreting that as an UPDATE event.

Very true, but the used HAL_LPTIM_TimeOut_Start_IT() does not appear to use either.

Probably some other Cube/HAL incantation ought to be used? I don't use Cube/HAL.

JW

clee.10
Associate III

Hi TDK,

Thank you for your sample code.

I have replaced HAL_LPTIM_TimeOut_Start_IT() with HAL_LPTIM_Counter_Start_IT().

It is work to trigger HAL_LPTIM_UpdateEventCallback event. (I got 1 event every 5 interrupts.)

Actually, it is not what I want. Since each interrupt will wake-up MCU from low power mode.

Nevertheless, thank you for your help.