Merge pull request #190 from dalathegreat/bugfix/voltage-limits-as-variables

All batteries: Voltage limits as variables
This commit is contained in:
Daniel Öster 2024-02-17 23:17:39 +02:00 committed by GitHub
commit e60eca78e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 177 additions and 145 deletions

View file

@ -54,9 +54,9 @@ ModbusServerRTU MBserver(Serial2, 2000);
#endif #endif
// Common inverter parameters. Batteries map their values to these variables // 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 max_voltage = 5000; //V+1, 0-500.0 (0-5000)
uint16_t min_voltage = ABSOLUTE_MIN_VOLTAGE; // If lower disables discharging battery 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_voltage = 3700; //V+1, 0-500.0 (0-5000)
uint16_t battery_current = 0; uint16_t battery_current = 0;
uint16_t SOC = 5000; //SOC%, 0-100.00 (0-10000) uint16_t SOC = 5000; //SOC%, 0-100.00 (0-10000)
uint16_t StateOfHealth = 9900; //SOH%, 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_inverter();
inform_user_on_battery();
#ifdef BATTERY_HAS_INIT
init_battery(); init_battery();
#endif
// BOOT button at runtime is used as an input for various things // BOOT button at runtime is used as an input for various things
pinMode(0, INPUT_PULLUP); pinMode(0, INPUT_PULLUP);
@ -358,9 +354,9 @@ void inform_user_on_inverter() {
#endif #endif
} }
void inform_user_on_battery() { void init_battery() {
// Inform user what battery is used // Inform user what battery is used and perform setup
announce_battery(); setup_battery();
#ifdef SERIAL_LINK_RECEIVER #ifdef SERIAL_LINK_RECEIVER
Serial.println("SERIAL_DATA_LINK_RECEIVER selected"); Serial.println("SERIAL_DATA_LINK_RECEIVER selected");
#endif #endif

View file

@ -21,7 +21,6 @@
#ifdef NISSAN_LEAF_BATTERY #ifdef NISSAN_LEAF_BATTERY
#include "NISSAN-LEAF-BATTERY.h" //See this file for more LEAF battery settings #include "NISSAN-LEAF-BATTERY.h" //See this file for more LEAF battery settings
#define BATTERY_HAS_INIT
#endif #endif
#ifdef RENAULT_KANGOO_BATTERY #ifdef RENAULT_KANGOO_BATTERY
@ -52,7 +51,7 @@
void update_values_battery(); void update_values_battery();
void receive_can_battery(CAN_frame_t rx_frame); void receive_can_battery(CAN_frame_t rx_frame);
void send_can_battery(); void send_can_battery();
void announce_battery(void); void setup_battery(void);
#endif #endif
#endif #endif

View file

@ -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"); 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 #endif

View file

@ -7,25 +7,27 @@
#define BATTERY_SELECTED #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 // These parameters need to be mapped for the inverter
extern uint16_t SOC; extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000)
extern uint16_t StateOfHealth; extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000)
extern uint16_t battery_voltage; extern uint16_t SOC; //SOC%, 0-100.00 (0-10000)
extern uint16_t battery_current; extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000)
extern uint16_t capacity_Wh; extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000)
extern uint16_t remaining_capacity_Wh; extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485)
extern uint16_t max_target_discharge_power; extern uint16_t capacity_Wh; //Wh, 0-60000
extern uint16_t max_target_charge_power; extern uint16_t remaining_capacity_Wh; //Wh, 0-60000
extern uint8_t bms_char_dis_status; extern uint16_t max_target_discharge_power; //W, 0-60000
extern uint16_t stat_batt_power; extern uint16_t max_target_charge_power; //W, 0-60000
extern uint16_t temperature_min; extern uint8_t bms_char_dis_status; //Enum, 0-2
extern uint16_t temperature_max; extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530)
extern uint16_t CANerror; extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385)
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385)
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false 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 #endif

View file

@ -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"); 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 #endif

View file

