Battery backup not holding time in RTC chip

Go To Last Post
37 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi I have installed a number of PCBs (approx 50) with an Atmega162 taking time of day from a DS1337 and displaying this on 7 segment displays.
The RTC is backed up by a lithium cell battery (CR2032) to store the time when the unit is powered off/power failure.

Everything was working fine with no problems until a few of the more recent installations seems to be loosing the time.

These are all installed in a location where a power failure is simulated once a week and a backup generator kicks in.

Does it sound likely that there is something in the gererator supply that the chips may not be used in the usual mains supply (230VAC 50 HZ) like a spike or harmonic?

The power supply on the PCB is transformer to approx 15 V then rectified in a chip and 5 V regulator to give 5VDC.

Or another reason could be the more than usual frequency of power off/on. I have seen this in an installation before that turned off automatically every night and on in the morning, seemed to drain the battery very quickly. To get around this i programed the chip to swich on and start at 0900 each morning.

Planning to go to the installation tomorrow but would be interested to hear anybodys thoughts as to what else may be the problem...

Thanks

Justin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But the DS1337 does not have a external battery backup pin.

So how does it get backup power from battery? Maybe main power drops off and it pulls DS1337 VCC pin down briefly too?

What if it does not like the fact that I2C SDA/SCL pins are then low too, when there is no main power?

What if AVR resets while reading from RTC chip, so the RTC chip is driving data to the bus, so AVR can't even transmit a start condition when it goes out of reset?

Very little info, and even from that, very many things can go wrong here.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is brown-out-detection enabled?

What is connected to the CR2032? Only VCC of DS1337? If you have the pullups according to the typical operating circuit as shown in the datasheet, it could be discharged, if INTA or INTB are connected to other compontents (as ATmega162)?

/Martin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mtaschl wrote:
If you have the pullups according to the typical operating circuit as shown in the datasheet, it could be discharged, if INTA or INTB are connected to other compontents (as ATmega162)?

Good point. Pull-up resistors should be on the AVR VCC side, not on the RTC VCC side. Unpowered AVR tries to suck power through pull-up resistors and protection diodes to VCC.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why use a 1337 and a kludged CR2032 battery when you could be using a 1307 with its proper backup battery design that doesn't power other parts of your circuit?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is the layout of the schematic for that part of the circuit.
The SCL and SDA pins are connected to the AVR (bitbang) and the SQW is connected to PCINT10 C2.

This works fine 99% of the time.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

...but there are pullup resistors on the SDA and SCL lines somewhere as well?

What are those diodes for after the regulator?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To be honest Im not sure, I didnt design the board, i programmed the chip.
No at present there are not pullup resistors on the SDA and SCL line and I know they should be there and why they should be there but it was kinda the same thing, the desgn of the PCB works.

The last time there was a re spin of the board, i made sure they included spare pads to allow for additional pullups in these locations if there was ever a problem arose from their absence.

Do you think this could be the reason?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

justint wrote:
To be honest Im not sure, I didnt design the board, i programmed the chip.
No at present there are not pullup resistors on the SDA and SCL line and I know they should be there and why they should be there but it was kinda the same thing, the desgn of the PCB works.

The last time there was a re spin of the board, i made sure they included spare pads to allow for additional pullups in these locations if there was ever a problem arose from their absence.

Do you think this could be the reason?

Yes.

So you have a bit-banged I2C, do you do illegal push-pull operations on the line too or does it magically work without pull-up resistors 99% of the time by using leakage currents?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
What are those diodes for after the regulator?
They would be causing a voltage drop to supply the 1337 vcc to keep it within spec. A simple trick!

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gregsmithcts wrote:
Quote:
What are those diodes for after the regulator?
They would be causing a voltage drop to supply the 1337 vcc to keep it within spec. A simple trick!

Within what spec? Two of them just drops more voltage while single diode would suffice. It's a 5V chip after all.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
t's a 5V chip after all.
Really? The data sheet I looked at say's it has a max Vcc of 4 volts. Anyway, i was answering the question, not validating the circuits design.

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gregsmithcts wrote:
Quote:
t's a 5V chip after all.
Really? The data sheet I looked at say's it has a max Vcc of 4 volts. Anyway, i was answering the question, not validating the circuits design.

Which datasheet would that be? I have here the Maxim DS1337 datasheet which says it is good for 5.5V operation, absolute max being 6V. Do I have the wrong device type or is it a some subtype of DS1337 or from different manufacturer?

If it really is a max 4V device, then it has already went kaboom, as it won't consume anywhere near 1mA, and two shottky diodes won't drop even near 800mV at 1mA.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

http://pdf1.alldatasheet.com/datasheet-pdf/view/58488/DALLAS/DS1337.html
This one.
Anyway, why on earth are you making an issue about this? What else could the diodes possibly be there for? Perhaps I should have phrased it 'recommended spec' ?

As my sig say's 'Just learning' -- so why would the designer put them in, if not to drop the voltage?

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gregsmithcts wrote:
-- so why would the designer put them in, if not to drop the voltage?
Perhaps for the same reason that this designer did the other loopy things, like omitting the I2C pullups, hanging a 100K/30+uA load across the supply rail, putting a resistor in series with the backup battery. Let's face it, the design is sub-standard and another go is needed.

