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
Posted on March 07, 2018 at 12:21

No doubt. The mains is a 5000 mAh battery + it was connected to the charger. Even if power went down the battery would last about 60h.

Also no reset events in the logs.

Posted on March 07, 2018 at 12:30

Thanks for the example Szymon, exactly what I needed.

So I have the scope view here:

0690X00000609VdQAI.png

The time for a full period is ~3.5 us, which gives 32786,8852459016393442623 Hz. I think that it is correct. I am not sure however why is the MCO output PWM not 50 %.

Can the crystal frequency be ruled out as a problem ir is the measurement not precise enough?

Posted on March 07, 2018 at 13:21

3.5us period means a frequency just shy of 300khz. Something is seriously wrong here.

Those crystals have a pullability of about 0.5hz per pf. So they cannot possibly account for a material portion of your error here.

Posted on March 07, 2018 at 14:47

sorry, its a mistype in the post. Its 5 us, not 3.5 us. That gives the proper frequency.

Albert
Associate II
Posted on March 08, 2018 at 11:56

Your design is wrong. You should have 6pF for (C16.C17/C16+C17) + Cx, with Cx tracks + STM32 pins capacitance (few pF).

Crystals with CL=6pF are made for direct connection to microcontroller/RTC and hard to design.

Take a 12.5pF crystal (the most used value) and C16=C17=22pF. Have a look on the STM32 hardware manual regarding the crystal power.

Theo.

Danilotto Runi
Associate II
Albert
Associate II
Posted on March 08, 2018 at 14:01

thanks for the like.

To be complete, capacitors should be 22pF/C0G class and at 32kHz, the crystal is thick and you can't destroy it even at full power. But you can tweak it to reduce power consumption.

Theo

Albert
Associate II
Posted on March 08, 2018 at 14:40

Fine.  As suggested by Danilotto Runi, make a quick calculations with the Application Note regarding ESR and max power for your resonator.

Theo

henry.dick
Senior II
Posted on March 08, 2018 at 15:16

There are two parts to this issue?

1. Why is the crystal 600ppm off?

2. Why is the rtc 6000ppm off?

Once you lay that out, it becomes crystal clear where to focus your effort.