From ad27142cd89eee02e57624e5e6ad3aaf85659c6c Mon Sep 17 00:00:00 2001 From: Martin Jaeger <17674105+martinjaeger@users.noreply.github.com> Date: Mon, 11 Nov 2019 19:33:30 +0100 Subject: [PATCH] Fix DC/DC and PWM switch current limit control (#79) --- src/power_port.cpp | 16 ++++++++-------- src/power_port.h | 8 ++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/power_port.cpp b/src/power_port.cpp index b448c24..bf66afd 100644 --- a/src/power_port.cpp +++ b/src/power_port.cpp @@ -54,7 +54,7 @@ void PowerPort::init_load(float max_load_voltage) void PowerPort::energy_balance() { // remark: timespan = 1s, so no multiplication with time necessary for energy calculation - if (current >= 0) { + if (current >= 0.0F) { pos_energy_Wh += voltage * current / 3600.0; } else { @@ -71,15 +71,15 @@ void PowerPort::pass_voltage_targets(PowerPort *port) port->src_voltage_stop = src_voltage_stop + pos_droop_res * current; } -void ports_update_current_limits(PowerPort *p_dcdc, PowerPort *p_bat, PowerPort *p_load) +void ports_update_current_limits(PowerPort *internal, PowerPort *p_bat, PowerPort *p_load) { - p_dcdc->pos_current_limit = p_bat->pos_current_limit - p_bat->current + p_load->current; + // charging direction of battery + internal->pos_current_limit = p_bat->pos_current_limit + p_load->current; - // this is a bit tricky... in theory, we could add the available DC/DC current to keep the - // load switched on as long as solar power is available, even if the battery is empty. This - // needs a fast point-of-load (PoL) control of the DC/DC, which is not possible (yet). - p_dcdc->neg_current_limit = p_bat->neg_current_limit - p_bat->current; + // discharging direction of battery + internal->neg_current_limit = p_bat->neg_current_limit; - // this statement enables or disables the load output + // 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; } diff --git a/src/power_port.h b/src/power_port.h index 1072257..9bc06c6 100644 --- a/src/power_port.h +++ b/src/power_port.h @@ -109,8 +109,12 @@ public: void pass_voltage_targets(PowerPort *port); }; -/** Sets current limits of DC/DC and load according to battery status +/** Sets current limits of DC/DC or PWM switch according to load and battery status + * + * @param internal DC/DC or PWM switch internal port that can be controlled + * @param p_bat Battery terminal port whose current limits have to be respected + * @param p_load Load output port with current determined by external consumers */ -void ports_update_current_limits(PowerPort *p_dcdc, PowerPort *p_bat, PowerPort *p_load); +void ports_update_current_limits(PowerPort *internal, PowerPort *p_bat, PowerPort *p_load); #endif /* POWER_PORT_H */