A problem with DS1307 Real Time Clock not keeping SECONDS while on battery back
ElectricAye
Posts: 4,561
First, A Safe and Happy Thanksgiving to all out there!
And now that you're bored to death listening to your in-laws and other relatives talk about the endless minutiae of their lives, here's a profound problem you might consider pondering while drowsing over your third helping of peas and mashed potatoes:
I've been using a DS1307 Real Time Clock, which seems to work great while on normal power. Recently, I added a backup battery to it and at first glance it seemed to work out okay. Problem is, I later discovered it will only keep track of the SECONDS for a short while after the main power is shut off. After a few minutes(?), upon repowering and reading the DS1307, the SECONDS appears as some value greater than 60, usually 80 or more. And, after that, it will neither advance the seconds nor the minutes, etc. It will, however, remember the date and year and hour and minute at which it lost power. It will not advance the time and date while on battery backup, though. This seems odd to me, since I would guess it would lose all of its memory, not just forget the SECONDS.
I tried a new battery and I've been religious about preventing ESD from hitting it, plus upon repowering the device, I've allowed the clock two seconds for the main power to stabilize before interrogating it, but the problem persists.
Anyone have any clues what I might be doing wrong?
Thanks to all on this Thanksgiving Day,
Mark
And now that you're bored to death listening to your in-laws and other relatives talk about the endless minutiae of their lives, here's a profound problem you might consider pondering while drowsing over your third helping of peas and mashed potatoes:
I've been using a DS1307 Real Time Clock, which seems to work great while on normal power. Recently, I added a backup battery to it and at first glance it seemed to work out okay. Problem is, I later discovered it will only keep track of the SECONDS for a short while after the main power is shut off. After a few minutes(?), upon repowering and reading the DS1307, the SECONDS appears as some value greater than 60, usually 80 or more. And, after that, it will neither advance the seconds nor the minutes, etc. It will, however, remember the date and year and hour and minute at which it lost power. It will not advance the time and date while on battery backup, though. This seems odd to me, since I would guess it would lose all of its memory, not just forget the SECONDS.
I tried a new battery and I've been religious about preventing ESD from hitting it, plus upon repowering the device, I've allowed the clock two seconds for the main power to stabilize before interrogating it, but the problem persists.
Anyone have any clues what I might be doing wrong?
Thanks to all on this Thanksgiving Day,
Mark
Comments
1) It takes more energy to run an oscillator and counter than just to maintain the contents of a memory cell. There's may be something wrong with how you have the backup battery connected. The DS1307 is designed for use with a primary Lithium backup battery (at 3V).
2) The DS1307 oscillator, like other RTC oscillators, is fussy about layout because of the very low energy levels involved. If the layout isn't right, the oscillator may be working intermittantly. The datasheet is very explicit about how the crystal should be connected and the PCB traces in the neighborhood.
The DS1307 works in backup mode for lots of other people. What's different about what you're doing? You might look at SparkFun's version (www.sparkfun.com/commerce/product_info.php?products_id=99) and compare with what you've got.
Post Edited (Mike Green) : 11/27/2008 5:28:30 PM GMT
Hmmm... your second comment seems to strike a bell somewhere in the back of my brain. I have noticed the DS1307 seems to be sensitive to even the thought of my approaching it before making sure I was well connected to ground. I'll go back and study this layout thing in more detail.
For the backup battery, I'm using one of those flat Lithium 2032 3volt coin-like doo-hickeys. Would that be the wrong kind? And are some crystals more energy hogs than others?
thanks so much,
Mark
Backup batteries are typically coin-like doo-hickies. As long as they provide 3V for as long as you need it, you should be ok.
Different crystals do require different amounts of energy to vibrate. These days, since 32KHz crystals are mostly used for timekeeping, a crystal manufacturer won't sell too many if they're really energy hogs.
Post Edited (Mike Green) : 11/27/2008 5:32:54 PM GMT
The high bit of the seconds register goes to 1 when the the clock is in the stop state. That is why you see a value greater than 80 in seconds register. The fact that the clock remembers the old values proves that the clock has backup power. The oscillator draws less than one microamp in backup mode with the oscillator running, and a little less than that when in stop mode. There is a command that stops the DS1307 oscillator, but maintains the most recent values. Could it be that your program inadvertently issued that command? Another thing. Do not leave the pullups on to a rail that is still powered on while the DS1307 is off. The pullups should come down at the same time as the power supply voltage. Otherwise there will be a parasite power situation and the DS1307 can do some really weird things.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
That raises some concerns, since I think the Prop, when plugged into my PC, still has some kind of power on it. I didn't know things like DS1307 would go into a parasitic mode but I guess I now have something new to worry about.
I'm using the DS1307 object from the Object Exchange, so I'm not sure it would command the DS1307 to STOP during a power down mode. I have yet to learn how such protocols actually communicate with chips. So far I've just been using these types of programs in a blind plug and chug mode. Something else to learn when I get the chance, I spoze.
Thanks for the suggestions,
Mark
You should learn the I2C protocol....lots of good stuff you can easily connect to once you have an understanding of it. At least learn how the addressing and registers work, if not how the SDA and SCL pins need to work.
The attached files from OBEX may help a great deal when working with I2C devices. Especially the diagram.
·Notice the DS1307 is connected to 5v but is on the 3v3 side of the pullups. It does not have enough drive to work on the 5v side. My circuit is like this and it works. The DS1307 still keeps time even when unplugged from the·protoboard·board with its onboard 3v battery.
Okay, Shanghai, I think you might have shown me at least one thing I've done wrong. I have the DS1307 powered by 5 volts but I also have its pullup resistors connected to 5 volts, not to 3.3 volts as shown in the Obex i2c file. Hmmmm... But this arrangement seems weird to me. The DS1307 data sheet shows a "Typical Operating Circuit" on page 13 (see attachment) that shows the pullups connected to Vcc, which is 5 volts. So I'm not sure why what I'm doing there is wrong. Your attached photo has convinced me, however, that my lack of ground plane is probably not the issue.
I'm still pondering this parasitic power thing and the STOP bit issue: it's the kind of thing gives me a pounding headache and reminds me of how ignorant I am when it comes to these things.
thanks you guys,
Mark
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It might be the Information Age but the Eon of Ignorance has yet to end.
Post Edited (ElectricAye) : 11/29/2008 3:47:35 AM GMT
Sorry, I forgot something. The pullups shown are for several devices on the circuit. The demo board had an internal 10k for the eeprom. I do have separate 2.7k pullups to 5v on the clock board.
The value of the pullups seem to be a little critical for different devices. The 2.7k works on the Propeller as well as my Picaxe.
Yeah, the layout doesn't seen too critical. Mine has been running for months (unplugged), only off by a few seconds.
I just plugged it into the prop last week to verify the code. I ran the attached demo and it found it OK.
Hope I didn't cause too much trouble. I should always wait until my second cup of coffee to respond.
Donald
PS My board is EXACTLY like your drawing with the 2.7k pullups.
In you case, there could be a significant difference between having pullups to 3.3 volts versus 5 volts, as far as parasite power is concerned. The 3.3 volts is not much higher than a 3 volt backup battery and would not forward bias the substrate diodes, but 5 volts would, being more than a diode drop higher than 3 volts. It is something to try. It is strange that the RTC would appear to run correctly and get stuck only a few minutes after you removed the power. Maybe a power supply capacitor discharge issue.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
many thanks for your inputs on this. I'm away from my circuit right now but on Monday I hope to take the collected wisdom of your responses and give several things a try. It's probably something I'm doing that's really dumb. It usually is.
cheers,
Mark
the culprit turns out to be some bizarro behavior of my clunky old wall-wart power supply. It does not mess up the SECONDS when it powers down - it somehow only messes up the SECONDS during power up. (If I power up with a 9 volt battery, all works perfectly fine.) I have no idea why this is happening, but I do know that I'm getting a better wall wart very soon. As far as I'm concerned, this aggravating little Problem Elvis has left the building.
Thanks to all who've helped me keep sane while tracking it down.
Mark
Post Script - I found out that my wall wart, which is the kind that has tiny switches that allow you to change its voltage and current, had accidently got bumped off 9 volts and onto 7.5 volts. So at 7.5 volts going into the 5 volt regulator, all worked well.... EXCEPT for this one little glitch. How weird is that?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It might be the Information Age but the Eon of Ignorance has yet to end.
Post Edited (ElectricAye) : 12/8/2008 4:23:51 AM GMT
I have RCT module from parkfun i·going to use with Bs2 for my project but i can`t write the code for it , could·anyone help ?thank
Please post your request in the proper forum (BASIC Stamp). This forum is for the Propeller. There are examples of real time clock use with the Stamp in the Nuts and Volts Columns. The index is here: www.parallax.com/Resources/NutsVoltsColumns/tabid/272/Default.aspx. The StampWorks Manual also has some sample code: www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/txtSearch/stampworks/List/1/ProductID/144/Default.aspx?SortField=ProductName%2cProductName.
Post Edited (Mike Green) : 12/13/2008 4:25:09 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
that sounds like good advice. It seems like just about anything that doesn't give the DS1307 a smooth transition in power will mess up something on it.
thanks for sharing your experiences on this,
Mark
I have a couple of DS1307 boards - one homemade and one from Futurlec.
They are pretty accurate when I connect them to Basic Stamps or Arduinos but they were losing time when hooked to a USB Prop Protoboard.
I am using a Radioshack adjustable (3-12v) switching type power supply.
I tried various things in an effort to identify the source of the problem.
Unplugging the power supply instead of turning the board off using the onboard switch solved the problem. Strange since the switch allows disconnects the power.
The problem also disappeared when I set the power supply to 9v instead of 7.5v. Using the switch works fine at 9v but not at 7.5v
Sounds like the same situation you experienced! Strange....
Yes, it does sound like a similar problem. One thing I learned from that problem is to always give voltage regulators plenty of extra voltage so they can "drop down" to the desired voltage. (But to not give them too much extra voltage, of course, else they will just waste power.)
Thanks for bringing back the memories!