# my ds1307 module drift too much ...?!

#### vtc

Joined Apr 3, 2018
37

#### ericgibbs

Joined Jan 29, 2010
11,551
hi vtc,
The DS1307 RTC is not stable, I started using the DS3231 module in my projects, check the d/s.
The DS3231 in my data logger has gained only 1 minute in almost 12 months.

E

#### Attachments

• 824.1 KB Views: 3
• 66.9 KB Views: 10

#### Raymond Genovese

Joined Mar 5, 2016
1,658
hi,

i am trying to use the following DS1307 module with arduino..
View attachment 158332

i am using spark fun arduino library and i test the demo code in library.i set the rtc to pc clock with 1 sec delay.

https://github.com/sparkfun/SparkFu.../examples/DS1307_RTC_Demo/DS1307_RTC_Demo.ino

i disconnect the module from the arduino and after 24 hours i found a delay about 20 SEC.

how can i solve the problem ?
I am in complete agreement with @ericgibbs but if you do not want to get a better RTC, there may be some things that you can do that can help. 20 sec per day is a lot (~ 240 ppm?).

I personally, do not like the idea of running the battery backup off of a rechargeable lithium battery (as in your picture) in a very inexpensive board. Not sure that is what you are doing, but you may want to see if there is a change in the error if you leave the Arduino on and powering the RTC for 24 hours.

You can also look into correcting the error in software. There are several approaches to do this, see this thread for example and your own search should reveal more.

Hope this helps.

#### ericgibbs

Joined Jan 29, 2010
11,551
hi Raymond,
The 'quality' of the batteries that came with the modules was poor and so was their longevity.
So I bought some branded batteries and they have kept the DS timing very good for months, that is including the 2 spares on the shelf [not being charged]
E

#### Raymond Genovese

Joined Mar 5, 2016
1,658
hi Raymond,
The 'quality' of the batteries that came with the modules was poor and so was their longevity.
So I bought some branded batteries and they have kept the DS timing very good for months, that is including the 2 spares on the shelf [not being charged]
E
Yeah. Given the amount of error, and the fact that he reports it while leaving the Arduino off overnight, I would want to see if it is a power issue. That's why I raised the issue that he should see if there is less error if running of Arduino or non-battery power.

Maybe I could back off of my personal dislike of rechargeable Lithium on cheap boards, but I have seen some pictures of fatty Li cells in a product and it stuck with me. I don't really know how good the recharging circuit is or know enough about recharing, period. One think for sure - you need a good battery in there for good time keeping when primary power is off. I have built several RTCs and used good quality batteries and they do work for a real long time - but not forever.

#### vtc

Joined Apr 3, 2018
37
hi all,

i cant find ds3231 one in our stores ,only ds1307 and ds3234 module (cost 23 $>_<). i tried to keep the arduino on the same drift occurred. You can also look into correcting the error in software. There are several approaches to do this, see this thread for example and your own search should reveal more. i read the example on the thread you post but i cant understand it thank you All #### Raymond Genovese Joined Mar 5, 2016 1,658 hi all, i cant find ds3231 one in our stores ,only ds1307 and ds3234 module (cost 23$ >_<).

i tried to keep the arduino on the same drift occurred.

i read the example on the thread you post but i cant understand it

thank you All
Fair enough. There are, however, many such DS3231 boards that are less expensive ones like this one for US$5 https://www.ebay.com/itm/DS3231-RTC-Precision-Real-time-clock-for-Arduino-/391722762771 But I understand that availability may be different where you are. In any event, you can always come back to it as your needs and experience grows. Thread Starter #### vtc Joined Apr 3, 2018 37 thank you I will order ds3231 and test it. I wonder how some devices like automatic school bill we have based on ds1307 RTC and have drift 5-6 minutes per year anyway i have used another external power supply the drift decreased to 15 sec/day. then i tried to replace the arduino nano with pic16f877a the drift decreased to 11 Sec. finally i replaced the crystal and the drift decreased to 5 sec/day. all tests done without disconnect the ds1307 module from the MCU. regards #### Raymond Genovese Joined Mar 5, 2016 1,658 thank you I will order ds3231 and test it. I wonder how some devices like automatic school bill we have based on ds1307 RTC and have drift 5-6 minutes per year anyway i have used another external power supply the drift decreased to 15 sec/day. then i tried to replace the arduino nano with pic16f877a the drift decreased to 11 Sec. finally i replaced the crystal and the drift decreased to 5 sec/day. all tests done without disconnect the ds1307 module from the MCU. regards Just as an aside, as a result of this thread, I ended up purchasing this one. To be sure, I must have 5 RTC boards including a couple that I built. I don't need another, but I couldn't resist. A DS3231 with an EPROM for US$1.82 - how do you make that, send it from China (no shipping charge to me) and sell it for $1.82? I don't think I could by a genuine DS3231chip for less than US$4.

I am sure this will end up being given to and installed for, an Arduino friend (unless it is a complete and total POJ).

#### ericgibbs

Joined Jan 29, 2010
11,551
Hi Raymond,
That looks identical to the RTC modules I am using, as you may know it has a readable temperature output as well as the real time.
If required you can operate the DS3231 at the end of a 1 to 2mtr screened cable if you need to measure temperature away from the MCU.
The original battery in the module may not last more than a few weeks.

E

#### vtc

Joined Apr 3, 2018
37
Hi ALL,

I found Timer Based Real Time clock (Zero drift).

here is the code

do you advice to use this method ?

VTC

#### Raymond Genovese

Joined Mar 5, 2016
1,658
Hi ALL,

I found Timer Based Real Time clock (Zero drift).

here is the code/---/

do you advice to use this method ?

