Low power shutdown/failure/t'is quittin' time ...

I suppose this could apply to a bunch of stuff, but this is specific to what I'm doing here. It might help someone else out though. I have a 328p that's running a sketch that's using two pins acting as DATA and CLK, driving a bunch of WS2801 LED drivers. The 328p as well as the LED strings are both powered via Vin. Now, when the battery voltage drops too low, the Atmel quits, or shuts off. However, because the LED string is powered separately, that will stay on (till the batteries go completely dead), and stuck on whatever the last command was.

Now, programmatically, I can send 0x0's down the string and the LEDs will shut off - the string is still powered, but nothing is lit. Is there a way to do that when the Atmel shuts off? (In other words, does the Atmel, at any time, know when it's about to die?)

Or should I be looking at an external solution (to the Atmel) that can detect when the Atmel goes 'kerplunk' and it kills power to the LED strings? Then there's the issue of the batteries possibly regenerating just enough juice to restart the Atmel again ... I wouldn't want that to happen ... once dead, it needs to stay dead till I replace the batteries.

To solve this, I run a voltage divider circuit from my battery to an analog input pin. It needs to be divided down so that the max voltage on Vbatt equals the voltage on your board (presumably 5V).

In this particular circuit, I'm using a 1M/470 combo, which gets 15V down to 5V.


Battery Voltage Measurement.sch by maniacbug, on Flickr

HOLD THE PHONE!

I just realized something ... it's not the Atmel that's quitting, it's the 5V regulator. So forget everything I said earlier about the Atmel. The regulator is quitting when V*bat* gets too low for it to function properly, however since the string is powered directly from V*bat, it kills the Atmel, but the string remains lit. So I need to rethink this. Need to figure out a way to also kill Vbat* going to the string when the regulator cuts power to the Atmel and related electronics.

The processor has brown-out detection in it, but maniacbug's suggestion of monitoring the Vbat line might be the way to go for you.

Yeah, BOD won't work in this case because it's the regulator that quits, not the Atmel itself. So I'm thinking maybe a small relay of sorts that's connected to one of the pins on the Atmel. Bring the pin high and the relay provides Vbat to the string. If the Atmel dies, that pin will go low, relay will shut off Vbat to the string.

Other suggestions besides a voltage divider or my idea above?

What is the range for Vbat?

A transistor that the processor has to drive high for the LEDs to work (a MOSFET or something)?

Can you get rid of the voltage regulator?

Vbat is 4x AA batteries. A fresh set measures about 6.4V.

The Atmel isn't driving the LEDs directly. It's driving a bunch of WS2801 via a DATA and CLK pin. Those will in turn drive the LEDs. This is why the LED string is powered directly from Vbat, while the Atmel is powered from the regulator.

Come to think of it, it doesn't matter what I end up doing with the different components in the circuit, ultimately I still need to drop that 6Vbat down to at the very minimum, 5Vreg. I can also drop it to 3.3Vreg (I thought the RF module needed 5V, turns out I can power it between 3.3V to 7V) Still, I need a regulator to handle that.

The initial problem is still there though, how to cut Vbat from the string once the Atmel dies, since the string is powered from Vbat, not Vreg.

What would be ideal is something like a LiPo protection circuit that completely cuts off power when the voltage is lower than a certain point, right? Then you just have to set it for above whatever the BOD is set at (+~1.5 for the regulator) and they should shut off at the same time.

That would work, though the cut off would have to be somewhere around 3.0V - any lower and the RF module dies.

Another thought as I keep pondering this ... the regulator I'm using has an ENable pin. As long as that pin is high, it's working. Bring the pin low and the regulator shuts off. What if I wire that pin to one of the Atmel pins and use that to cut the power? I know, it's a chicken and egg problem ... Atmel can't bring it high because there's no power and there's no power because the pin isn't high. But, couldn't I wire a momentary switch in parallel from Vbat to the ENable pin, and push it to kick-start the regulator which in turn starts the Atmel which then brings (and keeps) the pin high till it quits?

And once it quits, it stays down regardless of what the batteries are doing, at least till someone hits the switch again?

What's wrong with that theory?

[ an hour later ]
Now that I think about it some more ... that would put the full Vbat voltage onto the Atmel's pin when I push the button, and then to bring the Atmel's pin also high ... I smell disaster.

You can do that if you isolate the AVR pin from the high V, say with a high-side FET in parallel with the switch.


Rob

I'd say the best bet is for the AVR to monitor the input voltage to the regulator through an appropriate voltage divider or whatever. Some experimentation may be needed to determine at what level the regulator gives up, and then program the AVR to react at a slightly higher level, perhaps by going to sleep after it shuts down the LEDs. With a nominal 6V input to a 5V regulator, there may not be a lot of headroom to play with, even with LDO regulators. If this project is not a one-off, then individual calibration may be needed to avoid unreasonably early shut-down decisions. If it's not an LDO regulator, the input voltage could be borderline-insufficient even with fresh batteries.

The BOD is probably not a solution, because it just basically holds the AVR in a reset state once Vcc falls below a certain trigger point, and does not supply an "early warning".

I've done some minor modifications now. Originally it was 6Vbat going to a 5V regulator and that still got me plenty of usage, upwards of 10 hours. For what this project is for, that's about 4x more than what's really needed. However, I too realized that's a small margin to work with, so I've since then replaced the regulator for a 3.3V one. Everything in the circuit can function as low as 3.3V so I'm okay there. That will give me a bit more breathing room as well ...

And I think you are correct, I may just have to do a quick and dirty voltage divider and have the Atmel read that in and go from there.

Another thought: what about using a diode on the Atmel's pin, so that when the switch is pushed, power doesn't feed into the Atmel. I suspect I would need one on the pin at the switch, or just after as well, so the voltage coming from the Atmel doesn't feed back into Vbat and cause all kinds of nastiness ...

Without knowing the exact regulator, would something like this work? No switch. The pullup resistor keeps the regulator enabled until the MCU drives the pin connected to the transistor high. GPIO pins are inputs at reset time, so until the pin is configured as an output and driven high, the regulator stays enabled. When the MCU decides it's quittin' time, it drives its control pin high and goes to sleep.

sch1.jpg

It's the MIC5205 regulator. Its ENable pin needs to be driven HIGH to enable it, or LOW to shut it off.

KirAsh4:
It's the MIC5205 regulator. Its ENable pin needs to be driven HIGH to enable it, or LOW to shut it off.

Yep, I might try that circuit then. I also see the dropout voltage is 165mV at the max current output of 150mA, so not bad.

Where I'm uncertain is when you say the MCU drives its pin high when it quits. When the MCU quits, it shuts down, doesn't drive anything high ... they just go bye-bye.

Oh wait, maybe I'm going in circles here. Hmmm...