How to solve the problem of power-on reset confusion in single-chip microcomputers
[Copy link]
In the application of single-chip microcomputer, it is often necessary to save the running data when the power is off (including manual shutdown and accidental external power failure). At present, the common method is to add a larger capacitor (generally more than 2000 μf, and some are in the farad level) to the single-chip microcomputer separately. After the external power is off, the electricity stored in the large capacitor is slowly discharged to provide the time required for the single-chip microcomputer to store data in the eeprom. The selected capacitor is small, the time provided is short, and the storage data is unreliable. The selected capacitor is large and the time provided is long, and the storage data is reliable. However, the problem that follows is that during the discharge of the capacitor after power failure, the power supply voltage of the single-chip microcomputer is slowly decreasing. When it reaches a certain value but has not yet dropped to the reset threshold voltage, if it is turned on again at this time, the single-chip microcomputer cannot start normally, resulting in confusion after the single-chip microcomputer is repeatedly powered on. The following is a detailed analysis of this process and a solution.
Let's first understand the power-on reset characteristics of AVR. The above table is the power-on reset parameters provided by the AVR data manual.
AVR reset characteristics
, that is, when the microcontroller is powered on, its power supply voltage must be lower than this value to reset the microcontroller. The normal working power supply voltage range of the microcontroller is 2.7~5.5V. When the power supply voltage is lower than 2.7V, the microcontroller has stopped working. If the voltage is higher than 1.3V at this time and it is powered on again, the microcontroller cannot be reset normally, resulting in work confusion. Power outages in some occasions may be instantaneous, including artificial power outages, which may be instantaneous. It may be powered on again within a few seconds, and the voltage of the microcontroller capacitor is just above the reset voltage and below the normal working voltage at this time, and the above phenomenon will occur. This is the situation I encountered in actual application.
It can be seen that although the data protection problem has been solved, it has brought new troubles. Therefore, when solving the data protection of the microcontroller when it is powered off, it should be noted that sufficient time should be guaranteed for data storage, and discharge should be done as soon as possible to ensure normal power-on.
The figure above is the circuit used in this article. In the figure, the AC power is input through CON2, and after rectification and filtering, it reaches the three-terminal voltage regulator block 7806 (note that 7806 is used here instead of 7805). The output of 7806 is sent to the microcontroller (cpu_v=5.3V) through dl, which is used to power the microcontroller alone. The power consumption of the microcontroller is usually less than 5 mA. Due to the use of C4 (2200μf) capacitor, the discharge time of this power supply is longer. Another power supply is sent to the circuit load through d2 (VCC=5.3V). Usually, the current of this power supply is larger, exceeding tens of mA.
In this way, after power failure, Vcc is discharged quickly due to the large discharge current and small filter capacitor, usually within a few milliseconds. As for the other cpu_v, the discharge is very slow due to the large filter capacitor and small discharge current, t>2200μf×10-6×5V/5ma×10-3=2.2s; Vcc is connected to the input ain0 of the microcontroller comparator through R4 and W2, and cpu_v is connected to the ain'I terminal of the microcontroller comparator through R6 and the voltage regulator (3.3V). When the circuit is working normally, adjust the potentiometer W2 so that the ain0 voltage is 0.2V greater than the ain1 voltage. When power is off (or power failure), ain0 drops faster and ainl drops slower. When ain0 is lower than ainl, the comparator flips. The flip of the AVR comparator can trigger an interrupt, and the eeprom data is saved in the interrupt. The working function of Q1 and the surrounding circuits in the figure is: when powered on for the first time, since the voltage across the capacitor C1 cannot change suddenly, the voltage of the b and e junctions of the transistor is OV, and it is in the cut-off state. The cut-off time depends on the time constants of Cl and R2. The parameters in this circuit can ensure that the cut-off time exceeds 10ms. Within this time, the CPU has entered the normal working state. The OUT terminal is set to "1" level in the program to continue to cut off the transistor. When a power outage occurs, the data is first stored in eep-rom, and then the out terminal is set to "0" level. The transistor is saturated and turned on, and the cpu_v power supply is immediately discharged. R3 is a current limiting resistor. In this way, the discharge time depends on R3 and C4, and the maximum
|