VTC
That looks like an RTC based on interrupt "ticks". The accuracy trick there is to get ticks that are consistent with normal time keeping (interrupt frequency that is easily divisible by 60 or 100 for example).

Regardless, when you remove power, the interrupts and, therefore, the timekeeping stop. It does not appear that you actually want such a clock if I assume that you want correct time whenever you power up no matter how long the board has been powered down.

The DS3231 does have some adjustment potential (the aging trim register) that might correct any drift to your required accuracy. Many people either use a GPS or WiFi interface (e.g., query a Time server) to make certain the RTC remains accurate.

Last edited:

#### ericgibbs

Joined Jan 29, 2010
11,551
hi vtc,
I agree with Raymond about the same problems with software clocks.
GPS modules with RS232 real time output are ideal if accuracy is important, not too expensive.
E

#### vtc

Joined Apr 3, 2018
37
sorry All for wasting your time with my problem

i only need the RTC to build 10 Alarms system :*

thank you All for your informative comments . i learned a lot from them ^_^

Regards

#### Raymond Genovese

Joined Mar 5, 2016
1,658
Hi Raymond,
That looks identical to the RTC modules I am using, as you may know it has a readable temperature output as well as the real time.
If required you can operate the DS3231 at the end of a 1 to 2mtr screened cable if you need to measure temperature away from the MCU.
The original battery in the module may not last more than a few weeks.

E
I received my $1.82 RTC the other day and thought I would take the time to pass on my thoughts/opinions. Time since ordering to receiving ~33 days. The board is the ZS-042 as as advertised. I have now done some testing. No battery was included. The good: It has a pass through I2C port. It has an AT24C32 EEPROM on board (address lines A0/A1/A2 can be solder blob jumped). It tested fine, including the EEPROM The ok: It has 4.7k pull ups installed on the I2C lines as well as the SQWINT line – these are fine, if you know that they are there. The bad: The big issue with the board is, fortunately, well known…it has a charging circuit for the battery on board. That is, it sends Vcc to the battery through a diode and 200 ohm resistor. Apparently, it is designed for use with an LIR2032, but note that some do not think charging would work well depending on Vcc. I am not concerned because I don’t care to use a rechargeable battery. I removed the resistor and installed a CR2025 (that I had handy) and it should also work with the higher capacity CR2032 (same size). It seems to me that installing a CR2032 without removing the resistor or otherwise removing Vcc to the battery is a distinctly bad idea - and there are reports of swollen CR2032s after a few days. I did verify that Vcc (minus the expected drop) is at the battery terminal when powered (without the battery of course). Once you get rid of that charging business, it is a decent DS3231 board, especially for US$1.82.

There is much available on this board, but here is one of the better sources that I found https://thecavepearlproject.org/2014/05/21/using-a-cheap-3-ds3231-rtc-at24c32-eeprom-from-ebay/ and here you can get the schematic as well as some relevant datasheets https://www.play-zone.ch/en/combo-b...ratur-zeit-24c32-memory.html?___from_store=de

#### ericgibbs

Joined Jan 29, 2010
11,551
hi Raymond,
My DS3231 is as same as the d/s circuit from your link, 100R in series with a diode.
If you recall I did say they were delivered with crappy batteries, which I replaced with CR2032's.
These two modules have been running for almost 18 months, powered from +5V.
Just double checked no signs of swelling or other signs of failure.
It is highly likely that the reported swelling is occurring in sub standard CR2032 batteries which have been supplied with the modules.

Eric

#### Raymond Genovese

Joined Mar 5, 2016
1,658
hi Raymond,
My DS3231 is as same as the d/s circuit from your link, 100R in series with a diode.
If you recall I did say they were delivered with crappy batteries, which I replaced with CR2032's.
These two modules have been running for almost 18 months, powered from +5V.
Just double checked no signs of swelling or other signs of failure.
It is highly likely that the reported swelling is occurring in sub standard CR2032 batteries which have been supplied with the modules.

Eric
Hi Eric,

If you are up to it, can you check whether you have VCC-drop on the battery terminal. That is, with no coin cell battery installed and the board powered by +5 and GND (as connected normally with an Arduino or similar), do you see ~4.7V (edited I am going from memory on the ~4.7, it may have been a little lower - the diode looks like a usual 914 and I guess, without looking it up, it should have about a .7V drop) from the + terminal to GND?

Don't know for sure about the voracity of the swollen CRs, but, unless I am missing something basic, it is a distinctly bad idea to be pumping Vcc into a non-rechargeable battery. But, even identical looking boards may have some differences and that is why I am asking. For example, the advert for the board I originally linked to (not the one I ended up buying) says outright that it works with CR2032.

Last edited:

#### ericgibbs

Joined Jan 29, 2010
11,551
hi,
Vcc = 4.49V [module at end of 1 mtr cable]
+Vbty module terminal = 4.49V [bty in]
+Vbty module terminal = 4.51V [bty out]
Vbty out of unit = 2.52V [ bty on the bench]

E

#### Raymond Genovese

Joined Mar 5, 2016
1,658
hi,
Vcc = 4.49V [module at end of 1 mtr cable]
+Vbty module terminal = 4.49V [bty in]
+Vbty module terminal = 4.51V [bty out]
Vbty out of unit = 2.52V [ bty on the bench]

E
So, yours also has a charging circuit, although I don't know why you don't see a diode drop. My point is that when plugged in (5V power supply) you should not see that Vcc at the empty battery terminal. I'm not waving a huge red flag about this, but I don't like it and that is why I removed the resistor.

#### ericgibbs

Joined Jan 29, 2010
11,551
hi,
As I get a 0.02V drop , battery in/out via 100R + diode and for discussion say that is is across the 100R , thats only 200uA.
So I suspect the diode forward leakage is coming into play.??

If I have a problem in the near future, I will post my results.
E