1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-20 06:45:16 +03:00

biquad to Vbat

This commit is contained in:
borisbstyle 2016-02-12 16:33:05 +01:00
parent f47b332b6f
commit 468cebcec2

View file

@ -38,7 +38,7 @@
#include "io/beeper.h" #include "io/beeper.h"
#define VBATT_PRESENT_THRESHOLD_MV 10 #define VBATT_PRESENT_THRESHOLD_MV 10
#define VBATT_LPF_FREQ 1.0f #define VBATT_LPF_FREQ 0.4f
// Battery monitoring stuff // Battery monitoring stuff
uint8_t batteryCellCount = 3; // cell count uint8_t batteryCellCount = 3; // cell count
@ -64,16 +64,16 @@ uint16_t batteryAdcToVoltage(uint16_t src)
static void updateBatteryVoltage(void) static void updateBatteryVoltage(void)
{ {
uint16_t vbatSample; uint16_t vbatSample;
static filterStatePt1_t vbatFilterState; static biquad_t vbatFilterState;
static uint32_t previousTime; static bool vbatFilterStateIsSet;
uint32_t now;
// store the battery voltage with some other recent battery voltage readings // store the battery voltage with some other recent battery voltage readings
vbatSample = vbatLatestADC = adcGetChannel(ADC_BATTERY); vbatSample = vbatLatestADC = adcGetChannel(ADC_BATTERY);
now = micros(); if (!vbatFilterStateIsSet) {
float delta = (now - previousTime) * 0.000001f; BiQuadNewLpf(VBATT_LPF_FREQ, &vbatFilterState, 50000); //50HZ Update
previousTime = now; vbatFilterStateIsSet = true;
vbatSample = filterApplyPt1(vbatSample, &vbatFilterState, VBATT_LPF_FREQ, delta); }
vbatSample = applyBiQuadFilter(vbatSample, &vbatFilterState);
vbat = batteryAdcToVoltage(vbatSample); vbat = batteryAdcToVoltage(vbatSample);
} }