From 03eaef2c8fb91bfb1c48d03cebe0eba287fc2690 Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 11 Feb 2020 16:04:25 -0800 Subject: [PATCH] power measurement work --- TODO.md | 4 +++- src/main.ino | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index c7db5373..9d42be13 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,7 @@ # High priority +* platformio sdkconfig CONFIG_PM and turn on modem sleep mode +* finish power measurements and est battery life * have node info screen show real info (including time since last contact, distance and heading) * make debug info screen show real data (including battery level & charging) * make real implementation of getNumOnlineNodes @@ -27,7 +29,7 @@ * keep cpu 100% in sleep (some sort - deep?) Sleep until irq from radio wakes it (make plan based on power draw spreadsheet). Then stay awake for 30 secs to attempt delivery to phone. * have radiohead ISR send messages to RX queue directly, to allow that thread to block until we have something to send -* use https://lastminuteengineers.com/esp32-sleep-modes-power-consumption/ association sleep pattern to save power - but see https://github.com/espressif/esp-idf/issues/2070 +* use https://lastminuteengineers.com/esp32-sleep-modes-power-consumption/ association sleep pattern to save power - but see https://github.com/espressif/esp-idf/issues/2070 and https://esp32.com/viewtopic.php?f=13&t=12182 it seems with BLE on the 'easy' draw people are getting is 80mA * stop using loop() instead use a job queue and let cpu sleep * move lora rx/tx to own thread and block on IO * measure power consumption and calculate battery life assuming no deep sleep diff --git a/src/main.ino b/src/main.ino index 1414a9c7..95bc3bfa 100644 --- a/src/main.ino +++ b/src/main.ino @@ -145,6 +145,23 @@ void doDeepSleep(uint64_t msecToWake) esp_deep_sleep_start(); // TBD mA sleep current (battery) } +#include "esp32/pm.h" +#include "esp_pm.h" + +/** + * enable modem sleep mode as needed and available. Should lower our CPU current draw to an average of about 20mA. + * + * per https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/power_management.html + */ +void enableModemSleep() { + static esp_pm_config_esp32_t config; // filled with zeros because bss + + config.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ; + config.min_freq_mhz = 10; // 10Mhz is minimum recommended + config.light_sleep_enable = false; + DEBUG_MSG("Sleep request result %x\n", esp_pm_configure(&config)); +} + void sleep() { #ifdef SLEEP_MSECS @@ -366,6 +383,8 @@ void setup() BLEServer *serve = initBLE(getDeviceName(), HW_VENDOR, APP_VERSION); // FIXME, use a real name based on the macaddr createMeshBluetoothService(serve); } + + enableModemSleep(); } void loop() @@ -425,6 +444,7 @@ void loop() if (!wasPressed) { // just started a new press DEBUG_MSG("pressing\n"); + esp_pm_dump_locks(stdout); // FIXME, do this someplace better wasPressed = true; minPressMs = millis() + 3000; screen_press();