cancel
Showing results for 
Search instead for 
Did you mean: 

RTC clock ticking faster than actual.

AKetc
Associate III

Hello everyone,

I am currently developing a code for my custom board that has BLE communication along with RTC and timer(PWM) initialized. I am currently testing my code first on the PNucleoWB55 development board. The issue is that the normal RTC_Alarm Example from the SDK is working fine and alarm interrupt occurs exactly after 30 seconds. However, when I initialize the RTC in BLE_p2pServer, the RTC interrupt occurs much quicker (approx 5 seconds when programmed to occur after 30 seconds). What could be the issue? If someone can help me, I shall be grateful.

1 ACCEPTED SOLUTION

Accepted Solutions
Jack Peacock_2
Senior III

The LSI is 32KHz +/-5% tolerance. If your RTC is running fast the reason is the oscillator is not exactly 32KHz.

The RTCCLK one second tick uses two dividers, async and sync, to divide down the nominal 32KHz input to 1Hz. Set the async prescaler to 32, and the sync prescaler to 1000 +/- a calibration value. You'll have to determine how far off your LSI is (and this will vary by temperature) to calculate that calibration factor.

I use an 'L476 Discovery eval board with the RTC driven by LSI. In my particular case the sync prescaler is set to 1014 instead of 1000, or an LSI of about 32.45KHz. This still doesn't yield the same accuracy as an LSE crystal but the daily deviation is under 60 seconds, rather than several minutes. That's good enough for my application, which isn't time of day critical.

Since you're running fast on the RTC try increasing the synchronous prescaler. I don;t use Cube so no idea how to change the prescaler with it.

Jack Peacock

View solution in original post

5 REPLIES 5

LSI and LSE typical need different prescalers to address the frequency differences.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
AKetc
Associate III

I am using LSI in my case for RTC. How to adjust the prescaler?

According to clock configuration diagram in CubeMX, the clock being supplied to RTC is 32Khz from LSI which is the same as in RTC_Alarm Example.

Jack Peacock_2
Senior III

The LSI is 32KHz +/-5% tolerance. If your RTC is running fast the reason is the oscillator is not exactly 32KHz.

The RTCCLK one second tick uses two dividers, async and sync, to divide down the nominal 32KHz input to 1Hz. Set the async prescaler to 32, and the sync prescaler to 1000 +/- a calibration value. You'll have to determine how far off your LSI is (and this will vary by temperature) to calculate that calibration factor.

I use an 'L476 Discovery eval board with the RTC driven by LSI. In my particular case the sync prescaler is set to 1014 instead of 1000, or an LSI of about 32.45KHz. This still doesn't yield the same accuracy as an LSE crystal but the daily deviation is under 60 seconds, rather than several minutes. That's good enough for my application, which isn't time of day critical.

Since you're running fast on the RTC try increasing the synchronous prescaler. I don;t use Cube so no idea how to change the prescaler with it.

Jack Peacock

AKetc
Associate III

I got it working after your suggestion. Thanks alot.

Hi @AKetc​ ,

Please select the best answer that helped you.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.