From 7ff1b7c86be4451e55821fcec3a8939469e3c6fb Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Fri, 3 Jul 2026 09:51:32 +0200 Subject: [PATCH] =?UTF-8?q?fix(wio-tracker-l1):=20battery=20voltage=20read?= =?UTF-8?q?s=20high/jittery=20=E2=80=94=20divider=20always=20on?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The per-read VBAT_ENABLE gating from 4d46abb2 (energy optimizations) powered the battery voltage divider HIGH for only 10ms before each ADC read, then LOW. 10ms is too short for the high-impedance divider node to settle before the nRF52 SAADC samples it, so readings came out high and inconsistent (e.g. 4.6-5.0V on a LiPo that maxes ~4.2V). Hold VBAT_ENABLE HIGH continuously again (as before 4d46abb2) so the node is always settled at sample time, and drop the toggle + delay(10) from getBattMilliVolts(). Standby cost is ~2uA on the 2x1M divider, negligible next to the device's mA-level draw. The CPU-sleep and LED-off energy optimizations from 4d46abb2 are left untouched — those are the real savings; only the VBAT gating is reverted. --- variants/wio-tracker-l1/WioTrackerL1Board.cpp | 4 +++- variants/wio-tracker-l1/WioTrackerL1Board.h | 6 +++--- variants/wio-tracker-l1/variant.cpp | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/variants/wio-tracker-l1/WioTrackerL1Board.cpp b/variants/wio-tracker-l1/WioTrackerL1Board.cpp index 61be5369..ef90e03a 100644 --- a/variants/wio-tracker-l1/WioTrackerL1Board.cpp +++ b/variants/wio-tracker-l1/WioTrackerL1Board.cpp @@ -9,7 +9,9 @@ void WioTrackerL1Board::begin() { pinMode(PIN_VBAT_READ, INPUT); // VBAT ADC input pinMode(VBAT_ENABLE, OUTPUT); - digitalWrite(VBAT_ENABLE, LOW); // keep voltage divider off; enabled only during ADC read + digitalWrite(VBAT_ENABLE, HIGH); // voltage divider always on: gating it per-read left + // the divider node unsettled at sample time (10ms was + // too short), reading high & jittery. ~2uA standby cost. // Set all button pins to INPUT_PULLUP pinMode(PIN_BUTTON1, INPUT_PULLUP); pinMode(PIN_BUTTON2, INPUT_PULLUP); diff --git a/variants/wio-tracker-l1/WioTrackerL1Board.h b/variants/wio-tracker-l1/WioTrackerL1Board.h index 14a9746b..59cbe1dd 100644 --- a/variants/wio-tracker-l1/WioTrackerL1Board.h +++ b/variants/wio-tracker-l1/WioTrackerL1Board.h @@ -22,12 +22,12 @@ public: #endif uint16_t getBattMilliVolts() override { - digitalWrite(VBAT_ENABLE, HIGH); + // VBAT_ENABLE is held HIGH continuously (see begin()/initVariant()) so the + // divider node is already settled — don't gate it per-read, that reads high + // and jittery because 10ms wasn't enough for the divider to stabilize. analogReadResolution(12); analogReference(AR_INTERNAL); - delay(10); // allow voltage divider to stabilize int adcvalue = analogRead(PIN_VBAT_READ); - digitalWrite(VBAT_ENABLE, LOW); return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096; } diff --git a/variants/wio-tracker-l1/variant.cpp b/variants/wio-tracker-l1/variant.cpp index d09e4a90..b039d08a 100644 --- a/variants/wio-tracker-l1/variant.cpp +++ b/variants/wio-tracker-l1/variant.cpp @@ -67,9 +67,11 @@ void initVariant() { pinMode(PIN_QSPI_CS, OUTPUT); digitalWrite(PIN_QSPI_CS, HIGH); - // VBAT_ENABLE: keep LOW by default, WioTrackerL1Board::getBattMilliVolts() toggles it + // VBAT_ENABLE: hold HIGH so the battery voltage divider is always on and its + // node stays settled for the ADC read (getBattMilliVolts). Per-read gating + // left it unsettled at sample time -> high/jittery readings. pinMode(VBAT_ENABLE, OUTPUT); - digitalWrite(VBAT_ENABLE, LOW); + digitalWrite(VBAT_ENABLE, HIGH); // set LED pin as output and set it low pinMode(PIN_LED, OUTPUT);