Store it Quickly 2.0 Schematic Circuit Diagram
Some microcontroller applications require status information or other important data to be stored to EEPROM immediately as a power to the equipment is turned off or fails. When power is resumed this information will then be available for use as required. To solve this problem Rainer Reusch developed a circuit (Figure 1) and it appeared in Elektor magazine as a Design Tip [1]. The principle behind this original circuit is that the voltage at the anode of D1 falls sooner than the voltage across reservoir capacitor C2. A comparator evaluates these levels and outputs a signal to the microcontroller indicating that the input voltage has fallen. Thanks to D1 and a C2 voltage at the non-inverting input to IC1.A falls faster than the voltage at the inverting input. This produces a Low level at the comparator output, triggering an interrupt. As long as there is sufficient energy stored in the reservoir capacitor, the microcontroller now has time to store all important data to EEPROM before the supply rail sinks too low.
The circuit functions effectively, at least in simple situations. One problem is that it takes a few milliseconds to write data to EEPROM cells. The value of C2 must, therefore, be larger than is strictly necessary since it must also act as a reservoir to supply the regulator when the input voltage falls. Apart from that the calculation of C1, for the ripple voltage is not so easy. Even more of a problem is if the power is supplied from a wall wart type adapter which includes built-in voltage regulation or switch-mode supply. In this case, the circuit cannot work because the voltage at the input to R1 does not fall fast enough thanks to the reservoir capacitors integrated into the adapter. These shortcomings led the author to set about tweaking the original design; the result can be seen in Figure 2 which is both a better and simpler solution. The comparator has now been moved to after the voltage regulator. With this configuration, we are comparing the input voltage with the voltage output from the regulator. We no longer need the diode in series with the voltage regulator. The reservoir capacitor C1 does not need to be so big now. The biggest improvement, however, is that now the circuit is not dependant on how quickly the input voltage falls. When the voltage from the power adapter sinks the level on the output of the regulator is held constant by regulatory action. When dimensioned correctly the voltage divider at the non-inverting input of the comparator produces an input voltage lower than the level at the inverting input, generating a low output to trigger an interrupt in the microcomputer.
The circuit values have been calculated assuming the mains adapter has a 9 V output and the voltage regulator produces 5 V. D1 protects the regulator from current flowing in the reverse direction. With C1 equal to 100 µF and a load current of 5 mA the microcontroller has at least 17 ms in which to store data to EEPROM. An edge-triggered interrupt is used here. When it is possible to disable power-hungry features of the microcontroller such as an A/D converters, that’ll give extra time to store data.
[1] Store it Quickly! Elektor January 2009, www.elektor.com/080379