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
*/