Subsecond resolution alarm on a RTC without subseconds (STM32L152 Cat.1)
Hi
Timekeeping in my application is pretty standard: 32 bit unsigned integers which store milliseconds since boot, overflowing every 49 days.
To reduce power consumption, i need a way to wake up from stop mode at a set time in ms. But my device has neither the RTC subsecond or shift control registers. Which leaves me with two options:
Reduce both of the prescalers to make a "second" much shorter, and distort the alarm date to compensate. For example if PREDIV_A = 127 and PREDIV_S = 0, a RTC 'second' will be 3.938 ms. The downside is that the alarm is only about 21 bits wide (28*24*60*60), with such a short 'second', the maximum delay is 2.64 hours (while being 4 ms rough). Also, it is not clear why is the minimum division factor 2 in Cat.1 devices. And haven't been able to find out what happens when the RTC year counter overflows.
The second option is keep the default configuration, and split each wait into two parts: first sleep for the whole second part using an alarm, and then sleep for the remainder using the wakeup timer. But because i cannot read subseconds, it is impossible to wait until a specific time within less than one second, only delays (wait for, not wait until) are possible at such a time scale.
Currently i favor the first option because one spurious wakeup every few hours is better than one on every wait longer than 1 second. Although reducing PREDIV_A lower than 127 (to get better precision) "may increase power consumption", but then again, so will running longer because the MCU cannot wake up exactly on time for an event.
