From 8c88352c5f1b44bba1f4d093bc18a4a836baeb9b Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 11 Nov 2023 22:47:48 +0200 Subject: [PATCH] Rewrite max/min voltage to save memory --- Software/Software.ino | 16 +++------------- Software/src/inverter/BYD-CAN.cpp | 14 +++++++------- Software/src/inverter/BYD-CAN.h | 4 ++-- Software/src/inverter/BYD-MODBUS.cpp | 4 ++-- Software/src/inverter/BYD-MODBUS.h | 5 ++--- Software/src/inverter/LUNA2000-MODBUS.h | 5 ++--- Software/src/inverter/PYLON-CAN.cpp | 16 ++++++++-------- Software/src/inverter/PYLON-CAN.h | 4 ++-- Software/src/inverter/SMA-CAN.cpp | 14 +++++++------- Software/src/inverter/SMA-CAN.h | 4 ++-- Software/src/inverter/SOFAR-CAN.cpp | 8 ++++---- Software/src/inverter/SOFAR-CAN.h | 4 ++-- Software/src/inverter/SOLAX-CAN.cpp | 8 ++++---- Software/src/inverter/SOLAX-CAN.h | 4 ++-- 14 files changed, 49 insertions(+), 61 deletions(-) diff --git a/Software/Software.ino b/Software/Software.ino index cf9631093..b1f2f7bd0 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -53,19 +53,9 @@ ModbusServerRTU MBserver(Serial2, 2000); #define UPDATING 5 //Common inverter parameters uint16_t capacity_Wh_startup = BATTERY_WH_MAX; -uint16_t max_power = 40960; //41kW -const uint16_t max_voltage = ABSOLUTE_MAX_VOLTAGE; //if higher charging is not possible (goes into forced discharge) -const uint16_t min_voltage = ABSOLUTE_MIN_VOLTAGE; //if lower Gen24 disables battery -uint16_t min_volt_byd_can = min_voltage; -uint16_t max_volt_byd_can = max_voltage; -uint16_t min_volt_solax_can = min_voltage; -uint16_t max_volt_solax_can = max_voltage; -uint16_t min_volt_pylon_can = min_voltage; -uint16_t max_volt_pylon_can = max_voltage; -uint16_t min_volt_modbus_byd = min_voltage; -uint16_t max_volt_modbus_byd = max_voltage; -uint16_t min_volt_sma_can = min_voltage; -uint16_t max_volt_sma_can = max_voltage; +uint16_t max_power = 40960; //41kW +uint16_t max_voltage = ABSOLUTE_MAX_VOLTAGE; //if higher charging is not possible (goes into forced discharge) +uint16_t min_voltage = ABSOLUTE_MIN_VOLTAGE; //if lower Gen24 disables battery uint16_t battery_voltage = 3700; uint16_t battery_current = 0; uint16_t SOC = 5000; //SOC 0-100.00% //Updates later on from CAN diff --git a/Software/src/inverter/BYD-CAN.cpp b/Software/src/inverter/BYD-CAN.cpp index f80af4985..75b9b7034 100644 --- a/Software/src/inverter/BYD-CAN.cpp +++ b/Software/src/inverter/BYD-CAN.cpp @@ -110,8 +110,8 @@ static long inverter_timestamp = 0; void update_values_can_byd() { //This function maps all the values fetched from battery CAN to the correct CAN messages //Calculate values - charge_current = ((max_target_charge_power * 10) / - max_volt_byd_can); //Charge power in W , max volt in V+1decimal (P=UI, solve for I) + charge_current = + ((max_target_charge_power * 10) / max_voltage); //Charge power in W , max volt in V+1decimal (P=UI, solve for I) //The above calculation results in (30 000*10)/3700=81A charge_current = (charge_current * 10); //Value needs a decimal before getting sent to inverter (81.0A) if (charge_current > MAXCHARGEAMP) { @@ -119,7 +119,7 @@ void update_values_can_byd() { //This function maps all the values fetched from } discharge_current = ((max_target_discharge_power * 10) / - max_volt_byd_can); //Charge power in W , max volt in V+1decimal (P=UI, solve for I) + max_voltage); //Charge power in W , max volt in V+1decimal (P=UI, solve for I) //The above calculation results in (30 000*10)/3700=81A discharge_current = (discharge_current * 10); //Value needs a decimal before getting sent to inverter (81.0A) if (discharge_current > MAXDISCHARGEAMP) { @@ -131,11 +131,11 @@ void update_values_can_byd() { //This function maps all the values fetched from //Map values to CAN messages //Maxvoltage (eg 400.0V = 4000 , 16bits long) - BYD_110.data.u8[0] = (max_volt_byd_can >> 8); - BYD_110.data.u8[1] = (max_volt_byd_can & 0x00FF); + BYD_110.data.u8[0] = (max_voltage >> 8); + BYD_110.data.u8[1] = (max_voltage & 0x00FF); //Minvoltage (eg 300.0V = 3000 , 16bits long) - BYD_110.data.u8[2] = (min_volt_byd_can >> 8); - BYD_110.data.u8[3] = (min_volt_byd_can & 0x00FF); + BYD_110.data.u8[2] = (min_voltage >> 8); + BYD_110.data.u8[3] = (min_voltage & 0x00FF); //Maximum discharge power allowed (Unit: A+1) BYD_110.data.u8[4] = (discharge_current >> 8); BYD_110.data.u8[5] = (discharge_current & 0x00FF); diff --git a/Software/src/inverter/BYD-CAN.h b/Software/src/inverter/BYD-CAN.h index 8bab8550c..411506d7d 100644 --- a/Software/src/inverter/BYD-CAN.h +++ b/Software/src/inverter/BYD-CAN.h @@ -18,8 +18,8 @@ extern uint16_t stat_batt_power; extern uint16_t temperature_min; extern uint16_t temperature_max; extern uint16_t CANerror; -extern uint16_t min_volt_byd_can; -extern uint16_t max_volt_byd_can; +extern uint16_t min_voltage; +extern uint16_t max_voltage; // Definitions for BMS status #define STANDBY 0 #define INACTIVE 1 diff --git a/Software/src/inverter/BYD-MODBUS.cpp b/Software/src/inverter/BYD-MODBUS.cpp index a4da13658..a79b4fff9 100644 --- a/Software/src/inverter/BYD-MODBUS.cpp +++ b/Software/src/inverter/BYD-MODBUS.cpp @@ -37,9 +37,9 @@ void handle_update_data_modbusp201_byd() { system_data[4] = (max_power); // Id.: p205 Value.: 14500 Scaled value.: 30,42kW Comment.: Max Charge/Discharge Power=10.24kW (lowest value of 204 and 205 will be enforced by Gen24) system_data[5] = - (max_volt_modbus_byd); // Id.: p206 Value.: 3667 Scaled value.: 362,7VDC Comment.: Max Voltage, if higher charging is not possible (goes into forced discharge) + (max_voltage); // Id.: p206 Value.: 3667 Scaled value.: 362,7VDC Comment.: Max Voltage, if higher charging is not possible (goes into forced discharge) system_data[6] = - (min_volt_modbus_byd); // Id.: p207 Value.: 2776 Scaled value.: 277,6VDC Comment.: Min Voltage, if lower Gen24 disables battery + (min_voltage); // Id.: p207 Value.: 2776 Scaled value.: 277,6VDC Comment.: Min Voltage, if lower Gen24 disables battery system_data[7] = 53248; // Id.: p208 Value.: 53248 Scaled value.: 53248 Comment.: Always 53248 for this BYD, Peak Charge power? system_data[8] = 10; // Id.: p209 Value.: 10 Scaled value.: 10 Comment.: Always 10 diff --git a/Software/src/inverter/BYD-MODBUS.h b/Software/src/inverter/BYD-MODBUS.h index 65214729a..4252ba0e5 100644 --- a/Software/src/inverter/BYD-MODBUS.h +++ b/Software/src/inverter/BYD-MODBUS.h @@ -25,11 +25,10 @@ extern uint16_t bms_char_dis_status; extern uint16_t stat_batt_power; extern uint16_t temperature_min; extern uint16_t temperature_max; - extern uint16_t capacity_Wh_startup; extern uint16_t max_power; -extern uint16_t max_volt_modbus_byd; -extern uint16_t min_volt_modbus_byd; +extern uint16_t max_voltage; +extern uint16_t min_voltage; void handle_static_data_modbus_byd(); void handle_update_data_modbusp201_byd(); diff --git a/Software/src/inverter/LUNA2000-MODBUS.h b/Software/src/inverter/LUNA2000-MODBUS.h index 028c9dfa0..b3766b0ea 100644 --- a/Software/src/inverter/LUNA2000-MODBUS.h +++ b/Software/src/inverter/LUNA2000-MODBUS.h @@ -25,11 +25,10 @@ extern uint16_t bms_char_dis_status; extern uint16_t stat_batt_power; extern uint16_t temperature_min; extern uint16_t temperature_max; - extern uint16_t capacity_Wh_startup; extern uint16_t max_power; -extern uint16_t max_volt_modbus_byd; -extern uint16_t min_volt_modbus_byd; +extern uint16_t max_voltage; +extern uint16_t min_voltage; void update_modbus_registers_luna2000(); void handle_update_data_modbus32051(); diff --git a/Software/src/inverter/PYLON-CAN.cpp b/Software/src/inverter/PYLON-CAN.cpp index 5a258bb00..a7b91df9b 100644 --- a/Software/src/inverter/PYLON-CAN.cpp +++ b/Software/src/inverter/PYLON-CAN.cpp @@ -200,16 +200,16 @@ void update_values_can_pylon() { //This function maps all the values fetched fr PYLON_4211.data.u8[7] = (StateOfHealth * 0.01); //Minvoltage (eg 300.0V = 3000 , 16bits long) Charge Cutoff Voltage - PYLON_4220.data.u8[0] = (min_volt_pylon_can >> 8); - PYLON_4220.data.u8[1] = (min_volt_pylon_can & 0x00FF); - PYLON_4221.data.u8[0] = (min_volt_pylon_can >> 8); - PYLON_4221.data.u8[1] = (min_volt_pylon_can & 0x00FF); + PYLON_4220.data.u8[0] = (min_voltage >> 8); + PYLON_4220.data.u8[1] = (min_voltage & 0x00FF); + PYLON_4221.data.u8[0] = (min_voltage >> 8); + PYLON_4221.data.u8[1] = (min_voltage & 0x00FF); //Maxvoltage (eg 400.0V = 4000 , 16bits long) Discharge Cutoff Voltage - PYLON_4220.data.u8[2] = (max_volt_pylon_can >> 8); - PYLON_4220.data.u8[3] = (max_volt_pylon_can & 0x00FF); - PYLON_4221.data.u8[2] = (max_volt_pylon_can >> 8); - PYLON_4221.data.u8[3] = (max_volt_pylon_can & 0x00FF); + PYLON_4220.data.u8[2] = (max_voltage >> 8); + PYLON_4220.data.u8[3] = (max_voltage & 0x00FF); + PYLON_4221.data.u8[2] = (max_voltage >> 8); + PYLON_4221.data.u8[3] = (max_voltage & 0x00FF); //In case we run into any errors/faults, we can set charge / discharge forbidden if (bms_status == FAULT) { diff --git a/Software/src/inverter/PYLON-CAN.h b/Software/src/inverter/PYLON-CAN.h index 632d0ca45..4a29b22ee 100644 --- a/Software/src/inverter/PYLON-CAN.h +++ b/Software/src/inverter/PYLON-CAN.h @@ -18,8 +18,8 @@ extern uint16_t stat_batt_power; extern uint16_t temperature_min; extern uint16_t temperature_max; extern uint16_t CANerror; -extern uint16_t min_volt_pylon_can; -extern uint16_t max_volt_pylon_can; +extern uint16_t min_voltage; +extern uint16_t max_voltage; // Definitions for BMS status #define STANDBY 0 #define INACTIVE 1 diff --git a/Software/src/inverter/SMA-CAN.cpp b/Software/src/inverter/SMA-CAN.cpp index a229bbc32..cca016d8f 100644 --- a/Software/src/inverter/SMA-CAN.cpp +++ b/Software/src/inverter/SMA-CAN.cpp @@ -125,13 +125,13 @@ static int ampere_hours_remaining = 0; void update_values_can_sma() { //This function maps all the values fetched from battery CAN to the correct CAN messages //Calculate values - charge_current = ((max_target_charge_power * 10) / - max_volt_sma_can); //Charge power in W , max volt in V+1decimal (P=UI, solve for I) + charge_current = + ((max_target_charge_power * 10) / max_voltage); //Charge power in W , max volt in V+1decimal (P=UI, solve for I) //The above calculation results in (30 000*10)/3700=81A charge_current = (charge_current * 10); //Value needs a decimal before getting sent to inverter (81.0A) discharge_current = ((max_target_discharge_power * 10) / - max_volt_sma_can); //Charge power in W , max volt in V+1decimal (P=UI, solve for I) + max_voltage); //Charge power in W , max volt in V+1decimal (P=UI, solve for I) //The above calculation results in (30 000*10)/3700=81A discharge_current = (discharge_current * 10); //Value needs a decimal before getting sent to inverter (81.0A) @@ -142,11 +142,11 @@ void update_values_can_sma() { //This function maps all the values fetched from //Map values to CAN messages //Maxvoltage (eg 400.0V = 4000 , 16bits long) - SMA_358.data.u8[0] = (max_volt_sma_can >> 8); - SMA_358.data.u8[1] = (max_volt_sma_can & 0x00FF); + SMA_358.data.u8[0] = (max_voltage >> 8); + SMA_358.data.u8[1] = (max_voltage & 0x00FF); //Minvoltage (eg 300.0V = 3000 , 16bits long) - SMA_358.data.u8[2] = (min_volt_sma_can >> 8); //Minvoltage behaves strange on SMA, cuts out at 56% of the set value? - SMA_358.data.u8[3] = (min_volt_sma_can & 0x00FF); + SMA_358.data.u8[2] = (min_voltage >> 8); //Minvoltage behaves strange on SMA, cuts out at 56% of the set value? + SMA_358.data.u8[3] = (min_voltage & 0x00FF); //Discharge limited current, 500 = 50A, (0.1, A) SMA_358.data.u8[4] = (discharge_current >> 8); SMA_358.data.u8[5] = (discharge_current & 0x00FF); diff --git a/Software/src/inverter/SMA-CAN.h b/Software/src/inverter/SMA-CAN.h index 8097cd6d4..9c5b2c0f4 100644 --- a/Software/src/inverter/SMA-CAN.h +++ b/Software/src/inverter/SMA-CAN.h @@ -19,8 +19,8 @@ extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 funct extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) extern uint16_t cell_max_voltage; //mV, 0-4350 extern uint16_t cell_min_voltage; //mV, 0-4350 -extern uint16_t min_volt_sma_can; -extern uint16_t max_volt_sma_can; +extern uint16_t min_voltage; +extern uint16_t max_voltage; extern uint8_t LEDcolor; //Enum, 0-2 // Definitions for BMS status #define STANDBY 0 diff --git a/Software/src/inverter/SOFAR-CAN.cpp b/Software/src/inverter/SOFAR-CAN.cpp index e80ba5c3a..3edb3b279 100644 --- a/Software/src/inverter/SOFAR-CAN.cpp +++ b/Software/src/inverter/SOFAR-CAN.cpp @@ -281,15 +281,15 @@ CAN_frame_t SOFAR_7C0 = {.FIR = {.B = void update_values_can_sofar() { //This function maps all the values fetched from battery CAN to the correct CAN messages //Maxvoltage (eg 400.0V = 4000 , 16bits long) Charge Cutoff Voltage - SOFAR_351.data.u8[0] = (max_volt_sofar_can >> 8); - SOFAR_351.data.u8[1] = (max_volt_sofar_can & 0x00FF); + SOFAR_351.data.u8[0] = (max_voltage >> 8); + SOFAR_351.data.u8[1] = (max_voltage & 0x00FF); //SOFAR_351.data.u8[2] = DC charge current limitation (Default 25.0A) //SOFAR_351.data.u8[3] = DC charge current limitation //SOFAR_351.data.u8[4] = DC discharge current limitation (Default 25.0A) //SOFAR_351.data.u8[5] = DC discharge current limitation //Minvoltage (eg 300.0V = 3000 , 16bits long) Discharge Cutoff Voltage - SOFAR_351.data.u8[6] = (min_volt_sofar_can >> 8); - SOFAR_351.data.u8[7] = (min_volt_sofar_can & 0x00FF); + SOFAR_351.data.u8[6] = (min_voltage >> 8); + SOFAR_351.data.u8[7] = (min_voltage & 0x00FF); //SOC SOFAR_355.data.u8[0] = (SOC / 100); diff --git a/Software/src/inverter/SOFAR-CAN.h b/Software/src/inverter/SOFAR-CAN.h index b3cbb284a..ece158e8c 100644 --- a/Software/src/inverter/SOFAR-CAN.h +++ b/Software/src/inverter/SOFAR-CAN.h @@ -22,8 +22,8 @@ extern uint16_t cell_max_voltage; //mV, 0-4350 extern uint16_t cell_min_voltage; //mV, 0-4350 extern uint8_t batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern uint8_t LEDcolor; //Enum, 0-2 -extern uint16_t min_volt_sofar_can; -extern uint16_t max_volt_sofar_can; +extern uint16_t min_voltage; +extern uint16_t max_voltage; // Definitions for BMS status #define STANDBY 0 #define INACTIVE 1 diff --git a/Software/src/inverter/SOLAX-CAN.cpp b/Software/src/inverter/SOLAX-CAN.cpp index c0012be23..47d2072a5 100644 --- a/Software/src/inverter/SOLAX-CAN.cpp +++ b/Software/src/inverter/SOLAX-CAN.cpp @@ -150,10 +150,10 @@ void update_values_can_solax() { //This function maps all the values fetched fr //Put the values into the CAN messages //BMS_Limits - SOLAX_1872.data.u8[0] = (uint8_t)max_volt_solax_can; //Todo, scaling OK? - SOLAX_1872.data.u8[1] = (max_volt_solax_can >> 8); - SOLAX_1872.data.u8[2] = (uint8_t)min_volt_solax_can; //Todo, scaling OK? - SOLAX_1872.data.u8[3] = (min_volt_solax_can >> 8); + SOLAX_1872.data.u8[0] = (uint8_t)max_voltage; //Todo, scaling OK? + SOLAX_1872.data.u8[1] = (max_voltage >> 8); + SOLAX_1872.data.u8[2] = (uint8_t)min_voltage; //Todo, scaling OK? + SOLAX_1872.data.u8[3] = (min_voltage >> 8); SOLAX_1872.data.u8[4] = (uint8_t)(max_charge_rate_amp * 10); //Todo, scaling OK? SOLAX_1872.data.u8[5] = ((max_charge_rate_amp * 10) >> 8); SOLAX_1872.data.u8[6] = (uint8_t)(max_discharge_rate_amp * 10); //Todo, scaling OK? diff --git a/Software/src/inverter/SOLAX-CAN.h b/Software/src/inverter/SOLAX-CAN.h index 9abf694ba..0857faf97 100644 --- a/Software/src/inverter/SOLAX-CAN.h +++ b/Software/src/inverter/SOLAX-CAN.h @@ -22,8 +22,8 @@ extern uint16_t stat_batt_power; extern uint16_t temperature_min; extern uint16_t temperature_max; extern uint16_t CANerror; -extern uint16_t min_volt_solax_can; -extern uint16_t max_volt_solax_can; +extern uint16_t min_voltage; +extern uint16_t max_voltage; extern uint16_t cell_max_voltage; extern uint16_t cell_min_voltage; extern uint8_t inverterAllowsContactorClosing;