Problem with data logger shield (SD card reader + DS1307)

While I am debugging my sketch something is continually causing the RTC on my shield to stop 'ticking'.

I have read that pulling the USB cable out can cause a power spike that resets the RTC and that installing a 4.7uF cap across 5V/GND can suppress the power spike....and I have done this.

However my RTC is still being reset regardless of the RTC battery being fine.

Has anyone had this sort of problem and have they successfully solved it?

I have used the DS3231 RTC with Pro Minis, never had that problem with that configuration. Haven't seen the problem while developing the sketches with an UNO either.

Your RTC battery is OK?

.

boylesg: I have read that pulling the USB cable out can cause a power spike that resets the RTC and that installing a 4.7uF cap across 5V/GND can suppress the power spike....and I have done this.

I have used several DS1307s and now a couple of DS3231s, and I have never heard of such a thing but, if it were true, you wouldn't be in much doubt about it, as you would have a time record of the incident. This might have been something worth checking before you bothered to install the capacitor.

causing the RTC on my shield to stop 'ticking'.

RTC is still being reset

"Reset" and "stop ticking" don't sound like the same thing. Please describe what the RTC does when you disconnect and reconnect the USB power.

cattledog: "Reset" and "stop ticking" don't sound like the same thing. Please describe what the RTC does when you disconnect and reconnect the USB power.

I mean the clock oscillator has been turned off.

I have to load the example sketch from the RTC_DS1307 library, re-start the clock and reset the time.

There does not seem to be any pattern that I can discern as to when it happens.

I just re-connect my mega to the USB cable, start doing some more debugging and find that the RTC clock oscillator has stopped.

I have done some googling on this and found others have had the same problem. There was the power spike problem at power disconnect with the cap solution and a problem involving a random value in the DS1307 register that turns the clock oscillator on and off when the arduino power goes down (or something along those lines)

You might want to review this Maxim application note on design considerations for RTC.

https://www.maximintegrated.com/en/app-notes/index.mvp/id/504

The capacitor across the power is a good start, but the application note also refers to the use of a Shottky diode as a reverse voltage clamp.

Data Loss/Data Corruption

Data loss is usually caused by one of two things: inadvertent writes to the clock, or negative voltage glitches being applied to the IC. Data loss caused by negative voltage inputs to the IC can sometimes be identified because the CH or EOSC bit (on clocks with an oscillator control bit) will be in their default “halt” state. For clocks with an oscillator stop flag (OSF) bit, the OSF bit will usually be set. Additionally, the data in most, if not all, of the registers will be corrupted. Inadvertent writes normally occur during power cycling as well, but will usually only affect one register. It usually does not affect serial clocks.

Some switching power supplies will, on power-up and/or power-down, create a voltage spike on VCC. This voltage spike can go negative by 5V or 6V, or more. This negative voltage will couple onto the internal supply of the clock through input-protection diodes. If the power supply can source more current than the battery, data will be lost. In most cases, a Schottky diode can be used to clamp the negative voltage spike.