Change current/voltage filters from biquad to pt1
This commit is contained in:
parent
b8bfc7ce12
commit
62fafe8041
|
@ -88,7 +88,7 @@ void currentMeterReset(currentMeter_t *meter)
|
|||
// ADC/Virtual shared
|
||||
//
|
||||
|
||||
static biquadFilter_t adciBatFilter;
|
||||
static pt1Filter_t adciBatFilter;
|
||||
|
||||
#ifndef CURRENT_METER_SCALE_DEFAULT
|
||||
#define CURRENT_METER_SCALE_DEFAULT 400 // for Allegro ACS758LCB-100U (40mV/A)
|
||||
|
@ -141,7 +141,7 @@ currentMeterADCState_t currentMeterADCState;
|
|||
void currentMeterADCInit(void)
|
||||
{
|
||||
memset(¤tMeterADCState, 0, sizeof(currentMeterADCState_t));
|
||||
biquadFilterInitLPF(&adciBatFilter, GET_BATTERY_LPF_FREQUENCY(batteryConfig()->ibatLpfPeriod), HZ_TO_INTERVAL_US(50));
|
||||
pt1FilterInit(&adciBatFilter, pt1FilterGain(GET_BATTERY_LPF_FREQUENCY(batteryConfig()->ibatLpfPeriod), HZ_TO_INTERVAL(50)));
|
||||
}
|
||||
|
||||
void currentMeterADCRefresh(int32_t lastUpdateAt)
|
||||
|
@ -149,7 +149,7 @@ void currentMeterADCRefresh(int32_t lastUpdateAt)
|
|||
#ifdef USE_ADC
|
||||
const uint16_t iBatSample = adcGetChannel(ADC_CURRENT);
|
||||
currentMeterADCState.amperageLatest = currentMeterADCToCentiamps(iBatSample);
|
||||
currentMeterADCState.amperage = currentMeterADCToCentiamps(biquadFilterApply(&adciBatFilter, iBatSample));
|
||||
currentMeterADCState.amperage = currentMeterADCToCentiamps(pt1FilterApply(&adciBatFilter, iBatSample));
|
||||
|
||||
updateCurrentmAhDrawnState(¤tMeterADCState.mahDrawnState, currentMeterADCState.amperageLatest, lastUpdateAt);
|
||||
#else
|
||||
|
|
|
@ -106,7 +106,7 @@ void voltageMeterReset(voltageMeter_t *meter)
|
|||
typedef struct voltageMeterADCState_s {
|
||||
uint16_t voltageFiltered; // battery voltage in 0.01V steps (filtered)
|
||||
uint16_t voltageUnfiltered; // battery voltage in 0.01V steps (unfiltered)
|
||||
biquadFilter_t filter;
|
||||
pt1Filter_t filter;
|
||||
} voltageMeterADCState_t;
|
||||
|
||||
extern voltageMeterADCState_t voltageMeterADCStates[MAX_VOLTAGE_SENSOR_ADC];
|
||||
|
@ -164,7 +164,7 @@ void voltageMeterADCRefresh(void)
|
|||
uint8_t channel = voltageMeterAdcChannelMap[i];
|
||||
uint16_t rawSample = adcGetChannel(channel);
|
||||
|
||||
uint16_t filteredSample = biquadFilterApply(&state->filter, rawSample);
|
||||
uint16_t filteredSample = pt1FilterApply(&state->filter, rawSample);
|
||||
|
||||
// always calculate the latest voltage, see getLatestVoltage() which does the calculation on demand.
|
||||
state->voltageFiltered = voltageAdcToVoltage(filteredSample, config);
|
||||
|
@ -194,7 +194,7 @@ void voltageMeterADCInit(void)
|
|||
voltageMeterADCState_t *state = &voltageMeterADCStates[i];
|
||||
memset(state, 0, sizeof(voltageMeterADCState_t));
|
||||
|
||||
biquadFilterInitLPF(&state->filter, GET_BATTERY_LPF_FREQUENCY(batteryConfig()->vbatLpfPeriod), HZ_TO_INTERVAL_US(50));
|
||||
pt1FilterInit(&state->filter, pt1FilterGain(GET_BATTERY_LPF_FREQUENCY(batteryConfig()->vbatLpfPeriod), HZ_TO_INTERVAL(50)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ void voltageMeterADCInit(void)
|
|||
typedef struct voltageMeterESCState_s {
|
||||
uint16_t voltageFiltered; // battery voltage in 0.01V steps (filtered)
|
||||
uint16_t voltageUnfiltered; // battery voltage in 0.01V steps (unfiltered)
|
||||
biquadFilter_t filter;
|
||||
pt1Filter_t filter;
|
||||
} voltageMeterESCState_t;
|
||||
|
||||
static voltageMeterESCState_t voltageMeterESCState;
|
||||
|
@ -218,7 +218,7 @@ void voltageMeterESCInit(void)
|
|||
{
|
||||
#ifdef USE_ESC_SENSOR
|
||||
memset(&voltageMeterESCState, 0, sizeof(voltageMeterESCState_t));
|
||||
biquadFilterInitLPF(&voltageMeterESCState.filter, GET_BATTERY_LPF_FREQUENCY(batteryConfig()->vbatLpfPeriod), HZ_TO_INTERVAL_US(50));
|
||||
pt1FilterInit(&voltageMeterESCState.filter, pt1FilterGain(GET_BATTERY_LPF_FREQUENCY(batteryConfig()->vbatLpfPeriod), HZ_TO_INTERVAL(50)));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -228,7 +228,7 @@ void voltageMeterESCRefresh(void)
|
|||
escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED);
|
||||
if (escData) {
|
||||
voltageMeterESCState.voltageUnfiltered = escData->dataAge <= ESC_BATTERY_AGE_MAX ? escData->voltage : 0;
|
||||
voltageMeterESCState.voltageFiltered = biquadFilterApply(&voltageMeterESCState.filter, voltageMeterESCState.voltageUnfiltered);
|
||||
voltageMeterESCState.voltageFiltered = pt1FilterApply(&voltageMeterESCState.filter, voltageMeterESCState.voltageUnfiltered);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue