fix(wio-tracker-l1): battery voltage reads high/jittery — divider always on

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.
This commit is contained in:
Jakub
2026-07-03 09:51:32 +02:00
parent 3419e590fe
commit 7ff1b7c86b
3 changed files with 10 additions and 6 deletions

View File

@@ -9,7 +9,9 @@ void WioTrackerL1Board::begin() {
pinMode(PIN_VBAT_READ, INPUT); // VBAT ADC input pinMode(PIN_VBAT_READ, INPUT); // VBAT ADC input
pinMode(VBAT_ENABLE, OUTPUT); 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 // Set all button pins to INPUT_PULLUP
pinMode(PIN_BUTTON1, INPUT_PULLUP); pinMode(PIN_BUTTON1, INPUT_PULLUP);
pinMode(PIN_BUTTON2, INPUT_PULLUP); pinMode(PIN_BUTTON2, INPUT_PULLUP);

View File

@@ -22,12 +22,12 @@ public:
#endif #endif
uint16_t getBattMilliVolts() override { 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); analogReadResolution(12);
analogReference(AR_INTERNAL); analogReference(AR_INTERNAL);
delay(10); // allow voltage divider to stabilize
int adcvalue = analogRead(PIN_VBAT_READ); int adcvalue = analogRead(PIN_VBAT_READ);
digitalWrite(VBAT_ENABLE, LOW);
return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096; return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
} }

View File

@@ -67,9 +67,11 @@ void initVariant() {
pinMode(PIN_QSPI_CS, OUTPUT); pinMode(PIN_QSPI_CS, OUTPUT);
digitalWrite(PIN_QSPI_CS, HIGH); 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); pinMode(VBAT_ENABLE, OUTPUT);
digitalWrite(VBAT_ENABLE, LOW); digitalWrite(VBAT_ENABLE, HIGH);
// set LED pin as output and set it low // set LED pin as output and set it low
pinMode(PIN_LED, OUTPUT); pinMode(PIN_LED, OUTPUT);