cancel
Showing results for 
Search instead for 
Did you mean: 

RTC and Alarm subsecond mask

JAN R
Associate III

Dear,

I want to use an Alarm A in RTC mode. But have some trouble with it.

1) I use LSI 37000 Hz

2) for 1 Hz I selected PREDIV_S=7399 and PREDIV_A=4

It means that my Granulanity is 1/(7399+1)

When I want to wakeup for example in 100 ms.

1) I read actual time form RTC reg

2) Calculate in what time I will have to wakeup

3) Set the calculted time to ALARM reg.

But It seems the wakeup does not work reliably. Sometimes it seems like the Alarm occurs much more earlier the it should be.

When my PREDIV_S is 7399=(0b1110011100111) it is 13 bits so I set ALAM Subsecond mask as RTC_ALARMSUBSECONDMASK_SS14_13 (13<<24) but I am not sure about it. Is that correct?

Thank you very much for help.

Jan.

3 REPLIES 3

Mask sounds about right, although you might also leave the whole register unmasked (i.e. use 15 as the mask value). The purpose of mask is to have repeated alarms every 1/2^K seconds without the need to rewrite the alarm register (this of course works only if PREDIV_S is 2^N-1)

Please specify "Alarm occurs much more earlier". How exactly do you perform the next-value calculation? do you have BYPSHAD set, and if not, do you take into account the shadow lock/unlock mechanism when reading the current time?

Which STM32?

LSI in some STM32 models is quite unprecise and jittery; 10% off nominal value may be normal.

JW

JAN R
Associate III

Thanks for reply.

I use STM32L152. My task is simple.

0) MCU makes some work.

1) I Set wakeup time to 100 ms and then I go to STOP mode.

2) After 100 ms the processor exits from STOP mode, makes some work.

1) I set the wakeup time to 100 ms again.....

ETC.

So if I understand it then I can leave the whole register unmasked (RTC_ALARMSUBSECONDMASK_NONE). Is not it?

It is really difficult to debug it. But I can measure with oscilloscope that sometimes (about 1 case form 20) the processor is woken approximately in 700 us instead of 100 ms.

I come form this function:

https://github.com/arduino/mkrwan1300-fw/blob/master/Middlewares/Third_Party/Lora/Conf/Src/hw_rtc_template.c#L473

My PREDIV_S is 7399 - it is not 2^N-1 value.

Any idea ?

Thank you very much, Jan.

JAN R
Associate III

I find out, that when Alarm wakeup earlier then should be, so Alarm wakes up ALWAYS in 7 ticks. But I know it should still sleep..