rtc time lag

Hello everyone,
I m interfacing a RTC of ds1307 with microcontroller c8051f020
I follow rtc datasheet
My circuit is working fine.
In the software, I m initializing the interrupt then smbus and after that rtc.
Initialization of rtc includes initializing internal oscillator and generation of 1 sec pulse
1 sec pulse is used as 1 sec interrupt
I read rtc after every one sec in while(1) loop. Flag is set in 1sec interrupt routine and display time on lcd
My problem is, when I switch on the machine I find the lag in seconds
To test it I switched off and on the machine several times and it was noticed that seconds lag is increasing
To check again, I downloaded the program and reset the microcontroller for several times and run it
Still I get lag in seconds as I increase the resets of microcontroller
Is it a mistake of my code or hardware fault?
Lag is of few seconds but if this continues then in a month it will be in minutes
thank u all

Parents
  • when I switch on the machine I find the lag in seconds

    Please be more specific. What do you mean when you speak of a "lag in seconds"?

    I m initializing the interrupt then smbus and after that rtc.

    Did you consider that maybe by re-initializing the RTC, you interrupt its ongoing time measurements? That might well cause it to "forget" about the fractional second it was in, so it would fall behind real time by anything between 0 and 1 second.

Reply
  • when I switch on the machine I find the lag in seconds

    Please be more specific. What do you mean when you speak of a "lag in seconds"?

    I m initializing the interrupt then smbus and after that rtc.

    Did you consider that maybe by re-initializing the RTC, you interrupt its ongoing time measurements? That might well cause it to "forget" about the fractional second it was in, so it would fall behind real time by anything between 0 and 1 second.

Children
More questions in this forum