mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 14:55:21 +03:00
Addition for detection of 1S batteries.
This commit is contained in:
parent
0d136b6f9c
commit
e8ce7b4e58
3 changed files with 14 additions and 11 deletions
|
@ -418,7 +418,7 @@ const clivalue_t valueTable[] = {
|
|||
{ "vbat_hysteresis", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 250 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, vbathysteresis) },
|
||||
{ "current_meter", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CURRENT_METER }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, currentMeterSource) },
|
||||
{ "battery_meter", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_VOLTAGE_METER }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, voltageMeterSource) },
|
||||
{ "bat_detect_thresh", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 200 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, batteryNotPresentLevel) },
|
||||
{ "vbat_detect_cell_voltage", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 200 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, vbatnotpresentcellvoltage) },
|
||||
{ "use_vbat_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, useVBatAlerts) },
|
||||
{ "use_cbat_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, useConsumptionAlerts) },
|
||||
{ "cbat_alert_percent", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 100 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, consumptionWarningPercentage) },
|
||||
|
|
|
@ -97,12 +97,12 @@ PG_RESET_TEMPLATE(batteryConfig_t, batteryConfig,
|
|||
.vbatmaxcellvoltage = 43,
|
||||
.vbatmincellvoltage = 33,
|
||||
.vbatwarningcellvoltage = 35,
|
||||
.batteryNotPresentLevel = 55, // VBAT below 5.5 V will be ignored
|
||||
.vbatnotpresentcellvoltage = 30, //A cell below 3 will be ignored
|
||||
.voltageMeterSource = DEFAULT_VOLTAGE_METER_SOURCE,
|
||||
|
||||
// current
|
||||
.batteryCapacity = 0,
|
||||
.currentMeterSource = DEFAULT_VOLTAGE_METER_SOURCE,
|
||||
.currentMeterSource = DEFAULT_CURRENT_METER_SOURCE,
|
||||
|
||||
// warnings / alerts
|
||||
.useVBatAlerts = true,
|
||||
|
@ -162,16 +162,19 @@ void batteryUpdatePresence(void)
|
|||
{
|
||||
static uint16_t previousVoltage = 0;
|
||||
|
||||
bool isVoltageStable = (
|
||||
previousVoltage > 0
|
||||
&& ABS(voltageMeter.filtered - previousVoltage) <= VBAT_STABLE_MAX_DELTA
|
||||
);
|
||||
bool isVoltageStable = ABS(voltageMeter.filtered - previousVoltage) <= VBAT_STABLE_MAX_DELTA;
|
||||
|
||||
bool isVoltageFromBat = (voltageMeter.filtered >= batteryConfig()->vbatnotpresentcellvoltage //above ~0V
|
||||
&& voltageMeter.filtered <= batteryConfig()->vbatmaxcellvoltage) //1s max cell voltage check
|
||||
|| voltageMeter.filtered > batteryConfig()->vbatnotpresentcellvoltage*2; //USB voltage - 2s or more check
|
||||
|
||||
|
||||
if (
|
||||
voltageState == BATTERY_NOT_PRESENT
|
||||
&& voltageMeter.filtered > batteryConfig()->batteryNotPresentLevel
|
||||
&& isVoltageFromBat
|
||||
&& isVoltageStable
|
||||
) {
|
||||
/* Want to disable battery getting detected around USB voltage or 0V*/
|
||||
/* battery has just been connected - calculate cells, warning voltages and reset state */
|
||||
|
||||
|
||||
|
@ -187,10 +190,10 @@ void batteryUpdatePresence(void)
|
|||
batteryCriticalVoltage = batteryCellCount * batteryConfig()->vbatmincellvoltage;
|
||||
} else if (
|
||||
voltageState != BATTERY_NOT_PRESENT
|
||||
&& voltageMeter.filtered <= batteryConfig()->batteryNotPresentLevel
|
||||
&& isVoltageStable
|
||||
&& !isVoltageFromBat
|
||||
) {
|
||||
/* battery has been disconnected - can take a while for filter cap to disharge so we use a threshold of batteryConfig()->batterynotpresentlevel */
|
||||
/* battery has been disconnected - can take a while for filter cap to disharge so we use a threshold of batteryConfig()->vbatnotpresentcellvoltage */
|
||||
|
||||
consumptionState = voltageState = BATTERY_NOT_PRESENT;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ typedef struct batteryConfig_s {
|
|||
uint8_t vbatmaxcellvoltage; // maximum voltage per cell, used for auto-detecting battery voltage in 0.1V units, default is 43 (4.3V)
|
||||
uint8_t vbatmincellvoltage; // minimum voltage per cell, this triggers battery critical alarm, in 0.1V units, default is 33 (3.3V)
|
||||
uint8_t vbatwarningcellvoltage; // warning voltage per cell, this triggers battery warning alarm, in 0.1V units, default is 35 (3.5V)
|
||||
uint8_t batteryNotPresentLevel; // Below this level battery is considered as not present
|
||||
uint8_t vbatnotpresentcellvoltage; // Between vbatmaxcellvoltage and 2*this is considered to be USB powered. Below this it is notpresent
|
||||
|
||||
voltageMeterSource_e voltageMeterSource; // source of battery voltage meter used, either ADC or ESC
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue