rtc time lag

Thread Starter

kppp

Joined Apr 23, 2008
14
Hello everyone,
I m continuing from the problem I posted about RTC time lag.
I read datasheet of DS1307 and KDS32.768Khz oscillator
RTC requires crystal of load capacitance of 12.5pf and KDS 32.768Khz has the same.
I m implementing the same circuits as used in datasheet of DS1307
But there was a lag in the time by 3 to 4 hours within 5-6 days
Then I connected a capacitor of 15pf between oscillator lead going to pin no-1 of rtc and ground.
Now my problem is minimized, but still there is a lag of 5min within 4 days
Track between oscillator and ic is hardly 1-2 cm.
To check the software fault, I generated 1 sec interrupt from RTC and monitored it on port pin of controller, 1sec interrupt is also properly generated.
Can u tell me why this is happening?
How can I make clock accurate?
thank u all.........
:)
 

beenthere

Joined Apr 20, 2004
15,819
RTC crystals simply do not have the accuracy to accurately keep time over significant periods. The error is not too bad either - that is 6 hours in 518,400 - considerably better than .001%.
 

Thread Starter

kppp

Joined Apr 23, 2008
14
hi;
thanx for reply.
error is big b'cos we use this time in printing the reports and if time varies then user has to set it every time.
report contains the cycles which start at particular time and ended at particular time hence i need time accurate
from the hardware point of view what can i do for checking?
is it a problem of analog ground and degital ground?
b'cos 2 grounds are shorted on pcb, and crystal is given the same ground
crystal is kept horizontal touching the pcb
thanx for help
take care
 

SgtWookie

Joined Jul 17, 2007
22,230
Even with a TCXO (temperature controlled crystal oscillator) you'll have drift over time.

If your xtal is hanging out in the breeze, you don't have much hope of keeping it rock-steady. Small temperature fluctuations will cause slight shifts in frequency. If your clock is near the printer, it's heat output will vary greatly between standby, ready, and printing modes.

If you really want accurate time, look into getting a time code reciever IC like a U4226B or similar. Alternatively, you could look at the zero crossing of the 60Hz power using an optoisolator with a suitable current limiting resistor. In the States, the power grid is synchronized to the national time standards. It may vary slightly during the day, but it averages out. You can have your clock "kick in" to save the time in a back-up mode.

Have a look at NIST:
http://tf.nist.gov/timefreq/stations/wwvb.htm
wwvb broadcasts at 60KHz; it's frequency is extremely accurate. Build a receiver for it, and a frequency divider. While you're at it, use the time code receiver IC to keep your clock set to the national time standards.
 

AlexR

Joined Jan 16, 2008
732
The normal configuration for a crystal oscillator driving a RTC, microcontroller etc is to have a capacitor connected between each end of the crystal and earth. The value of each capacitor should be twice the load capacitance of the crystal. If your crystal is a 12.5pF unit then a 22pF or 27pF each side of the crystal should do the trick.

You should be able to get an accuracy of well under a minute a day. If needs be you can reduce one of the capacitors and put a small trimmer capacitor across it. Adjusting the trimmer will pull the oscillator frequency a little and give you a fine control over the clock rate.
 

Thread Starter

kppp

Joined Apr 23, 2008
14
Hello everyone,
-My time lag problem is solved a bit. It was my software mistake.
-There is inbuilt register in rtc whose 7th bit should be zero to start the internal oscillator of the rtc for time and date, Same register is shared with second bits.
-On the power-on I was making the whole register zero to clear the oscillator bit which was making seconds also zero, thus on every power ON I used to lose seconds to zero.
-This was the reason that minutes were also lagging.
-I have solved the problem.

-But still I get few seconds lag, I have noticed that when machine is switched off and then on, there is seconds lag, this lag is random
-To test it I switched off the machine and ON it. I did it for 7-8 times and I noticed that lag is increased to 7 seconds, this lag is not constant.
-If this continues then in a month, I will get few minutes lag
-Is it a problem of VCC which is 5V or battery of 3V battery used is MAXELL CR2032?

-I connected oscillator to the leads of rtc to avoid track capacitance.
-I have also connected the capacitor of 12pF between oscillator and ground but still the problem is same
-It is power problem or anything else?
please suggest
thank u all for the reply, it helped me lot to study the hardware
 

m.majid

Joined May 28, 2008
53
the problem may be in hardware or in software,
to solve this problem firstly realize if is it in software or hardware. do the following:

let your circuit be on (don't shut down) and just reset your µController, then wait some seconds, then reset again and wait, and do this several times.
if time lag apears again, so the problem is in software, in initialization code.
otherwise it is in hardware.

i have used RTC in some projects, i didn't connect any capacitor to crystal,
i just soldered the body of crystal to ground of circuit, and connected 1 bypass capacitor (100nF) between Vcc of RTC and ground.

i should say i have around 1 minute time lapse in 1 year
 

Thread Starter

kppp

Joined Apr 23, 2008
14
Hello,
Thank you for reply
I checked according to your suggestion.
I got lag in seconds
But I m still not understanding mistake in software
In intialisation routines, I m initializing the interrupt then smbus rotines as I m using c8051f020 and then initialization of RTC
In this routine I intialise the internal oscillator for time and 1sec pulse for 1sec interrupt and reading the rtc after every 1sec
But still there is lag when controller is reset
what else do i need to check?
Thank u
 

m.majid

Joined May 28, 2008
53
u know if the 8th bit of SECOND register is set to 1, the rtc will stop.
check your code and be sure u did not set this bit to 1.
or any code that causes this bit to be 1.
 
Top