|
| 1 | +| Supported Targets | ESP32-H2 | ESP32-P4 | |
| 2 | +| ----------------- | -------- | -------- | |
| 3 | + |
| 4 | +# VBAT Example |
| 5 | + |
| 6 | +(See the README.md file in the upper level 'examples' directory for more information about examples.) |
| 7 | + |
| 8 | +When the application is idle and the chip enters deepsleep, you may want to turn off the main power to save power (because the main power usually also drives other power-consuming devices on the board), but you also want the ESP chip to maintain the RTC timing and wake-up functions. Or you want to enter deepsleep mode that only maintains RTC timing but with another power supply when the main power is about to undervoltage. In these cases, you can use this feature, which allows the chip to switch to backup battery power when entering deepsleep. |
| 9 | + |
| 10 | +This example demonstrates the ESP backup battery power supply solution, which has the following features: |
| 11 | + |
| 12 | + - Supports using backup power (VBAT) during deepsleep, and RTC Timer can keep timing after the main power is lost. |
| 13 | + - Supports automatic power switching by PMU during sleep/wake-up, automatically switches to backup power supply when entering sleep mode and switches to main power supply when waking up. |
| 14 | + - Support battery voltage detection, wake up the chip and switch to the main power supply when undervoltage occurs. |
| 15 | + - Support battery charging, automatically stop charging when threshold voltage is reached, and charging current can be configured. |
| 16 | + - Supports selection of chip status when charging the battery, options include keep active, entering lightsleep or entering deepsleep. |
| 17 | + |
| 18 | +## How to use example |
| 19 | + |
| 20 | +### Hardware Required |
| 21 | + |
| 22 | +This example should be run on a development board with a backup battery. Currently the following development boards are supported: |
| 23 | + - [ESP32-P4-Function-EV-Board Rev](https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32p4/esp32-p4-function-ev-board/index.html#esp32-p4-function-ev-board) |
| 24 | + |
| 25 | +``` |
| 26 | + 0(%1)NC ┌──────────┐ |
| 27 | + BAT ─────^^^^─────┐ │ │ |
| 28 | + │ │ │ |
| 29 | + │ │ ESP32-P4 │ |
| 30 | + │ │ │ |
| 31 | + ESP_3V3 ─────^^^^─────┴────┤VBAT │ |
| 32 | + 0(%1) └──────────┘ |
| 33 | +``` |
| 34 | + |
| 35 | +By default, the ESP_VBAT power supply on this development board is shorted to ESP_3V3 through a 0 Ω resistor. |
| 36 | + |
| 37 | +**You need to re-solder the resistor 0 Ω on ESP_3V3 to the empty pad on BAT. (You can find the resistor position on the schematic doc of the development board). Then connect `RTC_Battery +` to the positive terminal of the battery and `RTC_Battery -` to the negative terminal of the battery.** |
| 38 | + |
| 39 | +### Configure the project |
| 40 | + |
| 41 | +``` |
| 42 | +idf.py menuconfig |
| 43 | +``` |
| 44 | + |
| 45 | +- If you are using a non-rechargeable battery, VBAT brownout wakeup can be enabled via `Component config → Hardware Settings → Power Supplier → RTC Backup Battery`. |
| 46 | +- If you are using a rechargeable battery, the automatic wake-up charging feature can be enabled via `Component config → Hardware Settings → Power Supplier → RTC Backup Battery -> The battery for RTC battery is a rechargeable battery`. |
| 47 | +- The charging current limiting resistor can be configured via `Component config → Hardware Settings → Power Supplier → RTC Backup Battery -> vbat charger circuit resistor value (ohms)`. |
| 48 | +- The chip state while waiting for battery charging the battery can be selected by `Example Configuration → Configure the chip state while waiting for battery charging`. |
| 49 | +- The period to check whether the battery has been charged done can be selected by `Battery charging done check period (in seconds)`. |
| 50 | + |
| 51 | +### Build and Flash |
| 52 | + |
| 53 | +Build the project and flash it to the board, then run monitor tool to view serial output: |
| 54 | + |
| 55 | +``` |
| 56 | +idf.py -p PORT flash monitor |
| 57 | +``` |
| 58 | + |
| 59 | +(Replace PORT with the name of the serial port to use.) |
| 60 | + |
| 61 | +(To exit the serial monitor, type ``Ctrl-]``.) |
| 62 | + |
| 63 | +See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. |
| 64 | + |
| 65 | +## Example Output |
| 66 | + |
| 67 | +On initial startup, this example will detect that this is the first boot and output the following log: |
| 68 | + |
| 69 | +``` |
| 70 | +... |
| 71 | +I (271) main_task: Started on CPU0 |
| 72 | +I (281) main_task: Calling app_main() |
| 73 | +Not a deep sleep reset |
| 74 | +Current RTC Time: 110106 (us) |
| 75 | +Entering deep sleep |
| 76 | +``` |
| 77 | + |
| 78 | +Then the chip will then enter deep sleep, and switch to VBAT power supply. |
| 79 | + |
| 80 | +If non-rechargeable battery is used, nothing will happens when VBAT is undervoltage by default, but if `CONFIG_ESP_VBAT_WAKEUP_CHIP_ON_VBAT_BROWNOUT` is enabled, when the battery voltage drops to the configured brownout threshold `ESP_VBAT_BROWNOUT_DET_LVL_SEL`, the chip will wake up and go to sleep again, but will not switch to VBAT power during deepsleep. |
| 81 | + |
| 82 | +``` |
| 83 | +W VBAT: RTC battery voltage low, please change battery... |
| 84 | +Battery is low, VBAT power will not be used during deep sleep! |
| 85 | +Current RTC Time: 18493666 (us) |
| 86 | +Entering deep sleep |
| 87 | +``` |
| 88 | + |
| 89 | +If rechargeable battery is used, when the battery voltage drops to the configured charging threshold (`CONFIG_ESP_VBAT_DET_LVL_LOW_SEL`), the chip will wake up and start charge the battery, when the battery voltage rises to the configured stop charging threshold (`CONFIG_ESP_VBAT_DET_LVL_HIGH_SEL`), the chip will stop charging the battery and re-enter deepsleep, and so on. The following log will be output: |
| 90 | + |
| 91 | +``` |
| 92 | +... |
| 93 | +W VBAT: RTC battery voltage low, start charging... |
| 94 | +Wake up from Low power VBAT |
| 95 | +Battery is low, waiting for charging to complete before going to sleep! |
| 96 | +W VBAT: RTC battery voltage reaches high limit , stop charging... |
| 97 | +Current RTC Time: 20753113 (us) |
| 98 | +Entering deep sleep |
| 99 | +... |
| 100 | +``` |
0 commit comments