martenjacobs
Posts: 5
Joined: Fri Sep 26, 2014 9:04 am

DS1307 RTC drifting hours per day [SOLVED]

Fri Sep 26, 2014 9:45 am

Hi all,

For a project I'm using an RPi as test machine, and one of the things I'm testing is an RTC. As it will be part of a larger PBC, buying a pre-built package was not an option. I therefore assembled my breadboard as follows:
Schermafbeelding 2014-09-26 om 11.15.48.jpg
Breadboard
Schermafbeelding 2014-09-26 om 11.15.48.jpg (59.64 KiB) Viewed 2178 times
The DS1307 works on the Pi's 5V, but as soon as I shut down my RPi (so it switches to backup power) it starts drifting. It's always running slow, and this morning when I switched on my Pi, it had drifted almost 2 hours in about 40 hours (almost 5%!). A few days ago I tested it with my Pi on for a few hours (by running "watch -n 10 'sudo hwclock -r && date'"), and it worked perfectly, so it's only an issue when on backup power. The battery I'm using is brand new, and I also tested it for a few hours with my lab bench PSU, both producing the same result. Reading and writing the DS1307 from my Pi works perfectly. The parts I'm using are:
- Maxim DS1307+ RTC (Farnell 1188042)
- Battery holder (Farnell 1339840)
- Abracon crystal (Farnell 1611828)
- A 100nF ceramic capacitor

Is my DS1307 simply broken or am I doing something wrong?

Regards,
Marten
Last edited by martenjacobs on Thu Oct 02, 2014 6:49 am, edited 1 time in total.

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: DS1307 RTC drifting hours per day

Fri Sep 26, 2014 10:39 am

Hi and welcome to the forum.
Well the DS1307 is as cheap as chips so why not just try another?
Of course there are much more accurate RTC chips available - the DS3231 for example.
rgds
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
Burngate
Posts: 6290
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: DS1307 RTC drifting hours per day

Fri Sep 26, 2014 11:35 am

It could be a faulty chip - try another, as texy says. Or try a different crystal. Losing 5% sounds like the oscillator is on edge with the lower battery supply.

However, before that, try swapping things round on the breadboard.
From your diagram, I would move the battery to the right, and down, so that the leads are shorter. That would allow you to move the crystal up towards the chip.

Breadboards are wonderful things, but they're not perfect. Connections can go high-resistance, for example. Even a bit of Veroboard would be better, now that you know the basic design works, because you can keep tracks short, and make sure all connections are solid.

jdb
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2351
Joined: Thu Jul 11, 2013 2:37 pm

Re: DS1307 RTC drifting hours per day

Fri Sep 26, 2014 5:44 pm

The problem is the breadboard.

You're attaching a 32.768kHz crystal via "long" wires (breadboard tracks) and multiple connections. Additional series resistance and leakage capacitance/resistance will alter the frequency of the crystal from the design spec.

One thing you can do is solder/bodge the crystal on to the DS1307 pins directly so that stray effects can be minimised. Maybe bend the XTAL pins on the DS1307 straight out so they don't plug into the breadboard,then solder the crystal directly to them.
Rockets are loud.
https://astro-pi.org

User avatar
Burngate
Posts: 6290
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: DS1307 RTC drifting hours per day

Sat Sep 27, 2014 10:46 am

jdb wrote:...
He says it's ok when using 5v power. Long tracks etc. would have the same effect whatever the power source, wouldn't they?
Crystals don't go that far off frequency whatever capacitance / resistance you put round them. 0.005% maybe, but not 5%
More likely to my mind is that it's not oscillating correctly, and the divider is mis-counting at the lower voltage.

Shorter tracks, etc. will give the crystal a better chance, and a new crystal may be better

martenjacobs
Posts: 5
Joined: Fri Sep 26, 2014 9:04 am

Re: DS1307 RTC drifting hours per day

Tue Sep 30, 2014 2:13 pm

Hi all,
Thank you for your responses. I've just received a few new RTC's and get the same results. Because of this I just soldered a little prototype board with everything very close together, and after having waited for about an hour, it's still on time! I guess it had to do with the crystal's resistance being off on the breadboard. Luckily my schema seems to be OK, so it'll probably work on the PCB I'm having etched.

Thanks again for all your feedback!

Marten

[UPDATE]: after letting it run for two days, it's still completely on time, so it's clear that the problem was due to my breadboard.

Return to “Troubleshooting”