Sleep mode and Supercap

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

I've run into a problem that I can't seem to solve.
Since I'm not a HW guy, maybe there's a simple solution that I'm unaware of.

The problem:
I have a project where I need to maintain time.
Using 32.768KHz crystal mounted to TOSC1.2.
If Mains power is lost I need to keep RTC running.
Mains will probably be back after some hours.
Decided to use a Supercap to run AVR in sleep mode only awakening to tick time.
Sleep mode consume only 0.3µA. Very nice.

Since other devices are connected to 5v I need to isolate them from AVR 5v.
I have tried two different approaches.

1. Using a Schottky in btw "main" 5v and AVR 5v supply.
This works but AVR supply voltage is 0.3 V smaller than "outside" 5v.
Disadvantages are:
Supercap never get charged to 5v, so I loose some of its capacity.
Having signals fed into AVR 0.3 V higher than AVR's supply feels uncomfortable. Datasheet says Vcc +0.5 is the limit.
8 ADC inputs are used, with bias reistors connected to main 5v. Not using same voltage for AVR means all my thermistor calculated values will be off and need recalculation.
I believe Schottky diodes have a small leakage that will consume some of the stored charge in Supercap(not sure about this).

2. Decided to use a relay.
This would give AVR same voltage as "main" 5v.
All disadvantages described above gone.
Problem is I can't turn off the relay...
Since Supercap is connected to "main" supply it will feed relay coil with its charged current.

Am I missing something obvious?
What would you suggest?

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

Sense the mains voltage (ADC or comparator) and use I/O port to control logic level FET that switches 5v to non-AVR components.

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

Use two diodes.
One to cap + avr
One to other circuitry.
Still have the diode drop, but everybody is running on same voltage.

If you have a voltage regulator, tweak it's output to compensate for the diode drop. (for example, add yet another diode in series with the gnd/sense pin on a 78xx series regulator).

-carl

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

Reconsider your choice of using the AVR as an RTC. A separate RTC chip with backup battery (some can also do tickle charging) not only provides the time, but also isolation between the main power and the backup power.

Stealing Proteus doesn't make you an engineer.

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

This is my new favourite typo :lol:

Quote:
tickle charging

Thank you Arnold :lol:

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

Quote:
Use two diodes.
One to cap + avr
One to other circuitry.
Still have the diode drop, but everybody is running on same voltage.

That will do the trick.
Like you say I can crank up the regulator a bit to compensate for the diode drop.
Thanks!

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

Small cheap latching relays are available. The single coil type require reversing polarity
to set and reset the relay. Dual coil type have separate coils for set and reset.
These are an obvious choice for battery powered thermostats.

Omron - Signal Relay Product Brochure

This is interesting
Omron - Technical Information Datasheet

Stan

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

Quote:
Sleep mode consume only 0.3µA.

Which AVR do you use? At what voltages? Even with pico-power technology and with the lowest voltage possible (1.8V) this is half of the datasheet specification.. Are you sure about the current? Where did you get the information from?

Another question: What super-cap do you use, or another way: How long black-outs do you expect?

No RSTDISBL, no fun!

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

Hello Brutte,

I thought this thread had died in peace.

Quote:
Which AVR do you use? At what voltages?
I use m164P at appx 4.85 Volt.

Was a bit surprised that the current consumption was that low, especially since it's mounted on a breadboard.
Even more surprising was that when I removed another DVM that measured the voltage while sleeping, the single decimal went to zero (00.0µA), thus making actual value impossible to read.

I actually have two 164P mounted on same breadboard.
They measured 0.6µA when both was connected to same voltage supply, (one connected measured 0.3µA).

The caps are 0.47F
http://www.futurlec.com/Capacito...
I have two mounted on the breadboard, since the finished app will have one m164 and one supercap on each PCB.
I do not expect power to be out for more than a few hours or possibly 24 hrs.
I need to keep RTC working during the black out, so twice a sec TCNT2 ISR awakes m164 and a pin is tested to see if power returned.
BOD temporarily off, Watchdog disabled, ADC disabled. All pins except power sensing pin low outputs. I use internal osc, therefore Power Down Mode is used.

