DS1307 - anyone have one? Accuracy?

Go To Last Post
26 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a DS1307 clock chip (I2C), a crystal and battery - on a little PC board. Interfaced to a Mega32.

Is it just my bad luck that it has lost 90 seconds or so of time since I set the clock to match NIST (atomic clock)? Each day it is a few more seconds farther behind, according to my radio clock and according to NTP setting my PCs clock.

Bad luck that I have a rotten crystal?

The little board came from SparkFun electronics.

I've got the AVR reading the date/time once a second. Is it possible that this causes the DS1307 to lose time accuracy? I assumed not.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Crystal tolerances are in the order of 30-50ppm which corresponds to a few seconds a day.

Ralph Hilton

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

why are all the wristwatches I've owned seemingly so more accurate?
Not crystal controlled?
Calibrated at factory?

32,768Hz crystal

a "few" ppm a'int much at this low crystal freq.

I suppose I need to go read about these "watch" crystals used with the DS1307. My expectations were greater.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

It sounds like you have a mis-match in your crystal capacitance and your ds1307 internal capacitance. Check that you have the right cystal for the ds1307. I have a unit using the ds1302 that is with in .5secs in one month.

Caleb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
why are all the wristwatches I've owned seemingly so more accurate?

It's because the crystal is cut in way that gives the best frequence stabiltiy for the temperature obtained for a device worn on the wrist (about 32 degrees Celsius if I recall it right). If a wrist watch is not worn it will be less accurate.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

austca wrote:
Hi,

It sounds like you have a mis-match in your crystal capacitance and your ds1307 internal capacitance. Check that you have the right cystal for the ds1307. I have a unit using the ds1302 that is with in .5secs in one month.

Caleb

Where do you get your crystals?
Even a TCXO doesn't generally have that sort of accuracy.

Ralph Hilton

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Well if you want to know more about how I know my time drift for the ds1302, I have a pc connect to a project, common these days:), and set the time a month ago, a few days ago I looked at the time on the unit and it was still 1/2 a sec behind "phone time. When it was set it was 1 sec behind "phone time." Ok, so that is only one data point for how well the unit is keeping time, but still it is a full month(+/- a few days) between testing the time.

Ok, so this morning I looked at the datasheet for the ds1307, and here is a quote

Quote:

"X1, X2 – Connections for a standard 32.768kHz quartz crystal. The internal oscillator circuitry is
designed for operation with a crystal having a specified load capacitance (CL) of 12.5pF."

Note the 12.5pF load capacitance, if the "watch crystal" has say a 6pF load capacitance, then things are going to run alot different than expected. I have seen this happen personally. The first version of my unit had this problem, so I made the changes and the new unit works very well.

look at the following link, this is a pdf from Citizen,
http://www.citizencrystal.com/im....

Note the curve at the bottom of the pdf. the most stable point of the crystal is at 25C. Above or below this temperature the ppm error will be larger, So to get your ds1307 to run at a stable error rate keep it at as stable a temperature as you can, once you know your error rate you can use software to fix there drift in time, a sec a .(week, month...). if you change the loading capacitance, a small amount, you can adjust for the ppm error of the crystal as well.

I get most of my parts from digikey, and maybe I got lucky with my ds1302( it has been in a nice stable temperature zone).

Caleb Austin, EE

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So if you have a tweaker variable cap like the hams use, you can dial it right in to 12.5?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sure:)

Well I did not do that, as it is better to keep the leads from the crystal to the pins on the ds130X very short, short as possible. Starting with a good capacitance match between the crystal and the ds1307 will keep the circuit running with in specs of the parts. PCB layout will also impact the accuracy of the system. There are many factors that also have to be looked at, stray signals flying around the pcb can make the jitter level rise and that will change the "ppm error" of the system, ds1307+crystal, adding a ground ring around the 32k768 crystal will help keep such signals out of the xtal input pins.

Three main points:

1. Load capacitance match
2. Temperature change
3. Stray signals

Keeping the three points in mind one can make a very stable crystal based time system. Take a look at this app note from Maxim

http://pdfserv.maxim-ic.com/en/a...

and

http://pdfserv.maxim-ic.com/en/a...

I am only sharing this as help, if you have read and understand this stuff than great, maybe you can share with me too:)

Caleb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Many RTC chips have some 'tuning/trimming' capability. Typically the chips come tuned for a specific crystal, from a particular manufacturer, if you use a different crystal, you may need to adjust the tune/trim values to get better accuracy. The good news is that, once you have tuned it, the same values can usually be used in production, if the crystal manufacturer is consistent in their cut.

[edit]
After reading the DS, it appears that this chip is not tunable. So in this case you will need to make sure that the xtal you purchase, matches the characteristics given in the table in the DS.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The DS1307 data sheet description, their sample circuit and the SparkFun Electronics PCB have no capacitor on the crystal. The chip seems to be designed thusly. I assume that the crystal on the PCB is per the datasheet's requirements - in terms of load capacitance.

