If the problem is loss of time, check the crystal...
The internal oscillator of DS1307 circuitry is designed for operation with a crystal having a specified load capacitance (CL) of 12.5pF.
The frequency accuracy of a crystal-based oscillator circuit is mainly dependent upon the accuracy of the crystal and the accuracy of the match between the crystal and the oscillator capacitive load. If the capacitive load is less than the crystal was designed for, the oscillator runs fast. If the capacitive load is greater than what the crystal was designed for, the oscillator runs slow.
Fast Clocks
The following are the most common scenarios that cause a crystal-based RTC to run fast.
1. Noise coupling into the crystal from adjacent signals. This problem has been extensively covered above. Noise coupling usually causes an RTC to be grossly inaccurate.
2. Wrong crystal. An RTC typically runs fast if a crystal with a specified load capacitance (CL) greater than the RTC-specified load capacitance is used. The severity of the inaccuracy is dependent on the value of the CL. For example, using a crystal with a CL of 12pF on an RTC designed with a 6pF CL causes the RTC to be about 3 to 4 minutes per month fast.
Slow Clocks
The following are the most common scenarios that cause a crystal-based RTC to run slow.
1. Overshoots on RTC input pins. It is possible to cause a RTC to run slow by periodically stopping the oscillator. This can be inadvertently accomplished by noisy input signals to the RTC. If an input signal rises to a voltage that is greater than a diode drop (~0.3V) above VDD, the ESD protection diode for the input pin will forward bias, allowing the substrate to be flooded with current. This, in turn, stops the oscillator until the input signal voltage decreases to below a diode drop above VDD.
This mechanism can cause the oscillator to stop frequently if input signals are noisy. Therefore, care should be taken to ensure there is no overshoot on input signals.
Another situation that is common to overshoot problem is having an input to the RTC at 5V when the RTC is in battery-backup mode. This can be a problem in systems that systematically shut down certain circuits but keep others powered up. It is very important to ensure there are no input signals to the RTC that are greater than the battery voltage (unless stated otherwise in the device data sheet) when the device is in battery-backup mode.
2. Wrong crystal. A RTC typically runs slow if a crystal with a specified CL is less than the CL of the RTC. The severity of the inaccuracy is dependent on the value of the CL.
3. Stray capacitance. Stray capacitance between the crystal pins and/or to ground can slow an RTC down. Therefore, care must be taken when designing the PC board layout to ensure the stray capacitance is kept to a minimum.
4. Temperature. The further the operating temperature is from the crystal turnover temperature, the slower the crystal oscillates. See Figures 3 and 4.
**broken link removed**