Go Down

Topic: DS3231 slow down (Read 7435 times) previous topic - next topic

jboyton

#15
Sep 07, 2015, 05:54 pm Last Edit: Sep 07, 2015, 06:01 pm by jboyton
I have been measuring my DS3234 (same as DS3231 except the interface is SPI instead of I2C). I bought the chip, soldered it to a simple SMC-DIP adapter board and plugged that into a breadboard. Straight out of the box, maintained with a CR2032 battery and at room temperature (range 16-26°C) it drifted forward 43ms in a 24 hour period. That corresponds to a drift of about 1 second every 3 weeks. By tuning the aging register I was able to improve this to a drift rate equivalent to about 1 second every 6 months, at least at room temperature.

If yours is drifting 2 seconds per day there's something seriously wrong.

kwow

thank you guys for replays,
this is my code:
Code: [Select]
#include <Wire.h>
#include <DS3231.h>
 
DS3231 clock;
RTCDateTime dt;
 
void setup()
{
  Serial.begin(115200);
 

  Serial.println("Initialize DS3231");;
  clock.begin();
 

  clock.setDateTime(__DATE__, __TIME__);
}
 
void loop()
{

  dt = clock.getDateTime();
 
  Serial.print("Raw data: ");
  Serial.print(dt.year);   Serial.print("-");
  Serial.print(dt.month);  Serial.print("-");
  Serial.print(dt.day);    Serial.print(" ");
  Serial.print(dt.hour);   Serial.print(":");
  Serial.print(dt.minute); Serial.print(":");
  Serial.print(dt.second); Serial.println("");
 
  delay(1000);
}


Could you tell me if code does matter if RTC isn't connected to arduino? I set it up and disconnect arduino. All DS3231 work only on battery

Riva

This
Code: [Select]
clock.setDateTime(__DATE__, __TIME__);
I think will set the RTC to the sketch compile date and time that will be at least a few seconds different to real time and maybe a lot more.

I use a different library to you but the principle I use should be the same. I check to see if the year is zero and assume date/time is not set if it is, else I just roll through setup of date/time.
Code: [Select]
  RTC.switchTo24h();                                  // Not really important but...
  RTC.readClock();                                    // Read the clock
  RTC.writeData(0x0E,0x00);                           // Enable 1Hz output on INT pin
  if(RTC.getYear() == 0){                             // If Year = 0 then clock probably not set
    eAdjust();                                        // Call Adjust Routine
    RTC.setClock();
  }
  RTC.getFormatted2k(formatted);
  Serial.println(formatted);
Don't PM me for help as I will ignore it.

el_supremo

I've had problems with RTC slowing down when I read it very frequently, such as once a second as you are doing.
Change your code to print the time once every five minutes and see if it loses as much time as before.
Code: [Select]
  delay(300000L);

Pete

Don't send me technical questions via Private Message.

jboyton

I've had problems with RTC slowing down when I read it very frequently, such as once a second as you are doing.
Change your code to print the time once every five minutes and see if it loses as much time as before.
Reading the time registers has no effect on how well the RTC keeps the time. If you see benefit from reading the registers less frequently it only means that something else is wrong.

It really sounds like the OP has a sketch that SETS the time every time it's run.

el_supremo

Quote
It really sounds like the OP has a sketch that SETS the time every time it's run.
The code kwow posted clearly sets the time once and then reads it every second.

I have had problems when reading an RTC frequently and it did slow the clock down.
It's easy enough to test by reading the clock every five minutes and see if it gets better or stays the same.

Pete
Don't send me technical questions via Private Message.

jboyton

I have had problems when reading an RTC frequently and it did slow the clock down.
It's easy enough to test by reading the clock every five minutes and see if it gets better or stays the same.
I've done this with each RTC I've tested. The frequency of reads has had no effect on the accuracy of the clock. Zero.

It shouldn't in theory. If your RTC is affected by how often you read it then there's something wrong with that RTC. Or the circuit. It's possible that I2C activity could couple with the crystal, generate spurious pulses and cause it to run fast.

kwow

I've done this with each RTC I've tested. The frequency of reads has had no effect on the accuracy of the clock. Zero.

It shouldn't in theory. If your RTC is affected by how often you read it then there's something wrong with that RTC. Or the circuit. It's possible that I2C activity could couple with the crystal, generate spurious pulses and cause it to run fast.

