RTC slows down after a few minutes and doesn't keep the correct time pace

Thread Starter

Dabi_aljv

Joined Dec 11, 2024
2
Hello everyone.

I'm working on an automatic irrigation system using Arduino Mega 2560, TFT screen ILI9488, RTC module DS3231 and a KY-023 joystick module in a physical assembly (schematics are shown below).
1738284610231.png

Everything works fine. The problem is that the RTC doesn't keep the correct time. When the system is switched on, after a few minutes it starts to get delayed by seconds. The more time it is on, the more delay it gets. I'll leave the code I used here. It's a long code, mainly because of the screen part (it's also in Spanish, as it's my first language, you could ask some AI to translate the comments for you, sorry for that).

I would be very grateful for your help. Thanks in advance.
 

Attachments

Ian0

Joined Aug 7, 2020
13,097
A separate crystal is not used with the DS3231 – it's internal to the chip and temperature-compensated.

I have a number of clocks built around DS3231...they are accurate to a couple minutes per year.
at risk of hijacking the post. . .
Thanks for that recommendation. I’ll give it a try. Pity it’s not pin compatible with the DS1338 I already use.
 

Ian0

Joined Aug 7, 2020
13,097
I get a lot of ideas for devices to use from discussions on the forum, and I like to give credit when it is due. But let’s get back to the TS’s problem.
Is the time loss gradual, or does it lose time at certain events? (e.g. My Jaguar XE loses one second every time it starts, so after 30 days’ commuting to work it has lost a minute)
How often does the software write the time back to the RTC?
 
Last edited:

sagor

Joined Mar 10, 2019
1,046
That device is supposed to be accurate to 2 minutes per year. If your clock is in error more than that, I would suspect your code is setting something in that clock module to cause it. You have two instances of adjusting the clock in your code:
"rtc.adjust(DateTime(year, month, day, hour, minute, second))"
I would look at how that code is used and if it is used in error somewhere. That is the only place the clock could be changed on an ongoing basis, producing a larger error than the clock itself can have. Why would you ever have to adjust the clock once it is set?
 

schmitt trigger

Joined Jul 12, 2010
2,027
If you have access to an accurate, and I mean ACCURATE frequency meter, you can monitor pin 1 and it should be exactly 32768 Hz.
Be aware that this is an open collector output, it requires a resistor pullup to 5 volts.

If this frequency is correct, then it is your code.
 

SamR

Joined Mar 19, 2019
5,470
That was a problem Hewlett Packard never could fix with their first-generation HP Vectra computers. And it wasn't always because their on the motherboard coin battery was at fault. In fact, it's still a problem that would still be with us if not for the internet being used as the time source. Still, it was a much better solution than having to enter the correct date and time every time you booted up the computer.
 

sagor

Joined Mar 10, 2019
1,046
To account for Summer Time aka Daylight Saving Time?
Adjusting twice a year would not produce the continuous clock drift the original post described. I still suspect the code is adjusting unnecessarily, or incorrect adjustment. Adjusting a whole hour should not change the minutes or seconds.
Another solution is to run the code/clock (RTC) in UTC time always, and adjust the code to account for the daylight time otherwise.
 

Georg_B

Joined Apr 18, 2022
16
Where did you got the DS3231 module? If it's from Aliexpress/eBay etc., desolder the DS3231 chip and install a chip from reliable source. I (and some of my buddies from other forums) have meet this problem first around four-five years ago. Looks like one or more batch of IC contains this error and these modules are not sold out yet...
 

atferrari

Joined Jan 6, 2004
5,001
The clock in my 2018 Toyota ETIOS, looses approximately 2 sec per month (not actually checked). Got used to it and I reset the time once in a while.
 

schmitt trigger

Joined Jul 12, 2010
2,027
2 seconds per month is about 0.8 ppm, which is well within the tolerance of a TCXO like the DS3231, which has a worst case 3.5 ppm over the full automotive temperature range.

If your auto is only subjected to limited temperature excursions, it is reasonable to see about 1.5 ppm, or perhaps less, if the Time Gods are smiling at you.
 
Top