当前位置:网站首页>Understand esp32 sleep mode and its power consumption

Understand esp32 sleep mode and its power consumption

2022-07-01 06:37:00 Morning breeze

Translated by Chen Tuo 2022/05/30-2022/05/30

original text https://lastminuteengineers.com/esp32-sleep-modes-power-consumption/

 

without doubt ,ESP32 It's a lot of WiFi/MCU SOC A strong competitor of , Often beat it in performance and price . however , According to its state ,ESP32 It may be a relatively power consuming device .

When your Internet of things project is powered by a plug on the wall , You often don't care much about power consumption . But if you plan to use batteries to power your project , Every milliampere is important .

The solution here is to use ESP32 A sleep mode to reduce its power consumption . For projects that do not need to be active all the time , This is really a good strategy to greatly extend battery life .

What is? ESP32 Sleep mode ?

ESP32 Sleep mode is a power-saving state ,ESP32 You can enter this state when not in use .ESP32 The state of remains RAM in . When ESP32 When entering sleep mode , The power supply of any unwanted digital peripheral devices will be cut off , and RAM The received power is just enough to retain data .

ESP32 Inside the chip

In order to understand ESP32 How to save energy , We need to know what is inside the chip . The image below shows ESP32 Functional block diagram of the chip .

 

ESP32 The core of the chip is a dual core 32 Bit microprocessor , with 448 KB Of ROM、520 KB Of SRAM and 4MB Flash memory .

It also contains WiFi modular 、 Bluetooth module 、 Encryption Accelerator ( A coprocessor designed to perform cryptographic operations )、RTC Modules and many peripherals .

ESP32 Power mode

because ESP32 Advanced power management , It provides 5 Configurable power modes . According to the power requirements , The chip can switch between different power modes . Patterns include :

  • Activity mode
  • Modem sleep mode
  • Light sleep mode
  • Deep sleep mode
  • Sleep mode

Each mode has its unique function and energy saving function . Let's take a look one by one .

ESP32 Activate mode

Normal mode is also called active mode . In this mode , All functions of the chip are active .

Because the active mode makes everything ( In especial WiFi modular 、 Processing core and Bluetooth module ) Always on , So the chip needs 240mA The above current can work . We also observed that , If used at the same time WiFi And Bluetooth , Sometimes high power peaks occur ( The maximum is 790mA).

 

If you look at ESP32 Data sheet , In case of RF operation , The power consumption in active power mode is as follows :

obviously , This is the most inefficient model , Will consume the most current . therefore , If we want to save electricity , We must disable them when not in use ( By using one of the other power modes ).

ESP32 Modem sleep

In modem sleep mode , Everything is active , And only WiFi、 Bluetooth and wireless communication are disabled .CPU It can also run , The clock can be configured .

In this mode , The chip consumes about... At low speed 3mA, Consumption at high speed 20mA.

 

In order to maintain WiFi/ Bluetooth connection is active ,CPUWi-Fi、 Bluetooth and wireless communication will wake up at predefined intervals . This is called associative sleep patterns .

During this sleep mode , Power mode switches between active mode and modem sleep mode .

ESP32 Only in order to Station Mode can enter the modem sleep mode only when it is connected to the router .ESP32 adopt DTIM The beacon mechanism keeps the connection with the router .

To save power ,ESP32 In two DTIM Between beacon intervals... Is disabled Wi-Fi modular , And automatically wake up before the next beacon arrives .

The sleep time is determined by the router DTIM Beacon interval determines , Usually it is 100ms To 1000ms.

What is? DTIM Beacon mechanism ?

DTIM It's English Delivery Traffic Indication Message abbreviation .

stay DTIM beacon (DTIM-Beacon) In mechanism , Access point (AP)/ The router sends beacon frames regularly . Each frame contains all the information about the network . It is used to announce the existence of wireless networks and synchronize all connected members .

ESP32 Light sleep

