From f47b332b6f79f7b3e8aa8b8f72f23247f2bdfd63 Mon Sep 17 00:00:00 2001 From: borisbstyle Date: Fri, 12 Feb 2016 10:20:30 +0100 Subject: [PATCH] Fix delta for battery filtering fix --- src/main/sensors/battery.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index 03b38cb5d5..fe3d0d866a 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -65,10 +65,14 @@ static void updateBatteryVoltage(void) { uint16_t vbatSample; static filterStatePt1_t vbatFilterState; + static uint32_t previousTime; + uint32_t now; // store the battery voltage with some other recent battery voltage readings vbatSample = vbatLatestADC = adcGetChannel(ADC_BATTERY); - float delta = micros() * 0.000001f; + now = micros(); + float delta = (now - previousTime) * 0.000001f; + previousTime = now; vbatSample = filterApplyPt1(vbatSample, &vbatFilterState, VBATT_LPF_FREQ, delta); vbat = batteryAdcToVoltage(vbatSample); }