Arduino Mega + 1307 Time Clock gains almost a minute per day! Help!

Hey guys!

So im building a project which relies on having an accurate time clock ticking away to trigger various things within my house all defined within a schedule.

This issue is when I sync the time clock via my serial I can get it 7 seconds behind my PCs time which im fine with but within 24 hours or so its about a minute in front! Iv re synced it many times and get fairly consistent results…
This is obviously a deal breaker for a schedule based system and is know where near what I expected to be able to get even with a “cheap” DS1307 from ebay!

Im using the <DS1307RTC.h> library which is linked to from the Arduino Library page so it should not be the issue?

Do you think I have a factory dud? Is there a chance my project code could be causing the time drift? I do not do any kind of RTC write commands, I set the time using a separate demo sketch then upload my real project seconds later.

Also my project is quite large at 51,58Bytes

Horendus:
Im using the <DS1307RTC.h> library which is linked to from the Arduino Library page so it should not be the issue?

I’m not familiar with the library and don’t see it on the Arduino Library page, but it’s possible that you are using it incorrectly. Does the library come with any examples? If so, I suggest you see whether any of those would enable you to check the accuracy of your clock.

The library demo updates the RTC time. Is that what you are using to "set" the clock?

Gaining a minute a day is unusual; sounds like hardware to me. What hardware are you using? Maybe it is getting power supply noise??

Probably need to substitute a different hardware clock....

I recommend paying the premium for an RTC with the DS3231 chip in it. DS3231-based RTCs can be had from cheap Asian exporters for about $7 if cost is a concern.

tylernt: I recommend paying the premium for an RTC with the DS3231 chip in it.

I second that.

Or, tack on a 12, 15, 22pF cap per the datasheet and slow the crystal a little if it's really gaining that much time.

This is the library page, the Arduino Time library page links to it as its compatible with the normal arduino Time Library.

http://www.pjrc.com/teensy/td_libs_DS1307RTC.html

I have a few more DS1307 on the way which im looking forward to testing to see if I get the same POOR results.

In the meantime i will also order a DS3231 time chip as keeping accurate time is the underpinning of my project and having to re sync my current clock with my PC every other day is a massive pain!

CrossRoads: Or, tack on a 12, 15, 22pF cap per the datasheet and slow the crystal a little if it's really gaining that much time.

Im not that concerned with salvaging a potentially faulty RTC, rather replace it

terryking228: The library demo updates the RTC time. Is that what you are using to "set" the clock?

Gaining a minute a day is unusual; sounds like hardware to me. What hardware are you using? Maybe it is getting power supply noise??

Probably need to substitute a different hardware clock....

Hardware is a Arduino Mega, Ethernet shield and DS1307 clock.

Im using this command in the setup loop setSyncProvider(RTC.get); and this command to grab the current time as variable t time_t t = now();

What im I will do right now is re sync my timeclock (as over night it has gained 37 seconds) and leave the clock un connected to my project. In 12 hours I will plug it back into my project and see if its gained the same amount of time while being disconnected. This will answer my question to whether my project is influencing my RTCs time keeping abilty.

Horendus: What im I will do right now is re sync my timeclock (as over night it has gained 37 seconds) and leave the clock un connected to my project. In 12 hours I will plug it back into my project and see if its gained the same amount of time while being disconnected. This will answer my question to whether my project is influencing my RTCs time keeping abilty.[/b]

Best way to go.

I do have to chuckle at your "handle" here - "Horendus" - as in Horology. :D

Horendus: This is obviously a deal breaker for a schedule based system and is know where near what I expected to be able to get even with a "cheap" DS1307 from ebay!

Do you mean a DS1307 chip or a RTC module complete with 32768Hz crystal?

Do you think I have a factory dud?

If its just a chip you bought, then possibly, but its more likely to be a clone. And if so where did you get the crystal?

If its a cheap module the crystal is likely out-of-spec (maybe factory reject, but see below).

Be aware that RTC modules are not normally very accurate as they use standard watch quartz crystals which are designed to work at body temperature and typically don't have to cope with a wide range of temperature.

I also suspect that many watches these days use cheaper low-spec crystals and have a frequency-correction value pre-programmed into the controller chip during manufacture - thus a lot of watch crystals are not as high a spec as you'd imagine. Well I can see this being a plausible cost-reduction measure.

Nope these ebay rtc clocks are that bad.. i used an ethernet shield or serial usb to update time every few hours or modify the circuit slow the crystal...

So after leaving the clock overnight not connected to anything it still gains lots of time. Would it be fair to say the crystal runs too fast?

CrossRoads: Or, tack on a 12, 15, 22pF cap per the datasheet and slow the crystal a little if it's really gaining that much time.

Where exactly would the cap sit? Does higher pF cap slow the time down more than a low pF one?

In the meantime if ordered a couple of these DS3232's based on the chip at24c32. Has anyone used these?

I wants a RTC that can keep time to within a second or so per month. Is this reasonable?

See
http://www.maximintegrated.com/app-notes/index.mvp/id/58
Try a low value capacitance right across the xtal pins on the DS1307.

See Slow Clocks section:
Stray capacitance. Stray capacitance between the crystal pins and/or to ground can slow an RTC down. Therefore, care must be taken when designing the PCB layout to ensure the stray capacitance is kept to a minimum.

Running fast? Add some!

Horendus: I wants a RTC that can keep time to within a second or so per month. Is this reasonable?

The DS3232 officially keeps time to within +/- two minutes per year. Anecdotal evidence suggests it's even better than that.

http://www.ebay.com.au/itm/1-Pcs-INBOARD-RTC-DS3232-Real-Time-Clock-and-Temperature-Sensor-I2C-BUS-PIC-/360672379910?pt=LH_DefaultDomain_0&hash=item53f9bfc406

It really is get what you pay for, next step up would be an atomic clock to keep your time accurate.

May i add, that using a DS3231 saves you from adding a crystal since it is built in.

I purchased a couple of these back in March/April. I set them once when they first arrived. They still seem to be correct to within a minute.
http://www.ebay.co.uk/itm/mini-RTCpro-DS3231-high-precision-clock-module-environment-temperature-measure-/390521397685?pt=LH_DefaultDomain_0&hash=item5aece3a1b5

The right-angle connectors came soldered on. They were a b****rd to get off!

PaulRB: I purchased a couple of these back in March/April. I set them once when they first arrived. They still seem to be correct to within a minute. http://www.ebay.co.uk/itm/mini-RTCpro-DS3231-high-precision-clock-module-environment-temperature-measure-/390521397685?pt=LH_DefaultDomain_0&hash=item5aece3a1b5

The right-angle connectors came soldered on. They were a b****rd to get off!

Heat gun or as my soldering instructure said heat every pin with the soldering iron, then simply pull each pin out one at a time, it's a bit time consuming but it worked great for me... or simply use a heat gun.