@ -7,26 +7,27 @@
#define BATTERY_SELECTED #define BATTERY_SELECTED
#define ABSOLUTE_MAX_VOLTAGE \ // These parameters need to be mapped for the inverter
4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000)
#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled 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 void setup_battery(void);
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
#endif #endif

View file

@ -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"); 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 #endif

View file

@ -7,27 +7,28 @@
#define BATTERY_SELECTED #define BATTERY_SELECTED
#define ABSOLUTE_MAX_VOLTAGE \ // These parameters need to be mapped for the Inverter
4040 // 404.4V,if battery voltage goes over this, charging is not possible (goes into forced discharge) extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000)
#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000)
extern uint16_t SOC; //SOC%, 0-100.00 (0-10000)
// These parameters need to be mapped for the Gen24 extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000)
extern uint16_t SOC; extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000)
extern uint16_t StateOfHealth; extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485)
extern uint16_t battery_voltage; extern uint16_t capacity_Wh; //Wh, 0-60000
extern uint16_t battery_current; extern uint16_t remaining_capacity_Wh; //Wh, 0-60000
extern uint16_t capacity_Wh; extern uint16_t max_target_discharge_power; //W, 0-60000
extern uint16_t remaining_capacity_Wh; extern uint16_t max_target_charge_power; //W, 0-60000
extern uint16_t max_target_discharge_power; extern uint8_t bms_char_dis_status; //Enum, 0-2
extern uint16_t max_target_charge_power; extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530)
extern uint8_t bms_char_dis_status; extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385)
extern uint16_t stat_batt_power; extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385)
extern uint16_t temperature_min; extern uint16_t cell_max_voltage; //mV, 0-4350
extern uint16_t temperature_max; extern uint16_t cell_min_voltage; //mV, 0-4350
extern uint16_t CANerror; extern uint16_t cellvoltages[120]; //mV 0-4350 per cell
extern uint16_t cell_max_voltage; extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery.
extern uint16_t cell_min_voltage;
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
void setup_battery(void);
#endif #endif

View file

@ -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"); 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 #endif

View file

@ -7,13 +7,12 @@
#define BATTERY_SELECTED #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 MAXCHARGEPOWERALLOWED 10000
#define MAXDISCHARGEPOWERALLOWED 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 SOC; //SOC%, 0-100.00 (0-10000)
extern uint16_t StateOfHealth; //SOH%, 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_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 extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
uint16_t convertToUnsignedInt16(int16_t signed_value); uint16_t convertToUnsignedInt16(int16_t signed_value);
void setup_battery(void);
#endif #endif

View file

