mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-07 04:36:11 +00:00
fix(wio-tracker-l1): battery voltage reads high/jittery — divider always on
The per-read VBAT_ENABLE gating from4d46abb2(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 before4d46abb2) 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 from4d46abb2are left untouched — those are the real savings; only the VBAT gating is reverted.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user