PDA

View Full Version : Power loss - Brown out?



clocks
- 19th October 2010, 15:03
I have made a clock (using PIC16F870 & DS1302 RTC) which works fine.

However, when power is lost to the circuit, the clock looses the time and start's up in its 'set the time' routine. Now I have found a way to attach a backup battery to the DS1302, but I do not know how to get the PIC to skip the 'set the time' routine. From what I can gather this can be done with brown out detection. But I don't understand how that works - or how you set a different start point for the program to run (ie not go through the 'set the time' routine when power comes back)

Any and all help really appreciated!

prstein
- 19th October 2010, 15:19
At the start of your code, check to see if PCON.0 = 0. If it does, a brownout has occurred. Set PCON.0 to 1 and jump past the Set Time routine.

However, PCON.0 must have been previously set to 1 in your code, probably within the Time Set routine.

Another approach (that I use on the Xicor X1226) is to read the clock on startup. If is a good value, skip the Set Time routine.

Hope this helps,
Paul

clocks
- 19th October 2010, 15:26
that seems simple enough! thanks!

mackrackit
- 19th October 2010, 16:05
A coin cell feeding the RTC and a diode between the RTC VDD and the PIC VDD works well.

For the code jump add a button. At startup if the time needs reset for some reason hold the button.

clocks
- 24th October 2010, 23:34
A coin cell feeding the RTC and a diode between the RTC VDD and the PIC VDD works well.

For the code jump add a button. At startup if the time needs reset for some reason hold the button.

Thanks mackrackit for this advice - I've got the battery working and added a rest button. I've also been looking into the diode you mentioned - it seems that this is actually essential to prevent the accidental charging of the battery, and hence a possible explosion! What diode would I use here how is it connected? I don't understand your comment about connecting it between the two power sources - is it not simply in series between the ds1302 and the battery?

The data sheet says:
"UL recognized to ensure against reverse charging current when used in conjunction with a
lithium battery."

Does that mean I can trust the d1302 to protect the battery?

Thanks again,
O.

mackrackit
- 25th October 2010, 10:56
I forgot the DS1302 has two supplies.
I would connect the DS1302 as shown here but use a diode with the battery, and have the trickle charger turned off. I do not have enough experience with the DS1302 to say about trusting it. http://www.maxim-ic.com/images/appnotes/3449/3449Fig02.pdf

A 1N914 woks for the diode.
Here is what I was getting at when I posted before. The whole system runs on 3.3 volts.
4880