Please don't tell me the design is good for 99 percent of the time. It FAILS 100 percent of the time when the regular power source is removed!

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Perhaps for the same reason that this designer did the other loopy things, like omitting the I2C pullups, hanging a 100K/30+uA load across the supply rai

Ok, what am I missing here, I saw only the schematic of the 1337 and it's supply.
I answered the question 'What are those diodes for after the regulator? ' as best as I could. I still don't see that my answer to that question is wrong? Is it? I can't comment (nor would I) about the entire circuit, as I've not seen it. I'm still learning about about circuit design and uC's in general. Is the entire circuit design schematic available in this post somewhere? And, no, I personally would not jury rig a backup supply to a chip which was not designed to accommodate one (at least, not like that). But that is not the question I was addressing.
It rather seems that peeps think I'm validating the design, WHICH I AM NOT!!! I was just trying to answer the question asked, which was 'What are those diodes for after the regulator? ' Now, if somebody has another answer, I'd be very happy to hear it. (And I still maintain they are there to drop the Vcc to the 1337 to below 4 volts).

BTW.. none of this actually helps the OP in solving his problem!

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You may be on track here, you read datasheet version 012003 which does have 4V maximum, while I read a datasheet version 7/09 directly from manufacturer website which has 5V maximum.

So based on that, maybe that is why the diodes are there, trying to drop the voltage from 5V to 4V, but as far as I can tell they fail at the job (because they are Schottky diodes so about 0.3V drop per diode), and look suspicious. Thus the question what they do there, or trying to do, was a bit rhetorical and we can't know for sure, so there is no right or wrong answer in my opinion.

What the real problem (Again!) is that a hardware designer does sloppy job and software engineers have to live with that, compensating quirks in software.

If the I2C bus specification says there must be resistors on the bus, then there must be, and that is final. Another thing is if it can be compensated with software tricks, and to some extent it may be possible. And my answer to that is, not reliably on an AVR, as you can't have reliable transitions on bus that has to go through lo-hiz-pullup or pullup-hiz-lo sequence. Stray capacitance may help a bit. Some people also use push-pull SCL output, but it requires that all other chips never try to drive SCL.

Edit: Actually that battery-resistor-diode is somewhat valid, as seen from some Dallas/Maxim datasheets. Schottky diodes have quite a big leakage current, and the resistor limits charging of battery from regulated 5V when available. It may even be some kind of UL requirement to have both.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
So based on that, maybe that is why the diodes are there, trying to drop the voltage from 5V to 4V, but as far as I can tell they fail at the job (because they are Schottky diodes so about 0.3V drop per diode), and look suspicious. Thus the question what they do there, or trying to do, was a bit rhetorical and we can't know for sure, so there is no right or wrong answer in my opinion.

Ok. :) the data sheet I looked at for the diodes suggested that they could drop a forward voltage upto 650mv (depending on current) which would result in vcc of 3.7 volts.

I won't argue with your other points as I myself am a software engineer and admit to still learning about circuit design. Friends? :)

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gregsmithcts wrote:

Ok. :) the data sheet I looked at for the diodes suggested that they could drop a forward voltage upto 650mv (depending on current) which would result in vcc of 3.7 volts.

You are right, the drop is max 650mV per diode at 20mA current, but the RTC chip does not consume even 1mA. Diode has minimum drop of 260mV at 2mA, so even if the RTC chip consumed 2mA, the voltage could still be 4.48V.

gregsmithcts wrote:

I won't argue with your other points as I myself am a software engineer and admit to still learning about circuit design. Friends? :)

It is unfortunate that us software engineers need to be the ones that tell hardware engineers what works and what does not. So it is a good thing to get involved in hardware design reviews so that you have a chance to point out hardware guys how to connect microcontroller pins the optimally and what is possible with software and what must be done in hardware. Friends! :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok thanks for the comments. It seems that the main issue to tackle is to add in the pullups and change the bit bang programming accordingly.

Quote:
It FAILS 100 percent of the time when the regular power source is removed!

This is not the case, in most applications, the time IS battery backed up in the RTC. the unit has been off for weeks at a time and continued on as normal when switched on.

Im not sure what you mena when you say 'illegal'??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

justint wrote:
Ok thanks for the comments. It seems that the main issue to tackle is to add in the pullups and change the bit bang programming accordingly.

Im not sure what you mena when you say 'illegal'??

Why do you need to change bit-bang programming if only pull-ups are added? So you have used the AVR IO pins to output logic high, haven't you?

By illegal bus use I mean you must never ever force a logic high on the bus by setting AVR pin as output high, as it is an open-collector bus.

Devices are only allowed to pull bus low, or let it float high with the resistors. Otherwise there is a chance your AVR pulls high while slave chip pulls low, so there is a shortcut of two drivers fighting and extraneous current flowing through IO pins.

