Average battery ADC samples

- Read battery 5 times and average for a steadier voltage estimate
This commit is contained in:
2026-02-02 23:28:54 +01:00
parent 2199627a35
commit b8a4c27daa
2 changed files with 7 additions and 3 deletions

View File

@@ -261,7 +261,7 @@ inline constexpr uint16_t EXPECTED_SENDER_IDS[NUM_SENDERS] = { 0xF19C };
- 4.2 V = 100% - 4.2 V = 100%
- Uses deep sleep between cycles (`SENDER_WAKE_INTERVAL_SEC`). - Uses deep sleep between cycles (`SENDER_WAKE_INTERVAL_SEC`).
- Sender CPU is throttled to 80 MHz and LoRa RX is only enabled in short windows (ACK wait or time-sync). - Sender CPU is throttled to 80 MHz and LoRa RX is only enabled in short windows (ACK wait or time-sync).
- Battery sampling uses a single ADC read and updates at most once per `BATTERY_SAMPLE_INTERVAL_MS` (default 60s). - Battery sampling averages 5 ADC reads and updates at most once per `BATTERY_SAMPLE_INTERVAL_MS` (default 60s).
## Web UI ## Web UI
- AP SSID: `DD3-Bridge-<short_id>` (prefix configurable) - AP SSID: `DD3-Bridge-<short_id>` (prefix configurable)

View File

@@ -34,8 +34,12 @@ void power_configure_unused_pins_sender() {
} }
void read_battery(MeterData &data) { void read_battery(MeterData &data) {
uint32_t raw = analogRead(PIN_BAT_ADC); uint32_t sum = 0;
float v = (static_cast<float>(raw) / 4095.0f) * ADC_REF_V * BATTERY_DIVIDER * BATTERY_CAL; for (uint8_t i = 0; i < 5; ++i) {
sum += analogRead(PIN_BAT_ADC);
}
float avg = static_cast<float>(sum) / 5.0f;
float v = (avg / 4095.0f) * ADC_REF_V * BATTERY_DIVIDER * BATTERY_CAL;
data.battery_voltage_v = v; data.battery_voltage_v = v;
data.battery_percent = battery_percent_from_voltage(v); data.battery_percent = battery_percent_from_voltage(v);