24 hours ago, I changed the AVR to read the date/time from the DS1307 every 60 seconds instead of every second. Thinking that the once per second rate was slowing the time keeping. 24 hours now, and the '1307 is pretty close in agreement with my so-called atomic clock (WWV). That clock is always 5-7 seconds different than my PC's clock after I tell windows to synch to NIST.

So, a day or two more and I'll see if the slowness was due to the high read rate. I'll read the data sheet to see if reading will indeed affect accuracy. Seems like it shouldn't.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

glitch wrote:
Many RTC chips have some 'tuning/trimming' capability.

e.g. Xicor X122x. Xicor (now part of Intersil) sends free samples. Other chance might be one of those Epson RTC's (e.g. RTC 4513) - the crystal is integrated so you shouldn't run into issues with crystal receiving noise from the environment.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Glad to hear things are working better now.

Cheers,
Caleb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What time *is* it?

After I tell my PC to resynch with NIST (using NTP), and I understand that this does some averaging to acount for Internet latency - my PC is consistently 5-7 seconds ahead of my Oregon Scientific "Atomic" clock which receives WWV off the air. This is consistent over many weeks.

Also consistent is that the DS1307 loses 5 seconds or so a day, every day, relative to the PC where I run NTP every day. Reducing the rate at which I read the date/time via I2C had no effect. So I guess the crystal is just not that accurate.

To speed up the oscillator, I'd have to put a capacity in series with the crystal, rather than in parallel, it seems to me. BTW, this crystal looks to me the same as you see in watches. (Glad my Omega watch is more accurate!). I'd need to borrow a super accurate freq counter and figure out how to couple it in without de-tuning the osc.

Seems like a 32768 Hz oscillator based on a crystal could do better than 5 parts in 86,000 (seconds per day).

Well, what I should do is buy a cheap GPS receiver on eBay and use it for a time reference. This is for a particular home automation project I'm doing which needs to match standard time by a second or two.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Honestly, I'd try sourcing a different crystal, you might have better luck, 5 seconds a day is awefully high.. Try digikey, they will have several from different manufacturers in the same style package. Alternatively, if you know that it's 5 seconds, and it's consistant, you can digitally trim this in software. by adding a second to the time every 5 hours (4:48 to be exact, for 5 sec/24hr period). Write back the adjusted time to the RTC, this way you know that whatever time you read, should be within 1 sec of the real time. Basically you will be introducing a leap second every few hours to compensate for the RTC's error.

Also check your supply to the RTC. RTC's tend to drift in time, if their supply voltage is not sufficient. (Though I usually see them run fast rahter than slow when this happens)

A final alternative is to count zero crossings on your AC mains. AC is, typically, a very stable waveform, when looked at over longer periods. The only real drawback is that if you lose power, you lose time.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

stevech wrote:
I'd need to borrow a super accurate freq counter and figure out how to couple it in without de-tuning the osc.

To measure the osc, you could use a little loop anenna over the chip. Even ground lead of your cro probe, connected to the cro tip might do. Turn up the v/div till you see a signal, and plug the freq counter to the CHX out of the cro (if one is there).
Even a cheap and nasty counter will have an accuracy <1ppm.
Phil

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

stevech wrote:
What time *is* it?

You mean now?
stevech wrote:
After I tell my PC to resynch with NIST (using NTP), and I understand that this does some averaging to acount for Internet latency - my PC is consistently 5-7 seconds ahead of my Oregon Scientific "Atomic" clock which receives WWV off the air. This is consistent over many weeks.

I too sync my PC with NIST and my PC is consistently less than one second different from my SkyScan Atomic Clock. NISTIME shows an approximate network delay of 15487 microseconds for the server I use (NYC). With a California server, the network delay is approximately 54998 microseconds. I don't understand why your PC time would be off by that much.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why dont you guyz use NTP to sync the pc's ??

NTP will keep the PC time within 128 ms from ref-clock.

XP actually uses a "basic" sntp client but the update once a week is to low , to keep the clock within a reasonable accuracy.

Quote:

To control the number of seconds to wait between attempts to synchronize the system clock to an time source on the Internet using the following Windows XP registry hack:
Hive: HKEY_LOCAL_MACHINE
Key: SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient
Name: SpecialPollInterval
Type: REG_DWORD
Value: #secondsdesired default

I set mine to 3600 , meaning it will update once every hour.

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What you need is one of these Dallas/Maxim goodies:

http://www.maxim-ic.com/products/timers/precision_oscillators.cfm

The DS32KHz performs active temperaure compensation of the crystal to achieve ±1 minute per year. It is also inexpensive and fairly good on power. (Compared to other TCXO)

I'm about to test these next week but since Maxim don't usually lie about specs I'm sure it "does what it says on the tin"