I do not know how reliable my DVM measuring current is. Prize around $100, so it's neither the cheapest nor the most expensive. I have never measured such low currents before, but in general the DVM have been pretty accurate.

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

Actually my datasheet for mega164P says typically 0.17µA @3V (with WDT disabled).

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

Guys, several weeks ago I was involved in a pointless discussion about count of timers in ATMega1284 and the conclusion was I downloaded the datasheet that had an error..

To avoid such stupid misunderstandings:

ATMega164P, rev. M, page 327, table 25-1:
"Power-save mode, TOSC on, Vcc=1.8V->500nA, 3V->600nA typically" (with everything but RTC off).

Quote:
Actually my datasheet for mega164P says typically 0.17µA @3V (with WDT disabled).

Could you please give me some reference about such low current consumption RTC? It is lower than original standalone microchip RTC's (typically 200nA)!

Quote:
the single decimal went to zero (00.0µA), thus making actual value impossible to read.

Perhaps it is because you have a simplified auto-range DVM (it does not switch shunt resistor, but only gain). Modify your software so that AVR consumes equal current all the measuring time (cli and put it permanently into power-save with RTC running) and use a regular DVM with switched shunt resistor.

I use the cheapest 4$ digital multimeter (1%, 12 bits ADC) but on the lowest range of 200uA it has a shunt resistor of 1.1k - I am able to sense 100nA (with poor accuracy).

If you expect 24H blackout and your AVR-RTC consumes average constant current of 0.6uA), then it needs 0.6e-6*60*60*24=~5.2e-2 coulombs of charge. Your supercap 0.47F*4.85V gives 2.27 coulombs of charge, of which only some part can be consumed (<70%) before voltage drops below 1.8V. Anyway, 0.7*2.27/5.2e-2 gives about 30.5 times the value required. With 0.3uA consumption the difference is 60 times that high.

Monster, not a super-cap.

No RSTDISBL, no fun!

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

I've had products that run the RTC with a M168 and a supercap for some time now, and after some tweaking I can achieve at least 48 hours from a 0.33F (and have known them to still have the right time after 5 days). The CPU/cap is just isolated from the main 5V supply with a regular silicon diode, so it runs at about 4.5V.

I found two things extended the sleep life enormously, so for the benefit of anyone trying to do the same thing, here they are:

1. Get into sleep mode as soon as possible when the power goes off. At first I just used a sense input tied to the 5V supply, but when the power went off the chip's VCC followed the main 5V down to some level below 2V because of the supercap's internal resistance, taking the input threshold with it. So the CPU didn't detect the 5V loss and go to sleep until the cap was partly discharged. The supercap voltage recovered back to nearly 5V once sleep started, so this went unnoticed for some time. The solution was to use a supervisor chip (MCP130-475) on the main 5V for early detection. This pulls the detect pin to an unambiguous 0V as soon as the 5V starts to drop.

2. Turn the clock speed down in sleep mode with the clock prescaler. This may seem pointless, but after the interrupt wakes the CPU up it has to stay awake for a whole timer clock period doing nothing except waiting for a register to clear. If it spends the waiting time running at 8MHz, it consumes more power during that brief waking than in a whole second of sleep. If the last thing you do before putting it to sleep is set the clock prescaler to some high value like 256, the CPU spends many fewer cycles at much reduced power waiting for the timer tick, and its endurance increases dramatically. When the 5V is restored, set the prescaler back to its running value.

I've tried many times to measure the current during CPU sleep, and never been able to get a good reading even with quite sophisticated instruments. All I can say is the data sheet spec must be a worst-case and the actual consumption can be considerably less.

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

Quote:
The CPU/cap is just isolated from the main 5V supply with a regular silicon diode, so it runs at about 4.5V.

There are specialized schottky pair diodes for that. This gives 0.5V higher voltage and lets you extend usable range significantly (instead 4.5-1.8=2.7V you have 3.2V which lets you use over 20% smaller cap than with silicone diode).

Quote:
At first I just used a sense input tied to the 5V supply

