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:
+8
-12
@@ -17,21 +17,17 @@
|
||||
|
||||
#include "tests.h"
|
||||
|
||||
DcBus lv_bus;
|
||||
PowerPort lv_terminal(&lv_bus); // low voltage terminal (battery for typical MPPT)
|
||||
PowerPort lv_terminal; // low voltage terminal (battery for typical MPPT)
|
||||
|
||||
#if FEATURE_DCDC_CONVERTER
|
||||
DcBus hv_bus;
|
||||
PowerPort hv_terminal(&hv_bus); // high voltage terminal (solar for typical MPPT)
|
||||
PowerPort dcdc_port_hv(&hv_bus); // internal high voltage side port of DC/DC converter
|
||||
PowerPort dcdc_port_lv(&lv_bus); // internal low voltage side of DC/DC converter
|
||||
Dcdc dcdc(&dcdc_port_hv, &dcdc_port_lv, DCDC_MODE_INIT);
|
||||
PowerPort hv_terminal; // high voltage terminal (solar for typical MPPT)
|
||||
PowerPort dcdc_lv_port; // internal low voltage side of DC/DC converter
|
||||
Dcdc dcdc(&hv_terminal, &dcdc_lv_port, DCDC_MODE_INIT);
|
||||
#endif
|
||||
|
||||
#if FEATURE_PWM_SWITCH
|
||||
DcBus pwm_bus;
|
||||
PowerPort pwm_terminal(&pwm_bus); // external terminal of PWM switch port (normally solar)
|
||||
PowerPort pwm_port_int(&lv_bus); // internal side of PWM switch
|
||||
PowerPort pwm_terminal; // external terminal of PWM switch port (normally solar)
|
||||
PowerPort pwm_port_int; // internal side of PWM switch
|
||||
PwmSwitch pwm_switch(&pwm_terminal, &pwm_port_int);
|
||||
PowerPort &solar_terminal = pwm_terminal;
|
||||
#else
|
||||
@@ -39,7 +35,7 @@ PowerPort &solar_terminal = SOLAR_TERMINAL; // defined in config.h
|
||||
#endif
|
||||
|
||||
#if FEATURE_LOAD_OUTPUT
|
||||
PowerPort load_terminal(&lv_bus); // load terminal (also connected to lv_bus)
|
||||
PowerPort load_terminal; // load terminal (also connected to lv_bus)
|
||||
LoadOutput load(&load_terminal);
|
||||
#endif
|
||||
|
||||
@@ -63,7 +59,7 @@ int main()
|
||||
{
|
||||
adc_tests();
|
||||
bat_charger_tests();
|
||||
dc_bus_tests();
|
||||
power_port_tests();
|
||||
half_brigde_tests();
|
||||
dcdc_tests();
|
||||
log_tests();
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ void bat_charger_tests();
|
||||
|
||||
void adc_tests();
|
||||
|
||||
void dc_bus_tests();
|
||||
void power_port_tests();
|
||||
|
||||
void half_brigde_tests();
|
||||
|
||||
|
||||
+5
-5
@@ -9,28 +9,28 @@ static adc_values_t adcval;
|
||||
|
||||
void check_solar_terminal_readings()
|
||||
{
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.solar_voltage, round(hv_terminal.bus->voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.solar_voltage, round(hv_terminal.voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.dcdc_current / adcval.solar_voltage * adcval.battery_voltage,
|
||||
-round(hv_terminal.current * 10) / 10);
|
||||
}
|
||||
|
||||
void check_bat_terminal_readings()
|
||||
{
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.battery_voltage, round(lv_terminal.bus->voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.battery_voltage, round(lv_terminal.voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.dcdc_current - adcval.load_current,
|
||||
round(lv_terminal.current * 10) / 10);
|
||||
}
|
||||
|
||||
void check_load_terminal_readings()
|
||||
{
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.battery_voltage, round(load_terminal.bus->voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.battery_voltage, round(load_terminal.voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.load_current, round(load_terminal.current * 10) / 10);
|
||||
}
|
||||
|
||||
void check_lv_bus_int_readings()
|
||||
{
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.battery_voltage, round(dcdc_port_lv.bus->voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.dcdc_current, round(dcdc_port_lv.current * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.battery_voltage, round(dcdc_lv_port.voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.dcdc_current, round(dcdc_lv_port.current * 10) / 10);
|
||||
}
|
||||
|
||||
void check_temperature_readings()
|
||||
|
||||
+21
-21
@@ -13,14 +13,14 @@ static void init_structs()
|
||||
battery_init_dc_bus(&bat_terminal, &bat_conf, 1);
|
||||
charger.state = CHG_STATE_IDLE;
|
||||
charger.bat_temperature = 25;
|
||||
bat_terminal.bus->voltage = 14.0;
|
||||
bat_terminal.voltage = 14.0;
|
||||
bat_terminal.current = 0;
|
||||
}
|
||||
|
||||
void no_start_at_high_voltage()
|
||||
{
|
||||
init_structs();
|
||||
bat_terminal.bus->voltage = bat_conf.voltage_recharge + 0.1;
|
||||
bat_terminal.voltage = bat_conf.voltage_recharge + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_IDLE, charger.state);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ void no_start_after_short_rest()
|
||||
{
|
||||
init_structs();
|
||||
charger.time_state_changed = time(NULL) - bat_conf.time_limit_recharge + 1;
|
||||
bat_terminal.bus->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
bat_terminal.voltage = bat_conf.voltage_recharge - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_IDLE, charger.state);
|
||||
}
|
||||
@@ -38,7 +38,7 @@ void no_start_outside_temperature_limits()
|
||||
{
|
||||
init_structs();
|
||||
charger.bat_temperature = bat_conf.charge_temp_max + 1;
|
||||
bat_terminal.bus->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
bat_terminal.voltage = bat_conf.voltage_recharge - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_IDLE, charger.state);
|
||||
|
||||
@@ -51,7 +51,7 @@ void start_if_everything_just_fine()
|
||||
{
|
||||
init_structs();
|
||||
charger.time_state_changed = time(NULL) - bat_conf.time_limit_recharge - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
bat_terminal.voltage = bat_conf.voltage_recharge - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_BULK, charger.state);
|
||||
}
|
||||
@@ -60,10 +60,10 @@ void enter_topping_at_voltage_setpoint()
|
||||
{
|
||||
init_structs();
|
||||
charger.time_state_changed = time(NULL) - bat_conf.time_limit_recharge - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
bat_terminal.voltage = bat_conf.voltage_recharge - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_BULK, charger.state);
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.voltage = bat_conf.topping_voltage + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TOPPING, charger.state);
|
||||
}
|
||||
@@ -73,7 +73,7 @@ void stop_topping_after_time_limit()
|
||||
enter_topping_at_voltage_setpoint();
|
||||
|
||||
charger.time_state_changed = time(NULL) - bat_conf.topping_duration + 1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff + 0.1;
|
||||
|
||||
charger.charge_control(&bat_conf);
|
||||
@@ -89,7 +89,7 @@ void stop_topping_at_cutoff_current()
|
||||
enter_topping_at_voltage_setpoint();
|
||||
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TRICKLE, charger.state);
|
||||
@@ -101,7 +101,7 @@ void trickle_to_idle_for_li_ion()
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_LFP, 4, 100);
|
||||
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_IDLE, charger.state);
|
||||
@@ -113,7 +113,7 @@ void no_trickle_if_low_current_because_of_low_input()
|
||||
|
||||
charger.time_state_changed = time(NULL) - 200;
|
||||
charger.time_voltage_limit_reached = time(NULL) - 3;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage - 0.1;
|
||||
bat_terminal.voltage = bat_conf.topping_voltage - 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
|
||||
charger.charge_control(&bat_conf);
|
||||
@@ -136,7 +136,7 @@ void no_equalization_if_disabled()
|
||||
time(NULL) - bat_conf.equalization_trigger_days * 24*60*60;
|
||||
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_NOT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
@@ -154,7 +154,7 @@ void no_equalization_if_limits_not_reached()
|
||||
time(NULL) - (bat_conf.equalization_trigger_days - 1) * 24*60*60;
|
||||
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_NOT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
@@ -168,7 +168,7 @@ void trickle_to_equalization_if_enabled_and_time_limit_reached()
|
||||
time(NULL) - bat_conf.equalization_trigger_days * 24*60*60;
|
||||
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
@@ -183,7 +183,7 @@ void trickle_to_equalization_if_enabled_and_deep_dis_limit_reached()
|
||||
charger.num_deep_discharges - bat_conf.equalization_trigger_deep_cycles;
|
||||
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
@@ -195,7 +195,7 @@ void stop_equalization_after_time_limit()
|
||||
trickle_to_equalization_if_enabled_and_time_limit_reached();
|
||||
|
||||
charger.time_state_changed = time(NULL) - bat_conf.equalization_duration + 1;
|
||||
bat_terminal.bus->voltage = bat_conf.equalization_voltage + 0.1;
|
||||
bat_terminal.voltage = bat_conf.equalization_voltage + 0.1;
|
||||
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
@@ -214,11 +214,11 @@ void stop_discharge_at_low_voltage()
|
||||
{
|
||||
init_structs();
|
||||
|
||||
bat_terminal.bus->voltage = 14;
|
||||
bat_terminal.voltage = 14;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal.dis_current_limit);
|
||||
|
||||
bat_terminal.bus->voltage = bat_conf.voltage_load_disconnect - 0.1;
|
||||
bat_terminal.voltage = bat_conf.voltage_load_disconnect - 0.1;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.dis_current_limit);
|
||||
}
|
||||
@@ -248,17 +248,17 @@ void restart_discharge_if_allowed()
|
||||
init_structs();
|
||||
|
||||
// stop because of undervoltage
|
||||
bat_terminal.bus->voltage = bat_conf.voltage_load_disconnect - 0.1;
|
||||
bat_terminal.voltage = bat_conf.voltage_load_disconnect - 0.1;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.dis_current_limit);
|
||||
|
||||
// increase voltage slightly above DISconnect voltage
|
||||
bat_terminal.bus->voltage = bat_conf.voltage_load_disconnect + 0.1;
|
||||
bat_terminal.voltage = bat_conf.voltage_load_disconnect + 0.1;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal.dis_current_limit);
|
||||
|
||||
// increase voltage above REconnect voltage
|
||||
bat_terminal.bus->voltage = bat_conf.voltage_load_reconnect + 0.1;
|
||||
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);
|
||||
}
|
||||
|
||||
+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);
|
||||
|
||||
+4
-4
@@ -9,7 +9,7 @@
|
||||
|
||||
void reset_counters_at_start_of_day()
|
||||
{
|
||||
solar_terminal.bus->voltage = bat_terminal.bus->voltage - 1;
|
||||
solar_terminal.voltage = bat_terminal.voltage - 1;
|
||||
|
||||
log_data.day_counter = 0;
|
||||
|
||||
@@ -37,7 +37,7 @@ void reset_counters_at_start_of_day()
|
||||
TEST_ASSERT_EQUAL(0, log_data.day_counter);
|
||||
|
||||
// now solar power comes back
|
||||
solar_terminal.bus->voltage = bat_terminal.bus->voltage + 1;
|
||||
solar_terminal.voltage = bat_terminal.voltage + 1;
|
||||
log_update_energy(&log_data);
|
||||
|
||||
// day counter should be increased and daily energy counters reset
|
||||
@@ -50,14 +50,14 @@ void reset_counters_at_start_of_day()
|
||||
|
||||
void log_new_solar_voltage_max()
|
||||
{
|
||||
solar_terminal.bus->voltage = 40;
|
||||
solar_terminal.voltage = 40;
|
||||
log_update_min_max_values(&log_data);
|
||||
TEST_ASSERT_EQUAL(40, log_data.solar_voltage_max);
|
||||
}
|
||||
|
||||
void log_new_bat_voltage_max()
|
||||
{
|
||||
bat_terminal.bus->voltage = 31;
|
||||
bat_terminal.voltage = 31;
|
||||
log_update_min_max_values(&log_data);
|
||||
TEST_ASSERT_EQUAL(31, log_data.battery_voltage_max);
|
||||
}
|
||||
|
||||
@@ -69,29 +69,29 @@ void charging_energy_calculation_valid()
|
||||
{
|
||||
energy_calculation_init();
|
||||
// charging only during sun hours
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(sun_hours * lv_terminal.bus->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.chg_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.bus->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.dis_energy_Wh));
|
||||
}
|
||||
|
||||
void solar_input_energy_calculation_valid()
|
||||
{
|
||||
energy_calculation_init();
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(sun_hours * lv_terminal.bus->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.dis_energy_Wh));
|
||||
}
|
||||
|
||||
void load_output_energy_calculation_valid()
|
||||
{
|
||||
energy_calculation_init();
|
||||
TEST_ASSERT_EQUAL_FLOAT(round((sun_hours + night_hours) * lv_terminal.bus->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.chg_energy_Wh));
|
||||
}
|
||||
|
||||
void dc_bus_tests()
|
||||
void power_port_tests()
|
||||
{
|
||||
energy_calculation_init();
|
||||
|
||||
Reference in New Issue
Block a user