Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
4 years, 9 months ago.
LPC1768 RTC: 40 minutes too slow every day?
Hi all, I've made a device that synchronises its internal RTC every day with the time, derived from a GPS-module. All interesting events are logged into a file on an SD-card.
Now that I look at the logs, I see the time being synchronized every day at 23:20 (instead of 0:00). So every day, the RTC is 40 minutes late, compared to the GPS. The device is continuously powered, and also the backup-battery is connected to the mbed. I'm using a PWM output, some interrupts and quite some calls to RTC=time(null).
Can anyone of you think of a reason why the RTC would run too slow, or miss cycles, hickup or whatever?
Thanks, bye, Patrick
4 years, 8 months ago.
With a 40 minute error, I suspect there may be a hardware reason for that much error. You show the LPC1768 in your profile and that does have the 32 Khz crystal.
If you have access to a scope, perhaps you could probe the crystal. Take care that on one side, it will be quite sensitive to the scope itself, and on the other it should be less-so. There may also be a way to enable a "clock out" - but I have not had the need, so I'm not sure.
Next, do you have a coin cell powering the clock? I couldn't quite tell from your note if the backup-battery is for the whole module, or just the clock. [Should that make a difference? I don't know. My modules with RTC needs all have the coin cell, so I never tried without one]
The RTC does have an adjustment register, to compensate for tolerance error - but I would not imagine it has the range to compensate for 40 minutes in a day... But, let's not rule that out. If that register picked up a bad value, perhaps that is it.
That said, I have some code that tries to make the adjustment, you're welcome to look it over, try it, and perhaps make it better. Along the way I hope you solve your issue. TimeInterface is my project, and as I recall, I had only a few seconds a day deviation to compensate for.
4 years, 8 months ago.
The spec for the LPC1768 RTC crystal is 20 ppm, so you are seeing frequency errors far out of spec. I had measured my RTC crystal frequency error at 20 ppm. You can measure frequency with a GPS PPS signal or with an NTP host. Or you can use the MCU's crystal (Timer microseconds) as in the following program https://developer.mbed.org/users/manitou/code/driftrtc/ Another way to check RTC drift is with RTC second-alarm handler (checking how many micros between RTC 1 second interrupts).
Of course, these short-term internal measurements may not reveal a problem where the RTC and/or MCU is pausing. To detect such pauses, you'd need a program to alert you when the RTC time has suddenly deviated a large amount from the GPS time.