Charger: Add follower state for power sharing

This state is enabled if the device receives a current target signal from
a device with higher priority via CAN. After not receiving the messages
for 1 second the state machine automatically goes back to normal operation.
This commit is contained in:
Martin Jäger
2021-07-29 14:21:14 +02:00
parent fbf7eca764
commit 88bb8059f3
2 changed files with 47 additions and 1 deletions
+26
View File
@@ -459,6 +459,10 @@ void Charger::charge_control(BatConf *bat_conf)
dev_stat.clear_error(ERR_BAT_OVERVOLTAGE);
}
if (state != CHG_STATE_FOLLOWER && (uptime() - time_last_ctrl_msg) <= 1) {
enter_state(CHG_STATE_FOLLOWER);
}
// state machine
switch (state) {
case CHG_STATE_IDLE: {
@@ -475,6 +479,7 @@ void Charger::charge_control(BatConf *bat_conf)
port->bus->sink_voltage_intercept = bat_conf->topping_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
port->pos_current_limit = bat_conf->charge_current_max;
target_current_control = port->pos_current_limit;
full = false;
dev_stat.clear_error(ERR_BAT_CHG_OVERTEMP);
dev_stat.clear_error(ERR_BAT_CHG_UNDERTEMP);
@@ -499,6 +504,9 @@ void Charger::charge_control(BatConf *bat_conf)
port->bus->sink_voltage_intercept = bat_conf->topping_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
// power sharing: multiple devices in parallel supply the same current
target_current_control = port->current_filtered;
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
@@ -546,6 +554,8 @@ void Charger::charge_control(BatConf *bat_conf)
port->bus->sink_voltage_intercept = bat_conf->trickle_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
target_current_control = port->current_filtered;
if (port->bus->voltage >= port->bus->sink_control_voltage()) {
time_target_voltage_reached = uptime();
}
@@ -568,6 +578,8 @@ void Charger::charge_control(BatConf *bat_conf)
port->bus->sink_voltage_intercept = bat_conf->equalization_voltage +
bat_conf->temperature_compensation * (bat_temperature - 25);
target_current_control = port->current_filtered;
// current or time limit for equalization reached
if (uptime() - time_state_changed > bat_conf->equalization_duration)
{
@@ -589,6 +601,20 @@ void Charger::charge_control(BatConf *bat_conf)
}
break;
}
case CHG_STATE_FOLLOWER: {
if ((uptime() - time_last_ctrl_msg) > 1) {
// go back to normal state machine
port->pos_current_limit = bat_conf->charge_current_max;
enter_state(CHG_STATE_BULK);
}
else {
// set current target as received from external device
port->pos_current_limit = target_current_control;
// set safety limit for voltage
port->bus->sink_voltage_intercept = bat_conf->voltage_absolute_max;
}
break;
}
}
}