ATMEGA as RTC?

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

I see in teh ATMega64/128 specs that you can run the async oscillator in sleep mode to act as an RTC.

I looked on Atmel's web site, and found information on this usage, but not how to design a circuit for power-off operation.

Namely, how does one send power to the ATMEGA128 from a small coin battery to keep the RTC running, and sleep when main power is down, bringing the M128 back to life on power up?

My naive thoughts as an interrupt pin hooked to main power, with the battery and the main power attached to the ATMEGA128 via diodes to prevent battery from powering other things. Still, I doubt that's enough. Has anyone done this?

Alternatively, is there a small RTC option that folks use in lieu of using the M128 or M64 as an RTC?

Jim

Jim Brain

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

You wouldn't want to use that chip >>just<< as an RTC, for a number of reasons:

1) That family is an AVR generation or two back. Start with a V or P suffix chip, and you'll be able to keep an 8-bit timer and the 32k crystal running on a few uA.

2) It is a big mother chip, that costs US$6 to $10 in moderate quantities. "Real" RTCs cost a fraction of that.

There are a number of reasons to hang the 32k crystal on an AVR that is doing other AVR "stuff". But I don't think I'd develop an AVR app solely as an RTC--it isn't worth the effort and isn't cost effective.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I think I understand your question. This is the sequence of events I understand:

Device is fully powered from say a DC wall adapter
User unplugs wall adapter, power goes away
AVR realizes this and switches its power source to the battery
When the wall adapter is plugged back in the AVR resumes full power mode

You have the right idea - use a battery with a diode in-line to prevent it from powering anything when the wall jack is plugged in. Detecting when the wall jack is plugged in is the hard part. Without thinking too much I'd say use a comparator judge whether the wall jack is plugged in. Have the AVR monitor the comparator signal and when it goes low put it to sleep.

Let me know if this helps.

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

Most AVRs have a built-in comparator that can be used to monitor supply voltage, eg. main supply vs. backup battery. If you want to use a separate RTC chip, the DS1307 is a classic. Should run a long time on a small button cell or even a supercap. Ask Google to dig up a datasheet for you.

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

I've used DS1305 alot, and it's a good chip. Never used DS1307 but I'd guess it's very simular.

The DS1305/7 is antique before the battery runs out :)

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

I'd say take a look at the Butterfly kit. Should give you more than enough to think about.

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

To clarify, the M128 is doing other things, but I need a reliable time source that stay current during power outages.

sfriederichs: My main issue is the diode idea allows the coin cell to provide power when there is wall power available. I'd rather shut coin cell power off. Unless, if the coin cell is 3V or so, the diode would drop that to 2.3, and if my main V source is 5 volts, then the diode would have more potential on the cathode side when the power is on, preventing the coin cell from discharging. I've never dealt with RTC power requirements.

knutbr/blader: I grabbed a 1305 and 1307 datasheet, but I thought I'd see if there are others.

GroovBird: How would the Butterfly help? I already have a designed M128 board, I just need to do a rev on the PCB to add either a RTC or the 32kHz osc.

Jim Brain

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

Not sure how much I can say but you may not have to wait exactly a lifetime to see the Xmegas and you may find that they are better suited for RTC usage - the current involved in doing it could well turn out to be very attractive and might avoid the need to explore Dallas chips or whatever. Just speculation of course !

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

jbrain: Yes, it was my assumption that the battery would be 3.3V or so. Even if it was the same voltage as your main source the diode would still prevent it from drawing power. The main source would need to be about .7V less than the battery voltage for the diode to turn on and supply power.

If you're looking for other ideas you could use an SPDT IC switch like the CD4066 to switch between the two power sources. I don't like this idea as much because 1) you have to power the switch 2) these switches are sometimes hard to work with because of oscillations, etc.

Another idea is to rig up something more complicated than a simple diode using transistors, etc. You can have all sorts of biasing fun in a situation like that. I wouldn't even TRY to talk you through that sort of idea - you just have to scribble enough til you find a situation that works.

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

I had done some apps with ATmega64, 128 and 1281 that keep time with a LiPol batt, and from time to time, the uC wakes up part of the circuitry, does something, and then it goes back to sleep mode.

Not too difficult, a little job trying to reduce power from batteries, and it ended up lasting about one week powered from a (full charged) 3V7 550mAH LiPol batt. Precision in the order of 0.02%.

I simly used two schottky diodes to switch from 5VDC SMPS when mains present, or from batt when no mains. 3V3 linear LDO with powerdown input pin (ATmega controled), battery monitoring, and 'voilà'.

PS: Cliff, are you in possesion of certain privileged information about Xmega? Or are you trying to generate some expectation about this? ;) :P

Guillem.
"Common sense is the least common of the senses" Anonymous.

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

Guillem,

I had a visit from the "men from Atmel". In fact they had tried to arrange it before Christmas and the whole purpose of the sales pitch was to introduce the xmega and convince me that it'd be worth paying the $'s. You might be surprised about exactly how imminent they suggested the launch might be.

They also confirmed a lot of the details that had already been seen in early "leaked" PDF files - the chips have lots of goodies (a value of x3,000 and also one of 1% are looking particularly interesting!)

Cliff

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

jbrain wrote:

GroovBird: How would the Butterfly help? I already have a designed M128 board, I just need to do a rev on the PCB to add either a RTC or the 32kHz osc.

Well, it also uses a 32.768KHz to run a clock while it's sleeping, and the source code to the firmware is available, so it could be like an example you could use, right?

Dave

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

@Cliff:

Do you refer to this: http://electronix.ru/forum/index...
Speed x3, DMA, 'et alter'?

Perhaps that's a little bit overkill as a simple RTC...

Guillem.
"Common sense is the least common of the senses" Anonymous.

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

get a Maxim ds3232. Works quite good. Ask for samples :D . Cheap and accurate. I've got one running for almost a years and it's off by less than one second :mrgreen: .