I'm sure that it isn't problem with reads in this case. I keep disconnected my RTC so for few days i didn't read anything. Also every RTC display different time after these days




Riva thank you for your code. I think that the problem isnt there.
I set time for every RTC. I compare it after few minutes and it was the same (according to one second). Then I leave all RTC. When i turned it again i did it without setting time again.


Thank you for your code and library. I'll try to use it. Do you think that library could generate some errors?

Riva

Hi Riva,
were you able to test your DS3231?
Well it's been two weeks since I setup then unplugged two of these modules and when I just plugged them back in they are both within a second of correct time.
They look almost identical to the image you posted earlier but I have removed a resistor that is part of the battery charging circuit as the coin cell is not a rechargeable one and I have read reports of the battery being damaged because of this.
Don't PM me for help as I will ignore it.

kwow

thanks guys for help!
the your advice helps and my ds3231 seems fine, after I chenged lib

SHARANYADAS

Hi all.Although this topic is neary an year old,but i thought to give it a try.

Recently i was building a precise timeclock with mega328 and GLCD and DS3231.I was using a Casio G-shock(Pretty accurate I think) as my reference.I found that my DS3231 clock was about 17sec slow as compared to my reference Casio after a 12hr runtime.At the whole time,DS3231 as well as the whole circuit was powered by external 5v(not by internal battery of DS3231).I was reading the DS3231 every second and was updating the reading to the GLCD.Then i thought to sync after every 5 mins.This time i ran the clock for nearly 24hr and found a delay of nearly 2s with my reference clock.

Now I upgraded the hardware(pulled up the sqw line and changed the cpu to mega32 for higher pincount) and set the DS3231 to give a square wave output of 1hz.Now the Idea is to sync every second for update without reading the RTC using level change interrupt.I have planned to read the RTC only two times a day(every am to pm conversion or vice-versa).

 

Is it normal for the DS3231 to get slow if reading it frequently??I have read the datasheet but found no such illustration.Someone faced this sort of things??Previously I have used DS1307,but in that case also,it was getting damn slow.

Riva

Is it normal for the DS3231 to get slow if reading it frequently??I have read the datasheet but found no such illustration.Someone faced this sort of things??Previously I have used DS1307,but in that case also,it was getting damn slow.
I had forgotten about this thread and have since used at least one of the RTC modules in another project so cannot do the experiment to confirm/deny if polling the RTC causes slowdown or not. I personally feel that fast polling the RTC does cause it to loose time but others will disagree (hence the idea to do the test).
Don't PM me for help as I will ignore it.

mostafanfs

I had forgotten about this thread and have since used at least one of the RTC modules in another project so cannot do the experiment to confirm/deny if polling the RTC causes slowdown or not. I personally feel that fast polling the RTC does cause it to loose time but others will disagree (hence the idea to do the test).
What do you mean by "polling the RTC" ?
You mean keep reading the RTC ? Is that what you meant ?

Anyway I have this bloody problem as well. I mean I have set the time and date for this stupid DS3231SN with my computer date and time (I wrote a separate program for this and a program for PC to send date time through a serial port) but it has not been even a day it started to go 1 second faster than my computer time. And I'm sure it keeps getting worse and worse.
Seriously what's wrong with this RTC ?
And yes I did keep reading it continuously for a while if that is a wrong thing to do.

Budvar10

#28
Oct 24, 2016, 10:33 pm Last Edit: Oct 24, 2016, 10:35 pm by Budvar10
I'm using DS3231 (bought on ebay) without any problem. I have four watches with this chip and the worst case drift is ~1s/week. Maybe, it is just luck but many people use the same chip with similar experience.
It is very accurate RTC and low cost, of course far from Swiss watches.
Arduino clone with ATmega1284P   http://forum.arduino.cc/index.php?topic=277260.0

mostafanfs

I had forgotten about this thread and have since used at least one of the RTC modules in another project so cannot do the experiment to confirm/deny if polling the RTC causes slowdown or not. I personally feel that fast polling the RTC does cause it to loose time but others will disagree (hence the idea to do the test).
Hi Riva.
Ok I've done some testing and I can totally approve your theory that polling the RTC (keep reading it) does make it to loose time. It's a weird fact I guess. Thank you for coming up with something like that.

Go Up