Arduino Forum

Using Arduino => Networking, Protocols, and Devices => Topic started by: kwow on Aug 21, 2015, 05:36 pm

Title: DS3231 slow down
Post by: kwow on Aug 21, 2015, 05:36 pm
Hi everybody!
I try to use ds3231 RTC, but it slow down. I made clear code on arduino Pro mini 5V . The code display only time.
Then i turned off arduino and RTC works only on coin battery.
After 2 days I turned it on and I get 4s delay on RTC time.

I checked voltage on battery and it is 3.32....

could you give me some adivce how to run it correctly?
Title: Re: DS3231 slow down
Post by: Riva on Aug 21, 2015, 05:52 pm
I think 2 seconds per day is (almost) with normal tolerance. If this is not good enough then register 0x10 is an ageing offset that you can alter to fine tweak the clock speed.
Title: Re: DS3231 slow down
Post by: kwow on Aug 21, 2015, 06:48 pm
I'm not an expert, but I saw in datasheet that DS3231 works on 2ppm, so the accuracy should be about 5s per month.
Please correct me if I'm wrong.
Title: Re: DS3231 slow down
Post by: Riva on Aug 21, 2015, 07:08 pm
I'm not an expert, but I saw in datasheet that DS3231 works on 2ppm, so the accuracy should be about 5s per month.
Please correct me if I'm wrong.
Now I look, my datasheet for the DS3231 says 5ppm and a +-0.432 seconds per day tolerance so 4 seconds in 2 days is excessive. Is it a genuine Maxim IC or a Chinese cheapy?
Title: Re: DS3231 slow down
Post by: kwow on Aug 22, 2015, 12:41 pm
thanks for help!
i bought modules on ebay. One is ZS-042 and on second is only "LC" sign.
Thats they look:
http://i.ebayimg.com/00/s/NzAwWDcwMA==/z/UzoAAOxyFd1SKA37/$(KGrHqJ,!o4FI(f)kVNRBSK!37gVsQ~~60_35.JPG

The second (litle) i set up about 6month ago and right now it has about 16 min delay
I thought that delay will be couple of seconds per year.
Title: Re: DS3231 slow down
Post by: Riva on Aug 22, 2015, 01:03 pm
i bought modules on ebay. One is ZS-042 and on second is only "LC" sign.
Thats they look:
http://i.ebayimg.com/00/s/NzAwWDcwMA==/z/UzoAAOxyFd1SKA37/$(KGrHqJ,!o4FI(f)kVNRBSK!37gVsQ~~60_35.JPG

