diff --git a/Software/Software.ino b/Software/Software.ino index 7e08e6bc..0cbbf5c8 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -54,9 +54,9 @@ ModbusServerRTU MBserver(Serial2, 2000); #endif // Common inverter parameters. Batteries map their values to these variables -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 disables discharging battery -uint16_t battery_voltage = 3700; //V+1, 0-500.0 (0-5000) +uint16_t max_voltage = 5000; //V+1, 0-500.0 (0-5000) +uint16_t min_voltage = 2500; //V+1, 0-500.0 (0-5000) +uint16_t battery_voltage = 3700; //V+1, 0-500.0 (0-5000) uint16_t battery_current = 0; uint16_t SOC = 5000; //SOC%, 0-100.00 (0-10000) uint16_t StateOfHealth = 9900; //SOH%, 0-100.00 (0-10000) @@ -145,11 +145,7 @@ void setup() { inform_user_on_inverter(); - inform_user_on_battery(); - -#ifdef BATTERY_HAS_INIT init_battery(); -#endif // BOOT button at runtime is used as an input for various things pinMode(0, INPUT_PULLUP); @@ -358,9 +354,9 @@ void inform_user_on_inverter() { #endif } -void inform_user_on_battery() { - // Inform user what battery is used - announce_battery(); +void init_battery() { + // Inform user what battery is used and perform setup + setup_battery(); #ifdef SERIAL_LINK_RECEIVER Serial.println("SERIAL_DATA_LINK_RECEIVER selected"); #endif diff --git a/Software/src/battery/BATTERIES.h b/Software/src/battery/BATTERIES.h index e80ea3c4..f6efe68e 100644 --- a/Software/src/battery/BATTERIES.h +++ b/Software/src/battery/BATTERIES.h @@ -21,7 +21,6 @@ #ifdef NISSAN_LEAF_BATTERY #include "NISSAN-LEAF-BATTERY.h" //See this file for more LEAF battery settings -#define BATTERY_HAS_INIT #endif #ifdef RENAULT_KANGOO_BATTERY @@ -52,7 +51,7 @@ void update_values_battery(); void receive_can_battery(CAN_frame_t rx_frame); void send_can_battery(); -void announce_battery(void); +void setup_battery(void); #endif #endif diff --git a/Software/src/battery/BMW-I3-BATTERY.cpp b/Software/src/battery/BMW-I3-BATTERY.cpp index ee42cae4..11c6794f 100644 --- a/Software/src/battery/BMW-I3-BATTERY.cpp +++ b/Software/src/battery/BMW-I3-BATTERY.cpp @@ -193,8 +193,11 @@ void send_can_battery() { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("BMW i3 battery selected"); + + max_voltage = 4040; // 404.4V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/BMW-I3-BATTERY.h b/Software/src/battery/BMW-I3-BATTERY.h index 4e3697d7..c12a1402 100644 --- a/Software/src/battery/BMW-I3-BATTERY.h +++ b/Software/src/battery/BMW-I3-BATTERY.h @@ -7,25 +7,27 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - // These parameters need to be mapped for the inverter -extern uint16_t SOC; -extern uint16_t StateOfHealth; -extern uint16_t battery_voltage; -extern uint16_t battery_current; -extern uint16_t capacity_Wh; -extern uint16_t remaining_capacity_Wh; -extern uint16_t max_target_discharge_power; -extern uint16_t max_target_charge_power; -extern uint8_t bms_char_dis_status; -extern uint16_t stat_batt_power; -extern uint16_t temperature_min; -extern uint16_t temperature_max; -extern uint16_t CANerror; -extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false -extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) +extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) +extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485) +extern uint16_t capacity_Wh; //Wh, 0-60000 +extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 +extern uint16_t max_target_discharge_power; //W, 0-60000 +extern uint16_t max_target_charge_power; //W, 0-60000 +extern uint8_t bms_char_dis_status; //Enum, 0-2 +extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) +extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +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 cellvoltages[120]; //mV 0-4350 per cell +extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery. +extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false + +void setup_battery(void); #endif diff --git a/Software/src/battery/CHADEMO-BATTERY.cpp b/Software/src/battery/CHADEMO-BATTERY.cpp index 628746f1..846c08bc 100644 --- a/Software/src/battery/CHADEMO-BATTERY.cpp +++ b/Software/src/battery/CHADEMO-BATTERY.cpp @@ -221,8 +221,10 @@ void send_can_battery() { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Chademo battery selected"); -} + max_voltage = 4040; // 404.4V, over this, charging is not possible (goes into forced discharge) + min_voltage = 2000; // 200.0V under this, discharging further is disabled +} #endif diff --git a/Software/src/battery/CHADEMO-BATTERY.h b/Software/src/battery/CHADEMO-BATTERY.h index 1bce665b..bd49c943 100644 --- a/Software/src/battery/CHADEMO-BATTERY.h +++ b/Software/src/battery/CHADEMO-BATTERY.h @@ -7,26 +7,27 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) +extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) +extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485) +extern uint16_t capacity_Wh; //Wh, 0-60000 +extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 +extern uint16_t max_target_discharge_power; //W, 0-60000 +extern uint16_t max_target_charge_power; //W, 0-60000 +extern uint8_t bms_char_dis_status; //Enum, 0-2 +extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) +extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +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 cellvoltages[120]; //mV 0-4350 per cell +extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery. +extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false -// These parameters need to be mapped -extern uint16_t SOC; -extern uint16_t StateOfHealth; -extern uint16_t battery_voltage; -extern uint16_t battery_current; -extern uint16_t capacity_Wh; -extern uint16_t remaining_capacity_Wh; -extern uint16_t max_target_discharge_power; -extern uint16_t max_target_charge_power; -extern uint8_t bms_status; -extern uint8_t bms_char_dis_status; -extern uint16_t stat_batt_power; -extern uint16_t temperature_min; -extern uint16_t temperature_max; -extern uint16_t CANerror; -extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false -extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +void setup_battery(void); #endif diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index 4ccaf57e..7530c37e 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -227,8 +227,11 @@ void send_can_battery() { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Mitsubishi i-MiEV / Citroen C-Zero / Peugeot Ion battery selected"); + + max_voltage = 4040; // 404.4V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h index 1d125a08..dd690a1c 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h @@ -7,27 +7,28 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - -// These parameters need to be mapped for the Gen24 -extern uint16_t SOC; -extern uint16_t StateOfHealth; -extern uint16_t battery_voltage; -extern uint16_t battery_current; -extern uint16_t capacity_Wh; -extern uint16_t remaining_capacity_Wh; -extern uint16_t max_target_discharge_power; -extern uint16_t max_target_charge_power; -extern uint8_t bms_char_dis_status; -extern uint16_t stat_batt_power; -extern uint16_t temperature_min; -extern uint16_t temperature_max; -extern uint16_t CANerror; -extern uint16_t cell_max_voltage; -extern uint16_t cell_min_voltage; +// These parameters need to be mapped for the Inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) +extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) +extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485) +extern uint16_t capacity_Wh; //Wh, 0-60000 +extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 +extern uint16_t max_target_discharge_power; //W, 0-60000 +extern uint16_t max_target_charge_power; //W, 0-60000 +extern uint8_t bms_char_dis_status; //Enum, 0-2 +extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) +extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +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 cellvoltages[120]; //mV 0-4350 per cell +extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery. extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +void setup_battery(void); + #endif diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp index aa6d2f3d..4cb3a4cb 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp @@ -599,8 +599,11 @@ uint16_t convertToUnsignedInt16(int16_t signed_value) { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Kia Niro / Hyundai Kona 64kWh battery selected"); + + max_voltage = 4040; // 404.0V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h index 36e63b4c..c9901608 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h @@ -7,13 +7,12 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled #define MAXCHARGEPOWERALLOWED 10000 #define MAXDISCHARGEPOWERALLOWED 10000 -// These parameters need to be mapped for the Gen24 +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -34,5 +33,6 @@ extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false uint16_t convertToUnsignedInt16(int16_t signed_value); +void setup_battery(void); #endif diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp index 29f19f39..a476b5b3 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp @@ -257,8 +257,7 @@ void update_values_battery() { /* This function maps all the values fetched via } //Check if SOC% is plausible - if (battery_voltage > - (ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT + if (battery_voltage > (max_voltage - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT if (LB_SOC < 650) { set_event(EVENT_SOC_PLAUSIBILITY_ERROR, LB_SOC / 10); // Set event with the SOC as data } else { @@ -922,12 +921,12 @@ uint16_t Temp_fromRAW_to_F(uint16_t temperature) { //This function feels horrib return static_cast(1094 + (309 - temperature) * 2.5714285714285715); } -void init_battery(void) { - nof_cellvoltages = 96; -} - -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Nissan LEAF battery selected"); + + nof_cellvoltages = 96; + max_voltage = 4040; // 404.4V, over this, charging is not possible (goes into forced discharge) + min_voltage = 2450; // 245.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.h b/Software/src/battery/NISSAN-LEAF-BATTERY.h index 12b183aa..7c4b1b83 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.h +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.h @@ -7,11 +7,9 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - // These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -33,7 +31,6 @@ extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false uint16_t convert2unsignedint16(int16_t signed_value); uint16_t Temp_fromRAW_to_F(uint16_t temperature); bool is_message_corrupt(CAN_frame_t rx_frame); - -void init_battery(void); +void setup_battery(void); #endif diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp index 794aface..eee07cb8 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp @@ -270,8 +270,11 @@ uint16_t convert2uint16(int16_t signed_value) { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Renault Kangoo battery selected"); + + max_voltage = 4040; // 404.0V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.h b/Software/src/battery/RENAULT-KANGOO-BATTERY.h index bfa8c9d6..2d6c5c35 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.h +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.h @@ -7,16 +7,15 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled #define ABSOLUTE_CELL_MAX_VOLTAGE \ 4100 // Max Cell Voltage mV! if voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_CELL_MIN_VOLTAGE \ 3000 // Min Cell Voltage mV! if voltage goes under this, discharging further is disabled #define MAX_CELL_DEVIATION_MV 500 //LED turns yellow on the board if mv delta exceeds this value -// These parameters need to be mapped for the Gen24 +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -36,5 +35,6 @@ extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false uint16_t convert2uint16(int16_t signed_value); +void setup_battery(void); #endif diff --git a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp index 977cdb91..1c718077 100644 --- a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp +++ b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp @@ -166,8 +166,11 @@ void send_can_battery() { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Renault Zoe battery selected"); + + max_voltage = 4040; // 404.0V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/RENAULT-ZOE-BATTERY.h b/Software/src/battery/RENAULT-ZOE-BATTERY.h index 7fbf5beb..a376f5ad 100644 --- a/Software/src/battery/RENAULT-ZOE-BATTERY.h +++ b/Software/src/battery/RENAULT-ZOE-BATTERY.h @@ -7,16 +7,15 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled #define ABSOLUTE_CELL_MAX_VOLTAGE \ 4100 // Max Cell Voltage mV! if voltage goes over this, charging is not possible (goes into forced discharge) #define ABSOLUTE_CELL_MIN_VOLTAGE \ 3000 // Min Cell Voltage mV! if voltage goes under this, discharging further is disabled #define MAX_CELL_DEVIATION_MV 500 //LED turns yellow on the board if mv delta exceeds this value -// These parameters need to be mapped for the Gen24 +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -35,4 +34,6 @@ extern uint16_t CANerror; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +void setup_battery(void); + #endif diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp index 8334a053..f6717089 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp @@ -177,8 +177,11 @@ uint8_t CalculateCRC8(CAN_frame_t rx_frame) { return (uint8_t)crc; } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Hyundai Santa Fe PHEV battery selected"); + + max_voltage = 4040; // 404.0V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.h b/Software/src/battery/SANTA-FE-PHEV-BATTERY.h index c96b0673..448a7a85 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.h +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.h @@ -7,27 +7,28 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4030 // 403.0V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - -// These parameters need to be mapped for the Gen24 -extern uint16_t SOC; -extern uint16_t StateOfHealth; -extern uint16_t battery_voltage; -extern uint16_t battery_current; -extern uint16_t capacity_Wh; -extern uint16_t remaining_capacity_Wh; -extern uint16_t max_target_discharge_power; -extern uint16_t max_target_charge_power; -extern uint8_t bms_char_dis_status; -extern uint16_t stat_batt_power; -extern uint16_t temperature_min; -extern uint16_t temperature_max; -extern uint16_t CANerror; -extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false -extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) +extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) +extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485) +extern uint16_t capacity_Wh; //Wh, 0-60000 +extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 +extern uint16_t max_target_discharge_power; //W, 0-60000 +extern uint16_t max_target_charge_power; //W, 0-60000 +extern uint8_t bms_char_dis_status; //Enum, 0-2 +extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) +extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) +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 cellvoltages[120]; //mV 0-4350 per cell +extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery. +extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false uint8_t CalculateCRC8(CAN_frame_t rx_frame); +void setup_battery(void); #endif diff --git a/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.h b/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.h index 089276a5..752d0118 100644 --- a/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.h +++ b/Software/src/battery/SERIAL-LINK-RECEIVER-FROM-BATTERY.h @@ -10,11 +10,9 @@ // https://github.com/mackelec/SerialDataLink -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - // These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index e1a446f9..ce9df946 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -50,10 +50,10 @@ static uint16_t regenerative_limit = 0; static uint16_t discharge_limit = 0; static uint16_t max_heat_park = 0; static uint16_t hvac_max_power = 0; -static uint16_t min_voltage = 0; static uint16_t max_discharge_current = 0; static uint16_t max_charge_current = 0; -static uint16_t max_voltage = 0; +static uint16_t bms_max_voltage = 0; +static uint16_t bms_min_voltage = 0; static uint16_t high_voltage = 0; static uint16_t low_voltage = 0; static uint16_t output_current = 0; @@ -258,10 +258,18 @@ void update_values_battery() { //This function maps all the values fetched via LFP_Chemistry = true; } + //Once cell chemistry is determined, set maximum and minimum total pack voltage safety limits + if (LFP_Chemistry) { + max_voltage = 3640; + min_voltage = 2450; + } else { // NCM/A chemistry + max_voltage = 4030; + min_voltage = 3100; + } + //Check if SOC% is plausible - if (battery_voltage > - (ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT - if (SOC < 6500) { //When SOC is less than 65.00% when approaching max voltage + if (battery_voltage > (max_voltage - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT + if (SOC < 6500) { //When SOC is less than 65.00% when approaching max voltage set_event(EVENT_SOC_PLAUSIBILITY_ERROR, SOC / 100); } } @@ -341,6 +349,7 @@ void update_values_battery() { //This function maps all the values fetched via if (LFP_Chemistry) { Serial.print("LFP chemistry detected!"); } + Serial.print(nof_cellvoltages); Serial.println(""); Serial.print("Cellstats, Max: "); Serial.print(cell_max_v); @@ -487,8 +496,10 @@ void receive_can_battery(CAN_frame_t rx_frame) { break; case 0x2d2: //Min / max limits - min_voltage = ((rx_frame.data.u8[1] << 8) | rx_frame.data.u8[0]) * 0.01 * 2; //Example 24148mv * 0.01 = 241.48 V - max_voltage = ((rx_frame.data.u8[3] << 8) | rx_frame.data.u8[2]) * 0.01 * 2; //Example 40282mv * 0.01 = 402.82 V + bms_min_voltage = + ((rx_frame.data.u8[1] << 8) | rx_frame.data.u8[0]) * 0.01 * 2; //Example 24148mv * 0.01 = 241.48 V + bms_max_voltage = + ((rx_frame.data.u8[3] << 8) | rx_frame.data.u8[2]) * 0.01 * 2; //Example 40282mv * 0.01 = 402.82 V max_charge_current = (((rx_frame.data.u8[5] & 0x3F) << 8) | rx_frame.data.u8[4]) * 0.1; //Example 1301? * 0.1 = 130.1? max_discharge_current = @@ -690,8 +701,11 @@ void printDebugIfActive(uint8_t symbol, const char* message) { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Tesla Model 3 battery selected"); + + max_voltage = 4030; // 403.0V, over this, charging is not possible (goes into forced discharge) + min_voltage = 3100; // 310.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.h b/Software/src/battery/TESLA-MODEL-3-BATTERY.h index 5d4904d0..901cc468 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.h +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.h @@ -7,14 +7,13 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4030 // 403.0V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 2450 // 245.0V if battery voltage goes under this, discharging further is disabled #define MAXCHARGEPOWERALLOWED 15000 // 15000W we use a define since the value supplied by Tesla is always 0 #define MAXDISCHARGEPOWERALLOWED \ 60000 // 60000W we need to cap this value to max 60kW, most inverters overflow otherwise -// These parameters need to be mapped for the Inverter +// These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -40,5 +39,6 @@ void printDebugIfActive(uint8_t symbol, const char* message); void print_int_with_units(char* header, int value, char* units); void print_SOC(char* header, int SOC); uint16_t convert2unsignedInt16(int16_t signed_value); +void setup_battery(void); #endif diff --git a/Software/src/battery/TEST-FAKE-BATTERY.cpp b/Software/src/battery/TEST-FAKE-BATTERY.cpp index c1fb00ae..045521f5 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.cpp +++ b/Software/src/battery/TEST-FAKE-BATTERY.cpp @@ -82,8 +82,11 @@ void send_can_battery() { } } -void announce_battery(void) { +void setup_battery(void) { // Performs one time setup at startup Serial.println("Test mode with fake battery selected"); + + max_voltage = 4040; // 404.4V, over this, charging is not possible (goes into forced discharge) + min_voltage = 2450; // 245.0V under this, discharging further is disabled } #endif diff --git a/Software/src/battery/TEST-FAKE-BATTERY.h b/Software/src/battery/TEST-FAKE-BATTERY.h index 877b2736..75d70513 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.h +++ b/Software/src/battery/TEST-FAKE-BATTERY.h @@ -7,11 +7,9 @@ #define BATTERY_SELECTED -#define ABSOLUTE_MAX_VOLTAGE \ - 4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) -#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled - // These parameters need to be mapped for the inverter +extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000) +extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000) extern uint16_t SOC; //SOC%, 0-100.00 (0-10000) extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000) extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000) @@ -31,4 +29,6 @@ extern uint16_t cellvoltages[120]; //mV 0-5000 per cell extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false +void setup_battery(void); + #endif