DS1307 not advancing on battery backup

Tony P

Member
I have a timer circuit running lights etc on my vivarium.
Up until yesterday it was working fine.
For some reason now, when I power down and power back on again the clock has not advanced.
If I remove the lithium cell and power down/up the clock displays ??:??:?? (I have also tried a new battery with the same results) so I assume it is not the battery at fault.
I have also swapped the DS1307 chip with the same results.
 

g6ejd

Senior Member
Are you sure it's not a software issue after power-down... Is there some status set in your software that on power-up is causing unpredicted behaviour.

How are you resetting the clock to get it running again.
 

Tony P

Member
I have run various older clock programs on this new circuit board that all work normally but on this new board they all show the same problem.
E.G. - Power off at 21:15:10 power back on several minutes later and clock shows 21:15:13 (3 seconds total initialisation time)

If the backup battery is removed then the clock shows 00:00:80 and the program does not run.
With the battery in place, the program runs fine apart from no time advance on power off
 

Technical

Technical Support
Staff member
You can't just remove the backup cell and test, as the Vbat pin needs to be specifically tied low if the cell is not connected.

Sounds like a hardware issue one the new board, the first thing to swap out and replace would be the clock resonator.
 

srnet

Senior Member
Indeed, could be that the resonator is happy enough to work when the IC has a full 5v to work with, but fails in low power battery backup mode.
 

Tony P

Member
Resonator changed. Still the same.

I have run the program on my AXE091 project board and it works perfectly as it used to.
 

stevesmythe

Senior Member
Are you running the AXE091 off the regulated supply or 3xAA batteries? Could be the voltage problem that I have referred to in post #3 of this thread
 
Last edited:

Tony P

Member
It runs off the regulated supply. I have just tried it off battery power to eliminate this possible problem but no difference
 

rossko57

Senior Member
What is the mystery component between the +5V rail, and the DS1307? A diode perhaps - don't forget that reduces the volts at the DS1307. eating into the needed 1.5V backup supply differential
 

hippy

Ex-Staff (retired)
What is the mystery component between the +5V rail, and the DS1307?
My guess would be "zero ohm resistor" from the other similar type components elsewhere. Those often are resistor packages with a single black band around them.
 

Hemi345

Senior Member
Only thing I can think is the placement of the crystal is causing problems or the 5V trace running under the battery (is it isolated?) While it's running on battery, have you poked around with a volt meter to ensure the 5V line (or other data lines) aren't showing anything?
 

Tony P

Member
I have checked all tracks etc.
This board has been running happily for several weeks. The problem started about 5 days ago
 

Technical

Technical Support
Staff member
We suspect it's a dodgy solder joint or swarf in between the tracks causing an issue. Check the continuity of all 0V ground connections as well, as the 0V rail is linked in several places. Did anyone do any helpful cleaning around the vivarium 5 days ago and knock it?...
 

Tony P

Member
Everything checked and double checked. All looks good and continuity checks out. All resistors read their correct values.

With my meter set at 200k I have been getting a reading of 96.5 across +v and Gnd. I removed the link to the OLED and this zeros. Could this be the issue? or is this normal?
 

hippy

Ex-Staff (retired)
With my meter set at 200k I have been getting a reading of 96.5 across +v and Gnd. I removed the link to the OLED and this zeros. Could this be the issue? or is this normal?
Measuring resistance across power rails isn't that useful in most cases, and such resistance readings are only meaningful when what is connected in the circuit is detailed when measured. Seeing resistance drop when a link is removed seems very odd.
 

Tony P

Member
I have disconnected everything (temperature probe, OLED, output LED and relay connections) and am just running a clock in debug mode. When I power down/up the problem still exists.
If I disconnect the backup battery the clock fails as would be expected. If I reconnect the battery the clock works but does not advance as said before
 

hippy

Ex-Staff (retired)
It's all very odd.

That it retains the time when powered-off suggests battery power is getting to the RTC, not remembering time when battery removed seems to confirm that.

It chugs along keeping time when powered but doesn't when on battery power. That suggests the crystal / oscillator is running when on main power but not on battery power.

Could the battery voltage be too low to run the oscillator but just enough to keep the time data retained ? Might be worth reading the battery voltage with a 1K across its + and - contacts.

The other possibility is that something is affecting the oscillator when the main power is removed. Could a PICAXE I/O pin be affecting X1 or X2 when the PICAXE isn't powered ? I would doubly check there are no shorts between the PICAXE and the left connections of the RTC.

The only other thing I can suspect is some weird parasitic powering issue but I can't see how that would stop the crystal oscillator working. I would however suggest unplugging the download cable, powering off, waiting, powering up and reconnecting the cable to see if that changes anything. I don't expect it will but it takes one possibility off the list.

I think you ideally need to check if the crystal oscillator is running when on battery power but not so easy if you don't have a scope. It might be worth measuring voltages to all DS1307 pins, when powered and when not. That might reveal something or suggest what's next.
 

Tony P

Member
Could the battery voltage be too low to run the oscillator but just enough to keep the time data retained ? Might be worth reading the battery voltage with a 1K across its + and - contacts.
Battery voltage 3.23v