You should have sensed the voltage of the power source (just before Groetz bridge). Usually linear stabilizers have ripple voltage rejection cap - this one should provide enough energy for worst case ISR scenario. Luckily AVRs have highest priority level interrupt(second after reset).

Quote:
it has to stay awake for a whole timer clock period doing nothing except waiting for a register to clear.

Actually the datasheet says:
Quote:
The interrupt logic needs one TOSC1 cycle to be reset.
so it is one clock of the 32kHz quartz and not timer (which is prescaled) because TOSC1 is the name of the physical pin.

With 4MHz F_CPU (max for full 1.8-5.5V range) one RTC clock gives 1/2^15 [s] which gives 122 cpu clocks. It is definitely more than needed to perform a simple variable increment. In asm this could be made with a single "adiw temp,1" command (+ISR+reti+sleep). 20 clocks maximum.
Did anybody tried to overcome this? Double ISRs waking cpu?

Quote:
All I can say is the data sheet spec must be a worst-case and the actual consumption can be considerably less.

The datasheet specifies 600nA max, at full temperature range, but I suppose if Lennart states it is 170nA, he must have found it or at least experienced it somewhere..

Quote:
I've tried many times to measure the current during CPU sleep, and never been able to get a good reading

Because you can do it neither with fixed shunt resistor (too small current), nor with switched one, when CPU wakes up every second (huge voltage drop on shunt resistor). Put AVR into sleep for all measuring time, use DVM with switched shunt resistor and you can catch the measurement without problem.

Besides, ATMega168 is not even pico-power, so RTC consumes 10uA in the deepest sleep!

No RSTDISBL, no fun!

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

Quote:
Could you please give me some reference about such low current consumption RTC?

I visited Atmel's site and tried to download datasheet for 164P. Something is broken and download crashes.
Looking at Atmel's site they offer Rev A, updated 1/10.
Already have this...
On p.329 Table 27.3
Power-down Mode WDT disabled Vcc=3V Typial 0.17µA Max 2.0µA.

I've tried to control my DVM with 10M resistor. It's in the ballpark but not accurate to claim anything except it's low consumption while running on Supercap.

I haven't really reached the point where exact measurement is meaningful. I have to switch AVR model to AT90USB1287 which seem to consume a bit more and I'm still on the breadboard and not 100 percent sure what final hardware will look like.
Right now I have one 1287 and one 164 on the board. It took quite some effort to solder 1287 to an extension board and solder 40+ wires with connectors at other end.
Since a couple of days there's also a microSD card on the board instead of the DataFlash that used to live there.
So at the present moment i'm banging my head against the changes needed in software for that.

My prime goal with Supercap was to see if it could replace a litium cell, thereby saving on component cost.
I liked the small footprint and the price of the ones I've bought.
Might switch to smaller when I get a better grip of final hardware.

@Peret

I don't see any dip in voltage when power goes out.
Maybe it's happening so fast that my DVM can't catch it.
How fast was the dip you had? Milliseconds?

I did see a dip in early stages, but I played around with both software and hardware since I never used sleep modes before and voltage dip is now a few millivolts when power goes off. As it seems...
I have BAT42 Schottky diodes from regulator both to "main Vcc" and AVR Vcc(to get same voltage levels).

Thanks for the advices regarding clock speed.
When I've soldered the second USB1287 and connected to board I will have another go with sleep mode power consumption.

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

Quote:
Power-down Mode WDT disabled Vcc=3V Typial 0.17µA Max 2.0µA.

From some time we are discussing running AVR and RTC from carbon capacitor. You cannot run AVR and its asynchronous timer in power-down sleep mode.

Quote:
I have to switch AVR model to AT90USB1287

These are not pico power and they have significantly higher power consumption. You cannot control BOR run-time then.

Quote:
My prime goal with Supercap was to see if it could replace a litium cell, thereby saving on component cost.

Even with external RTC and electrolytic cap, 24h is not a problem. I think still much cheaper than cell.

Quote:
So at the present moment i'm banging my head against the changes needed in software for that.

Then it is the best moment to move to ARM. AVRs are proprietary.

No RSTDISBL, no fun!

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

