Average battery ADC samples
- Read battery 5 times and average for a steadier voltage estimate
This commit is contained in:
@@ -261,7 +261,7 @@ inline constexpr uint16_t EXPECTED_SENDER_IDS[NUM_SENDERS] = { 0xF19C };
|
||||
- 4.2 V = 100%
|
||||
- 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).
|
||||
- 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
|
||||
- AP SSID: `DD3-Bridge-<short_id>` (prefix configurable)
|
||||
|
||||
@@ -34,8 +34,12 @@ void power_configure_unused_pins_sender() {
|
||||
}
|
||||
|
||||
void read_battery(MeterData &data) {
|
||||
uint32_t raw = analogRead(PIN_BAT_ADC);
|
||||
float v = (static_cast<float>(raw) / 4095.0f) * ADC_REF_V * BATTERY_DIVIDER * BATTERY_CAL;
|
||||
uint32_t sum = 0;
|
||||
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_percent = battery_percent_from_voltage(v);
|
||||
|
||||
Reference in New Issue
Block a user