PowerPort member variables renamed
Previous naming with chg/dis didn't make much sense e.g. for load output or solar panels. Voltage targets are now named with source or sink. Current limits are defined based on their direction (negative or positive). ASCII art graphic added for better explanation of passive sign convention.
This commit is contained in:
@@ -216,31 +216,31 @@ void stop_discharge_at_low_voltage()
|
||||
|
||||
bat_terminal.voltage = 14;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal.dis_current_limit);
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal.neg_current_limit);
|
||||
|
||||
bat_terminal.voltage = bat_conf.voltage_load_disconnect - 0.1;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.dis_current_limit);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.neg_current_limit);
|
||||
}
|
||||
|
||||
void stop_discharge_at_overtemp()
|
||||
{
|
||||
init_structs();
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal.dis_current_limit);
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal.neg_current_limit);
|
||||
|
||||
charger.bat_temperature = bat_conf.discharge_temp_max + 1;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.dis_current_limit);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.neg_current_limit);
|
||||
}
|
||||
|
||||
void stop_discharge_at_undertemp()
|
||||
{
|
||||
init_structs();
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal.dis_current_limit);
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal.neg_current_limit);
|
||||
|
||||
charger.bat_temperature = bat_conf.discharge_temp_min - 1;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.dis_current_limit);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.neg_current_limit);
|
||||
}
|
||||
|
||||
void restart_discharge_if_allowed()
|
||||
@@ -250,17 +250,17 @@ void restart_discharge_if_allowed()
|
||||
// stop because of undervoltage
|
||||
bat_terminal.voltage = bat_conf.voltage_load_disconnect - 0.1;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.dis_current_limit);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.neg_current_limit);
|
||||
|
||||
// increase voltage slightly above DISconnect voltage
|
||||
bat_terminal.voltage = bat_conf.voltage_load_disconnect + 0.1;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.dis_current_limit);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.neg_current_limit);
|
||||
|
||||
// increase voltage above REconnect voltage
|
||||
bat_terminal.voltage = bat_conf.voltage_load_reconnect + 0.1;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal.dis_current_limit);
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal.neg_current_limit);
|
||||
}
|
||||
|
||||
void battery_values_propagated_to_lv_bus_int()
|
||||
|
||||
+12
-12
@@ -13,7 +13,7 @@ static void init_structs_buck()
|
||||
{
|
||||
hv_terminal.init_solar();
|
||||
hv_terminal.voltage = 20;
|
||||
hv_terminal.dis_voltage_start = 18;
|
||||
hv_terminal.src_voltage_start = 18;
|
||||
hv_terminal.current = 0;
|
||||
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_GEL, 6, 100);
|
||||
@@ -45,7 +45,7 @@ static void init_structs_boost()
|
||||
|
||||
hv_terminal.init_solar();
|
||||
dcdc_lv_port.voltage = 20;
|
||||
dcdc_lv_port.dis_voltage_start = 18;
|
||||
dcdc_lv_port.src_voltage_start = 18;
|
||||
dcdc_lv_port.current = 0;
|
||||
dcdc_lv_port.power = 0;
|
||||
|
||||
@@ -127,7 +127,7 @@ void no_buck_start_if_bat_voltage_high()
|
||||
void no_buck_start_if_bat_chg_not_allowed()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_lv_port.chg_current_limit = 0;
|
||||
dcdc_lv_port.pos_current_limit = 0;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ void no_boost_start_if_bat_voltage_high()
|
||||
void no_boost_start_if_bat_chg_not_allowed()
|
||||
{
|
||||
init_structs_boost();
|
||||
hv_terminal.chg_current_limit = 0;
|
||||
hv_terminal.pos_current_limit = 0;
|
||||
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_lv_port.voltage = dcdc_lv_port.chg_voltage_target + 0.1;
|
||||
dcdc_lv_port.voltage = dcdc_lv_port.sink_voltage_max + 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_lv_port.current = dcdc_lv_port.chg_current_limit + 0.1;
|
||||
dcdc_lv_port.current = dcdc_lv_port.pos_current_limit + 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
@@ -219,7 +219,7 @@ void buck_derating_input_voltage_too_low()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
hv_terminal.voltage = hv_terminal.dis_voltage_stop - 0.1;
|
||||
hv_terminal.voltage = hv_terminal.src_voltage_stop - 0.1;
|
||||
dcdc_lv_port.current = 0.2;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
@@ -231,7 +231,7 @@ void buck_derating_input_current_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
hv_terminal.current = hv_terminal.dis_current_limit - 0.1;
|
||||
hv_terminal.current = hv_terminal.neg_current_limit - 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
@@ -300,7 +300,7 @@ void boost_derating_output_voltage_too_high()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
hv_terminal.voltage = hv_terminal.chg_voltage_target + 0.5;
|
||||
hv_terminal.voltage = hv_terminal.sink_voltage_max + 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();
|
||||
hv_terminal.current = hv_terminal.chg_current_limit + 0.1;
|
||||
hv_terminal.current = hv_terminal.pos_current_limit + 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
@@ -320,7 +320,7 @@ void boost_derating_input_voltage_too_low()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_lv_port.voltage = dcdc_lv_port.dis_voltage_stop - 0.1;
|
||||
dcdc_lv_port.voltage = dcdc_lv_port.src_voltage_stop - 0.1;
|
||||
hv_terminal.current = 0.2;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
@@ -331,7 +331,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.dis_current_limit - 0.1;
|
||||
dcdc_lv_port.current = dcdc_lv_port.neg_current_limit - 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
|
||||
+12
-12
@@ -13,10 +13,10 @@ void reset_counters_at_start_of_day()
|
||||
|
||||
log_data.day_counter = 0;
|
||||
|
||||
solar_terminal.dis_energy_Wh = 10.0;
|
||||
bat_terminal.dis_energy_Wh = 3.0;
|
||||
bat_terminal.chg_energy_Wh = 4.0;
|
||||
load_terminal.chg_energy_Wh = 9.0;
|
||||
solar_terminal.neg_energy_Wh = 10.0;
|
||||
bat_terminal.neg_energy_Wh = 3.0;
|
||||
bat_terminal.pos_energy_Wh = 4.0;
|
||||
load_terminal.pos_energy_Wh = 9.0;
|
||||
|
||||
// 5 houurs without sun
|
||||
for (int i = 0; i <= 5 * 60 * 60; i++) {
|
||||
@@ -28,10 +28,10 @@ void reset_counters_at_start_of_day()
|
||||
TEST_ASSERT_EQUAL(4, log_data.bat_chg_total_Wh);
|
||||
TEST_ASSERT_EQUAL(9, log_data.load_out_total_Wh);
|
||||
|
||||
TEST_ASSERT_EQUAL(10, solar_terminal.dis_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(3, bat_terminal.dis_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(4, bat_terminal.chg_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(9, load_terminal.chg_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(10, solar_terminal.neg_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(3, bat_terminal.neg_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(4, bat_terminal.pos_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(9, load_terminal.pos_energy_Wh);
|
||||
|
||||
// solar didn't come back yet
|
||||
TEST_ASSERT_EQUAL(0, log_data.day_counter);
|
||||
@@ -42,10 +42,10 @@ void reset_counters_at_start_of_day()
|
||||
|
||||
// day counter should be increased and daily energy counters reset
|
||||
TEST_ASSERT_EQUAL(1, log_data.day_counter);
|
||||
TEST_ASSERT_EQUAL(0, solar_terminal.dis_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.dis_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.chg_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(0, load_terminal.chg_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(0, solar_terminal.neg_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.neg_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.pos_energy_Wh);
|
||||
TEST_ASSERT_EQUAL(0, load_terminal.pos_energy_Wh);
|
||||
}
|
||||
|
||||
void log_new_solar_voltage_max()
|
||||
|
||||
+22
-22
@@ -29,10 +29,10 @@ void energy_calculation_init()
|
||||
log_data.load_out_total_Wh = 0;
|
||||
log_data.bat_chg_total_Wh = 0;
|
||||
log_data.bat_dis_total_Wh = 0;
|
||||
hv_terminal.dis_energy_Wh = 0.0;
|
||||
load_terminal.chg_energy_Wh = 0.0;
|
||||
lv_terminal.chg_energy_Wh = 0.0;
|
||||
lv_terminal.dis_energy_Wh = 0.0;
|
||||
hv_terminal.neg_energy_Wh = 0.0;
|
||||
load_terminal.pos_energy_Wh = 0.0;
|
||||
lv_terminal.pos_energy_Wh = 0.0;
|
||||
lv_terminal.neg_energy_Wh = 0.0;
|
||||
|
||||
// set desired measurement values
|
||||
adcval.bat_temperature = 25;
|
||||
@@ -69,26 +69,26 @@ void charging_energy_calculation_valid()
|
||||
{
|
||||
energy_calculation_init();
|
||||
// charging only during sun hours
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(sun_hours * lv_terminal.voltage * (dcdc_current_sun - load_current)), round(lv_terminal.chg_energy_Wh));
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(sun_hours * lv_terminal.voltage * (dcdc_current_sun - load_current)), round(lv_terminal.pos_energy_Wh));
|
||||
}
|
||||
|
||||
void discharging_energy_calculation_valid()
|
||||
{
|
||||
energy_calculation_init();
|
||||
// discharging (sum of current) only during dis hours
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(night_hours * lv_terminal.voltage * adcval.load_current), round(lv_terminal.dis_energy_Wh));
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(night_hours * lv_terminal.voltage * adcval.load_current), round(lv_terminal.neg_energy_Wh));
|
||||
}
|
||||
|
||||
void solar_input_energy_calculation_valid()
|
||||
{
|
||||
energy_calculation_init();
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(sun_hours * lv_terminal.voltage * dcdc_current_sun), round(hv_terminal.dis_energy_Wh));
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(sun_hours * lv_terminal.voltage * dcdc_current_sun), round(hv_terminal.neg_energy_Wh));
|
||||
}
|
||||
|
||||
void load_output_energy_calculation_valid()
|
||||
{
|
||||
energy_calculation_init();
|
||||
TEST_ASSERT_EQUAL_FLOAT(round((sun_hours + night_hours) * lv_terminal.voltage * adcval.load_current), round(load_terminal.chg_energy_Wh));
|
||||
TEST_ASSERT_EQUAL_FLOAT(round((sun_hours + night_hours) * lv_terminal.voltage * adcval.load_current), round(load_terminal.pos_energy_Wh));
|
||||
}
|
||||
|
||||
void pass_voltage_targets_to_adjacent_bus()
|
||||
@@ -96,28 +96,28 @@ 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);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.sink_voltage_min, dcdc_lv_port.sink_voltage_min);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.sink_voltage_max, dcdc_lv_port.sink_voltage_max);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.src_voltage_start, dcdc_lv_port.src_voltage_start);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.src_voltage_stop, dcdc_lv_port.src_voltage_stop);
|
||||
|
||||
// now with droop for positive current
|
||||
bat_terminal.current = 11;
|
||||
bat_terminal.chg_droop_res = 0.1;
|
||||
bat_terminal.pos_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);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.sink_voltage_min, dcdc_lv_port.sink_voltage_min);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.sink_voltage_max + 11*0.1, dcdc_lv_port.sink_voltage_max);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.src_voltage_start + 11*0.1, dcdc_lv_port.src_voltage_start);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.src_voltage_stop + 11*0.1, dcdc_lv_port.src_voltage_stop);
|
||||
|
||||
// now with droop for negative current
|
||||
bat_terminal.current = -11;
|
||||
bat_terminal.chg_droop_res = 0.1;
|
||||
bat_terminal.pos_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);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.sink_voltage_min, dcdc_lv_port.sink_voltage_min);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.sink_voltage_max - 11*0.1, dcdc_lv_port.sink_voltage_max);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.src_voltage_start - 11*0.1, dcdc_lv_port.src_voltage_start);
|
||||
TEST_ASSERT_EQUAL(bat_terminal.src_voltage_stop - 11*0.1, dcdc_lv_port.src_voltage_stop);
|
||||
}
|
||||
|
||||
void power_port_tests()
|
||||
|
||||
Reference in New Issue
Block a user