The working mode of light sleep is similar to modems Sleep works in a similar way . The chip also follows an associated sleep pattern .

The difference lies in , In light sleep mode , Digital peripherals 、 majority RAM and CPU All are clock gated .

What is clock gating ?

Clock gating is a technique to reduce dynamic power consumption .

It disables some circuits by turning off the clock pulse , In this way, the trigger in the circuit does not have to switch states . Switching states requires power consumption , If you don't switch , Power consumption will become zero .

In light sleep mode ,CPU Pause by turning off its clock , and RTC and ULP The coprocessor remains active . This results in lower power consumption than modem sleep mode ( about 0.8mA).

 

Before entering light sleep mode ,ESP32 Maintain its internal state , And resume operation after quitting sleep . It is called all RAM Retain .

esp_light_sleep_start() Function can be used to enter light sleep after configuring the wake-up source .

ESP32 Deep sleep

In deep sleep mode ,CPU、 Most of the RAM And all digital peripherals will be powered off . The only part of the chip that remains powered on is :RTC controller 、RTC Peripherals ( Include ULP Coprocessor ) and RTC Memory ( Slow and fast ).

The power consumption of the chip is about 0.15 mA( If ULP The coprocessor is powered ) to 10µA.

 

In deep sleep mode , Lord CPU power failure , and ULP The coprocessor measures the sensor according to the measured data of the sensor and wakes up the main system . This sleep pattern is called ULP Sensor monitoring mode .

except CPU outside , The main memory of the chip is also disabled . therefore , All contents stored in this memory will be erased , cannot access .

however ,RTC The memory remains powered on . therefore , Its contents are preserved during deep sleep , We can retrieve the chip after we wake it up . That's why , The chip is disabled Wi-Fi Before connecting data with Bluetooth , Will store it in RTC In the memory .

therefore , If you want to use data on reboot , Please define with RTC_DATA_ATTR Property to store it in RTC In the memory . for example ,RTC_DATA_ATTR int bootCount = 0;

In deep sleep mode , except RTC Outside the module , The power supply of the whole chip is cut off . therefore , Anything is not in RTC All data in the recovery memory will be lost , So the chip will restart by resetting . This means that the program is executed again from the beginning .

Tips

ESP32 Support running deep sleep wake-up stubs after deep sleep stub. This function runs immediately after the chip wakes up – Before any normal initialization , Boot loader code runs . After the wake-up stub runs , The chip can resume sleep or continue normal startup .

stub The official description of :

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/deep-sleep-stub.html

Different from other sleep patterns , The system cannot automatically enter deep sleep mode .esp_deep_sleep_start() Function can be used to enter deep sleep immediately after the wake source is configured .

By default ,ESP32 It will automatically turn off the power of peripheral devices that are not needed by the wake-up source . But you can choose to close / What peripherals are kept . For more information , Please check out API file :

https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/

To learn about ESP32 More about deep sleep and its wake-up sources , Please visit the following tutorial .

https://lastminuteengineers.com/esp32-deep-sleep-wakeup-sources/

ESP32 Deep sleep experiment

Here is my experimental article 《ESP32 How is the deep sleep current lower than 10uA》

https://zhuanlan.zhihu.com/p/521640890

https://blog.csdn.net/chentuo2000/article/details/125033711?spm=1001.2014.3001.5502

ESP32 Sleep mode

Different from deep sleep mode , In sleep mode , The chip also disables internal 8MHz Oscillator and ULP Coprocessor .RTC The recovery memory has also been powered off , This means that we cannot keep any data in sleep mode .

There is only one on the slow clock RTC Timers and some RTC GPIO Out of active ( They are responsible for waking the chip from sleep mode ), All other functions are turned off .

This further reduces power consumption . The chip only consumes about... In sleep mode 2.5µA.

 

原网站

版权声明
本文为[Morning breeze]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207010630010583.html