mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 15:25:36 +03:00
Prevent 0 in 'vbat_display_lpf_period' to avoid division by zero.
This commit is contained in:
parent
d63ba914c6
commit
b020917c4b
4 changed files with 14 additions and 12 deletions
|
@ -840,7 +840,7 @@ const clivalue_t valueTable[] = {
|
|||
{ "cbat_alert_percent", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, consumptionWarningPercentage) },
|
||||
{ "vbat_cutoff_percent", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 100 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, lvcPercentage) },
|
||||
{ "force_battery_cell_count", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, 24 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, forceBatteryCellCount) },
|
||||
{ "vbat_display_lpf_period", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 0, UINT8_MAX }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, vbatDisplayLpfPeriod) },
|
||||
{ "vbat_display_lpf_period", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 1, UINT8_MAX }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, vbatDisplayLpfPeriod) },
|
||||
#if defined(USE_BATTERY_VOLTAGE_SAG_COMPENSATION)
|
||||
{ "vbat_sag_lpf_period", VAR_UINT8 | MASTER_VALUE, .config.minmaxUnsigned = { 1, UINT8_MAX }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, vbatSagLpfPeriod) },
|
||||
#endif
|
||||
|
|
|
@ -232,7 +232,9 @@ void tasksInit(void)
|
|||
|
||||
#if defined(USE_BATTERY_VOLTAGE_SAG_COMPENSATION)
|
||||
// If vbat motor output compensation is used, use fast vbat samplingTime
|
||||
rescheduleTask(TASK_BATTERY_VOLTAGE, TASK_PERIOD_HZ(getBatteryVoltageTaskFrequencyHz()));
|
||||
if (isSagCompensationConfigured()) {
|
||||
rescheduleTask(TASK_BATTERY_VOLTAGE, TASK_PERIOD_HZ(FAST_VOLTAGE_TASK_FREQ_HZ));
|
||||
}
|
||||
#endif
|
||||
|
||||
const bool useBatteryCurrent = batteryConfig()->currentMeterSource != CURRENT_METER_NONE;
|
||||
|
|
|
@ -178,7 +178,7 @@ void voltageMeterADCRefresh(void)
|
|||
state->voltageUnfiltered = voltageAdcToVoltage(rawSample, config);
|
||||
|
||||
#if defined(USE_BATTERY_VOLTAGE_SAG_COMPENSATION)
|
||||
if (currentPidProfile->vbat_sag_compensation > 0) {
|
||||
if (isSagCompensationConfigured()) {
|
||||
uint16_t filteredSagSample = pt1FilterApply(&state->sagFilter, rawSample);
|
||||
state->voltageSagFiltered = voltageAdcToVoltage(filteredSagSample, config);
|
||||
}
|
||||
|
@ -206,18 +206,18 @@ void voltageMeterADCRead(voltageSensorADC_e adcChannel, voltageMeter_t *voltageM
|
|||
#endif
|
||||
}
|
||||
|
||||
uint16_t getBatteryVoltageTaskFrequencyHz(void)
|
||||
bool isSagCompensationConfigured(void)
|
||||
{
|
||||
uint16_t frequencyHz = SLOW_VOLTAGE_TASK_FREQ_HZ;
|
||||
bool isConfigured = false;
|
||||
#if defined(USE_BATTERY_VOLTAGE_SAG_COMPENSATION)
|
||||
for (unsigned i = 0; i < PID_PROFILE_COUNT; i++) {
|
||||
if (pidProfiles(i)->vbat_sag_compensation > 0) {
|
||||
frequencyHz = FAST_VOLTAGE_TASK_FREQ_HZ;
|
||||
isConfigured = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return frequencyHz;
|
||||
return isConfigured;
|
||||
}
|
||||
|
||||
void voltageMeterADCInit(void)
|
||||
|
@ -228,10 +228,10 @@ void voltageMeterADCInit(void)
|
|||
voltageMeterADCState_t *state = &voltageMeterADCStates[i];
|
||||
memset(state, 0, sizeof(voltageMeterADCState_t));
|
||||
|
||||
pt1FilterInit(&state->displayFilter, pt1FilterGain(GET_BATTERY_LPF_FREQUENCY(batteryConfig()->vbatDisplayLpfPeriod), HZ_TO_INTERVAL(getBatteryVoltageTaskFrequencyHz())));
|
||||
pt1FilterInit(&state->displayFilter, pt1FilterGain(GET_BATTERY_LPF_FREQUENCY(batteryConfig()->vbatDisplayLpfPeriod), HZ_TO_INTERVAL(isSagCompensationConfigured() ? FAST_VOLTAGE_TASK_FREQ_HZ : SLOW_VOLTAGE_TASK_FREQ_HZ)));
|
||||
#if defined(USE_BATTERY_VOLTAGE_SAG_COMPENSATION)
|
||||
if (currentPidProfile->vbat_sag_compensation > 0) {
|
||||
pt1FilterInit(&state->sagFilter, pt1FilterGain(GET_BATTERY_LPF_FREQUENCY(batteryConfig()->vbatSagLpfPeriod), HZ_TO_INTERVAL(getBatteryVoltageTaskFrequencyHz())));
|
||||
if (isSagCompensationConfigured()) {
|
||||
pt1FilterInit(&state->sagFilter, pt1FilterGain(GET_BATTERY_LPF_FREQUENCY(batteryConfig()->vbatSagLpfPeriod), HZ_TO_INTERVAL(FAST_VOLTAGE_TASK_FREQ_HZ)));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ void voltageMeterESCInit(void)
|
|||
{
|
||||
#ifdef USE_ESC_SENSOR
|
||||
memset(&voltageMeterESCState, 0, sizeof(voltageMeterESCState_t));
|
||||
pt1FilterInit(&voltageMeterESCState.displayFilter, pt1FilterGain(GET_BATTERY_LPF_FREQUENCY(batteryConfig()->vbatDisplayLpfPeriod), HZ_TO_INTERVAL(getBatteryVoltageTaskFrequencyHz())));
|
||||
pt1FilterInit(&voltageMeterESCState.displayFilter, pt1FilterGain(GET_BATTERY_LPF_FREQUENCY(batteryConfig()->vbatDisplayLpfPeriod), HZ_TO_INTERVAL(isSagCompensationConfigured() ? FAST_VOLTAGE_TASK_FREQ_HZ : SLOW_VOLTAGE_TASK_FREQ_HZ)));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -119,4 +119,4 @@ extern const uint8_t supportedVoltageMeterCount;
|
|||
extern const uint8_t voltageMeterIds[];
|
||||
void voltageMeterRead(voltageMeterId_e id, voltageMeter_t *voltageMeter);
|
||||
|
||||
uint16_t getBatteryVoltageTaskFrequencyHz(void);
|
||||
bool isSagCompensationConfigured(void);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue