Using the built-in comparator 0 of C8051F310 to realize power-down mode

Publisher:郑哥Latest update time:2011-01-23 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
In the fields of measurement and control, it is often required that the data in the internal RAM of the microcontroller is not lost when the power is off, and the data in the RAM can be kept intact when the power is restored, and the system can continue to execute the program after the power is restored. The built-in comparator 0 of the C8051F310 microcontroller is used to detect the power supply voltage in real time. When the main power is off, the comparator 0 interrupt service program is executed to save the content of the special function register, and the microcontroller is placed in power-off mode to reduce power consumption. The microcontroller is powered by a backup battery to keep the data in the RAM from being lost.

Based on the following points of C8051F310 microcontroller, the content to be discussed in this article is proposed and has been tested experimentally.

① The C8051F310 microcontroller enters power-down mode, the CPU stops running, all interrupts and timers (except the clock loss detector) are inactive, and the internal oscillator is stopped (the analog peripherals remain in the selected state, and the external oscillator is not affected). The data in the RAM can be kept unchanged when the supply voltage is greater than 1.5 V, and the power consumption is extremely low, with a current of less than 0.1 μA.
② There are two voltage comparators inside the C8051F31x device, and interrupts can be generated on both the rising and falling edges of the comparator output. The response time of the comparator is programmable, and the positive and negative hysteresis voltages of the comparator are also configurable.
③ The output of the comparator can be synchronized with the system clock or asynchronous. Even when the system clock stops, the comparator asynchronous output CP0A signal is still available, which allows the comparator to work and generate output when the device is in shutdown mode. When disabled, the power supply current of the comparator drops to less than 100 nA.
④ After C8051F310 is running, the contents of the internal data memory do not change during reset, and the data stored before reset remains unchanged. The data in the stack does not change.

Click here to view the image in a new window
Figure 1 MCU power supply and voltage detection principle

In the design of C8051F310 system, a battery is used as a backup power source (the battery voltage is greater than the RAM data retention voltage of C8051F310, 1.5 V). The principle of microcontroller power supply and voltage detection is shown in Figure 1. When the main power supply is normal, adjust the potentiometer so that the voltage at the CP0+ terminal is slightly greater than the voltage at the CP0- terminal. The voltage detection part has two functions: one is to provide an analog input signal for the built-in comparator of the microcontroller; the other is that the output of the operational amplifier drives the LED light to indicate that the main power supply is normal. CP0A can also be connected to the port pin through a cross switch to replace the power amplifier driving the power indicator light in Figure 1. The prerequisite is that the comparator is not disabled before entering the power-down mode and the battery voltage is greater than the minimum operating voltage of the microcontroller, which will increase the battery power consumption during power-down.

When the main power supply VCC is normal, the main power supply voltage is higher than the battery voltage, and the system is powered by the main power supply. When the main power supply voltage drops or is lost due to an accident, comparator 0 sends a power-off interrupt request to the microcontroller. The microcontroller responds to the interrupt and uses the remaining power stored in the filter capacitor on the main power supply to enter and execute the interrupt service subroutine in the shortest time. In the interrupt service subroutine, the contents of some special function registers that must be protected are saved to RAM (the stack area can be used), and analog peripherals such as comparators and analog-to-digital conversion are turned off to reduce power consumption. Finally, a power-off protection mark is established and the microcontroller enters the shutdown working state. After the main power is restored, the microcontroller performs a power-on reset and continues to execute the program from the breakpoint at the time of power failure.

The power-off flag must use the addressable bit in RAM (located at 20H~2FH units), because when the microcontroller is reset, the general flag in the special function register is reset. In the shutdown mode, the internal oscillator, CPU and all digital peripherals stop working, but the state of the external oscillator circuit is not affected. Therefore, it is recommended to use the internal oscillator when designing a low-power system; or use an external oscillator and switch to the internal oscillator in the power-off interrupt service program to further reduce battery consumption in power-off mode. According to Figure 1, the built-in comparator 0 is configured as a falling edge interrupt. The positive and negative hysteresis voltages are configured as 0, and the response time is preferably configured as mode 0. The comparator 0 interrupt service subroutine flow is shown in Figure 2.

Click here to view the image in a new window
Figure 2 Comparator 0 interrupt service routine flow

Click here to view the image in a new window
Figure 3 Main program flow

The main program flow is shown in Figure 3.

When using the power-down mode of the C8051F310 microcontroller, the following three points should be noted:

① Disable WDT (power monitor): prevent the microcontroller from being reset when the battery voltage is greater than the RAM data retention voltage but less than Vrst (microcontroller VDD monitor threshold voltage) after entering power-down mode, causing the microcontroller to be unable to continue executing the program from the breakpoint.
② In the case where the battery voltage is greater than Vrst in power-down mode, the clock loss detector should be disabled. In this way, when power is lost, the microcontroller is kept in power-down mode for a long time, extending the battery life. If the clock loss detector must be used on site, the clock can be selected from an off-chip oscillator, so that the clock is not lost even in power-down mode.
③ Disable comparator 0 reset.

Reference address:Using the built-in comparator 0 of C8051F310 to realize power-down mode

Previous article:Design of intelligent node of vehicle CAN bus based on C8051F040
Next article:Temperature display circuit based on DS18B20 and 89C2051

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号