cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 low RTC precision

Posted on March 05, 2018 at 07:57

Hello there,

I am using an STM32L4 family MCU. In an application, the RTC peripheral is utilized and clocked from an external crystal:

0690X00000609xVQAQ.png

0690X00000609vUQAQ.png

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.
71 REPLIES 71
T J
Lead
Posted on March 06, 2018 at 02:58

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.

Posted on March 06, 2018 at 05:32

Dhenry,

Just to make sure did you mean RTC? Or do you mean something else by etc?

Clive,

Ill try that, thank you.

Posted on March 06, 2018 at 05:34

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.

Posted on March 06, 2018 at 22:04

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.

Posted on March 06, 2018 at 23:14

'

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.

Posted on March 07, 2018 at 08:20

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.

Posted on March 07, 2018 at 11:23

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

Posted on March 07, 2018 at 11:24

But in this case the supercap had no chance to start working, since mains was always on.

Posted on March 07, 2018 at 11:56

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:

0690X00000609VeQAI.png

Then please move to Clock Configuration tab and select LSE as a clock source for MCO:

0690X00000609yJQAQ.png

Regarding pin configuration, please keep default slope setting, which is low:

0690X00000609yYQAQ.png

After connecting PA8 to the scope you will see shape and frequency of the LSE.

Regards

Szymon

Posted on March 07, 2018 at 12:19

Are you sure there was no power outage during the weekend?

JW