PowerPort added to store current independent from DC bus type
The DC bus type caused issues because current limits could not be defined individually for each connection to a junction, as described in issue #50. With this commit, also some structs were converted to C++ classes to improve readibility of the code and make sure that pointers (e.g. to PowerPort objects) are always assigned during initialization.
This commit is contained in:
+20
-11
@@ -17,19 +17,30 @@
|
||||
|
||||
#include "tests.h"
|
||||
|
||||
Dcdc dcdc = {};
|
||||
DcBus hv_terminal = {}; // high voltage terminal (solar for typical MPPT)
|
||||
DcBus lv_bus_int = {}; // internal low voltage side of DC/DC converter
|
||||
DcBus lv_terminal = {}; // low voltage terminal (battery for typical MPPT)
|
||||
DcBus load_terminal = {}; // load terminal
|
||||
DcBus *bat_terminal = NULL; // pointer to terminal where battery is connected
|
||||
DcBus *solar_terminal = NULL; // pointer to above terminal where solar panel is connected
|
||||
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
|
||||
|
||||
DcBus lv_bus;
|
||||
PowerPort dcdc_port_lv(&lv_bus); // internal low voltage side of DC/DC converter
|
||||
PowerPort lv_terminal(&lv_bus); // low voltage terminal (battery for typical MPPT)
|
||||
PowerPort load_terminal(&lv_bus); // load terminal (also connected to lv_bus)
|
||||
|
||||
PowerPort *bat_terminal = NULL; // pointer to terminal where battery is connected
|
||||
PowerPort *solar_terminal = NULL; // pointer to above terminal where solar panel is connected
|
||||
|
||||
Dcdc dcdc(&dcdc_port_hv, &dcdc_port_lv, DCDC_MODE_INIT);
|
||||
|
||||
PwmSwitch pwm_switch = {}; // only necessary for PWM charger
|
||||
|
||||
Charger charger(&lv_terminal);
|
||||
LoadOutput load(&load_terminal);
|
||||
|
||||
BatConf bat_conf; // actual (used) battery configuration
|
||||
BatConf bat_conf_user; // temporary storage where the user can write to
|
||||
Charger charger; // charger state information
|
||||
LoadOutput load;
|
||||
|
||||
LogData log_data;
|
||||
|
||||
extern ThingSet ts; // defined in data_objects.cpp
|
||||
|
||||
time_t timestamp; // current unix timestamp (independent of time(NULL), as it is user-configurable)
|
||||
@@ -38,8 +49,6 @@ int main()
|
||||
{
|
||||
bat_terminal = &lv_terminal;
|
||||
solar_terminal = &hv_terminal;
|
||||
dcdc_init(&dcdc, &hv_terminal, &lv_bus_int, MODE_MPPT_BUCK);
|
||||
load_init(&load, &lv_bus_int, &load_terminal);
|
||||
|
||||
adc_tests();
|
||||
bat_charger_tests();
|
||||
|
||||
+10
-14
@@ -3,38 +3,34 @@
|
||||
#include "adc_dma.h"
|
||||
#include "adc_dma_stub.h"
|
||||
|
||||
extern Dcdc dcdc;
|
||||
extern DcBus hv_terminal;
|
||||
extern DcBus lv_terminal;
|
||||
extern DcBus lv_bus_int;
|
||||
extern DcBus load_terminal;
|
||||
extern Charger charger;
|
||||
extern LoadOutput load;
|
||||
#include "main.h"
|
||||
|
||||
static adc_values_t adcval;
|
||||
|
||||
void check_solar_terminal_readings()
|
||||
{
|
||||
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);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.solar_voltage, round(hv_terminal.bus->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.voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.dcdc_current - adcval.load_current, round(lv_terminal.current * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.battery_voltage, round(lv_terminal.bus->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.voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.battery_voltage, round(load_terminal.bus->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(lv_bus_int.voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.dcdc_current, round(lv_bus_int.current * 10) / 10);
|
||||
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);
|
||||
}
|
||||
|
||||
void check_temperature_readings()
|
||||
|
||||
+52
-55
@@ -1,32 +1,29 @@
|
||||
|
||||
#include "tests.h"
|
||||
|
||||
#include "bat_charger.h"
|
||||
#include "dc_bus.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern BatConf bat_conf;
|
||||
extern Charger charger;
|
||||
extern DcBus *bat_terminal;
|
||||
#include "main.h"
|
||||
|
||||
extern PowerPort *bat_terminal;
|
||||
|
||||
static void init_structs()
|
||||
{
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_FLOODED, 6, 100);
|
||||
charger_init(&charger);
|
||||
battery_init_dc_bus(bat_terminal, &bat_conf, 1);
|
||||
//charger_init(&charger);
|
||||
battery_init_dc_bus(&lv_bus, bat_terminal, &bat_conf, 1);
|
||||
charger.state = CHG_STATE_IDLE;
|
||||
charger.bat_temperature = 25;
|
||||
bat_terminal->voltage = 14.0;
|
||||
bat_terminal->bus->voltage = 14.0;
|
||||
bat_terminal->current = 0;
|
||||
}
|
||||
|
||||
void no_start_at_high_voltage()
|
||||
{
|
||||
init_structs();
|
||||
bat_terminal->voltage = bat_conf.voltage_recharge + 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
bat_terminal->bus->voltage = bat_conf.voltage_recharge + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_IDLE, charger.state);
|
||||
}
|
||||
|
||||
@@ -34,8 +31,8 @@ void no_start_after_short_rest()
|
||||
{
|
||||
init_structs();
|
||||
charger.time_state_changed = time(NULL) - bat_conf.time_limit_recharge + 1;
|
||||
bat_terminal->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
bat_terminal->bus->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_IDLE, charger.state);
|
||||
}
|
||||
|
||||
@@ -43,12 +40,12 @@ void no_start_outside_temperature_limits()
|
||||
{
|
||||
init_structs();
|
||||
charger.bat_temperature = bat_conf.charge_temp_max + 1;
|
||||
bat_terminal->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
bat_terminal->bus->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_IDLE, charger.state);
|
||||
|
||||
charger.bat_temperature = bat_conf.charge_temp_min - 1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_IDLE, charger.state);
|
||||
}
|
||||
|
||||
@@ -56,8 +53,8 @@ void start_if_everything_just_fine()
|
||||
{
|
||||
init_structs();
|
||||
charger.time_state_changed = time(NULL) - bat_conf.time_limit_recharge - 1;
|
||||
bat_terminal->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
bat_terminal->bus->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_BULK, charger.state);
|
||||
}
|
||||
|
||||
@@ -65,11 +62,11 @@ void enter_topping_at_voltage_setpoint()
|
||||
{
|
||||
init_structs();
|
||||
charger.time_state_changed = time(NULL) - bat_conf.time_limit_recharge - 1;
|
||||
bat_terminal->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
bat_terminal->bus->voltage = bat_conf.voltage_recharge - 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_BULK, charger.state);
|
||||
bat_terminal->voltage = bat_conf.topping_voltage + 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
bat_terminal->bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TOPPING, charger.state);
|
||||
}
|
||||
|
||||
@@ -78,14 +75,14 @@ void stop_topping_after_time_limit()
|
||||
enter_topping_at_voltage_setpoint();
|
||||
|
||||
charger.time_state_changed = time(NULL) - bat_conf.topping_duration + 1;
|
||||
bat_terminal->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->current = bat_conf.topping_current_cutoff + 0.1;
|
||||
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TOPPING, charger.state);
|
||||
|
||||
charger.time_state_changed = time(NULL) - bat_conf.topping_duration - 1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TRICKLE, charger.state);
|
||||
}
|
||||
|
||||
@@ -94,9 +91,9 @@ void stop_topping_at_cutoff_current()
|
||||
enter_topping_at_voltage_setpoint();
|
||||
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->current = bat_conf.topping_current_cutoff - 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TRICKLE, charger.state);
|
||||
}
|
||||
|
||||
@@ -106,9 +103,9 @@ 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->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->current = bat_conf.topping_current_cutoff - 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_IDLE, charger.state);
|
||||
}
|
||||
|
||||
@@ -118,14 +115,14 @@ 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->voltage = bat_conf.topping_voltage - 0.1;
|
||||
bat_terminal->bus->voltage = bat_conf.topping_voltage - 0.1;
|
||||
bat_terminal->current = bat_conf.topping_current_cutoff - 0.1;
|
||||
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TOPPING, charger.state);
|
||||
|
||||
charger.time_voltage_limit_reached = time(NULL) - 1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TRICKLE, charger.state);
|
||||
}
|
||||
|
||||
@@ -141,9 +138,9 @@ void no_equalization_if_disabled()
|
||||
time(NULL) - bat_conf.equalization_trigger_days * 24*60*60;
|
||||
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->current = bat_conf.topping_current_cutoff - 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_NOT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
}
|
||||
|
||||
@@ -159,9 +156,9 @@ 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->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->current = bat_conf.topping_current_cutoff - 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_NOT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
}
|
||||
|
||||
@@ -173,9 +170,9 @@ 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->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->current = bat_conf.topping_current_cutoff - 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
}
|
||||
|
||||
@@ -188,9 +185,9 @@ 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->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
bat_terminal->current = bat_conf.topping_current_cutoff - 0.1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
}
|
||||
|
||||
@@ -200,13 +197,13 @@ 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->voltage = bat_conf.equalization_voltage + 0.1;
|
||||
bat_terminal->bus->voltage = bat_conf.equalization_voltage + 0.1;
|
||||
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
|
||||
charger.time_state_changed = time(NULL) - bat_conf.topping_duration - 1;
|
||||
battery_charge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TRICKLE, charger.state);
|
||||
}
|
||||
|
||||
@@ -219,12 +216,12 @@ void stop_discharge_at_low_voltage()
|
||||
{
|
||||
init_structs();
|
||||
|
||||
bat_terminal->voltage = 14;
|
||||
battery_discharge_control(bat_terminal, &bat_conf, &charger);
|
||||
bat_terminal->bus->voltage = 14;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal->dis_current_limit);
|
||||
|
||||
bat_terminal->voltage = bat_conf.voltage_load_disconnect - 0.1;
|
||||
battery_discharge_control(bat_terminal, &bat_conf, &charger);
|
||||
bat_terminal->bus->voltage = bat_conf.voltage_load_disconnect - 0.1;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal->dis_current_limit);
|
||||
}
|
||||
|
||||
@@ -234,7 +231,7 @@ void stop_discharge_at_overtemp()
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal->dis_current_limit);
|
||||
|
||||
charger.bat_temperature = bat_conf.discharge_temp_max + 1;
|
||||
battery_discharge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal->dis_current_limit);
|
||||
}
|
||||
|
||||
@@ -244,7 +241,7 @@ void stop_discharge_at_undertemp()
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal->dis_current_limit);
|
||||
|
||||
charger.bat_temperature = bat_conf.discharge_temp_min - 1;
|
||||
battery_discharge_control(bat_terminal, &bat_conf, &charger);
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(0, bat_terminal->dis_current_limit);
|
||||
}
|
||||
|
||||
@@ -253,18 +250,18 @@ void restart_discharge_if_allowed()
|
||||
init_structs();
|
||||
|
||||
// stop because of undervoltage
|
||||
bat_terminal->voltage = bat_conf.voltage_load_disconnect - 0.1;
|
||||
battery_discharge_control(bat_terminal, &bat_conf, &charger);
|
||||
bat_terminal->bus->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->voltage = bat_conf.voltage_load_disconnect + 0.1;
|
||||
battery_discharge_control(bat_terminal, &bat_conf, &charger);
|
||||
bat_terminal->bus->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->voltage = bat_conf.voltage_load_reconnect + 0.1;
|
||||
battery_discharge_control(bat_terminal, &bat_conf, &charger);
|
||||
bat_terminal->bus->voltage = bat_conf.voltage_load_reconnect + 0.1;
|
||||
charger.discharge_control(&bat_conf);
|
||||
TEST_ASSERT_LESS_THAN(0, bat_terminal->dis_current_limit);
|
||||
}
|
||||
|
||||
|
||||
+12
-25
@@ -3,29 +3,16 @@
|
||||
#include "adc_dma_stub.h"
|
||||
#include "adc_dma.h"
|
||||
|
||||
#include "bat_charger.h"
|
||||
#include "dc_bus.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
extern Dcdc dcdc;
|
||||
extern DcBus hv_terminal;
|
||||
extern DcBus lv_terminal;
|
||||
extern DcBus lv_bus_int;
|
||||
extern DcBus load_terminal;
|
||||
extern Charger charger;
|
||||
extern BatConf bat_conf;
|
||||
extern LoadOutput load;
|
||||
extern LogData log_data;
|
||||
#include "main.h"
|
||||
|
||||
static void init_structs()
|
||||
{
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_FLOODED, 6, 100);
|
||||
charger_init(&charger);
|
||||
battery_init_dc_bus(&lv_terminal, &bat_conf, 1);
|
||||
battery_init_dc_bus(&lv_bus, &lv_terminal, &bat_conf, 1);
|
||||
charger.state = CHG_STATE_IDLE;
|
||||
}
|
||||
|
||||
@@ -61,9 +48,9 @@ void energy_calculation_init()
|
||||
update_measurements();
|
||||
|
||||
for (int i = 0; i < 60*60*sun_hours; i++) {
|
||||
dc_bus_energy_balance(&hv_terminal);
|
||||
dc_bus_energy_balance(&lv_terminal);
|
||||
dc_bus_energy_balance(&load_terminal);
|
||||
hv_terminal.energy_balance();
|
||||
lv_terminal.energy_balance();
|
||||
load_terminal.energy_balance();
|
||||
}
|
||||
|
||||
// disable DC/DC = solar charging
|
||||
@@ -72,9 +59,9 @@ void energy_calculation_init()
|
||||
update_measurements();
|
||||
|
||||
for (int i = 0; i < 60*60*night_hours; i++) {
|
||||
dc_bus_energy_balance(&hv_terminal);
|
||||
dc_bus_energy_balance(&lv_terminal);
|
||||
dc_bus_energy_balance(&load_terminal);
|
||||
hv_terminal.energy_balance();
|
||||
lv_terminal.energy_balance();
|
||||
load_terminal.energy_balance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,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.bus->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.voltage * adcval.load_current), round(lv_terminal.dis_energy_Wh));
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(night_hours * lv_terminal.bus->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.voltage * dcdc_current_sun), round(hv_terminal.dis_energy_Wh));
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(sun_hours * lv_terminal.bus->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.voltage * adcval.load_current), round(load_terminal.chg_energy_Wh));
|
||||
TEST_ASSERT_EQUAL_FLOAT(round((sun_hours + night_hours) * lv_terminal.bus->voltage * adcval.load_current), round(load_terminal.chg_energy_Wh));
|
||||
}
|
||||
|
||||
void dc_bus_tests()
|
||||
|
||||
+97
-101
@@ -1,46 +1,41 @@
|
||||
|
||||
#include "tests.h"
|
||||
|
||||
#include "dcdc.h"
|
||||
#include "dc_bus.h"
|
||||
#include "log.h"
|
||||
#include "half_bridge.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
extern Dcdc dcdc;
|
||||
extern DcBus hv_terminal;
|
||||
extern DcBus lv_bus_int;
|
||||
extern BatConf bat_conf;
|
||||
#include "main.h"
|
||||
|
||||
static void init_structs_buck()
|
||||
{
|
||||
dc_bus_init_solar(&hv_terminal, 10);
|
||||
hv_terminal.voltage = 20;
|
||||
hv_terminal.dis_voltage_start = 18;
|
||||
hv_terminal.current = 0;
|
||||
dcdc_port_hv.init_solar(10);
|
||||
dcdc_port_hv.bus->voltage = 20;
|
||||
dcdc_port_hv.bus->dis_voltage_start = 18;
|
||||
dcdc_port_hv.current = 0;
|
||||
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_GEL, 6, 100);
|
||||
battery_init_dc_bus(&lv_bus_int, &bat_conf, 1);
|
||||
lv_bus_int.voltage = 14;
|
||||
lv_bus_int.current = 0;
|
||||
battery_init_dc_bus(&lv_bus, &dcdc_port_lv, &bat_conf, 1);
|
||||
dcdc_port_lv.bus->voltage = 14;
|
||||
dcdc_port_lv.current = 0;
|
||||
|
||||
dcdc.mode = MODE_MPPT_BUCK;
|
||||
dcdc.temp_mosfets = 25;
|
||||
dcdc.off_timestamp = 0;
|
||||
dcdc.power_prev = 0;
|
||||
dcdc.pwm_delta = 1;
|
||||
dcdc_init(&dcdc, &hv_terminal, &lv_bus_int, MODE_MPPT_BUCK);
|
||||
dcdc.enabled = true;
|
||||
}
|
||||
|
||||
static void start_buck()
|
||||
{
|
||||
init_structs_buck();
|
||||
half_bridge_init(70, 200, 12 / dcdc.hs_voltage_max, 0.97);
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_control(&dcdc); // call multiple times because of startup delay
|
||||
dcdc.control();
|
||||
dcdc.control();
|
||||
dcdc.control(); // call multiple times because of startup delay
|
||||
TEST_ASSERT_EQUAL(DCDC_STATE_MPPT, dcdc.state);
|
||||
}
|
||||
|
||||
@@ -48,68 +43,69 @@ static void init_structs_boost()
|
||||
{
|
||||
half_bridge_stop();
|
||||
|
||||
dc_bus_init_solar(&lv_bus_int, 10);
|
||||
lv_bus_int.voltage = 20;
|
||||
lv_bus_int.dis_voltage_start = 18;
|
||||
lv_bus_int.current = 0;
|
||||
lv_bus_int.power = 0;
|
||||
dcdc_port_hv.init_solar(10);
|
||||
dcdc_port_lv.bus->voltage = 20;
|
||||
dcdc_port_lv.bus->dis_voltage_start = 18;
|
||||
dcdc_port_lv.current = 0;
|
||||
dcdc_port_lv.power = 0;
|
||||
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_NMC, 10, 9);
|
||||
battery_init_dc_bus(&hv_terminal, &bat_conf, 1);
|
||||
hv_terminal.voltage = 3.7 * 10;
|
||||
hv_terminal.current = 0;
|
||||
hv_terminal.power = 0;
|
||||
battery_init_dc_bus(&hv_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;
|
||||
|
||||
dcdc.mode = MODE_MPPT_BOOST;
|
||||
dcdc.temp_mosfets = 25;
|
||||
dcdc.off_timestamp = 0;
|
||||
dcdc.power_prev = 0;
|
||||
dcdc.pwm_delta = -1;
|
||||
dcdc_init(&dcdc, &hv_terminal, &lv_bus_int, MODE_MPPT_BOOST);
|
||||
dcdc.pwm_delta = 1;
|
||||
dcdc.enabled = true;
|
||||
}
|
||||
|
||||
static void start_boost()
|
||||
{
|
||||
init_structs_boost();
|
||||
half_bridge_init(70, 200, 12 / dcdc.hs_voltage_max, 0.97);
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_control(&dcdc); // call multiple times because of startup delay
|
||||
dcdc.control();
|
||||
dcdc.control();
|
||||
dcdc.control(); // call multiple times because of startup delay
|
||||
TEST_ASSERT_EQUAL(DCDC_STATE_MPPT, dcdc.state);
|
||||
}
|
||||
|
||||
void start_valid_mppt_buck()
|
||||
{
|
||||
init_structs_buck();
|
||||
TEST_ASSERT_EQUAL(1, dcdc_check_start_conditions(&dcdc));
|
||||
TEST_ASSERT_EQUAL(1, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void start_valid_mppt_boost()
|
||||
{
|
||||
init_structs_boost();
|
||||
TEST_ASSERT_EQUAL(-1, dcdc_check_start_conditions(&dcdc));
|
||||
TEST_ASSERT_EQUAL(-1, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_start_before_restart_delay()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc.off_timestamp = time(NULL) - dcdc.restart_interval + 1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
dcdc.off_timestamp = time(NULL) - dcdc.restart_interval;
|
||||
TEST_ASSERT_EQUAL(1, dcdc_check_start_conditions(&dcdc));
|
||||
TEST_ASSERT_EQUAL(1, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_start_if_dcdc_disabled()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc.enabled = false;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_start_if_dcdc_lv_voltage_low()
|
||||
{
|
||||
init_structs_buck();
|
||||
lv_bus_int.voltage = dcdc.ls_voltage_min - 0.5;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
dcdc_port_lv.bus->voltage = dcdc.ls_voltage_min - 0.5;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
// buck
|
||||
@@ -117,36 +113,36 @@ void no_start_if_dcdc_lv_voltage_low()
|
||||
void no_buck_start_if_bat_voltage_low()
|
||||
{
|
||||
init_structs_buck();
|
||||
lv_bus_int.voltage = bat_conf.voltage_absolute_min - 0.1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
dcdc_port_lv.bus->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();
|
||||
lv_bus_int.voltage = bat_conf.topping_voltage + 0.1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
dcdc_port_lv.bus->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();
|
||||
lv_bus_int.chg_current_limit = 0;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
dcdc_port_lv.chg_current_limit = 0;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_buck_start_if_solar_voltage_high()
|
||||
{
|
||||
init_structs_buck();
|
||||
hv_terminal.voltage = dcdc.hs_voltage_max + 1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
dcdc_port_hv.bus->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();
|
||||
hv_terminal.voltage = 17;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
dcdc_port_hv.bus->voltage = 17;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
// boost
|
||||
@@ -154,36 +150,36 @@ void no_buck_start_if_solar_voltage_low()
|
||||
void no_boost_start_if_bat_voltage_low()
|
||||
{
|
||||
init_structs_boost();
|
||||
hv_terminal.voltage = bat_conf.voltage_absolute_min - 0.1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
dcdc_port_hv.bus->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();
|
||||
hv_terminal.voltage = bat_conf.topping_voltage + 0.1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
dcdc_port_hv.bus->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();
|
||||
hv_terminal.chg_current_limit = 0;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
dcdc_port_hv.chg_current_limit = 0;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_boost_start_if_solar_voltage_high()
|
||||
{
|
||||
init_structs_boost();
|
||||
lv_bus_int.voltage = dcdc.ls_voltage_max + 1;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
dcdc_port_lv.bus->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();
|
||||
lv_bus_int.voltage = 17;
|
||||
TEST_ASSERT_EQUAL(0, dcdc_check_start_conditions(&dcdc));
|
||||
dcdc_port_lv.bus->voltage = 17;
|
||||
TEST_ASSERT_EQUAL(0, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
// buck operation
|
||||
@@ -192,7 +188,7 @@ void buck_increasing_power()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_control(&dcdc);
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
}
|
||||
@@ -201,8 +197,8 @@ void buck_derating_output_voltage_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
lv_bus_int.voltage = lv_bus_int.chg_voltage_target + 0.1;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_lv.bus->voltage = dcdc_port_lv.bus->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
|
||||
TEST_ASSERT_EQUAL(DCDC_STATE_CV, dcdc.state);
|
||||
@@ -212,8 +208,8 @@ void buck_derating_output_current_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
lv_bus_int.current = lv_bus_int.chg_current_limit + 0.1;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_lv.current = dcdc_port_lv.chg_current_limit + 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
TEST_ASSERT_EQUAL(DCDC_STATE_CC, dcdc.state);
|
||||
@@ -223,23 +219,23 @@ 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;
|
||||
lv_bus_int.current = 0.2;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_hv.bus->voltage = dcdc_port_hv.bus->dis_voltage_stop - 0.1;
|
||||
dcdc_port_lv.current = 0.2;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
TEST_ASSERT_EQUAL(DCDC_STATE_CV, dcdc.state);
|
||||
TEST_ASSERT_EQUAL(DCDC_STATE_DERATING, dcdc.state);
|
||||
}
|
||||
|
||||
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;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_hv.current = dcdc_port_hv.dis_current_limit - 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
TEST_ASSERT_EQUAL(DCDC_STATE_CC, dcdc.state);
|
||||
TEST_ASSERT_EQUAL(DCDC_STATE_DERATING, dcdc.state);
|
||||
}
|
||||
|
||||
void buck_derating_temperature_limits_exceeded()
|
||||
@@ -247,7 +243,7 @@ void buck_derating_temperature_limits_exceeded()
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc.temp_mosfets = 81;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
}
|
||||
@@ -257,7 +253,7 @@ void buck_stop_input_power_too_low()
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc.power_good_timestamp = time(NULL) - 11;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc.control();
|
||||
TEST_ASSERT(half_bridge_enabled() == false);
|
||||
}
|
||||
|
||||
@@ -265,8 +261,8 @@ void buck_stop_high_voltage_emergency()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
lv_bus_int.voltage = dcdc.ls_voltage_max + 0.1;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_lv.bus->voltage = dcdc.ls_voltage_max + 0.1;
|
||||
dcdc.control();
|
||||
TEST_ASSERT(half_bridge_enabled() == false);
|
||||
}
|
||||
|
||||
@@ -274,16 +270,16 @@ void buck_correct_mppt_operation()
|
||||
{
|
||||
start_buck();
|
||||
|
||||
lv_bus_int.power = 5;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_lv.power = 5;
|
||||
dcdc.control();
|
||||
float pwm1 = half_bridge_get_duty_cycle();
|
||||
lv_bus_int.power = 7;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_lv.power = 7;
|
||||
dcdc.control();
|
||||
float pwm2 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm2 > pwm1);
|
||||
|
||||
lv_bus_int.power = 6; // decrease power to make the direction turn around
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_lv.power = 6; // decrease power to make the direction turn around
|
||||
dcdc.control();
|
||||
float pwm3 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm3 < pwm2);
|
||||
}
|
||||
@@ -295,7 +291,7 @@ void boost_increasing_power()
|
||||
// make sure that without changing anything, dcdc_control goes in direction of increasing power
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_control(&dcdc);
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
}
|
||||
@@ -304,8 +300,8 @@ 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;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_hv.bus->voltage = dcdc_port_hv.bus->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
|
||||
}
|
||||
@@ -314,8 +310,8 @@ 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;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_hv.current = dcdc_port_hv.chg_current_limit + 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
}
|
||||
@@ -324,9 +320,9 @@ void boost_derating_input_voltage_too_low()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
lv_bus_int.voltage = lv_bus_int.dis_voltage_stop - 0.1;
|
||||
hv_terminal.current = 0.2;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_lv.bus->voltage = dcdc_port_lv.bus->dis_voltage_stop - 0.1;
|
||||
dcdc_port_hv.current = 0.2;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
}
|
||||
@@ -335,8 +331,8 @@ void boost_derating_input_current_too_high()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
lv_bus_int.current = lv_bus_int.dis_current_limit - 0.1;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_lv.current = dcdc_port_lv.dis_current_limit - 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
}
|
||||
@@ -346,7 +342,7 @@ void boost_derating_temperature_limits_exceeded()
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc.temp_mosfets = 81;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
}
|
||||
@@ -355,15 +351,15 @@ void boost_stop_input_power_too_low()
|
||||
{
|
||||
start_boost();
|
||||
dcdc.power_good_timestamp = time(NULL) - 11;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc.control();
|
||||
TEST_ASSERT(half_bridge_enabled() == false);
|
||||
}
|
||||
|
||||
void boost_stop_high_voltage_emergency()
|
||||
{
|
||||
start_boost();
|
||||
hv_terminal.voltage = dcdc.hs_voltage_max + 0.1;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_hv.bus->voltage = dcdc.hs_voltage_max + 0.1;
|
||||
dcdc.control();
|
||||
TEST_ASSERT(half_bridge_enabled() == false);
|
||||
}
|
||||
|
||||
@@ -371,16 +367,16 @@ void boost_correct_mppt_operation()
|
||||
{
|
||||
start_boost();
|
||||
|
||||
hv_terminal.power = 5;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_hv.power = 5;
|
||||
dcdc.control();
|
||||
float pwm1 = half_bridge_get_duty_cycle();
|
||||
hv_terminal.power = 7;
|
||||
dcdc_control(&dcdc);
|
||||
dcdc_port_hv.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_control(&dcdc);
|
||||
dcdc_port_hv.power = 6; // decrease power to make the direction turn around
|
||||
dcdc.control();
|
||||
float pwm3 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm3 > pwm2);
|
||||
}
|
||||
|
||||
+11
-19
@@ -1,26 +1,18 @@
|
||||
|
||||
#include "tests.h"
|
||||
|
||||
#include "bat_charger.h"
|
||||
#include "dc_bus.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
extern BatConf bat_conf;
|
||||
extern Charger charger;
|
||||
extern DcBus *solar_terminal;
|
||||
extern DcBus *bat_terminal;
|
||||
extern DcBus load_terminal;
|
||||
extern LoadOutput load;
|
||||
extern Dcdc dcdc;
|
||||
extern LogData log_data;
|
||||
#include "main.h"
|
||||
|
||||
extern PowerPort *solar_terminal;
|
||||
extern PowerPort *bat_terminal;
|
||||
|
||||
void reset_counters_at_start_of_day()
|
||||
{
|
||||
solar_terminal->voltage = bat_terminal->voltage - 1;
|
||||
solar_terminal->bus->voltage = bat_terminal->bus->voltage - 1;
|
||||
|
||||
log_data.day_counter = 0;
|
||||
|
||||
@@ -48,7 +40,7 @@ void reset_counters_at_start_of_day()
|
||||
TEST_ASSERT_EQUAL(0, log_data.day_counter);
|
||||
|
||||
// now solar power comes back
|
||||
solar_terminal->voltage = bat_terminal->voltage + 1;
|
||||
solar_terminal->bus->voltage = bat_terminal->bus->voltage + 1;
|
||||
log_update_energy(&log_data, solar_terminal, bat_terminal, &load_terminal);
|
||||
|
||||
// day counter should be increased and daily energy counters reset
|
||||
@@ -61,28 +53,28 @@ void reset_counters_at_start_of_day()
|
||||
|
||||
void log_new_solar_voltage_max()
|
||||
{
|
||||
solar_terminal->voltage = 40;
|
||||
solar_terminal->bus->voltage = 40;
|
||||
log_update_min_max_values(&log_data, &dcdc, &charger, &load, solar_terminal, bat_terminal, &load_terminal);
|
||||
TEST_ASSERT_EQUAL(40, log_data.solar_voltage_max);
|
||||
}
|
||||
|
||||
void log_new_bat_voltage_max()
|
||||
{
|
||||
bat_terminal->voltage = 31;
|
||||
bat_terminal->bus->voltage = 31;
|
||||
log_update_min_max_values(&log_data, &dcdc, &charger, &load, solar_terminal, bat_terminal, &load_terminal);
|
||||
TEST_ASSERT_EQUAL(31, log_data.battery_voltage_max);
|
||||
}
|
||||
|
||||
void log_new_dcdc_current_max()
|
||||
{
|
||||
dcdc.lv_bus->current = 21;
|
||||
dcdc.lvs->current = 21;
|
||||
log_update_min_max_values(&log_data, &dcdc, &charger, &load, solar_terminal, bat_terminal, &load_terminal);
|
||||
TEST_ASSERT_EQUAL(21, log_data.dcdc_current_max);
|
||||
}
|
||||
|
||||
void log_new_load_current_max()
|
||||
{
|
||||
load.terminal->current = 21;
|
||||
load.port->current = 21;
|
||||
log_update_min_max_values(&log_data, &dcdc, &charger, &load, solar_terminal, bat_terminal, &load_terminal);
|
||||
TEST_ASSERT_EQUAL(21, log_data.load_current_max);
|
||||
}
|
||||
@@ -97,7 +89,7 @@ void log_solar_power_max()
|
||||
|
||||
void log_load_power_max()
|
||||
{
|
||||
load.terminal->power = 50;
|
||||
load.port->power = 50;
|
||||
log_update_min_max_values(&log_data, &dcdc, &charger, &load, solar_terminal, bat_terminal, &load_terminal);
|
||||
TEST_ASSERT_EQUAL(50, log_data.load_power_max_day);
|
||||
TEST_ASSERT_EQUAL(50, log_data.load_power_max_total);
|
||||
|
||||
Reference in New Issue
Block a user