Inaccurate DS1307

I'm prototyping a few bits for a bigger project I'm working on, and part of it requires a pretty accurate RTC.

I bought this DS1307 IC:

and paired it up with this crystal

It's wired up according to the standard DS1307 datasheet schematics, including the use of a pair of 4K7ohm pull up resistors on the SCL and SDA lines (which a lot of people seem to miss out), and a 3v coin cell battery.

In addition, I am using a standard 16x2 line LCD to output the time and date that is read from the DS1307.

Everything is running fine - almost. I was able to set an initial time with no problem, and that is remembered correctly through power off. The problem is that the clock is running fast. I left it running (fully powered) overnight, and it gained approximately 30 seconds in 10 hours. For the project I'm working on that's useless, I really want better than a few seconds a week if possible.

Is there any obvious trouble shooting steps I can take?

I'll post a pic of the breadboard and the sketch (although that is incredibly simple) when I get home this evening if it'll help.

This is amazingly similar to the process I'm currently going through. Only difference being that I'm using a breakout board from sparkfun for the DS1307/crystal/battery combination.

My understanding was that there are inbuilt pull up resistors on the pins used for the wire protocol so additional resistors are not needed.

As for running fast I haven't left my set up on long term yet so I'm not sure if I see the same issue. I'll try and remember to leave it running tonight and see what happens.

I would be curious to hear what you're working on.

[edit]Just for reference I'm using this product though I don't remember paying that much for it. :-? [/edit]

I would be curious to hear what you're working on.

In this instance I'm working on a clock, so having a reasonably accurate time source is fairly fundamental. :slight_smile:

Is there any obvious trouble shooting steps I can take?

Well the accuracy of the device is 100% dependent on the accuracy of the crystal. Perhaps your crystal was designed to have a load capacitor, series or parallel to ground. If you had a high input impedance frequency counter you could possibly measure the actual frequency the crystal is oscillating at.

I have a DS-1307 RTC module and it's been holding great time now for over 3 months compared to my PC clock that is updated with a on-line time standard service.

So possibly try a different crystal and see if your timing is changed.

Lefty

Unfortunately I have no way to measure the actual frequency of the crystal.

I'm still a noob at this sort of thing, so I don't know about a load capacitor. The data sheet for the DS1307 suggests the use of a crystal with 12pF capacitance, which is why I bought that crystal. How would I know if I should be adding an additional capacitor, and what rating?

I did buy 2 DS1307s and crystals, so I could try the other one. Although as they were bought at the same time, they're most likely the same batch so if one was faulty the other one would probably be too.

I did buy 2 DS1307s and crystals, so I could try the other one. Although as they were bought at the same time, they're most likely the same batch so if one was faulty the other one would probably be too.

Worth a try to see if the inaccuracy is the same or different. Could also be how your wiring layout is arranged, length of wiring for the crystal leads, etc. I do know that the chip can only be as accurate as the crystal time base, so that's where I would put your effort into.

Good luck
Lefty

Right, changed the crystal last night, and so far with around 20hours use it's accuracy is better than 1 second against the 40+ seconds for the other crystal. So looks like I have one faulty crystal.

Thanks all :slight_smile:

I have this ds1307 module from sparkfun:

It is wired in that way:
5V --- 5V
GND --- GND
SQW --- (not connected)
SCL --- analog pin 5
SDA --- analog pin 4
(without pull up resistances).

I set up it with real time yesterday, and it was running for 24 hours disconnected form the arduino duemilanove. I connected it again some minutes ago. It have about 6 seconds in difference respect to the time of my control clock (my laptop clock).

I will setup it again and check for other 24 hours to see if this is a regular problem...

If not, any idea about how to made it more accurate?

As for running fast I haven't left my set up on long term yet so I'm not sure if I see the same issue. I'll try and remember to leave it running tonight and see what happens.

I've just got around to checking this. I've powered up my arduino board and the error is less than a minute after leaving it for at least a week. I can't remember how accurately I had it set to begin with but any error seems to be small.

Replace that cheap crystal with a DS32kHz 32.768kHz Temperature-Compensated Crystal Oscillator.

Or maybe just buy a higher quality/better matched crystal.

-j

Ooooh, at 10x the price plus postage, I think I'll give it a miss for now unless I have a need for super accuracy in the future, but thanks for the info. At the moment this second crystal seems to be running at better than 1 second a day which is much better and good enough for me. :slight_smile:

I don't know if this is your issue, but the DS1307 data sheet specifies that exactly how you position the crystal next to the IC is very important too.

I have my crystal right next to the IC as they indicate, and my timing is spot on. I also don't use pull-ups in my application.

For fun, I may put the crystal on some long leads and see what I can do with it...

Thanks for the comments.

I have the ds1307 unplugged from the arduino, just powered with its own battery. I connected it for setup the date and time, unplugged and wired again just only to see how is its accuracy reading it with a simple sketch.

I will test it tomorrow to see if it still have this big error.

So may be Spinlock you are right, and the ds1307 retain a better accuracy when it is working wired to arduino. And the battery remain the date although with a low accurary just in case of lost of power in the arduino.

I will check tomorrow and test also connected to arduino for one day.
Cheers!

I saw that too on the datasheet. I've got the crystal plugged in as close as I physically can to the DS1307. I also tried grounding the crystal casing, but it didn't make a difference.

There is one other crystal specification listed in the Dallas datasheet -- ESR.
Do you know the ESR (effective series resistance) of the crystal? The 1307
states you should have a maximum ESR of 45KOhms. I am not sure the ESR
of your crystal but I have seen a number of crystals that have higher ESR.

(* jcl *)


www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks
blog: http://luciani.org

OK, how do I find that out - without a datasheet for the crystal? I've tried to test it with my multi-meter, but it seems to show open circuit with the crystal unconnected to anything. Is there a way I can try and read the ESR?

You would need the datasheet for the crystal.

This could be a half-baked idea -- if you set the DS1307 square wave
output to 32768Hz this should output the crystal frequency 1:1. You could
measure the frequency with an oscilloscope (or another Arduino). Any deviation
from 32768 would affect the time keeping accuracy.

(* jcl *)


www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks
blog: http://luciani.org

Dallas also recommends a separate ground plane for the xtal and related IC pins. Check the datasheet for details.

-j

@jluciani
Unfortunately I neither have access to an oscilloscope nor another Arduino, so testing the output would be hard. To be honest I'm not experienced enough at the moment to do that measurement with an Arduino anyway.

@kg4wsv
I'm very green with regards to electronics at the moment, so if grounding the body of the crystal isn't sufficient to achieve the 'ground plane' then can you point me at a resource so I can learn how to do this correctly.

I've just found a datasheet for the crystal, it has an ESR of 35kOhm, so it should be within tolerance.