DC/DC: Use high/low DcBus instead of PowerPort for control
This makes more sense because the DC/DC converter actually connects two DcBuses and does not need separate PowerPorts. Also makes the code look more clean as variable access like dcdc.hvs->bus->voltage is avoided. The DcBus pointers in the Dcdc are now called hvb and lvb for high- voltage side bus and low-voltage side bus.
This commit is contained in:
+48
-29
@@ -25,16 +25,18 @@ static void init_structs_buck(int num_batteries = 1)
|
||||
hv_terminal.update_bus_current_margins();
|
||||
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_GEL, 6, 100);
|
||||
charger.port = &dcdc_lv_port;
|
||||
charger.port = &lv_terminal;
|
||||
charger.init_terminal(&bat_conf);
|
||||
dcdc_lv_port.bus->voltage = 14 * num_batteries;
|
||||
dcdc_lv_port.bus->series_multiplier = num_batteries;
|
||||
dcdc_lv_port.current = 0;
|
||||
dcdc_lv_port.update_bus_current_margins();
|
||||
lv_terminal.bus->voltage = 14 * num_batteries;
|
||||
lv_terminal.bus->series_multiplier = num_batteries;
|
||||
lv_terminal.current = 0;
|
||||
lv_terminal.update_bus_current_margins();
|
||||
|
||||
dcdc.mode = DCDC_MODE_BUCK;
|
||||
dcdc.temp_mosfets = 25;
|
||||
dcdc.off_timestamp = 0;
|
||||
dcdc.inductor_current = 0;
|
||||
dcdc.power = 0;
|
||||
dcdc.power_prev = 0;
|
||||
dcdc.pwm_delta = 1;
|
||||
dcdc.enable = true;
|
||||
@@ -56,12 +58,12 @@ static void init_structs_boost(int num_batteries = 1)
|
||||
half_bridge_stop();
|
||||
|
||||
hv_terminal.init_solar();
|
||||
dcdc_lv_port.bus->voltage = 20;
|
||||
dcdc_lv_port.bus->src_voltage_intercept = 18;
|
||||
dcdc_lv_port.bus->series_multiplier = 1;
|
||||
dcdc_lv_port.current = 0;
|
||||
dcdc_lv_port.power = 0;
|
||||
dcdc_lv_port.update_bus_current_margins();
|
||||
lv_terminal.bus->voltage = 20;
|
||||
lv_terminal.bus->src_voltage_intercept = 18;
|
||||
lv_terminal.bus->series_multiplier = 1;
|
||||
dcdc.inductor_current = 0;
|
||||
dcdc.power = 0;
|
||||
lv_terminal.update_bus_current_margins();
|
||||
|
||||
int num_cells = (num_batteries == 1) ? 10 : 5;
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_NMC, num_cells, 9);
|
||||
@@ -134,7 +136,7 @@ void no_start_if_dcdc_disabled()
|
||||
void no_start_if_dcdc_lv_voltage_low()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_lv_port.bus->voltage = dcdc.ls_voltage_min - 0.5;
|
||||
lv_terminal.bus->voltage = dcdc.ls_voltage_min - 0.5;
|
||||
TEST_ASSERT_EQUAL(DCDC_MODE_OFF, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
@@ -143,14 +145,14 @@ void no_start_if_dcdc_lv_voltage_low()
|
||||
void no_buck_start_if_bat_voltage_high()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_lv_port.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
lv_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
TEST_ASSERT_EQUAL(DCDC_MODE_OFF, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_buck_start_if_bat_chg_not_allowed()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_lv_port.bus->sink_current_margin = 0;
|
||||
lv_terminal.bus->sink_current_margin = 0;
|
||||
TEST_ASSERT_EQUAL(DCDC_MODE_OFF, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
@@ -187,14 +189,14 @@ void no_boost_start_if_bat_chg_not_allowed()
|
||||
void no_boost_start_if_solar_voltage_high()
|
||||
{
|
||||
init_structs_boost();
|
||||
dcdc_lv_port.bus->voltage = dcdc.ls_voltage_max + 1;
|
||||
lv_terminal.bus->voltage = dcdc.ls_voltage_max + 1;
|
||||
TEST_ASSERT_EQUAL(DCDC_MODE_OFF, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_boost_start_if_solar_voltage_low()
|
||||
{
|
||||
init_structs_boost();
|
||||
dcdc_lv_port.bus->voltage = 17;
|
||||
lv_terminal.bus->voltage = 17;
|
||||
TEST_ASSERT_EQUAL(DCDC_MODE_OFF, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
@@ -213,7 +215,7 @@ void buck_derating_output_voltage_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_lv_port.bus->voltage = dcdc_lv_port.bus->sink_voltage_intercept + 0.1;
|
||||
lv_terminal.bus->voltage = lv_terminal.bus->sink_voltage_intercept + 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before); // less duty cycle = higher voltage
|
||||
@@ -224,7 +226,19 @@ void buck_derating_output_current_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_lv_port.current = dcdc_lv_port.pos_current_limit + 0.1;
|
||||
lv_terminal.current = lv_terminal.pos_current_limit + 0.1;
|
||||
lv_terminal.update_bus_current_margins();
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
TEST_ASSERT_EQUAL(DCDC_CONTROL_CC_LS, dcdc.state);
|
||||
}
|
||||
|
||||
void buck_derating_inductor_current_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc.inductor_current = dcdc.inductor_current_max + 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
@@ -236,7 +250,7 @@ void buck_derating_input_voltage_too_low()
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
hv_terminal.bus->voltage = hv_terminal.bus->src_voltage_intercept - 0.1;
|
||||
dcdc_lv_port.current = 0.2;
|
||||
dcdc.power = 1.2;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
@@ -248,6 +262,7 @@ void buck_derating_input_current_too_high()
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
hv_terminal.current = hv_terminal.neg_current_limit - 0.1;
|
||||
hv_terminal.update_bus_current_margins();
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
@@ -275,7 +290,7 @@ void buck_stop_input_power_too_low()
|
||||
void buck_stop_high_voltage_emergency()
|
||||
{
|
||||
start_buck();
|
||||
dcdc_lv_port.bus->voltage = dcdc.ls_voltage_max + 0.1;
|
||||
lv_terminal.bus->voltage = dcdc.ls_voltage_max + 0.1;
|
||||
dcdc.control();
|
||||
TEST_ASSERT(half_bridge_enabled() == false);
|
||||
}
|
||||
@@ -284,15 +299,15 @@ void buck_correct_mppt_operation()
|
||||
{
|
||||
start_buck();
|
||||
|
||||
dcdc_lv_port.power = 5;
|
||||
dcdc.power = 5;
|
||||
dcdc.control();
|
||||
float pwm1 = half_bridge_get_duty_cycle();
|
||||
dcdc_lv_port.power = 7;
|
||||
dcdc.power = 7;
|
||||
dcdc.control();
|
||||
float pwm2 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm2 > pwm1);
|
||||
|
||||
dcdc_lv_port.power = 6; // decrease power to make the direction turn around
|
||||
dcdc.power = 6; // decrease power to make the direction turn around
|
||||
dcdc.control();
|
||||
float pwm3 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm3 < pwm2);
|
||||
@@ -325,6 +340,7 @@ void boost_derating_output_current_too_high()
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
hv_terminal.current = hv_terminal.pos_current_limit + 0.1;
|
||||
hv_terminal.update_bus_current_margins();
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
@@ -334,10 +350,12 @@ void boost_derating_input_voltage_too_low()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_lv_port.bus->voltage = dcdc_lv_port.bus->src_voltage_intercept - 0.1;
|
||||
hv_terminal.current = 0.2;
|
||||
lv_terminal.bus->voltage = lv_terminal.bus->src_voltage_intercept - 0.1;
|
||||
dcdc.power = -1.2;
|
||||
hv_terminal.update_bus_current_margins();
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT_EQUAL(DCDC_CONTROL_CV_LS, dcdc.state);
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
}
|
||||
|
||||
@@ -345,7 +363,7 @@ void boost_derating_input_current_too_high()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_lv_port.current = dcdc_lv_port.neg_current_limit - 0.1;
|
||||
dcdc.inductor_current = lv_terminal.neg_current_limit - 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
@@ -381,15 +399,15 @@ void boost_correct_mppt_operation()
|
||||
{
|
||||
start_boost();
|
||||
|
||||
hv_terminal.power = 5;
|
||||
dcdc.power = -5;
|
||||
dcdc.control();
|
||||
float pwm1 = half_bridge_get_duty_cycle();
|
||||
hv_terminal.power = 7;
|
||||
dcdc.power = -7;
|
||||
dcdc.control();
|
||||
float pwm2 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm2 < pwm1);
|
||||
|
||||
hv_terminal.power = 6; // decrease power to make the direction turn around
|
||||
dcdc.power = -6; // decrease power to make the direction turn around
|
||||
dcdc.control();
|
||||
float pwm3 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm3 > pwm2);
|
||||
@@ -435,6 +453,7 @@ void dcdc_tests()
|
||||
RUN_TEST(buck_increasing_power);
|
||||
RUN_TEST(buck_derating_output_voltage_too_high);
|
||||
RUN_TEST(buck_derating_output_current_too_high);
|
||||
RUN_TEST(buck_derating_inductor_current_too_high);
|
||||
RUN_TEST(buck_derating_input_voltage_too_low);
|
||||
RUN_TEST(buck_derating_input_current_too_high);
|
||||
RUN_TEST(buck_derating_temperature_limits_exceeded);
|
||||
|
||||
Reference in New Issue
Block a user