# Is there a way to save state in a very low power way?

I basically want to determine if power has been totally disconnected in a low power device I am making that uses an Atmega328 chip.

The theory is that when power gets first applied the ATmega will power up, calibrate and take some readings then power down again. The rest of the circuit will still be powered until the chip wakes up again and takes more readings. What I need to be able to determine is if the battery was disconnected or not. If it was, I need to do a calibration again; if it wasn't, then I just take a reading as normal.

Is there any way of doing this which takes as little power as possible?

• Duplicate of How to make 1 bit permanent memory circuit? – Transistor Sep 24 '17 at 19:02
• Will the ATmega also be losing power? If so you can probably just calibrate on reset. If not, it seems like you want to be monitoring the power of the rest of the circuit. Done right, this should draw extremely little current. – Chris Stratton Sep 24 '17 at 19:10
• If the ATMega power is independant of the main supply, you can use some of the hints given there: electronics.stackexchange.com/questions/244335/… – dim Sep 24 '17 at 19:58
• Are you using Atmega with native tools, or with Arduino tools? That may be important for your strategy, because some aspects of low power operation are software-enabled. – Nick Alexeev Sep 24 '17 at 21:34
• Yes the ATmega will also lose power. The other articles mentioned are very interesting and I will take some time to go through them thanks. – SpeedOfSpin Sep 25 '17 at 7:34

So you can perform your inizialization routines in the very first part of your main() function.
When you finished doing your periodic measurements, do not remove power to the ATmega. Instead, put it in power-down or power-save mode through the sleep instruction.
This will draw less than $1 \mu A$ @25°C. When the wakeup interrupt occurs (e.g. timer expiration, external pin etc.), the interrupt will be executed and the program will restart from the instruction that follows sleep. In this way you can avoid any external hardware.