The other possibility is that something is affecting the oscillator when the main power is removed. Could a PICAXE I/O pin be affecting X1 or X2 when the PICAXE isn't powered ? I would doubly check there are no shorts between the PICAXE and the left connections of the RTC.
I have re-checked all tracks. All good

I think you ideally need to check if the crystal oscillator is running when on battery power but not so easy if you don't have a scope. It might be worth measuring voltages to all DS1307 pins, when powered and when not. That might reveal something or suggest what's next.
I do not have a scope. the voltages are as follows:
powered:
pin 1=0
pin 2=2.44v
pin 3=3.23v
pin 4=0
pin 5=5.01v
pin 6=5.01v
pin 7=0
pin 8=5.01v

un-powered:
pin 1=0
pin 2=1.58v
pin 3=3.23v
pins 4-8=0

As you can see the only change is X2 on pin 2 (apart from the obvious 5.01v on pins 5,6 & 8)
 

BeanieBots

Moderator
Those results suggest everything is OK!
Pin 2 should be about 1/2 supply when the clock is running which it is in both cases.
Odd?
 

hippy

Ex-Staff (retired)
Those results suggest everything is OK!
I would concur.

Pin 2 should be about 1/2 supply when the clock is running which it is in both cases.
Well spotted.

With the oscillator running, behaviour the same with other DS1307 chips, perhaps we are not looking in the right place - Could it be a problem with the PICAXE or its code ?

Could you try a different PICAXE ? Perhaps run the code on the AXE091 board but linked to the RTC on the stripboard.

It might be worth posting the full code. Is there anything in that which initialises, synchronises or adjusts the time ?

If it's not the DS1307, not the PICAXE, that brings us back round to it being a board problem. It might be worthwhile duplicating the board and seeing if that suffers the same problems.

I am still at a bit at a loss in your description of it having been working for a while yet also describing it as a new board. Perhaps you could clarify what was meant there.
 

hippy

Ex-Staff (retired)
One thing there doesn't seem to be in the schematic are any 100nF decoupling capacitors. Could be worth adding a couple across the 0V-5V rails.
 

Hemi345

Senior Member
I would concur.
It might be worth posting the full code. Is there anything in that which initialises, synchronises or adjusts the time ?
This bit me a few months back. I could not for the life of me figure out why the clock wouldn't advance time while on backup power. I literally went over the circuit wiring for almost half an hour powering up the device, then down, unplug, power back up and check the time. After a while I realized it was now losing time...just kept starting at 7:20 (or whatever time it was). I realized I hadn't commented out the line of code that kept setting the time on the RTC... :confused: :mad: :eek: :D
 

Tony P

Member
I have run the code with the picaxe and DS1307 off my board put onto my AXE091 board. All is fine.
I have also run just a simple code on the 'new' board as follows:
Code:
SYMBOL SECONDS=B0
SYMBOL MINS=B1
SYMBOL HOUR=B2
SYMBOL DAY=B3
SYMBOL DATE=B4
SYMBOL MONTH=B5
SYMBOL YEAR=B6
SYMBOL CONTROL=B7
SYMBOL SEC_T = B8     
SYMBOL SEC_U = B9 
SYMBOL MIN_T = B10     
SYMBOL MIN_U = B11
SYMBOL HR_T = B12
SYMBOL HR_U = B13

PAUSE 1000
SEROUT B.3,N2400,(254,1)
PAUSE 1000

MAIN:
	i2cslave %11010000, i2cslow, i2cbyte
	hi2cin 0,(SECONDS,MINS,HOUR)
	BCDTOASCII HOUR,HR_T,HR_U
	BCDTOASCII MINS,MIN_T,MIN_U
	BCDTOASCII SECONDS,SEC_T,SEC_U
	SEROUT B.3,N2400,(254,128,HR_T,HR_U,":",MIN_T,MIN_U,":",SEC_T,SEC_U,"        ")
GOTO MAIN
This displays the time as expected but upon power up the clock has not advanced
 

hippy

Ex-Staff (retired)
I have run the code with the picaxe and DS1307 off my board put onto my AXE091 board. All is fine.
It seems it is a hardware issue with the new board. Did you add decoupling capacitors ?

Next step after that is to run with the PICAXE on the AXE091, linked to the DS1307 on the new board. Then with the PICAXE on the new board linked to a DS1307 on the AXE091.
 

Tony P

Member
***UPDATE***

Having tried all of Hippy's suggestions with no joy I decided to purchase an OSC001 PCB Scope. This came this morning and within 5 minutes of setting it up I found the problem.:D

I noticed a dramatic change on the scope when connected to the crystal pin X2 when I powered on/off. I used a 24x jewellers eyepiece to scour the board but found no faults so I decided to remove the DS1307 and look inside the carrier. Here I found the smallest piece of metallic debris possible!! I could not see this with my naked eye.

This did not affect the readings from my multi-meter at all but, as I said, the output on the scope picked it up.

:D Many thanks for all your input :D

Now to start learning how to use a scope ;)
 
Top