Go Down

Topic: Inaccurate DS1307 (Read 3557 times) previous topic - next topic

Slugsie

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:
http://cpc.farnell.com/jsp/search/productdetail.jsp?SKU=SC08159

and paired it up with this crystal
http://cpc.farnell.com/jsp/search/productdetail.jsp?SKU=SC08198

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.

streety

#1
Nov 30, 2009, 04:41 pm Last Edit: Nov 30, 2009, 04:45 pm by streety Reason: 1
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]

Slugsie

#2
Nov 30, 2009, 05:18 pm Last Edit: Nov 30, 2009, 05:18 pm by Slugsie Reason: 1
Quote

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. :)

retrolefty

Quote
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

Slugsie

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.

retrolefty

Quote
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

Slugsie

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 :)

madepablo

#7
Dec 02, 2009, 07:36 pm Last Edit: Dec 02, 2009, 07:53 pm by madepablo Reason: 1
I have this ds1307 module from sparkfun:
http://www.sparkfun.com/commerce/product_info.php?products_id=99

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?

streety

Quote
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.

kg4wsv

#9
Dec 02, 2009, 09:02 pm Last Edit: Dec 02, 2009, 09:03 pm by kg4wsv Reason: 1
Replace that cheap crystal with a DS32kHz 32.768kHz Temperature-Compensated Crystal Oscillator.

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

-j

Slugsie

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. :)

Spinlock

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...

madepablo

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!


Slugsie

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.

jluciani

#14
Dec 03, 2009, 12:46 am Last Edit: Dec 03, 2009, 01:07 am by jluciani Reason: 1
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

www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks

Go Up