VCC shutdown detect

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

Hi!

I have a ATMega128 and 5V VCC.
I would like the AVR to "detect" power out.

I do have one example, where there is voltage divider before the VCC regulator (regulator input is 12V) and a fairly large cap to give the MCU time to shutdown.

The problem is, when I'm using battery power, the regulator is not used and hence I can not use the voltage divider neither.

I also guess the Vref changes too if the VCC goes low?

So how can I detect (reliably) that the voltage has dropped below acceptable level?

Any code examples? ISR AD or what?

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

Use a diode and a large cap. Tie the input power to an external interrupt input (high priority) through a series resistor. To test to see how much time you have, toggle an I/O pin forever in the interrupt routine. Watch the I/O pin on a scope. I did this once and had lots of time to write several bytes to EEPROM with 5X time to spare.

official AVR Consultant
www.veruslogic.com

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

Unless you have an external Brown Out Detector (BOD) circuit you should have the internal BOD enabled and set BODLEVEL for 4 volts since you are using 5 volt Vcc on the non-L mega128 version. There may be some variability because the internal brown out voltage isn't precise (data sheet Table 19. Reset Characteristics).

If you want more Vcc level headroom for power fail (much nicer for battery usage), use an ATmega128L at no more than 8 MHz clock. Then you can use a 2.6 volt BOD level. If you want better battery usage move up to an ATmega1281 which has slightly lower power consumption or look for suitable Pico power AVR chips for serious power saving.

For a simple hookup from a battery that doesn't use power draining voltage divider resistors, try this. You can use the internal bandgap as an ADC input with AVcc as the internal ADC reference (put a cap on the AREF pin and do not connect it to anything else). Sudden power fail detection would require a high clock rate on the ADC (1 MHz is the maximum with only 8 bit resolution, but you probably don't need to go near the maximum), auto ADC triggering/sampling and ADC completion interrupts. Slow power change detection can be much more leisurely and less power hungry without using interrupts or auto triggering.

A second voltage divider network (keep the AVR pin voltages below the Vcc + 0.5 volt maximum at all times) could connect the 12 volt regulator input to an ADC input pin.

You may find the battery ADC hookup above works well enough all by itself for both the battery and regulator (if you have a large enough power capacitor on the Vcc side of the regulator to provide a slow decay). Individual calibration would be required for each board, probably with a correction value stored in EEPROM.

If your processor sleeps a lot to save power, then you could probably setup your software so it doesn't care if power fails during sleep?

Another simpler, but more power consuming option, is to configure the Analog Comparator (AC) using external voltage divider resistors to adjust the external power level trigger to at the AC bandgap reference level. The AC will interrupt if it triggers. This would be better/quicker for short term event detection, but not as good for a small battery. I assume the voltage regulator is jumpered/switched out of the circuit when using the battery (so as not to load the Vcc lines with an unpowered regulator output). Since you have two voltage sources, the AC option would require a jumpered/switched power source with different voltage dividers as well.

With two power sources you could implement both ADC and AC solutions, the ADC for battery and AC for 12 volt power.

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

you can use the internal vref (probably 2.56v or 1.1v) and a voltage divider. I'm not sure what using a regulator has to do with it. a voltage divider is gonna use some current which you may not want on a battery powered device so perhaps you can use another pin, set it high, read the voltage from the divider at certain increments. depending on the overall power usage of the device you're probably gonna need a pretty big capacitor

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

Check out a similar discussion on this subject.

https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=74697