DC bus type introduced and unit tests added
This commit is contained in:
+25
-21
@@ -40,9 +40,10 @@
|
||||
Serial serial(PIN_SWD_TX, PIN_SWD_RX, "serial");
|
||||
|
||||
dcdc_t dcdc = {};
|
||||
power_port_t hs_port = {}; // high-side (solar for typical MPPT)
|
||||
power_port_t ls_port = {}; // low-side (battery for typical MPPT)
|
||||
power_port_t *bat_port = NULL;
|
||||
dc_bus_t hs_bus = {}; // high-side (solar for typical MPPT)
|
||||
dc_bus_t ls_bus = {}; // low-side (battery for typical MPPT)
|
||||
dc_bus_t *bat_bus = NULL;
|
||||
dc_bus_t load_bus = {}; // load terminal
|
||||
pwm_switch_t pwm_switch = {}; // only necessary for PWM charger
|
||||
battery_conf_t bat_conf; // actual (used) battery configuration
|
||||
battery_conf_t bat_conf_user; // temporary storage where the user can write to
|
||||
@@ -62,15 +63,15 @@ void system_control()
|
||||
static int counter = 0;
|
||||
|
||||
// convert ADC readings to meaningful measurement values
|
||||
update_measurements(&dcdc, &bat_state, &load, &hs_port, &ls_port);
|
||||
update_measurements(&dcdc, &bat_state, &load, &hs_bus, &ls_bus, &load_bus);
|
||||
|
||||
#ifdef CHARGER_TYPE_PWM
|
||||
pwm_switch_control(&pwm_switch, &hs_port, bat_port);
|
||||
pwm_switch_control(&pwm_switch, &hs_bus, bat_bus);
|
||||
leds_set_charging(pwm_switch_enabled());
|
||||
#else
|
||||
// control PWM of the DC/DC according to hs and ls port settings
|
||||
// (this function includes MPPT algorithm)
|
||||
dcdc_control(&dcdc, &hs_port, &ls_port);
|
||||
dcdc_control(&dcdc, &hs_bus, &ls_bus);
|
||||
leds_set_charging(half_bridge_enabled());
|
||||
#endif
|
||||
|
||||
@@ -82,8 +83,11 @@ void system_control()
|
||||
timestamp++;
|
||||
counter = 0;
|
||||
// energy + soc calculation must be called exactly once per second
|
||||
battery_update_energy(&bat_state, bat_port->voltage, bat_port->current, dcdc.ls_current, load.current);
|
||||
battery_update_soc(&bat_conf, &bat_state, bat_port->voltage, bat_port->current);
|
||||
dc_bus_energy_balance(&hs_bus);
|
||||
dc_bus_energy_balance(&ls_bus);
|
||||
dc_bus_energy_balance(&load_bus);
|
||||
log_update_energy(&log_data, &ls_bus, &hs_bus, &load_bus);
|
||||
battery_update_soc(&bat_conf, &bat_state, bat_bus->voltage, bat_bus->current);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
@@ -118,8 +122,8 @@ int main()
|
||||
dma_setup();
|
||||
adc_timer_start(1000); // 1 kHz
|
||||
wait(0.5); // wait for ADC to collect some measurement values
|
||||
update_measurements(&dcdc, &bat_state, &load, &hs_port, &ls_port);
|
||||
calibrate_current_sensors(&dcdc, &load);
|
||||
update_measurements(&dcdc, &bat_state, &load, &hs_bus, &ls_bus, &load_bus);
|
||||
calibrate_current_sensors();
|
||||
|
||||
// Communication interfaces
|
||||
uart_serial_init(&serial);
|
||||
@@ -130,19 +134,19 @@ int main()
|
||||
// Setup of DC/DC power stage
|
||||
switch(dcdc.mode) {
|
||||
case MODE_NANOGRID:
|
||||
power_port_init_nanogrid(&hs_port);
|
||||
power_port_init_bat(&ls_port, &bat_conf);
|
||||
bat_port = &ls_port;
|
||||
dc_bus_init_nanogrid(&hs_bus);
|
||||
dc_bus_init_bat(&ls_bus, &bat_conf);
|
||||
bat_bus = &ls_bus;
|
||||
break;
|
||||
case MODE_MPPT_BUCK: // typical MPPT charge controller operation
|
||||
power_port_init_solar(&hs_port);
|
||||
power_port_init_bat(&ls_port, &bat_conf);
|
||||
bat_port = &ls_port;
|
||||
dc_bus_init_solar(&hs_bus);
|
||||
dc_bus_init_bat(&ls_bus, &bat_conf);
|
||||
bat_bus = &ls_bus;
|
||||
break;
|
||||
case MODE_MPPT_BOOST: // for charging of e-bike battery via solar panel
|
||||
power_port_init_solar(&ls_port);
|
||||
power_port_init_bat(&hs_port, &bat_conf);
|
||||
bat_port = &hs_port;
|
||||
dc_bus_init_solar(&ls_bus);
|
||||
dc_bus_init_bat(&hs_bus, &bat_conf);
|
||||
bat_bus = &hs_bus;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -163,9 +167,9 @@ int main()
|
||||
|
||||
//printf("Still alive... time: %d, mode: %d\n", (int)time(NULL), dcdc.mode);
|
||||
|
||||
charger_state_machine(bat_port, &bat_conf, &bat_state, bat_port->voltage, bat_port->current);
|
||||
charger_state_machine(bat_bus, &bat_conf, &bat_state, bat_bus->voltage, bat_bus->current);
|
||||
|
||||
load_state_machine(&load, ls_port.input_allowed);
|
||||
load_state_machine(&load, ls_bus.dis_allowed);
|
||||
|
||||
eeprom_update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user