DC bus integrated into PowerPort class
Reason: Previous idea with storing the voltage only once and not in every port doesn't work well for droop settings, e.g. the DC/DC output port doesn't know the actual battery current, which should be used to calculate the droop caued by wire resistance.
This commit is contained in:
+45
-45
@@ -11,15 +11,15 @@
|
||||
|
||||
static void init_structs_buck()
|
||||
{
|
||||
dcdc_port_hv.init_solar();
|
||||
dcdc_port_hv.bus->voltage = 20;
|
||||
dcdc_port_hv.bus->dis_voltage_start = 18;
|
||||
dcdc_port_hv.current = 0;
|
||||
hv_terminal.init_solar();
|
||||
hv_terminal.voltage = 20;
|
||||
hv_terminal.dis_voltage_start = 18;
|
||||
hv_terminal.current = 0;
|
||||
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_GEL, 6, 100);
|
||||
battery_init_dc_bus(&dcdc_port_lv, &bat_conf, 1);
|
||||
dcdc_port_lv.bus->voltage = 14;
|
||||
dcdc_port_lv.current = 0;
|
||||
battery_init_dc_bus(&dcdc_lv_port, &bat_conf, 1);
|
||||
dcdc_lv_port.voltage = 14;
|
||||
dcdc_lv_port.current = 0;
|
||||
|
||||
dcdc.mode = MODE_MPPT_BUCK;
|
||||
dcdc.temp_mosfets = 25;
|
||||
@@ -43,17 +43,17 @@ static void init_structs_boost()
|
||||
{
|
||||
half_bridge_stop();
|
||||
|
||||
dcdc_port_hv.init_solar();
|
||||
dcdc_port_lv.bus->voltage = 20;
|
||||
dcdc_port_lv.bus->dis_voltage_start = 18;
|
||||
dcdc_port_lv.current = 0;
|
||||
dcdc_port_lv.power = 0;
|
||||
hv_terminal.init_solar();
|
||||
dcdc_lv_port.voltage = 20;
|
||||
dcdc_lv_port.dis_voltage_start = 18;
|
||||
dcdc_lv_port.current = 0;
|
||||
dcdc_lv_port.power = 0;
|
||||
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_NMC, 10, 9);
|
||||
battery_init_dc_bus(&dcdc_port_hv, &bat_conf, 1);
|
||||
dcdc_port_hv.bus->voltage = 3.7 * 10;
|
||||
dcdc_port_hv.current = 0;
|
||||
dcdc_port_hv.power = 0;
|
||||
battery_init_dc_bus(&hv_terminal, &bat_conf, 1);
|
||||
hv_terminal.voltage = 3.7 * 10;
|
||||
hv_terminal.current = 0;
|
||||
hv_terminal.power = 0;
|
||||
|
||||
dcdc.mode = MODE_MPPT_BOOST;
|
||||
dcdc.temp_mosfets = 25;
|
||||
@@ -104,7 +104,7 @@ void no_start_if_dcdc_disabled()
|
||||
void no_start_if_dcdc_lv_voltage_low()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_port_lv.bus->voltage = dcdc.ls_voltage_min - 0.5;
|
||||
dcdc_lv_port.voltage = dcdc.ls_voltage_min - 0.5;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
@@ -113,35 +113,35 @@ void no_start_if_dcdc_lv_voltage_low()
|
||||
void no_buck_start_if_bat_voltage_low()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_port_lv.bus->voltage = bat_conf.voltage_absolute_min - 0.1;
|
||||
dcdc_lv_port.voltage = bat_conf.voltage_absolute_min - 0.1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_buck_start_if_bat_voltage_high()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_port_lv.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
dcdc_lv_port.voltage = bat_conf.topping_voltage + 0.1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_buck_start_if_bat_chg_not_allowed()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_port_lv.chg_current_limit = 0;
|
||||
dcdc_lv_port.chg_current_limit = 0;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_buck_start_if_solar_voltage_high()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_port_hv.bus->voltage = dcdc.hs_voltage_max + 1;
|
||||
hv_terminal.voltage = dcdc.hs_voltage_max + 1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_buck_start_if_solar_voltage_low()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_port_hv.bus->voltage = 17;
|
||||
hv_terminal.voltage = 17;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
@@ -150,35 +150,35 @@ void no_buck_start_if_solar_voltage_low()
|
||||
void no_boost_start_if_bat_voltage_low()
|
||||
{
|
||||
init_structs_boost();
|
||||
dcdc_port_hv.bus->voltage = bat_conf.voltage_absolute_min - 0.1;
|
||||
hv_terminal.voltage = bat_conf.voltage_absolute_min - 0.1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_boost_start_if_bat_voltage_high()
|
||||
{
|
||||
init_structs_boost();
|
||||
dcdc_port_hv.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
hv_terminal.voltage = bat_conf.topping_voltage + 0.1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_boost_start_if_bat_chg_not_allowed()
|
||||
{
|
||||
init_structs_boost();
|
||||
dcdc_port_hv.chg_current_limit = 0;
|
||||
hv_terminal.chg_current_limit = 0;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_boost_start_if_solar_voltage_high()
|
||||
{
|
||||
init_structs_boost();
|
||||
dcdc_port_lv.bus->voltage = dcdc.ls_voltage_max + 1;
|
||||
dcdc_lv_port.voltage = dcdc.ls_voltage_max + 1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_boost_start_if_solar_voltage_low()
|
||||
{
|
||||
init_structs_boost();
|
||||
dcdc_port_lv.bus->voltage = 17;
|
||||
dcdc_lv_port.voltage = 17;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ void buck_derating_output_voltage_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_port_lv.bus->voltage = dcdc_port_lv.bus->chg_voltage_target + 0.1;
|
||||
dcdc_lv_port.voltage = dcdc_lv_port.chg_voltage_target + 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before); // less duty cycle = higher voltage
|
||||
@@ -208,7 +208,7 @@ void buck_derating_output_current_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_port_lv.current = dcdc_port_lv.chg_current_limit + 0.1;
|
||||
dcdc_lv_port.current = dcdc_lv_port.chg_current_limit + 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
@@ -219,8 +219,8 @@ void buck_derating_input_voltage_too_low()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_port_hv.bus->voltage = dcdc_port_hv.bus->dis_voltage_stop - 0.1;
|
||||
dcdc_port_lv.current = 0.2;
|
||||
hv_terminal.voltage = hv_terminal.dis_voltage_stop - 0.1;
|
||||
dcdc_lv_port.current = 0.2;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
@@ -231,7 +231,7 @@ void buck_derating_input_current_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_port_hv.current = dcdc_port_hv.dis_current_limit - 0.1;
|
||||
hv_terminal.current = hv_terminal.dis_current_limit - 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
@@ -261,7 +261,7 @@ void buck_stop_high_voltage_emergency()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_port_lv.bus->voltage = dcdc.ls_voltage_max + 0.1;
|
||||
dcdc_lv_port.voltage = dcdc.ls_voltage_max + 0.1;
|
||||
dcdc.control();
|
||||
TEST_ASSERT(half_bridge_enabled() == false);
|
||||
}
|
||||
@@ -270,15 +270,15 @@ void buck_correct_mppt_operation()
|
||||
{
|
||||
start_buck();
|
||||
|
||||
dcdc_port_lv.power = 5;
|
||||
dcdc_lv_port.power = 5;
|
||||
dcdc.control();
|
||||
float pwm1 = half_bridge_get_duty_cycle();
|
||||
dcdc_port_lv.power = 7;
|
||||
dcdc_lv_port.power = 7;
|
||||
dcdc.control();
|
||||
float pwm2 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm2 > pwm1);
|
||||
|
||||
dcdc_port_lv.power = 6; // decrease power to make the direction turn around
|
||||
dcdc_lv_port.power = 6; // decrease power to make the direction turn around
|
||||
dcdc.control();
|
||||
float pwm3 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm3 < pwm2);
|
||||
@@ -300,7 +300,7 @@ void boost_derating_output_voltage_too_high()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_port_hv.bus->voltage = dcdc_port_hv.bus->chg_voltage_target + 0.5;
|
||||
hv_terminal.voltage = hv_terminal.chg_voltage_target + 0.5;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before); // higher duty cycle = less power
|
||||
@@ -310,7 +310,7 @@ void boost_derating_output_current_too_high()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_port_hv.current = dcdc_port_hv.chg_current_limit + 0.1;
|
||||
hv_terminal.current = hv_terminal.chg_current_limit + 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
@@ -320,8 +320,8 @@ void boost_derating_input_voltage_too_low()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_port_lv.bus->voltage = dcdc_port_lv.bus->dis_voltage_stop - 0.1;
|
||||
dcdc_port_hv.current = 0.2;
|
||||
dcdc_lv_port.voltage = dcdc_lv_port.dis_voltage_stop - 0.1;
|
||||
hv_terminal.current = 0.2;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
@@ -331,7 +331,7 @@ void boost_derating_input_current_too_high()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_port_lv.current = dcdc_port_lv.dis_current_limit - 0.1;
|
||||
dcdc_lv_port.current = dcdc_lv_port.dis_current_limit - 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
@@ -358,7 +358,7 @@ void boost_stop_input_power_too_low()
|
||||
void boost_stop_high_voltage_emergency()
|
||||
{
|
||||
start_boost();
|
||||
dcdc_port_hv.bus->voltage = dcdc.hs_voltage_max + 0.1;
|
||||
hv_terminal.voltage = dcdc.hs_voltage_max + 0.1;
|
||||
dcdc.control();
|
||||
TEST_ASSERT(half_bridge_enabled() == false);
|
||||
}
|
||||
@@ -367,15 +367,15 @@ void boost_correct_mppt_operation()
|
||||
{
|
||||
start_boost();
|
||||
|
||||
dcdc_port_hv.power = 5;
|
||||
hv_terminal.power = 5;
|
||||
dcdc.control();
|
||||
float pwm1 = half_bridge_get_duty_cycle();
|
||||
dcdc_port_hv.power = 7;
|
||||
hv_terminal.power = 7;
|
||||
dcdc.control();
|
||||
float pwm2 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm2 < pwm1);
|
||||
|
||||
dcdc_port_hv.power = 6; // decrease power to make the direction turn around
|
||||
hv_terminal.power = 6; // decrease power to make the direction turn around
|
||||
dcdc.control();
|
||||
float pwm3 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm3 > pwm2);
|
||||
|
||||
Reference in New Issue
Block a user