Battery voltage & current filtering to improve charging algorithm

For PWM charge controllers, the topping stage was sometimes very short
and the battery did not get fully charged.

This commit adds a voltage_filtered and current_filtered member variable
to DcBus and PowerPort classes which can hold measurements more heavily
filtered (initial time constant setting: 10 seconds). This should fix
above issues with the charging algorithm.
This commit is contained in:
Martin Jäger
2021-02-04 17:28:52 +01:00
parent 269ce762a0
commit 35b390ff24
4 changed files with 44 additions and 2 deletions
+2 -2
View File
@@ -490,10 +490,10 @@ void Charger::charge_control(BatConf *bat_conf)
port->bus->sink_voltage_intercept = bat_conf->topping_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
if (port->bus->voltage >= port->bus->sink_control_voltage() - 0.05F) {
if (port->bus->voltage_filtered >= port->bus->sink_control_voltage() - 0.05F) {
// battery is full if topping target voltage is still reached (i.e. sufficient
// solar power available) and time limit or cut-off current reached
if (port->current < bat_conf->topping_current_cutoff ||
if (port->current_filtered < bat_conf->topping_current_cutoff ||
target_voltage_timer > bat_conf->topping_duration)
{
full = true;
+17
View File
@@ -22,6 +22,11 @@ LOG_MODULE_REGISTER(daq, CONFIG_DAQ_LOG_LEVEL);
// typical value for Semitec 103AT-5 thermistor: 3435
#define NTC_BETA_VALUE 3435
// filter parameter c for additional battery voltage and current low-pass filter
// c = dt / (tau + dt) = 0.1s / (10s + 0.1s)
#define LV_BUS_VOLTAGE_FILTER_CONST 0.0099F
#define LV_TERMINAL_CURRENT_FILTER_CONST 0.0099F
#if BOARD_HAS_DCDC
static uint16_t dcdc_current_offset_raw;
#endif
@@ -168,6 +173,15 @@ void daq_update()
// calculate lower voltage first, as it is needed for PWM terminal voltage calculation
lv_bus.voltage = adc_scaled(ADC_POS(v_low), vref, ADC_GAIN(v_low));
if (lv_bus.voltage_filtered != 0.0F) {
lv_bus.voltage_filtered = LV_BUS_VOLTAGE_FILTER_CONST * lv_bus.voltage +
(1.0F - LV_BUS_VOLTAGE_FILTER_CONST) * lv_bus.voltage_filtered;
}
else {
// initialize properly at startup
lv_bus.voltage_filtered = lv_bus.voltage;
}
#if BOARD_HAS_DCDC
hv_bus.voltage = adc_scaled(ADC_POS(v_high), vref, ADC_GAIN(v_high));
#endif
@@ -212,6 +226,9 @@ void daq_update()
lv_terminal.current = lv_terminal_current;
lv_terminal.power = lv_terminal.bus->voltage * lv_terminal.current;
lv_terminal.current_filtered = LV_TERMINAL_CURRENT_FILTER_CONST * lv_bus.voltage +
(1.0F - LV_TERMINAL_CURRENT_FILTER_CONST) * lv_bus.voltage_filtered;
#if BOARD_HAS_LOAD_OUTPUT
load.power = load.bus->voltage * load.current;
#endif
+16
View File
@@ -30,6 +30,14 @@ public:
*/
float voltage;
/**
* Filtered bus voltage
*
* Suitable filter time constants depend on type of DC bus. This filtering is applied in
* addition to the raw ADC value filtering.
*/
float voltage_filtered = 0;
/**
* Multiplier for series connection of batteries
*
@@ -182,6 +190,14 @@ public:
*/
float current = 0;
/**
* Filtered port current
*
* Suitable filter time constants depend on type of port. This filtering is applied in
* addition to the raw ADC value filtering.
*/
float current_filtered = 0;
/**
* Product of port current and bus voltage
*/
+9
View File
@@ -18,6 +18,7 @@ static void init_structs()
charger.state = CHG_STATE_IDLE;
charger.bat_temperature = 25;
bat_terminal.bus->voltage = 14.0;
bat_terminal.bus->voltage_filtered = 14.0;
bat_terminal.current = 0;
}
@@ -65,9 +66,11 @@ void enter_topping_at_voltage_setpoint()
init_structs();
charger.time_state_changed = time(NULL) - bat_conf.time_limit_recharge - 1;
bat_terminal.bus->voltage = bat_conf.voltage_recharge - 0.1;
bat_terminal.bus->voltage_filtered = bat_terminal.bus->voltage;
charger.charge_control(&bat_conf);
TEST_ASSERT_EQUAL(CHG_STATE_BULK, charger.state);
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
bat_terminal.bus->voltage_filtered = bat_terminal.bus->voltage;
charger.charge_control(&bat_conf);
TEST_ASSERT_EQUAL(CHG_STATE_TOPPING, charger.state);
}
@@ -78,7 +81,9 @@ void topping_to_bulk_after_8h_low_power()
charger.time_state_changed = time(NULL) - 8 * 60 * 60 + 1;
bat_terminal.bus->voltage = bat_conf.topping_voltage - 0.1;
bat_terminal.bus->voltage_filtered = bat_terminal.bus->voltage;
bat_terminal.current = bat_conf.topping_current_cutoff + 0.1;
bat_terminal.current_filtered = bat_terminal.current;
charger.charge_control(&bat_conf);
TEST_ASSERT_EQUAL(CHG_STATE_TOPPING, charger.state);
@@ -94,8 +99,10 @@ void stop_topping_after_time_limit()
charger.target_voltage_timer = bat_conf.topping_duration - 1;
bat_terminal.current = bat_conf.topping_current_cutoff + 0.1;
bat_terminal.current_filtered = bat_terminal.current;
bat_terminal.bus->voltage = bat_conf.topping_voltage -
bat_terminal.current * bat_terminal.bus->sink_droop_res + 0.1;
bat_terminal.bus->voltage_filtered = bat_terminal.bus->voltage;
charger.charge_control(&bat_conf);
TEST_ASSERT_EQUAL(CHG_STATE_TOPPING, charger.state);
@@ -111,8 +118,10 @@ void stop_topping_at_cutoff_current()
charger.target_voltage_timer = 0;
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
bat_terminal.current_filtered = bat_terminal.current;
bat_terminal.bus->voltage = bat_conf.topping_voltage -
bat_terminal.current * bat_terminal.bus->sink_droop_res + 0.1;
bat_terminal.bus->voltage_filtered = bat_terminal.bus->voltage;
charger.charge_control(&bat_conf);
TEST_ASSERT_EQUAL(CHG_STATE_TRICKLE, charger.state);
}