Move voltage control parameters to DcBus class

The sink and source voltage boundaries for droop control and battery
charge voltage management are now part of the DcBus class.
Also added source and sink current margins, which will be used by the
DC/DC for control targets instead of port current limits, which were
difficult to synchronize before.
This commit is contained in:
Martin Jaeger
2020-02-07 12:03:25 +01:00
parent a7d6dbc3b5
commit 43f90eea7c
16 changed files with 421 additions and 390 deletions
+8 -37
View File
@@ -10,37 +10,19 @@ void PowerPort::init_solar()
{
neg_current_limit = -50; // derating based on max. DC/DC or PWM switch current only
pos_current_limit = 0; // no current towards solar panel allowed
// also initialize the connected bus
src_voltage_start = 16.0;
src_voltage_stop = 14.0;
}
void PowerPort::init_nanogrid()
{
neg_current_limit = -5.0;
neg_droop_res = 0.1; // 1 Ohm means 1V change of target voltage per amp
pos_current_limit = 5.0;
pos_droop_res = 0.1; // 1 Ohm means 1V change of target voltage per amp
neg_current_limit = -5.0;
bus->droop_res = 0.1; // 1 Ohm means 1V change of target voltage per amp
// also initialize the connected bus
src_voltage_start = 30.0; // starting buck mode above this point
src_voltage_stop = 30.0; // stopping buck mode below this point
sink_voltage_max = 28.0; // starting idle mode above this point
sink_voltage_min = 10.0;
bus->src_voltage_bound = 30.0; // starting buck mode above this point
bus->sink_voltage_bound = 28.0; // boost mode until this voltage is reached
}
void PowerPort::init_load(float max_load_voltage)
{
sink_voltage_max = max_load_voltage; // above this voltage, load is switched off
sink_voltage_min = 0;
// other settings are not relevant for load output
}
// must be called exactly once per second, otherwise energy calculation gets wrong
void PowerPort::energy_balance()
{
// remark: timespan = 1s, so no multiplication with time necessary for energy calculation
@@ -52,24 +34,13 @@ void PowerPort::energy_balance()
}
}
void PowerPort::pass_voltage_targets(PowerPort *port)
{
// droop resistance added only to limits where current actually flows
port->sink_voltage_min = sink_voltage_min;
port->sink_voltage_max = sink_voltage_max + pos_droop_res * current;
port->src_voltage_start = src_voltage_start + pos_droop_res * current;
port->src_voltage_stop = src_voltage_stop + pos_droop_res * current;
}
void ports_update_current_limits(PowerPort *internal, PowerPort *p_bat, PowerPort *p_load)
void PowerPort::update_bus_current_margins()
{
// charging direction of battery
internal->pos_current_limit = p_bat->pos_current_limit + p_load->current;
bus->sink_current_margin = pos_current_limit - current;
// discharging direction of battery
internal->neg_current_limit = p_bat->neg_current_limit;
bus->src_current_margin = neg_current_limit - current;
// load output current = max. negative (discharging) battery current.
// this statement enables or disables the load output if discharging is not allowed
p_load->pos_current_limit = -p_bat->neg_current_limit;
//printf("pos: %.3f neg: %.3f current: %.3f\n", pos_current_limit, neg_current_limit, current);
}