Passing of bat voltage and current limits to other ports updated
This commit is contained in:
@@ -459,14 +459,3 @@ void battery_init_dc_bus(PowerPort *port, BatConf *bat, unsigned int num_batteri
|
||||
// negative sign for compensation of actual resistance
|
||||
port->chg_droop_res = -bat->wire_resistance * n;
|
||||
}
|
||||
|
||||
void update_dcdc_current_targets(PowerPort *dcdc_port, PowerPort *bat, PowerPort *load)
|
||||
{
|
||||
// relevant for DC/DC
|
||||
dcdc_port->chg_current_limit = bat->chg_current_limit - bat->current + 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).
|
||||
dcdc_port->dis_current_limit = bat->dis_current_limit - bat->current;
|
||||
}
|
||||
|
||||
@@ -367,8 +367,4 @@ void battery_conf_overwrite(BatConf *source, BatConf *destination, Charger *char
|
||||
*/
|
||||
void battery_init_dc_bus(PowerPort *port, BatConf *bat, unsigned int num_batteries);
|
||||
|
||||
/** Calculates targets for junction of load and battery bus at the DC/DC output
|
||||
*/
|
||||
void update_dcdc_current_targets(PowerPort *dcdc_port, PowerPort *bat, PowerPort *load);
|
||||
|
||||
#endif /* BAT_CHARGER_H */
|
||||
|
||||
+6
-1
@@ -148,7 +148,10 @@ int main()
|
||||
charger.charge_control(&bat_conf);
|
||||
|
||||
#if FEATURE_DCDC_CONVERTER
|
||||
update_dcdc_current_targets(&dcdc_lv_port, &bat_terminal, &load_terminal);
|
||||
bat_terminal.pass_voltage_targets(&dcdc_lv_port);
|
||||
#endif
|
||||
#if FEATURE_PWM_SWITCH
|
||||
bat_terminal.pass_voltage_targets(&pwm_port_int);
|
||||
#endif
|
||||
|
||||
load.state_machine();
|
||||
@@ -180,11 +183,13 @@ void system_control()
|
||||
update_measurements();
|
||||
|
||||
#if FEATURE_PWM_SWITCH
|
||||
ports_update_current_limits(&pwm_port_int, &bat_terminal, &load_terminal);
|
||||
pwm_switch.control();
|
||||
leds_set_charging(pwm_switch.active());
|
||||
#endif
|
||||
|
||||
#if FEATURE_DCDC_CONVERTER
|
||||
ports_update_current_limits(&dcdc_lv_port, &bat_terminal, &load_terminal);
|
||||
dcdc.control(); // control of DC/DC including MPPT algorithm
|
||||
leds_set_charging(half_bridge_enabled());
|
||||
#endif
|
||||
|
||||
@@ -53,3 +53,22 @@ void PowerPort::energy_balance()
|
||||
dis_energy_Wh -= voltage * current / 3600.0;
|
||||
}
|
||||
}
|
||||
|
||||
void PowerPort::pass_voltage_targets(PowerPort *port)
|
||||
{
|
||||
// droop resistance added only to limits where current actually flows
|
||||
port->chg_voltage_min = chg_voltage_min;
|
||||
port->chg_voltage_target = chg_voltage_target + chg_droop_res * current;
|
||||
port->dis_voltage_start = dis_voltage_start + chg_droop_res * current;
|
||||
port->dis_voltage_stop = dis_voltage_stop + chg_droop_res * current;
|
||||
}
|
||||
|
||||
void ports_update_current_limits(PowerPort *p_dcdc, PowerPort *p_bat, PowerPort *p_load)
|
||||
{
|
||||
p_dcdc->chg_current_limit = p_bat->chg_current_limit - p_bat->current + 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->dis_current_limit = p_bat->dis_current_limit - p_bat->current;
|
||||
}
|
||||
|
||||
+11
-1
@@ -19,7 +19,7 @@
|
||||
|
||||
/** @file
|
||||
*
|
||||
* @brief Definition of charge controller terminals and internal power port / connections
|
||||
* @brief Definition of charge controller terminals and internal DC buses
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
@@ -71,6 +71,16 @@ public:
|
||||
* Must be called exactly once per second, otherwise energy calculation gets wrong.
|
||||
*/
|
||||
void energy_balance();
|
||||
|
||||
/** Passes own voltage target settings to another port
|
||||
*
|
||||
* @param port Port where the voltage settings will be adjusted
|
||||
*/
|
||||
void pass_voltage_targets(PowerPort *port);
|
||||
};
|
||||
|
||||
/** Sets current limits of DC/DC and load according to battery status
|
||||
*/
|
||||
void ports_update_current_limits(PowerPort *p_dcdc, PowerPort *p_bat, PowerPort *p_load);
|
||||
|
||||
#endif /* POWER_PORT_H */
|
||||
|
||||
@@ -91,6 +91,35 @@ void load_output_energy_calculation_valid()
|
||||
TEST_ASSERT_EQUAL_FLOAT(round((sun_hours + night_hours) * lv_terminal.voltage * adcval.load_current), round(load_terminal.chg_energy_Wh));
|
||||
}
|
||||
|
||||
void pass_voltage_targets_to_adjacent_bus()
|
||||
{
|
||||
// without any droop
|
||||
bat_terminal.current = 0;
|
||||
bat_terminal.pass_voltage_targets(&dcdc_lv_port);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.chg_voltage_min, dcdc_lv_port.chg_voltage_min);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.chg_voltage_target, dcdc_lv_port.chg_voltage_target);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.dis_voltage_start, dcdc_lv_port.dis_voltage_start);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.dis_voltage_stop, dcdc_lv_port.dis_voltage_stop);
|
||||
|
||||
// now with droop for positive current
|
||||
bat_terminal.current = 11;
|
||||
bat_terminal.chg_droop_res = 0.1;
|
||||
bat_terminal.pass_voltage_targets(&dcdc_lv_port);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.chg_voltage_min, dcdc_lv_port.chg_voltage_min);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.chg_voltage_target + 11*0.1, dcdc_lv_port.chg_voltage_target);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.dis_voltage_start + 11*0.1, dcdc_lv_port.dis_voltage_start);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.dis_voltage_stop + 11*0.1, dcdc_lv_port.dis_voltage_stop);
|
||||
|
||||
// now with droop for negative current
|
||||
bat_terminal.current = -11;
|
||||
bat_terminal.chg_droop_res = 0.1;
|
||||
bat_terminal.pass_voltage_targets(&dcdc_lv_port);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.chg_voltage_min, dcdc_lv_port.chg_voltage_min);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.chg_voltage_target - 11*0.1, dcdc_lv_port.chg_voltage_target);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.dis_voltage_start - 11*0.1, dcdc_lv_port.dis_voltage_start);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.dis_voltage_stop - 11*0.1, dcdc_lv_port.dis_voltage_stop);
|
||||
}
|
||||
|
||||
void power_port_tests()
|
||||
{
|
||||
energy_calculation_init();
|
||||
@@ -103,5 +132,7 @@ void power_port_tests()
|
||||
RUN_TEST(solar_input_energy_calculation_valid);
|
||||
RUN_TEST(load_output_energy_calculation_valid);
|
||||
|
||||
RUN_TEST(pass_voltage_targets_to_adjacent_bus);
|
||||
|
||||
UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user