Chips do not need to operate reliably under those conditions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
What else could the diodes possibly be there for?
To keep the battery from feeding voltage back into the regulator when the AC power is removed. But, a single diode would have done that.
Quote:
and the resistor limits charging of battery from regulated 5V when available
The power supply can't charge the battery. The diode connected to the battery prevents that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bphillips wrote:
Quote:
What else could the diodes possibly be there for?
To keep the battery from feeding voltage back into the regulator when the AC power is removed. But, a single diode would have done that.
Quote:
and the resistor limits charging of battery from regulated 5V when available
The power supply can't charge the battery. The diode connected to the battery prevents that.

I already said the battery resistor *may* be because of UL safety requirements. Safety requirements say you must have either resistor or another diode there as a backup solution if single diode fails.

And no the Schottky diode is not enough to prevent charging, as safety requirements need less than 1uA of charging current, and the diode itself cannot guarantee that if the device is used in ambient temperature is larger than about 60C.

Same with the two VCC diodes - either they are required by safety regulations or it is a bad way to try to drop voltage.

We don't know why, we can only speculate.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
To keep the battery from feeding voltage back into the regulator when the AC power is removed.

Very good point, obvious, but I missed it :) Too focused on the voltage drop idea!
Quote:
We don't know why, we can only speculate.

That's what makes it 'fun' :)

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fortunately, the schematic shows you're not using /INTA, so you can change over to a DS1307 and cure this problem once and for all at the next board spin. Meantime you can drop a DS1307 in the same footprint to test it. Pull out the diode and resistor in series with the battery and connect it (the battery) directly to pin 3, and short out the other two diodes to supply full 5V to pin 8. With a couple of lines of firmware change you're done.

There are other similar clock chips that fit this same footprint, eg M41T82 (ST Microelectronics) and FM3130 (Ramtron), but they're more complicated to drive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

^^^^
..the best idea so far :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I have added the pullup resistors and chaged my bit bang program to open collector mode.
Everything is as it was before but the communication lines are not being driven high or low.

I am also using the SQW output from the DS1337 as a pin change interrupt to refresh my display and also as a stable time base. I know the data sheet shows a pullup on this line also but do I need it if the pin on the AVR is always configured as an input?

Have taken a look at the DS1307 and can see the difference in terms of battery backup.

Will probably go with what we are using at the moment for RTC/battery back up but will definetly look into you recommendations as an option for future spins. Will alter a few existing boards as described and test over a period of time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

justint wrote:
I know the data sheet shows a pullup on this line also but do I need it if the pin on the AVR is always configured as an input?
No that will be fine. Just ignore what the datasheet says ... hell what would Maxim know about electronics. Just don't come crying to us in a few weeks when it doesn't work. :lol:

Hint: The /SQW output is an open collector transistor. It only has one active state ... pulled to ground. The other state if floating.

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looks like the battery is not only backing up the clock as it should. It's backing up also the rest of the circiut which results in drainig your battery very quickly.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:
justint wrote:
I know the data sheet shows a pullup on this line also but do I need it if the pin on the AVR is always configured as an input?
No that will be fine. Just ignore what the datasheet says ... hell what would Maxim know about electronics. Just don't come crying to us in a few weeks when it doesn't work. :lol:

Hint: The /SQW output is an open collector transistor. It only has one active state ... pulled to ground. The other state if floating.

Ok I get it, your sarchasm speaks volumes. Lesson learned I suppose.

Ill include the pullup in a newer spin of the board.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

(the question should have been "can I use the internal pullup resistor on the input pin rather than the external pullup?" - to which the answer is more debatable (but I wouldn't do it personally))

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, that is what is being done at present, im looking into having it changed.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since you're using the square wave as a stable timing interrupt, you should use a pullup of 10k or so. No doubt it will work using just the internal pullup, but depending on the stray capacitance, you may get a shark-fin rising edge with a jittery switching point.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

justint wrote:
Ok I get it, your sarchasm speaks volumes. Lesson learned I suppose.

Ill include the pullup in a newer spin of the board.

Apologies. I guess I couldn't resist using sarcasm as my "educational tool of choice" on this occasion. I'm a "monkey see, monkey do" kind of learner myself.

Best of luck.

Ross

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Apologies. I guess I couldn't resist using sarcasm as my "educational tool of choice" on this occasion. I'm a "monkey see, monkey do" kind of learner myself.

No problem, I suppose it will stick in my mind better now after a bit of banter about it :)

Will let you know how things go after I have changed the hardware.

Thanks for the comments.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I assume, the CPU does some crazy things during power up or power down and thus the RTC was corrupted.

To avoid this, you should wait a while after power on and implement an early power fail to finish the current I2C transfer correctly.

An early power fail detection can be implemented in software by using VCC as reference and measure the internal band-gap (but only on AVRs with internal ADC).

Another solution, you read the RTC only once after power up and then count date/time internal with the main crystal (e.g. 12MHz) of the CPU (assuming, you use a crystal but not the internal RC clock).

Peter

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've had this issue on a HPw8000 for ages but have putup with it by keeping power conected at all times. Recently I had a very close look at the battery holder and can see that when I replaced the battery years ago I actually bent the contacts so no power was being supplied to the MoBo bent yhem back and now all is OK. If you have a mu;timeter its easy to check this/