Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AVR Power Failure Detection?

Not open for further replies.


Full Member level 1
Jul 1, 2007
Reaction score
Trophy points
Activity points
i am frequently writing some data to external nvram to be kept there during the power failure time.
i want the micro to understand the start of power failing and not to write anything in nvram during this period so that the data couldn't be corrupted.
plz give me a solution.

Re: avr power failure detection?

The answer depends.

Do you need some time between failure detection and actual power loss to finish data storage, or is your storage format prepared for safe recovery from interruption at any point, including a single corrupted data word?

The latter is possible but must be well considered. In the former case, you need a "pre-powerfail" signal, e.g. derived from a voltage comparator supervising the unregulated supply voltage and suffcient filter capacitors to allow µC operation for xx milliseconds.

Define Fault condition threshold and means of control available.
Power management ICs or comparator with logic level and battery backup.... or?

Windows uses journalling to keep track of scheduled writes and safe completes to all disk drives on the disk so a readback of scheduled addresses completed and the next values incomplete can be completed when power resumes. This may be more cumbersome than a battery backup.

Re: avr power failure detection?

No other software solution???not to add any hardware part.

Your original question refers to the power failure detection, and there is no other way do do that before the event occur without probing it as FvM mentioned.

At the firmware side you could do that once by exiting the ORG vector, but the failure event would be detected just after the system restart, too late. If you have enough storage space, could manage 2 equal arrays, being valid the last one saved.

I read the rotation of motor from an encoder and save it in a ds1307 ram that is backed up with a battery and every time that the system restart it will start through the saved position of motor in ds1307 . during writing data in every step in ds1307' ram if the system lose power I think it might cause corrupted data in the ram so my question is that the avr doesn't have any ability to sense the power supply voltage and if it goes Below a predefined value doesn't let the micro to write to external memory

I never used AVR, but at some uC's you can detect it by specific internal registers.
See datasheet to see if there is some kind of flag at this core.

Not open for further replies.

Part and Inventory Search

Welcome to