@ -257,8 +257,7 @@ void update_values_battery() { /* This function maps all the values fetched via
} }
//Check if SOC% is plausible //Check if SOC% is plausible
if (battery_voltage > if (battery_voltage > (max_voltage - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT
(ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT
if (LB_SOC < 650) { if (LB_SOC < 650) {
set_event(EVENT_SOC_PLAUSIBILITY_ERROR, LB_SOC / 10); // Set event with the SOC as data set_event(EVENT_SOC_PLAUSIBILITY_ERROR, LB_SOC / 10); // Set event with the SOC as data
} else { } else {
@ -922,12 +921,12 @@ uint16_t Temp_fromRAW_to_F(uint16_t temperature) { //This function feels horrib
return static_cast<uint16_t>(1094 + (309 - temperature) * 2.5714285714285715); return static_cast<uint16_t>(1094 + (309 - temperature) * 2.5714285714285715);
} }
void init_battery(void) { void setup_battery(void) { // Performs one time setup at startup
nof_cellvoltages = 96;
}
void announce_battery(void) {
Serial.println("Nissan LEAF battery selected"); 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 #endif

View file

@ -7,11 +7,9 @@
#define BATTERY_SELECTED #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 // 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 SOC; //SOC%, 0-100.00 (0-10000)
extern uint16_t StateOfHealth; //SOH%, 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_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 convert2unsignedint16(int16_t signed_value);
uint16_t Temp_fromRAW_to_F(uint16_t temperature); uint16_t Temp_fromRAW_to_F(uint16_t temperature);
bool is_message_corrupt(CAN_frame_t rx_frame); bool is_message_corrupt(CAN_frame_t rx_frame);
void setup_battery(void);
void init_battery(void);
#endif #endif

View file

@ -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"); 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 #endif

View file

@ -7,16 +7,15 @@
#define BATTERY_SELECTED #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 \ #define ABSOLUTE_CELL_MAX_VOLTAGE \
4100 // Max Cell Voltage mV! if voltage goes over this, charging is not possible (goes into forced discharge) 4100 // Max Cell Voltage mV! if voltage goes over this, charging is not possible (goes into forced discharge)
#define ABSOLUTE_CELL_MIN_VOLTAGE \ #define ABSOLUTE_CELL_MIN_VOLTAGE \
3000 // Min Cell Voltage mV! if voltage goes under this, discharging further is disabled 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 #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 SOC; //SOC%, 0-100.00 (0-10000)
extern uint16_t StateOfHealth; //SOH%, 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_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 extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
uint16_t convert2uint16(int16_t signed_value); uint16_t convert2uint16(int16_t signed_value);
void setup_battery(void);
#endif #endif

View file

@ -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"); 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 #endif

View file

@ -7,16 +7,15 @@
#define BATTERY_SELECTED #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 \ #define ABSOLUTE_CELL_MAX_VOLTAGE \
4100 // Max Cell Voltage mV! if voltage goes over this, charging is not possible (goes into forced discharge) 4100 // Max Cell Voltage mV! if voltage goes over this, charging is not possible (goes into forced discharge)
#define ABSOLUTE_CELL_MIN_VOLTAGE \ #define ABSOLUTE_CELL_MIN_VOLTAGE \
3000 // Min Cell Voltage mV! if voltage goes under this, discharging further is disabled 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 #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 SOC; //SOC%, 0-100.00 (0-10000)
extern uint16_t StateOfHealth; //SOH%, 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_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 batteryAllowsContactorClosing; //Bool, 1=true, 0=false
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
void setup_battery(void);
#endif #endif

View file

@ -177,8 +177,11 @@ uint8_t CalculateCRC8(CAN_frame_t rx_frame) {
return (uint8_t)crc; 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"); 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 #endif

View file

@ -7,27 +7,28 @@
#define BATTERY_SELECTED #define BATTERY_SELECTED
#define ABSOLUTE_MAX_VOLTAGE \ // These parameters need to be mapped for the inverter
4030 // 403.0V,if battery voltage goes over this, charging is not possible (goes into forced discharge) extern uint16_t max_voltage; //V+1, 0-500.0 (0-5000)
#define ABSOLUTE_MIN_VOLTAGE 3100 // 310.0V if battery voltage goes under this, discharging further is disabled extern uint16_t min_voltage; //V+1, 0-500.0 (0-5000)
extern uint16_t SOC; //SOC%, 0-100.00 (0-10000)
// These parameters need to be mapped for the Gen24 extern uint16_t StateOfHealth; //SOH%, 0-100.00 (0-10000)
extern uint16_t SOC; extern uint16_t battery_voltage; //V+1, 0-500.0 (0-5000)
extern uint16_t StateOfHealth; extern uint16_t battery_current; //A+1, Goes thru convert2unsignedint16 function (5.0A = 50, -5.0A = 65485)
extern uint16_t battery_voltage; extern uint16_t capacity_Wh; //Wh, 0-60000
extern uint16_t battery_current; extern uint16_t remaining_capacity_Wh; //Wh, 0-60000
extern uint16_t capacity_Wh; extern uint16_t max_target_discharge_power; //W, 0-60000
extern uint16_t remaining_capacity_Wh; extern uint16_t max_target_charge_power; //W, 0-60000
extern uint16_t max_target_discharge_power; extern uint8_t bms_char_dis_status; //Enum, 0-2
extern uint16_t max_target_charge_power; extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530)
extern uint8_t bms_char_dis_status; extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385)
extern uint16_t stat_batt_power; extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385)
extern uint16_t temperature_min; extern uint16_t cell_max_voltage; //mV, 0-4350
extern uint16_t temperature_max; extern uint16_t cell_min_voltage; //mV, 0-4350
extern uint16_t CANerror; extern uint16_t cellvoltages[120]; //mV 0-4350 per cell
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery.
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
uint8_t CalculateCRC8(CAN_frame_t rx_frame); uint8_t CalculateCRC8(CAN_frame_t rx_frame);
void setup_battery(void);
#endif #endif

View file

@ -10,11 +10,9 @@
// https://github.com/mackelec/SerialDataLink // 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 // 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 SOC; //SOC%, 0-100.00 (0-10000)
extern uint16_t StateOfHealth; //SOH%, 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_voltage; //V+1, 0-500.0 (0-5000)

View file

@ -50,10 +50,10 @@ static uint16_t regenerative_limit = 0;
static uint16_t discharge_limit = 0; static uint16_t discharge_limit = 0;
static uint16_t max_heat_park = 0; static uint16_t max_heat_park = 0;
static uint16_t hvac_max_power = 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_discharge_current = 0;
static uint16_t max_charge_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 high_voltage = 0;
static uint16_t low_voltage = 0; static uint16_t low_voltage = 0;
static uint16_t output_current = 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; 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 //Check if SOC% is plausible
if (battery_voltage > if (battery_voltage > (max_voltage - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT
(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 (SOC < 6500) { //When SOC is less than 65.00% when approaching max voltage
set_event(EVENT_SOC_PLAUSIBILITY_ERROR, SOC / 100); 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) { if (LFP_Chemistry) {
Serial.print("LFP chemistry detected!"); Serial.print("LFP chemistry detected!");
} }
Serial.print(nof_cellvoltages);
Serial.println(""); Serial.println("");
Serial.print("Cellstats, Max: "); Serial.print("Cellstats, Max: ");
Serial.print(cell_max_v); Serial.print(cell_max_v);
@ -487,8 +496,10 @@ void receive_can_battery(CAN_frame_t rx_frame) {
break; break;
case 0x2d2: case 0x2d2:
//Min / max limits //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 bms_min_voltage =
max_voltage = ((rx_frame.data.u8[3] << 8) | rx_frame.data.u8[2]) * 0.01 * 2; //Example 40282mv * 0.01 = 402.82 V ((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 = max_charge_current =
(((rx_frame.data.u8[5] & 0x3F) << 8) | rx_frame.data.u8[4]) * 0.1; //Example 1301? * 0.1 = 130.1? (((rx_frame.data.u8[5] & 0x3F) << 8) | rx_frame.data.u8[4]) * 0.1; //Example 1301? * 0.1 = 130.1?
max_discharge_current = 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"); 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 #endif

View file

@ -7,14 +7,13 @@
#define BATTERY_SELECTED #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 MAXCHARGEPOWERALLOWED 15000 // 15000W we use a define since the value supplied by Tesla is always 0
#define MAXDISCHARGEPOWERALLOWED \ #define MAXDISCHARGEPOWERALLOWED \
60000 // 60000W we need to cap this value to max 60kW, most inverters overflow otherwise 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 SOC; //SOC%, 0-100.00 (0-10000)
extern uint16_t StateOfHealth; //SOH%, 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_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_int_with_units(char* header, int value, char* units);
void print_SOC(char* header, int SOC); void print_SOC(char* header, int SOC);
uint16_t convert2unsignedInt16(int16_t signed_value); uint16_t convert2unsignedInt16(int16_t signed_value);
void setup_battery(void);
#endif #endif

View file

@ -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"); 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 #endif

View file

@ -7,11 +7,9 @@
#define BATTERY_SELECTED #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 // 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 SOC; //SOC%, 0-100.00 (0-10000)
extern uint16_t StateOfHealth; //SOH%, 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_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 batteryAllowsContactorClosing; //Bool, 1=true, 0=false
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
void setup_battery(void);
#endif #endif