1

I am using a DS1302 RTC module with an Arduino Mega 2560 Rev 3. I follow steps on this website since I have no experience with RTC module before. Here are the outputs I am getting.

17:15:21.835 -> Current Date / Time: 26/2/2023 17:15:44
17:15:26.830 -> Current Date / Time: 26/2/2023 17:16:13
17:15:31.856 -> Current Date / Time: 26/2/2023 17:16:42
17:15:36.853 -> Current Date / Time: 26/2/2023 17:17:11

As you can see from the above output, the DS1302 is running five times faster than the real time (output past 30 seconds as real word past 5 seconds). Same thing happened if use different codes with different libraries.

Does this mean the RTC module itself is broken, or I can modify RTC module's speed with code?

//This code is to use with DS1302 RTC module, it permits you to setup the actual time and date
//And you can visualize them on the serial monitor
//This code is a modified version of the code provided in virtuabotixRTC library
//Refer to https://Surtrtech.com for more information
 
#include <virtuabotixRTC.h> //Library used
 
//Wiring SCLK -> 6, I/O -> 7, CE -> 8
//Or CLK -> 6 , DAT -> 7, Reset -> 8
virtuabotixRTC myRTC(6, 7, 8); //If you change the wiring change the pins here also
 
void setup() {
 Serial.begin(9600);
 // Set the current date, and time in the following format:
 // seconds, minutes, hours, day of the week, day of the month, month, year
 myRTC.setDS1302Time(15, 15, 17, 7, 26, 2, 2023); //Here you write your actual time/date as shown above 
 //but remember to "comment/remove" this function once you're done
 //The setup is done only one time and the module will continue counting it automatically
}
 
void loop() {
 // This allows for the update of variables for time or accessing the individual elements.
 myRTC.updateTime();
 
 // Start printing elements as individuals
 Serial.print("Current Date / Time: ");
 Serial.print(myRTC.dayofmonth); //You can switch between day and month if you're using American system
 Serial.print("/");
 Serial.print(myRTC.month);
 Serial.print("/");
 Serial.print(myRTC.year);
 Serial.print(" ");
 Serial.print(myRTC.hours);
 Serial.print(":");
 Serial.print(myRTC.minutes);
 Serial.print(":");
 Serial.println(myRTC.seconds);
 
 // Delay so the program doesn't print non-stop
 delay(5000);
}
Edgar Bonet
45.1k4 gold badges42 silver badges81 bronze badges
asked Feb 27, 2023 at 1:28
5
  • There is a crystal (a metallic cylinder) on the RTC clock module. Can you please report what is written on it? Commented Feb 27, 2023 at 5:16
  • Is the backup battery installed? Commented Feb 27, 2023 at 5:19
  • The crystal is 32.768kHz and I think it has a specific load capacitance of 6 pF. The backup battery was installed and it was also connected to the 5V rail from the Arduino. Commented Feb 27, 2023 at 7:58
  • If I change delay(5000); to delay(1000);, it is still running 5 times faster. Commented Feb 27, 2023 at 7:59
  • 1
    This electrical stack exchange answer covers the problems, theory of design & testing of such crystal oscillators. It's likely more then you want to know. These things are cheap. Less than 10ドル from reputable suppliers and only a few from questionable sources. If you bought it from the likes of Adafruit, they might replace it. If I buy it from a questionable source I usually buy a few just in case one doesn't work. Commented Feb 27, 2023 at 13:15

1 Answer 1

1

I stumbled over the exact same issue today (using Arduino Uno/atmega328) and a module/board like this: https://surtrtech.com/2018/01/27/how-to-simply-use-ds1302-rtc-module-with-arduino-board-and-lcd-screen/ When reading out time after setting it, it runs 5-6 times too fast.

I found some hint here regarding precision: https://forum.arduino.cc/t/ds1302-drift/327796/7

However, they were talking about a 2 minutes of drift every 24 hours which for sure is a totally different thing. One comment there was to pay special attention to the ground as noise there might be interpreted as additional clock signals and speed up the clock. So I played with the grounds on the board and disconnected everything else connected so far to pins of the Arduino board, but that did not change anything, still 5-6 times faster.

I also played with and without CR2032 battery and 5V and 3.3V input to the clock board's VCC input pin and ...suddenly... it worked ok. I think with 3.3V input on VCC and no battery, it initially had the "normal" precision but now I can again connect it to 5V input and it still runs normal... I also kept it a while disconnected from external power source (only running on battery), then connecting it back to the Laptop and reading out date/time values and still it worked ok.

It is totally weird.

Regards, Dan

answered Apr 24, 2023 at 8:35
1
  • While this is a good answer in the sense that it shows a way how to get out the issue, would you mind to investigate this effect systematically? One thought model could be that the crystal oscillator starts in some overtone frequency when powered the wrong way. If you do, please share the results by editing your answer. Commented May 18, 2024 at 14:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.