Improve load voltage limits setup and update
This commit is contained in:
committed by
Martin Jäger
parent
cdb9183c11
commit
6af8e6d93d
+6
-21
@@ -395,7 +395,7 @@ void Charger::charge_control(BatConf *bat_conf)
|
||||
port->bus->sink_voltage_bound = num_batteries * (bat_conf->topping_voltage +
|
||||
bat_conf->temperature_compensation * (bat_temperature - 25));
|
||||
|
||||
if (port->bus->voltage > num_batteries *
|
||||
if (port->bus->voltage >
|
||||
port->bus->droop_voltage(port->bus->sink_voltage_bound))
|
||||
{
|
||||
target_voltage_timer = 0;
|
||||
@@ -408,7 +408,7 @@ void Charger::charge_control(BatConf *bat_conf)
|
||||
port->bus->sink_voltage_bound = num_batteries * (bat_conf->topping_voltage +
|
||||
bat_conf->temperature_compensation * (bat_temperature - 25));
|
||||
|
||||
if (port->bus->voltage >= num_batteries *
|
||||
if (port->bus->voltage >=
|
||||
port->bus->droop_voltage(port->bus->sink_voltage_bound) - 0.05F)
|
||||
{
|
||||
// battery is full if topping target voltage is still reached (i.e. sufficient
|
||||
@@ -503,29 +503,14 @@ void Charger::charge_control(BatConf *bat_conf)
|
||||
}
|
||||
}
|
||||
|
||||
void battery_init_terminal(PowerPort *port, BatConf *bat, unsigned int num_batteries)
|
||||
void Charger::init_terminal(BatConf *bat)
|
||||
{
|
||||
unsigned int n = (num_batteries == 2 ? 2 : 1); // only 1 or 2 allowed
|
||||
port->bus->sink_voltage_bound = bat->topping_voltage * num_batteries;
|
||||
port->bus->src_voltage_bound = bat->voltage_load_disconnect * num_batteries;
|
||||
|
||||
port->neg_current_limit = -bat->discharge_current_max;
|
||||
|
||||
// negative sign for compensation of actual resistance
|
||||
port->bus->droop_res = -(bat->internal_resistance + -bat->wire_resistance) * n;
|
||||
|
||||
port->bus->sink_voltage_bound = bat->topping_voltage * n;
|
||||
port->pos_current_limit = bat->charge_current_max;
|
||||
port->bus->src_voltage_bound = bat->voltage_load_disconnect * n;
|
||||
|
||||
// negative sign for compensation of actual resistance
|
||||
port->bus->droop_res = -bat->wire_resistance * n;
|
||||
}
|
||||
|
||||
void battery_init_load(LoadOutput *load, BatConf *bat, unsigned int num_batteries)
|
||||
{
|
||||
unsigned int n = (num_batteries == 2 ? 2 : 1); // only 1 or 2 allowed
|
||||
|
||||
load->reconnect_voltage = bat->voltage_load_reconnect * n;
|
||||
load->disconnect_voltage = bat->voltage_load_disconnect * n;
|
||||
|
||||
load->overvoltage = bat->voltage_absolute_max * n;
|
||||
port->bus->droop_res = -(bat->internal_resistance + bat->wire_resistance) * num_batteries;
|
||||
}
|
||||
|
||||
+7
-13
@@ -234,7 +234,7 @@ public:
|
||||
|
||||
uint32_t state; ///< Current charger state (see enum ChargerState)
|
||||
|
||||
int32_t num_batteries = 1; ///< Used for automatic 12V/24V battery detection at
|
||||
int32_t num_batteries = 1; ///< Used for automatic 12V/24V battery detection at
|
||||
///< start-up (can be 1 or 2 only)
|
||||
|
||||
float bat_temperature = 25; ///< Battery temperature in °C from ext. temperature sensor
|
||||
@@ -280,6 +280,12 @@ public:
|
||||
*/
|
||||
void update_soc(BatConf *bat_conf);
|
||||
|
||||
/** Initialize terminal and dc bus for battery connection
|
||||
*
|
||||
* @param bat Configuration to be used for terminal setpoints
|
||||
*/
|
||||
void init_terminal(BatConf *bat);
|
||||
|
||||
private:
|
||||
void enter_state(int next_state);
|
||||
|
||||
@@ -361,16 +367,4 @@ void battery_conf_overwrite(BatConf *source, BatConf *destination, Charger *char
|
||||
*/
|
||||
bool battery_conf_changed(BatConf *a, BatConf *b);
|
||||
|
||||
/** Initialize terminal and dc bus for battery connection
|
||||
*
|
||||
* @param num_batteries definies the number of series connected batteries, e.g. 2 for 24V system
|
||||
*/
|
||||
void battery_init_terminal(PowerPort *port, BatConf *bat, unsigned int num_batteries);
|
||||
|
||||
/** Initialize terminal and dc bus for battery connection
|
||||
*
|
||||
* @param num_batteries definies the number of series connected batteries, e.g. 2 for 24V system
|
||||
*/
|
||||
void battery_init_load(LoadOutput *port, BatConf *bat, unsigned int num_batteries);
|
||||
|
||||
#endif /* BAT_CHARGER_H */
|
||||
|
||||
@@ -447,6 +447,10 @@ void data_objects_update_conf()
|
||||
if (battery_conf_check(&bat_conf_user)) {
|
||||
printf("New config valid and activated.\n");
|
||||
battery_conf_overwrite(&bat_conf_user, &bat_conf, &charger);
|
||||
load.set_voltage_limits(
|
||||
bat_conf.voltage_load_disconnect * charger.num_batteries,
|
||||
bat_conf.voltage_load_reconnect * charger.num_batteries,
|
||||
bat_conf.voltage_absolute_max * charger.num_batteries);
|
||||
changed = true;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -216,3 +216,11 @@ void LoadOutput::stop(uint32_t error_flag)
|
||||
oc_timestamp = uptime();
|
||||
}
|
||||
}
|
||||
|
||||
void LoadOutput::set_voltage_limits(float lvd, float lvr, float ov)
|
||||
{
|
||||
disconnect_voltage = lvd;
|
||||
reconnect_voltage = lvr;
|
||||
|
||||
overvoltage = ov;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,15 @@ public:
|
||||
*/
|
||||
void stop(uint32_t error_flag = 0);
|
||||
|
||||
/**
|
||||
* Update of load voltage limits (typically based on battery configuration)
|
||||
*
|
||||
* @param lvd Low voltage disconnect setpoint
|
||||
* @param lvr Low voltage reconnect setpoint
|
||||
* @param ov Overvoltage setpoint
|
||||
*/
|
||||
void set_voltage_limits(float lvd, float lvr, float ov);
|
||||
|
||||
uint32_t state; ///< Current state of load output switch (DEPRECATED)
|
||||
uint32_t usb_state; ///< Current state of USB output (DEPRECATED)
|
||||
|
||||
|
||||
+5
-2
@@ -70,8 +70,11 @@ int main()
|
||||
#endif
|
||||
|
||||
charger.detect_num_batteries(&bat_conf); // check if we have 24V instead of 12V system
|
||||
battery_init_terminal(&bat_terminal, &bat_conf, charger.num_batteries);
|
||||
battery_init_load(&load, &bat_conf, charger.num_batteries);
|
||||
charger.init_terminal(&bat_conf);
|
||||
load.set_voltage_limits(
|
||||
bat_conf.voltage_load_disconnect * charger.num_batteries,
|
||||
bat_conf.voltage_load_reconnect * charger.num_batteries,
|
||||
bat_conf.voltage_absolute_max * charger.num_batteries);
|
||||
|
||||
wait(2); // safety feature: be able to re-flash before starting
|
||||
control_timer_start(CONTROL_FREQUENCY);
|
||||
|
||||
+5
-2
@@ -62,8 +62,11 @@ void main(void)
|
||||
#endif
|
||||
|
||||
charger.detect_num_batteries(&bat_conf); // check if we have 24V instead of 12V system
|
||||
battery_init_terminal(&bat_terminal, &bat_conf, charger.num_batteries);
|
||||
battery_init_load(&load, &bat_conf, charger.num_batteries);
|
||||
charger.init_terminal(&bat_conf);
|
||||
load.set_voltage_limits(
|
||||
bat_conf.voltage_load_disconnect * charger.num_batteries,
|
||||
bat_conf.voltage_load_reconnect * charger.num_batteries,
|
||||
bat_conf.voltage_absolute_max * charger.num_batteries);
|
||||
|
||||
k_sleep(2000); // safety feature: be able to re-flash before starting
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
static void init_structs()
|
||||
{
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_FLOODED, 6, 100);
|
||||
battery_init_terminal(&bat_terminal, &bat_conf, 1);
|
||||
charger.init_terminal(&bat_conf);
|
||||
charger.state = CHG_STATE_IDLE;
|
||||
charger.bat_temperature = 25;
|
||||
bat_terminal.bus->voltage = 14.0;
|
||||
@@ -93,8 +93,9 @@ void stop_topping_after_time_limit()
|
||||
enter_topping_at_voltage_setpoint();
|
||||
|
||||
charger.target_voltage_timer = bat_conf.topping_duration - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff + 0.1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TOPPING, charger.state);
|
||||
@@ -109,8 +110,9 @@ void stop_topping_at_cutoff_current()
|
||||
enter_topping_at_voltage_setpoint();
|
||||
|
||||
charger.target_voltage_timer = 0;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TRICKLE, charger.state);
|
||||
}
|
||||
@@ -121,8 +123,9 @@ void trickle_to_idle_for_li_ion()
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_LFP, 4, 100);
|
||||
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_IDLE, charger.state);
|
||||
}
|
||||
@@ -171,8 +174,9 @@ void trickle_to_equalization_if_enabled_and_time_limit_reached()
|
||||
time(NULL) - bat_conf.equalization_trigger_days * 24*60*60;
|
||||
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
}
|
||||
@@ -186,8 +190,9 @@ void trickle_to_equalization_if_enabled_and_deep_dis_limit_reached()
|
||||
charger.num_deep_discharges - bat_conf.equalization_trigger_deep_cycles;
|
||||
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
}
|
||||
@@ -198,7 +203,8 @@ void stop_equalization_after_time_limit()
|
||||
trickle_to_equalization_if_enabled_and_time_limit_reached();
|
||||
|
||||
charger.time_state_changed = time(NULL) - bat_conf.equalization_duration + 1;
|
||||
bat_terminal.bus->voltage = bat_conf.equalization_voltage + 0.1;
|
||||
bat_terminal.bus->voltage = bat_conf.equalization_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
|
||||
+4
-2
@@ -24,7 +24,8 @@ static void init_structs_buck()
|
||||
hv_terminal.update_bus_current_margins();
|
||||
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_GEL, 6, 100);
|
||||
battery_init_terminal(&dcdc_lv_port, &bat_conf, 1);
|
||||
charger.port = &dcdc_lv_port;
|
||||
charger.init_terminal(&bat_conf);
|
||||
dcdc_lv_port.bus->voltage = 14;
|
||||
dcdc_lv_port.current = 0;
|
||||
dcdc_lv_port.update_bus_current_margins();
|
||||
@@ -60,7 +61,8 @@ static void init_structs_boost()
|
||||
dcdc_lv_port.update_bus_current_margins();
|
||||
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_NMC, 10, 9);
|
||||
battery_init_terminal(&hv_terminal, &bat_conf, 1);
|
||||
charger.port = &hv_terminal;
|
||||
charger.init_terminal(&bat_conf);
|
||||
hv_terminal.bus->voltage = 3.7 * 10;
|
||||
hv_terminal.current = 0;
|
||||
hv_terminal.power = 0;
|
||||
|
||||
Reference in New Issue
Block a user