May 20, 2011 by gcharris I'm looking to build an power cutoff state saver for a project. Basically when the atmega power is cut off this will be trigger an interrupt that will save some state data to eeprom. What do you guys think would be a sufficient value capacitor to power the atmega for long enough to write a few values to eeprom (three double values and an int)? I'm guessing I should also have a diode to stop the capacitor from powering other non-processor loads. Any suggestions on a type? Well the current to the uC will be too small to damage any diode, so any regular diode should do. it's the capacitor I worry about. Let's see... ATmega168's power consumption is about 250mA at 5V... That's 250mA*5V = 1.25mW of power. That means that it will use 1.25mJ per second. Energy stored on a capacitor is: ``````W = 1/2 * C * V * V where W = energy stored (Joules) C = capacitance (Farad) V = potential difference (Voltage) `````` So 1.25mJ = 1/2 * C * V2, and we know that V is 5.0V, making ``````1.25mJ = 0.5 * C * 5V * 5V 1.25mJ = 0.5 * 25 V^2 * C 1.25mJ = 12.5 V^2 * C C = 1.25mJ / 12.5 V^2 C = 100uF `````` You'll probably have to connect 2 47uF electrolytic capacitors in parallel to get 94uF capacitance. Also, as soon as you detect that the power has been cut off, first thing you should do is set all the pins as inputs. That will cut off any leaking power. From there one second should be enough to save everything. Once that works, you can find out how much exactly it takes to cut off all the pins, and save the data, and from there you should be able to recalculate needed capacitor value to provide you with enough power. But remember, capacitor's charge should still be well above the brown-out voltage, otherwise uC will turn off. Thanks! I'll keep you posted on my progress.