Quote:
when the power went off the chip's VCC followed the main 5V down to some level below 2V because of the supercap's internal resistance, taking the input threshold with it. So the CPU didn't detect the 5V loss and go to sleep until the cap was partly discharged.
One of the things I added to get things going was a 47K pull-down resistor on power sense pin.
I sense the 5V on INT0 low level, disable INT0 and re-enable global interrupts to stay in INT0 ISR while sleeping.

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

Quote:
From some time we are discussing running AVR and RTC from carbon capacitor. You cannot run AVR and its asynchronous timer in power-down sleep mode.
Indeed, Power Save Mode is the one I'm using.
So 0.6µA is the figure. Who cares with a Monstercap-)
Quote:
Then it is the best moment to move to ARM. AVRs are proprietary.
So am I...

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

Thank you for your insights, Brutte. You are quite correct in what the data sheet says about the TOSC cycle, but how would you know a TOSC cycle had passed, except by waiting for a register to clear? The conventional way is like so:

; timer 2 needs one external clock cycle (34us) to complete update.
; Entering sleep again before update complete leaves the int flag set
        sts     OCR2B,zero              ; a dummy write	
p_restore_wait:
        lds     r24,ASSR                ; wait till busy bits clear
        andi    r24,0x1f                ; which takes 1 clock
        brne    p_restore_wait

I avoid the waste of power simply by slowing the clock down enough that it takes more than 34us to service the interrupt, check that the power is still off and go back to sleep.

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

Quote:
But how would you know a TOSC cycle had passed,

I did not know about the bug till yesterday, but it seems irrational to design RTC which behaves that way - it should have been made energy efficient, with the lowest energy consumption possible.
My proposition is to use OCR2 ISR (output compare register) in normal asynchronous mode. When you set TCNT2 period to 2s (prescaller=256) and OCR2 to 128, then timer will trigger OCIE2 after a second, then TOIE2 after the next one, then after a second OCIE2, then after a second TOIE2, then after a second OCIE2 and so on...

You can collect these two interrupt vectors into one ISR code and it seems there will be no need to know if TOSC have passed and wait for 122 clocks and complete it in max 20. Current interrupt logic will be reinitialized after a second, during sibling ISR wake-up.

I did not test it, it is just a suggestion. I have JTAG ICE MK1 and ATMega16 with RTC, but have no idea how to halt RTC while debugging to test it. Perhaps if I clocked TCNT2 externally with other timer? Debugging RTC is cunning because almost all its registers are mirrored.

No RSTDISBL, no fun!

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

Just out of interest :
What made you decide to use the AVR as rtc and not to use an external rtc with battery or supercap ?

For a design I did last year I chose for an external rtc because I was afraid the power consumption issue would 'infect' many routines in my uP. Also I was afraid testing the rtc would take much effort. Ok, the PCB did have several costly components so the RTC was only 2% extra component costs.

Were my expectations right ? Is it a pain in the a.. to make a software RTC running reliable or was I overconcerned ?

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

There were many discussions about internal/external RTCs on the forum and it seems that for low volume production external RTC is much more suitable solution. The major problem with internal one is to power down uC and disable any power consuming elements ASAP after black-out. This is made automatically with external RTC and must be made "by hand" with internal RTC, using power-save mode. This is not impossible, but requires careful calculations with a design. Such code requires much more attention with debugging, but has the advantage of keeping all the variables intact(NV-RAM).

No RSTDISBL, no fun!

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

One word of warning - if you use the popular DS1307 RTC, you cannot use a supercap for backup. This is because the DS1307 will not come out of power-down mode unless its Vcc is somewhat higher than Vbat. From the data sheet,

Quote:
The nominal power-fail trip point (VPF) voltage at which access to the RTC and user RAM is denied is set by the internal circuitry as 1.25 x VBAT nominal.

In other words, if you're running at 5V the Vbat terminal must be lower than 4V, or else the device will not respond to I2C, even to acknowledge its presence. Since a supercap will eventually charge all the way up to Vcc, even with a diode in the path, you can only use it if you make other arrangements for charging it, such as from a resistive divider. It's generally better to use a lithium battery. A CR2032 will keep it running until, hmm, about 2032.