2020-06-07 07:16 PM
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.
2020-06-07 07:26 PM
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.
2020-06-07 08:17 PM
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.
2020-06-08 05:32 AM
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.
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.
2020-06-08 03:10 PM
> 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
2020-06-08 08:53 PM
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.