Brownout Detection

Here's a question for those who understand AVR chips inside and out. I've read that these chips have "brownout detection," though I've never found a good reference for how this is supposed to work. I'm wondering if brownout detection is entirely a hardware thing or if it is a state that can be read and acted upon by software (possibly requiring an end-run around the normal Arduino environment). Here's why I'm interested:

My current Arduino project has a "shutdown routine" wherein it writes certain data to EEPROM just before it goes dead (this is mostly to keep the EEPROM from being written to too often and exceeding its 100,000 write cycle limit, although it could have other useful features as well, depending on the answer to this question.)

If brownout detection can be read by software, it would be possible for the Arduino to execute its brief shutdown routine whenever power failed, since there is always enough power left in its discharging capacitors for it to run for a few seconds following a power failure. This brief source of power quickly falls to a level triggering brownout detection and then, if I can read this from software, I run my shutdown routine. Please tell me if this makes no sense at all. Thanks!

Take a look at section 10.5 (page 48) of the mega168 datasheet.

  • Ben

Provided you read to the end of the description you will see that the internal brown-out detection looks at the actual Vcc on the CPU and generates an internal reset when it is too low.

To do what you have described you need to monitor the incoming supply BEFORE the capacitors are storing the energy, possibly using one of the multitude of detector/reset generator chips on the market.