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:
Martin Jaeger
2019-10-20 14:52:35 +02:00
parent d7ed3cdd13
commit 0399c4e877
25 changed files with 860 additions and 823 deletions
+12 -14
View File
@@ -83,8 +83,6 @@ void calibrate_current_sensors()
//----------------------------------------------------------------------------
void update_measurements()
{
//int v_temp, rts;
// reference voltage of 2.5 V at PIN_V_REF
//int vcc = 2500 * 4096 / (adc_filtered[ADC_POS_V_REF] >> (4 + ADC_FILTER_CONST));
@@ -96,17 +94,15 @@ void update_measurements()
//int vcc = 3300;
// calculate LS voltage first, as it is needed for HS voltage calculation for PWM charge controller
lv_terminal.voltage =
lv_bus.voltage =
(float)(((adc_filtered[ADC_POS_V_BAT] >> (4 + ADC_FILTER_CONST)) * vcc) / 4096) *
ADC_GAIN_V_BAT / 1000.0;
lv_bus_int.voltage = lv_terminal.voltage;
load_terminal.voltage = lv_terminal.voltage;
hv_terminal.voltage =
hv_bus.voltage =
(float)(((adc_filtered[ADC_POS_V_SOLAR] >> (4 + ADC_FILTER_CONST)) * vcc) / 4096) *
ADC_GAIN_V_SOLAR / 1000.0;
#ifdef ADC_OFFSET_V_SOLAR
hv_terminal.voltage = lv_terminal.voltage + -(vcc * ADC_OFFSET_V_SOLAR / 1000.0 + hv_terminal.voltage);
hv_bus.voltage = hv_bus.voltage + -(vcc * ADC_OFFSET_V_SOLAR / 1000.0 + hv_bus.voltage);
#endif
load_terminal.current =
@@ -120,18 +116,20 @@ void update_measurements()
ADC_GAIN_I_SOLAR / 1000.0 + solar_current_offset);
lv_terminal.current = -hv_terminal.current - load_terminal.current;
#else // MPPT
lv_bus_int.current =
dcdc_port_lv.current =
(float)(((adc_filtered[ADC_POS_I_DCDC] >> (4 + ADC_FILTER_CONST)) * vcc) / 4096) *
ADC_GAIN_I_DCDC / 1000.0 + solar_current_offset;
lv_terminal.current = lv_bus_int.current - load_terminal.current;
hv_terminal.current = -lv_bus_int.current * lv_bus_int.voltage / hv_terminal.voltage;
lv_terminal.current = dcdc_port_lv.current - load_terminal.current;
hv_terminal.current = -dcdc_port_lv.current * lv_bus.voltage / hv_bus.voltage;
dcdc_port_hv.current = hv_terminal.current;
#endif
// power calculations
hv_terminal.power = hv_terminal.voltage * hv_terminal.current;
lv_bus_int.power = lv_bus_int.voltage * lv_bus_int.current;
lv_terminal.power = lv_terminal.voltage * lv_terminal.current;
load_terminal.power = load_terminal.voltage * load_terminal.current;
dcdc_port_hv.power = hv_bus.voltage * dcdc_port_hv.current;
hv_terminal.power = hv_bus.voltage * hv_terminal.current;
dcdc_port_lv.power = lv_bus.voltage * dcdc_port_lv.current;
lv_terminal.power = lv_bus.voltage * lv_terminal.current;
load_terminal.power = lv_bus.voltage * load_terminal.current;
/** \todo Improved (faster) temperature calculation:
https://www.embeddedrelated.com/showarticle/91.php