The second (litle) i set up about 6month ago and right now it has about 16 min delay
I thought that delay will be couple of seconds per year.
Not relevant to your time problem but this (http://forum.arduino.cc/index.php?topic=278270.0) might be worth a look for your ZS-042 RTC.
16 minutes in 6 months is bad. Probably worse than can be expected from a DS1307. For me the DS3231 (I have 3 on the go ATM) is about 1 second per week without any tuning.
Title: Re: DS3231 slow down
Post by: kwow on Aug 22, 2015, 01:40 pm
I saw this link. I run RTC with Arduino Pro Mini 5V for 24 houres and i get delay to, but it is less then 2s. So it is quite better, but still bad.
Could you tell me how did you connect your RTC? I use only SCL and SDA. How about SQW and 32K?
Title: Re: DS3231 slow down
Post by: Riva on Aug 22, 2015, 02:14 pm
Could you tell me how did you connect your RTC? I use only SCL and SDA. How about SQW and 32K?
One I just use SCL/SDA/GND and poll about once per second. But later designs I use the SQW configured as 1Hz output to feed an interrupt pin on the Arduino. This saves me having to poll (and could even allow the MCU to sleep in low power systems) or delay waiting for ticks. I also use it to trigger a heartbeat LED to confirm RTC is working.
Title: Re: DS3231 slow down
Post by: kwow on Aug 24, 2015, 03:35 pm
Thank you Riva,
How do you think. Is it problem with module or code?
Could you tell me where did you buy your RTC, or recomend me some more accurate RTC?
Title: Re: DS3231 slow down
Post by: Riva on Aug 24, 2015, 05:17 pm
How do you think. Is it problem with module or code?
Could you tell me where did you buy your RTC, or recomend me some more accurate RTC?
The problem could be with either module of code but best to start with the code first and then assume the hardware is at fault.
I just bought some DS3231 chips (the 8 pin version) and just add the battery, decoupling and pullup resistors myself.
I have just bought a couple of modules from eBay so when they arrive I will set them up and see how well they do.
Title: Re: DS3231 slow down
Post by: kwow on Aug 27, 2015, 01:40 pm
I made some test. I run 2 DS3231 in almost same time. Both of them has realy close delay - to each other.
I also suppose that they slow down much after 24h. i didn't confirm it yet.
Title: Re: DS3231 slow down
Post by: kwow on Sep 07, 2015, 05:03 pm
Hi Riva,
were you able to test your DS3231?

I set up 5 ZS-042 and leave for 4 days only with coin battery. After that time i check te time and every RTC gave me different resault. It was about 10 seconds lag.
One of them has 2min delay.
Could you tell me which libs do you use?
Title: Re: DS3231 slow down
Post by: Riva on Sep 07, 2015, 05:28 pm
were you able to test your DS3231?
They only just arrived and I set them both up Saturday morning so not enough time has passed yet.

I set up 5 ZS-042 and leave for 4 days only with coin battery. After that time i check te time and every RTC gave me different resault. It was about 10 seconds lag.
One of them has 2min delay.
Could you tell me which libs do you use?
I use a version of this (https://github.com/davidhbrown/RealTimeClockDS1307) library, tweaked with my own additions.
Title: Re: DS3231 slow down
Post by: el_supremo on Sep 07, 2015, 05:28 pm
@kwow: post your code (in code tags)

Pete
Title: Re: DS3231 slow down
Post by: jboyton on Sep 07, 2015, 05:48 pm
I just bought some DS3231 chips (the 8 pin version) and just add the battery, decoupling and pullup resistors myself.
The DS3231 isn't available in an 8-pin version. Perhaps you mean the DS3231M. It uses a completely different compensation method and is less accurate than a DS3231.
Title: Re: DS3231 slow down
Post by: jboyton on Sep 07, 2015, 05:54 pm
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.
Title: Re: DS3231 slow down
Post by: kwow on Sep 08, 2015, 01:38 pm
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
Title: Re: DS3231 slow down
Post by: Riva on Sep 08, 2015, 02:26 pm
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);
Title: Re: DS3231 slow down
Post by: el_supremo on Sep 09, 2015, 12:44 am
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

Title: Re: DS3231 slow down
Post by: jboyton on Sep 09, 2015, 02:35 am
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.
Title: Re: DS3231 slow down
Post by: el_supremo on Sep 09, 2015, 05:08 am
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
Title: Re: DS3231 slow down
Post by: jboyton on Sep 09, 2015, 05:29 am
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.
Title: Re: DS3231 slow down
Post by: kwow on Sep 09, 2015, 03:27 pm
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?
Title: Re: DS3231 slow down
Post by: Riva on Sep 19, 2015, 10:59 am
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.
Title: Re: DS3231 slow down
Post by: kwow on Nov 06, 2015, 12:50 pm
thanks guys for help!
the your advice helps and my ds3231 seems fine, after I chenged lib
Title: Re: DS3231 slow down
Post by: SHARANYADAS on Jun 24, 2016, 12:47 pm
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.
Title: Re: DS3231 slow down
Post by: Riva on Jun 25, 2016, 08:15 am
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).
Title: Re: DS3231 slow down
Post by: mostafanfs on Oct 24, 2016, 10:08 pm
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.
Title: Re: DS3231 slow down
Post by: Budvar10 on Oct 24, 2016, 10:33 pm
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.
Title: Re: DS3231 slow down
Post by: mostafanfs on Nov 02, 2016, 09:36 am
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.
Title: Re: DS3231 slow down
Post by: gpsmikey on Nov 02, 2016, 04:24 pm
I don't have one, but it almost sounds like when you do a read operation, it latches the registers/counters while it does the read so you don't have changing data.  If that is the case and the counters are actually being latched instead of what should happen with latches off the counters so they are not affected, that could explain it being slow if you read it too often.  Doing the counter chain correctly would involve latches off the counters that could "freeze" the count during a read, however, if they actually "freeze" the counters themselves to do the read, that would explain the time loss.  Since all the complaints I have seen here seem to be that it is "too slow", that would be consistent with that idea (if it was something else, you would expect some to be too slow, some too fast etc.).