MCU Low power design (i) theory
Keywords: MCU low power consumption, stm8l low power, energy saving tips
A. MCU energy dissipation factor
Modern MCUs typically use CMOS technology, which includes 2 aspects of energy consumption:
The static consumption mainly is the transistor consumes the energy;
Dynamic consumption formula =CXV2XF, where C is the load capacitance of the CMOS, V is the supply voltage, F is the clock frequency;
Total power consumption is the sum of static consumption and dynamic consumption, i.e.: Idd=fxidynamicrun[ua/mhz]+istatic[ua].
Therefore, the power consumption depends on:
The size of the MCU chip or the number of transistors;
MCU supply voltage reduction voltage can be reduced to a square level of power consumption;
clock frequency can reduce the clock frequency to just meet the needs of the application;
The number of peripherals to enable more peripherals, the greater the energy consumption;
operating mode a reasonable choice of operating mode can greatly save energy, such as full-speed work extremely short time after entering sleep mode.
two. Energy Saving Method
1. Turn off the peripherals that you do not need to use;
2. All unused pins must be connected to a certain logic level;
3. Use the wait mode to obtain low power when a peripheral must remain active;
4. Use the appropriate VDD value;
5. Use low-power operation mode as much as possible;
6. If you cannot use low-power mode, then reduce the frequency to meet the minimum value of the application;
7. If possible, use the pull-up function that dynamically controls the I/O pin.
three. Low power mode
MCUs that support low power consumption typically have several operating modes, with St's stm8l as an example, which supports 5 low-power modes: Wait, low-power operation, low-power wait, active stop, and stop. Each mode of entry mode, energy-saving level and peripheral work requirements, summary table 1:
Table 1 stm8l Low-power operation mode
Mode |
Wait |
Low power operation |
Low power wait |
Active stop |
Stop it |
Entrance |
WFI |
WFE |
Software code |
Software Code +WFE |
HALT |
HALT |
Crystal |
open |
open |
LSI or LSE |
LSI or LSE |
LSI or LSE |
off |
Cpu |
Off |
Off |
Open |
Off |
Off |
Off |
Peripherals |
Open |
Open |
Open |
Open |
Off, only RTC Open |
Off |
wake-up |
All internal and external interrupts, reset |
all internal and external interrupts, resets, wake-up events |
software code, reset |
Span style= "font-size:18px" > internal and external events, reset |
external interrupt, RTC Interrupt, reset |
external interrupt, reset |
voltage regulator |
MVR |
MVR |
ulp |
ulp |
CLK_ICKCR |
ulp |
program execution area |
flash |
flash |
ram |
ram |
flash |
flash |
Flash+e2 |
Open |
Open |
Off |
Off |
Off |
Off |
Interrupt |
Allow |
Allow |
Ban |
Ban |
Allow |
Allow |
return status after interrupt service |
al=0:main al=1:wfi |
wfe |
/ |
/ |
al=0:main al=1 active stop |
al=0:main al=1: Stop |
event processing returns status |
/ |
main |
/ |
low power operation |
/ |
/ |
ram+ Register |
Keep |
Keep |
Keep |
Keep |
Keep |
Keep |
@3v/25℃ |
5.9uA |
5.4uA |
3.3uA |
1.0uA |
0.4uA |
Special matters |
/ |
/ |
Disable ADC |
/ |
Clear the peripheral suspension interrupt flag bit |
These low-power operating modes are a bit more for developers, especially if they are just touching the stm8l processor. We need general guidelines, and table 2 is the experience derived from practice.
Table 2 Choosing a reasonable stm8l energy saving mode
Energy Saving requirements |
Application situations |
Sleep duration |
Wake-up mode |
Recovery duration |
Operating mode |
Harsh |
CPU idle, waiting for external signal to wake up |
Long |
External interrupt |
≥2.8us |
HALT |
Harsh |
CPU idle, waiting for clock cycle to wake up |
Long |
RTC Cycle |
≥2.8us |
Active-halt |
Strict |
CPU has continuous, micro-load task run |
/ |
/ |
≥2.8us |
Low power operation |
Strict |
CPU briefly waits for interrupts to occur |
Short |
Arbitrary interrupts |
Short |
Wait for interrupt |
Strict |
CPU briefly waits for events to occur |
Short |
Registering events |
Short |
Wait for event |
Need |
CPU has a continuous, light load task running |
/ |
/ |
/ |
Adjust the frequency |
Four. Little-known tricks1. Save energy by using wait to replace queries
The common query method is as follows, at this time the CPU has nothing to dry, in vain power consumption.
ADC_CR1 = Adc_start; /* Start conversion */
while (!) ( ADC_SR & ADC_SR_EOC)); /* Wait for EOC bit set */
You can use wait events to save power.
First configure the ADC as the source of the event and enable the appropriate interrupts:
WFE_CR2 = Adc_comp_ev; /* Enable ADC as a source of event */
ADC_CR1 = Adc_eocie; /* Enable interrupt for end of conversion */
When the ADC conversion is complete, wake the waiting CPU:
ADC_CR1 = Adc_start; /* Start conversion */
_asm ("Wfe"); /* Enter wait mode until waked by adc_eocie*/
2. Interrupt mode without context switching
When the application is designed, if all the interrupt events are done by the ISR, you can save power by saving the Al position in the CFG_GCR register: Avoid saving/Recovering the context, without the main program running (return to WFI mode), as shown in 1.
Figure 1 Interrupt without context switch in WFI mode
The method of saving electricity in the AL position 1 can also be used in the halt mode, as shown in the Principle 2.
Figure 2 Interrupt without context switch in halt mode
3. Dynamically set the pull-up function of I/O port
Many applications require keystrokes as human-computer interfaces, and the keys are generally connected to I/O. When the key is not active, the I/O port sets the internal pull-up to obtain the determined logic level; Once the key is pressed, the I/O port will generate an additional 40~70ua current, which is very important for low battery power consumption.
Can dynamically control the pull-up of the I/O port to achieve energy-saving purposes: Once the key press, the interrupt service program will prohibit the pull-up function of the I/O port, and then the software timed execution-first enable pull-up function, and then detect I/O port status, if the key is still pressed again prohibit pull-up function, otherwise The entire logic is shown in 3:
Figure 3 Energy saving by dynamically setting the pull-up of I/O ports
4. CPU Idle Energy Saving policy
CPU idle energy is shown in 4, and its logic consists of the following steps:
(1) The discovery of CPU idle: With OS system, performance for the task no event needs to respond, or into the idle process, no OS system, the performance of the program run the end.
(2) Select a suitable CPU energy-saving mode: Chip_enterlowpower () complete the preparation before entering energy saving, including: Turn off peripheral, switch I/O pin to power saving state.
(3) exiting the Power saving mode requires calling Chip_exitlowpower (), which can occur in the following 2 scenarios:
A. The ISR that needs to use the closed peripherals:
B. Exit directly from the process;
The aftermath of the Chip_exitlowpower () includes: enabling peripherals, switching I/O pins to the working state. In order to avoid ISR and process two operations Chip_exitlowpower (), the function sets the state variable to avoid repeated exits.
Figure 4 CPU Idle Energy Saving policy
Related articles:
MCU low Power Design (ii) practice
"MCU Low-power design (iii) products"
Author Profile:
Shu Jun, male, master, is currently the CEO of Changsha Communications Technology Co., Ltd.
Engaged in communication research and embedded development 10, the main focus on micro-power wireless network.
Proficient in Lora Wireless spread spectrum communication, wireless star/tree-type/mesh network design;
Proficient in contiki,linux,uc/os-ii,osal and other operating systems;
Familiar with arm,dsp,stm8,pic,pc104 and other processors;
Good at AD,RF and other integrated IC development.
Web:www.rimelink.com
Email: [email protected]
QQ Group: 35212129
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MCU Low power design (i) theory