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 power 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 stored data is unreliable. The selected capacitor is large and the time provided is long, and the stored data is reliable. However, the problem that follows is that during the capacitor discharge process 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 table above is the power-on reset parameters provided by the AVR data sheet.
AVR reset characteristics
From the table above, we can see that the typical threshold voltage for power-on reset is 1.4V and 1.3V, 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. In some occasions, power outages may be instantaneous, including artificial power outages, which may be instantaneous. It may be powered on again within a few seconds, and at this time the voltage of the microcontroller capacitor is just above the reset voltage and below the normal working voltage, and the above phenomenon will occur. This is the situation I encountered in actual applications.
It can be seen that although the data protection problem has been solved, it has brought new troubles. Therefore, when solving the data protection problem of the microcontroller when it is powered off, it should be noted that sufficient time should be ensured for data storage, and the data should be discharged as soon as possible to ensure normal power-on.
The figure above is the circuit used in this article. In the figure, AC power is input through CON2, and reaches the three-terminal voltage regulator block 7806 (note that 7806 is used instead of 7805 here) after rectification and filtering. 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 (VCC=5.3V) through d2. Usually, the current of this power supply is larger, exceeding tens of mA.
In this way, after power failure, Vcc discharges quickly due to the large discharge current and small filter capacitor, usually within a few milliseconds. The other cpu_v discharges very slowly 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 terminal 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 failure (or power outage) occurs, ain0 drops quickly and ainl drops slowly. 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 the 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.
Previous article:The design of perpetual calendar program based on AVR microcontroller
Next article:Serial communication between AVR microcontroller USART and PC
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Max30102 heart rate blood oxygen sensor measuring heart rate problem
- 【Mil MYS-8MMX】Part 2: WIFI connection network
- It's too late if you don't buy it now! Choose this gift for Children's Day and both parents and children will be happy
- [Raspberry Pi Pico Review] Unable to identify USB serial port
- Design and Implementation of Secondary Bootloader for TMS320C6000 Series
- What exactly is the input and output voltage range of an operational amplifier?
- Micropython version that supports MCPWM function
- How to solve the problem of No rule to make target when developing zynq using xilinx SDK
- Design of control system for CNC engraving machine based on embedded system
- Development environment installation (II) Cross-compilation environment