2018-03-04 10:57 PM
Hello there,
I am using an STM32L4 family MCU. In an application, the RTC peripheral is utilized and clocked from an external crystal:
The problem I have noticed just now is that with time, the RTC timer looses sync. It is not easy to notice in short periods of time, but after leaving the application to log time for entire weekend, I noticed that the RTC timer is over 20 minutes later after my PC timer (they were both synced before the weekend).
What could be the cause of this problem? Its hard to believe for me that the RTC timer is simply this low precision, as I am using an external crystal. I would appreciate all help.
#precision #stm32l4 #rtc Note: this post was migrated and contained many threaded conversations, some content may be missing.2018-03-05 05:58 PM
To get good Time of Day,
Year after Year...
Dallas DS3232
otherwise,
once you have attained the correct quality xtal/caps values,
you must protect them from any humidity influence.
baking and conformal coating is your best chance.
2018-03-05 09:32 PM
Dhenry,
Just to make sure did you mean RTC? Or do you mean something else by etc?
Clive,
Ill try that, thank you.
2018-03-05 09:34 PM
Additional component just for date/time tracking here is not an option.
I can always sync with NTP server, what I do anyways. I just want to do it as rarely as I can (I was thinking once a week will be a good choice). But after around 50 hours I am 20 minutes off, so there has to be something wrong.
2018-03-06 02:04 PM
Like Clive said, you should use a frequency counter to check the crystal.
and the Caps should match the crystal load parameters. Then you should be much closer.
2018-03-06 03:14 PM
'
Additional component just for date/time tracking here is not an option.'
If the MCU is constantly running, you can construct a 'software' rtc whereby a counter is constantly incremented at a set interval of your choosing.
If anything fails, you may want to think of the possibility of your code or Hal being buggy.
Edit: here is the software rtc
https://github.com/dannyf00/software-RTC/tree/master/PIC24_Demo
Swrtc.c and swrtc.h to be included in your project. You will need to feed them with a constantly running tick - either systick or a timer of your choice.
It allows correction on sub-ppm levels.
2018-03-07 12:20 AM
Thanks for answer,
I really need the dedicated RTC peripheral. The main MCU frequency will vary in future, as I will need to slow it down or sleep the MCU for low power modes. Also the MCU can lose power. In that case for me an external supercap is holding the RTC. I just to figure this out. I will starts with changing the load caps to 6 pF from 6.8 pF, although this difference is very low, especially that caps capacitance is rated for 20 % probably.
I will also try to measure that RTC frequency with a scope, this should shed some light.
Thank you all for help. I do hope its not a bug in the HAL lib, but from retrospection that wouldnt be anything new.
2018-03-07 03:23 AM
In that case for me an external supercap is holding the RTC
Ah a supercap... Try a battery instead, just to see if it makes any difference.
JW
2018-03-07 03:24 AM
But in this case the supercap had no chance to start working, since mains was always on.
2018-03-07 03:56 AM
Hi Lukasz,
In order to output LSE on the pin please use MCO - Master Clock Output. Typically it is PA8. You can enable it in Pinout tab of STM32CubeMX like this:
Then please move to Clock Configuration tab and select LSE as a clock source for MCO:
Regarding pin configuration, please keep default slope setting, which is low:
After connecting PA8 to the scope you will see shape and frequency of the LSE.
Regards
Szymon
2018-03-07 04:19 AM
Are you sure there was no power outage during the weekend?
JW