Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All batteries: Voltage limits as variables #190

Merged
merged 5 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions Software/Software.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Software/src/battery/BATTERIES.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion Software/src/battery/BMW-I3-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 21 additions & 19 deletions Software/src/battery/BMW-I3-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions Software/src/battery/CHADEMO-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 21 additions & 20 deletions Software/src/battery/CHADEMO-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 21 additions & 20 deletions Software/src/battery/IMIEV-CZERO-ION-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions Software/src/battery/KIA-HYUNDAI-64-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
13 changes: 6 additions & 7 deletions Software/src/battery/NISSAN-LEAF-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

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
9 changes: 3 additions & 6 deletions Software/src/battery/NISSAN-LEAF-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
5 changes: 4 additions & 1 deletion Software/src/battery/RENAULT-KANGOO-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions Software/src/battery/RENAULT-KANGOO-BATTERY.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
5 changes: 4 additions & 1 deletion Software/src/battery/RENAULT-ZOE-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading
Loading