mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 14:58:12 +00:00
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.
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <MeshCore.h>
|
|
#include <Arduino.h>
|
|
#include <helpers/NRF52Board.h>
|
|
|
|
class WioTrackerL1Board : public NRF52BoardDCDC {
|
|
protected:
|
|
uint8_t btn_prev_state;
|
|
|
|
public:
|
|
WioTrackerL1Board() : NRF52Board("WioTrackerL1 OTA") {}
|
|
void begin();
|
|
|
|
#if defined(P_LORA_TX_LED)
|
|
void onBeforeTransmit() override {
|
|
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
|
|
}
|
|
void onAfterTransmit() override {
|
|
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
|
|
}
|
|
#endif
|
|
|
|
uint16_t getBattMilliVolts() override {
|
|
// 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);
|
|
int adcvalue = analogRead(PIN_VBAT_READ);
|
|
return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
|
|
}
|
|
|
|
const char* getManufacturerName() const override {
|
|
return "Seeed Wio Tracker L1";
|
|
}
|
|
|
|
void powerOff() override {
|
|
sd_power_system_off();
|
|
}
|
|
};
|