2019-04-10 03:05 AM
Hey guys,
I'm trying to configure my RTC to get ms on my STM32 F413
According to the reference i've to call HAL_RTC_GetTime() and directly after HAL_RTC_GetDate().
But i canot figure out how to confiure the prediders to get proper ms
My current settings look like this
However I'm gessing this gives me only a ms resolution of 1/255 But for ms i'd need 1/1024 resolution. How can i configure this?
Thx for your help
2019-04-10 06:16 AM
There are two RTC prescales, async and sync. The async divider prescales the RTC clock (LSI or LSE) to the input frequency for the RTC subseconds counter. The 15-bit sync divider generates the subseconds count to the 1Hz frequency for the RTC time and date registers.
So for LSE = 32.768KHz, async = 32 (1.024KHz), and sync = 1024 (subsecond = 1/1024 sec)
for LSI (32KHZ nominal) async = 32 (1KHz nominal) and sync = 1000 (subsecond = 1ms nominal)
LSE won't get you exact msec, and the LSI has a large tolerance so don't count on that 1msec being accurate. If you want exact 1msec subseconds count use a 32KHz crystal and low PPM with the LSE.
Jack Peacock
2019-04-10 07:04 AM
Thx for your clear answer :)
i got an LSE with 32.768kHz.
I did setup the RTC as you said
Just to be clear on how to calculate the ms
The manual says, that the subseconds register is downcounting. So the resulting ms shoudl be
milliseconds = 1000 - (1/1024) * subseconds
correct?