Nigel

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

On XP and NTP - I did the registry hack to increase the NTP update rate long ago.
Odd though, each time I manually tell XP to resynch with some NIST source on the web, the PC clock jumps 5-10 seconds. Maybe Mr. Gates' NTP is stupid. I should look for someone else's NTP. It would be nice if the PC and the Oregon Scientific's clocks would agree to a second or two!

DS32KHz - NEAT! I'd never seen that. Looks like it would replace the crystal on the DS1307 board I have. Wish it were in an 8 pin DIP rather than 14 pin or a BGA. Digikey has them.

Anyone have one to sell me?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

stevech wrote:
I should look for someone else's NTP. It would be nice if the PC and the Oregon Scientific's clocks would agree to a second or two!

Actually these guyzz maintain a fine NTP & BIND for WinNT(XP)
http://www.five-ten-sg.com/

All the way in bottom left

I have used it (WinNT) , it works excellent.
I seem to remember the ntp.conf is in /windows/etc

This one seems to be newer
At ntp.org http://ntp.isc.org/bin/view/Main...

They point at this for an XP port (Binaries are down the page)
http://www.meinberg.de/english/s...

Ohh and dont just use nist , use some Pool or "Stratum 2" servers on the net.
http://ntp.isc.org/bin/view/Serv...

Remember for using "Statum 2" servers , some of them requires that you ask for permission , i don't think the same apply's to pool servers.

With NTP the distance (delay) to the server is not a problem , as the net delay is compensated for.

Remember it takes up to 5 min for NTP to (trust)/"synch with the timeservers" , and that some daemons simply exits if the diff between the servers and your local clock is greater than 15 min. Then a manually setting of the clock is required , to make it within the 15 min.

When it's installed the : "ntpdc -p" command is used for checkking the status , of the servers you use.

Ohh i might expect that you have to stop/disable the XP-Build in time service , as it seems at least on Linux that the program doing the timeservice is allocating UDP/123 exclusively.

There is a fine program for basic XP registry household , at http://www.xp-antispy.org/

Sorry if i "Hijacked the thread" but i just thought this would be usefull

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Everyone seems to beleieve that the PC's clock is accurate!! :shock:

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

stevech wrote:
I should look for someone else's NTP. It would be nice if the PC and the Oregon Scientific's clocks would agree to a second or two!

I'm running Windows 2000 Professional and use nistime-32bit.exe available from this link. In the upper right, you'll see Software and Instructions. Click on Windows 95 and later (32 or 64-bit). Run nistime-32bit.exe and select File, Select Server. Select the nearest server and check the NTP box. Now select File, Save Config. Add nistime-32bit.exe to your Programs\Startup folder. See Help, Command Line for program parameters.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Vcc is 5.00 V per my DVM - from a 7805.
Vbat is 3.19V with Vcc present.

AC mains - well the intent of the DS1307 was to have a battery-backed up date/time that the AVR reads at power up and every so often during operation to keep the OS's time from drifting (the OS uses the AVR's timer).

Well,I guess the crystal is really crummy- seems like noise on the PCB would perhaps make it seem to run fast rather than slow. I'll swap out the crystal and see what happens.

Re atomic clock not matching NTP/NIST on the PCs - I found out that the clock was not receiving the WWV signal - a teeny little icon warned of this. I moved it to a window and it works and agrees now with the PC. I'd like to find a cheap atomic clock with a serial port output; much cheaper than GPS. Probably no market demand for such.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

stevech wrote:
Well,I guess the crystal is really crummy- seems like noise on the PCB would perhaps make it seem to run fast rather than slow. I'll swap out the crystal and see what happens.

Does your PCB contain the recommended guard ring (connected to ground) around the crystal and corresponding DS1307 pins?

The way to check to see if the cause is PCB noise is to check the accuracy over a time period (e.g., 24-hours) with the circuitry active compared to the system powered off and running off (i.e., DS1307 running off Vbat).

See Maxim Application Note 58: Crystal Considerations with Dallas Real-Time clocks (RTCs).

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don
Thanks for the idea. I left the system off for 48 hours - Vbat only. Now the DS1307 is 20 seconds behind my PC and Atomic clock (these two match to a second or so).

The Crystal is stamped "32C48" and Google didn't find a spec sheet. The SparkFun website shows crystals, not sure if they are the same as on this PCB. They say they all packaging options are 20pF. I think the DS1307 spec sheet said 12.5pF. Not sure if this is relevant.

website says:
Description: Standard frequency crystals - use these crystals to provide a clock input to your microprocessor. Rated at 20pF capacitance and +/- 50ppm stability.

PCB has a copper flow ground plane all around the crystal's traces to the chip. Not the same as shown in the DS1307 spec sheet. But wouldn't system noise cause the clock to appear fast rather than slow?

Well, maybe it's just a bum crystal.