diff --git a/Software/BMW-I3-BATTERY.cpp b/Software/BMW-I3-BATTERY.cpp index 311c52fd..95804658 100644 --- a/Software/BMW-I3-BATTERY.cpp +++ b/Software/BMW-I3-BATTERY.cpp @@ -100,8 +100,7 @@ void update_values_i3_battery() CANstillAlive--; } - if(printValues) - { //values heading towards the inverter + #ifdef DEBUG_VIA_USB Serial.print("SOC% battery: "); Serial.print(Display_SOC); Serial.print(" SOC% sent to inverter: "); @@ -114,7 +113,7 @@ void update_values_i3_battery() Serial.print(max_target_charge_power); Serial.print(" Max discharge power: "); Serial.print(max_target_discharge_power); - } + #endif } void receive_can_i3_battery(CAN_frame_t rx_frame) diff --git a/Software/BMW-I3-BATTERY.h b/Software/BMW-I3-BATTERY.h index c442970f..7d42010f 100644 --- a/Software/BMW-I3-BATTERY.h +++ b/Software/BMW-I3-BATTERY.h @@ -2,13 +2,10 @@ #define BMW_I3_BATTERY_H #include #include "ESP32CAN.h" +#include "USER_SETTINGS.h" -#define BATTERY_WH_MAX 24000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000 #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 MAXPERCENTAGE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached) -#define MINPERCENTAGE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached) -static byte printValues = 1; //Should debug values be printed to serial output? // These parameters need to be mapped for the inverter extern uint16_t SOC; diff --git a/Software/BYD-CAN.h b/Software/BYD-CAN.h index b505fd83..0bbe1e93 100644 --- a/Software/BYD-CAN.h +++ b/Software/BYD-CAN.h @@ -2,6 +2,7 @@ #define BYD_CAN_H #include #include "ESP32CAN.h" +#include "USER_SETTINGS.h" extern uint16_t SOC; extern uint16_t StateOfHealth; diff --git a/Software/CHADEMO-BATTERY.cpp b/Software/CHADEMO-BATTERY.cpp index bafeb977..c9f0c373 100644 --- a/Software/CHADEMO-BATTERY.cpp +++ b/Software/CHADEMO-BATTERY.cpp @@ -85,8 +85,7 @@ void update_values_chademo_battery() CANstillAlive--; } - if(printValues) - { //values heading towards the modbus registers + #ifdef DEBUG_VIA_USB if(errorCode > 0) { Serial.print("ERROR CODE ACTIVE IN SYSTEM. NUMBER: "); @@ -120,7 +119,7 @@ void update_values_chademo_battery() Serial.println(temperature_min); Serial.print("Temperature Max: "); Serial.println(temperature_max); - } + #endif } void receive_can_chademo_battery(CAN_frame_t rx_frame) diff --git a/Software/CHADEMO-BATTERY.h b/Software/CHADEMO-BATTERY.h index f44026f5..e8a79205 100644 --- a/Software/CHADEMO-BATTERY.h +++ b/Software/CHADEMO-BATTERY.h @@ -2,13 +2,10 @@ #define CHADEMO_BATTERY_H #include #include "ESP32CAN.h" +#include "USER_SETTINGS.h" -#define BATTERY_WH_MAX 24000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000 #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 MAXPERCENTAGE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached) -#define MINPERCENTAGE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached) -static byte printValues = 0; //Should debug values be printed to serial output? // These parameters need to be mapped extern uint16_t SOC; diff --git a/Software/IMIEV-CZERO-ION-BATTERY.cpp b/Software/IMIEV-CZERO-ION-BATTERY.cpp index ce50f388..a9da8f6b 100644 --- a/Software/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/IMIEV-CZERO-ION-BATTERY.cpp @@ -73,15 +73,14 @@ void update_values_imiev_battery() CANstillAlive--; } - if(printValues) - { //values heading towards the modbus registers + #ifdef DEBUG_VIA_USB Serial.print("BMU SOC: "); Serial.println(BMU_SOC); Serial.print("BMU Current: "); Serial.println(BMU_Current); Serial.print("BMU Battery Voltage: "); Serial.println(BMU_PackVoltage); - } + #endif } void receive_can_imiev_battery(CAN_frame_t rx_frame) diff --git a/Software/IMIEV-CZERO-ION-BATTERY.h b/Software/IMIEV-CZERO-ION-BATTERY.h index ca386b45..558c3365 100644 --- a/Software/IMIEV-CZERO-ION-BATTERY.h +++ b/Software/IMIEV-CZERO-ION-BATTERY.h @@ -2,13 +2,10 @@ #define IMIEV_CZERO_ION_BATTERY_H #include #include "ESP32CAN.h" +#include "USER_SETTINGS.h" -#define BATTERY_WH_MAX 22000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000 #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 MAXPERCENTAGE_ZOE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached) -#define MINPERCENTAGE_ZOE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached) -static byte printValues = 1; //Should modbus values be printed to serial output? // These parameters need to be mapped for the Gen24 extern uint16_t SOC; diff --git a/Software/KIA-HYUNDAI-64-BATTERY.cpp b/Software/KIA-HYUNDAI-64-BATTERY.cpp index b82bde78..5ac5c353 100644 --- a/Software/KIA-HYUNDAI-64-BATTERY.cpp +++ b/Software/KIA-HYUNDAI-64-BATTERY.cpp @@ -51,15 +51,14 @@ void update_values_kiaHyundai_64_battery() CANstillAlive--; } - if(printValues) - { //values heading towards the inverter + #ifdef DEBUG_VIA_USB Serial.print("SOC% candidate 1: "); Serial.println(SOC_1); Serial.print("SOC% candidate 2: "); Serial.println(SOC_2); Serial.print("SOC% candidate 3: "); Serial.println(SOC_3); - } + #endif } void receive_can_kiaHyundai_64_battery(CAN_frame_t rx_frame) diff --git a/Software/KIA-HYUNDAI-64-BATTERY.h b/Software/KIA-HYUNDAI-64-BATTERY.h index 6679a3da..3a610d25 100644 --- a/Software/KIA-HYUNDAI-64-BATTERY.h +++ b/Software/KIA-HYUNDAI-64-BATTERY.h @@ -2,13 +2,10 @@ #define KIA_HYUNDAI_64_BATTERY_H #include #include "ESP32CAN.h" +#include "USER_SETTINGS.h" -#define BATTERY_WH_MAX 60000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000 #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 MAXPERCENTAGE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached) -#define MINPERCENTAGE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached) -static byte printValues = 1; //Should debug values be printed to serial output? // These parameters need to be mapped for the Gen24 extern uint16_t SOC; diff --git a/Software/NISSAN-LEAF-BATTERY.cpp b/Software/NISSAN-LEAF-BATTERY.cpp index 902f685d..1b61a00a 100644 --- a/Software/NISSAN-LEAF-BATTERY.cpp +++ b/Software/NISSAN-LEAF-BATTERY.cpp @@ -293,8 +293,7 @@ void update_values_leaf_battery() } /*Finally print out values to serial if configured to do so*/ - if(printValues) - { + #ifdef DEBUG_VIA_USB if(errorCode > 0) { Serial.print("ERROR CODE ACTIVE IN SYSTEM. NUMBER: "); @@ -350,7 +349,7 @@ void update_values_leaf_battery() Serial.print(Battery_current_1); Serial.print(" Current 2: "); Serial.println(Battery_current_2); - } + #endif } void receive_can_leaf_battery(CAN_frame_t rx_frame) diff --git a/Software/NISSAN-LEAF-BATTERY.h b/Software/NISSAN-LEAF-BATTERY.h index 79e54f63..e0cf0381 100644 --- a/Software/NISSAN-LEAF-BATTERY.h +++ b/Software/NISSAN-LEAF-BATTERY.h @@ -2,14 +2,10 @@ #define NISSAN_LEAF_BATTERY_H #include #include "ESP32CAN.h" +#include "USER_SETTINGS.h" -#define BATTERY_WH_MAX 30000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000 #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 MAXPERCENTAGE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached) -#define MINPERCENTAGE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached) -//#define INTERLOCK_REQUIRED //Uncomment this line to skip requiring both high voltage connectors to be seated on the LEAF battery -static byte printValues = 0; //Should modbus values be printed to serial output? // These parameters need to be mapped for the Gen24 extern uint16_t SOC; diff --git a/Software/PYLON-CAN.h b/Software/PYLON-CAN.h index 2260fec0..8e96de45 100644 --- a/Software/PYLON-CAN.h +++ b/Software/PYLON-CAN.h @@ -2,6 +2,7 @@ #define PYLON_CAN_H #include #include "ESP32CAN.h" +#include "USER_SETTINGS.h" extern uint16_t SOC; extern uint16_t StateOfHealth; diff --git a/Software/RENAULT-ZOE-BATTERY.cpp b/Software/RENAULT-ZOE-BATTERY.cpp index 07246e21..dfe953bb 100644 --- a/Software/RENAULT-ZOE-BATTERY.cpp +++ b/Software/RENAULT-ZOE-BATTERY.cpp @@ -33,7 +33,7 @@ void update_values_zoe_battery() StateOfHealth = (LB_SOH * 100); //Increase range from 99% -> 99.00% //Calculate the SOC% value to send to Fronius - LB_SOC = LB_MIN_SOC + (LB_MAX_SOC - LB_MIN_SOC) * (LB_SOC - MINPERCENTAGE_ZOE) / (MAXPERCENTAGE_ZOE - MINPERCENTAGE_ZOE); + LB_SOC = LB_MIN_SOC + (LB_MAX_SOC - LB_MIN_SOC) * (LB_SOC - MINPERCENTAGE) / (MAXPERCENTAGE - MINPERCENTAGE); if (LB_SOC < 0) { //We are in the real SOC% range of 0-20%, always set SOC sent to Fronius as 0% LB_SOC = 0; @@ -98,8 +98,7 @@ void update_values_zoe_battery() temperature_min; temperature_max; - if(printValues) - { //values heading towards the modbus registers + #ifdef DEBUG_VIA_USB Serial.print("BMS Status (3=OK): "); Serial.println(bms_status); Serial.print("Max discharge power: "); @@ -118,7 +117,7 @@ void update_values_zoe_battery() Serial.println(temperature_min); Serial.print("Temperature Max: "); Serial.println(temperature_max); - } + #endif } void receive_can_zoe_battery(CAN_frame_t rx_frame) diff --git a/Software/RENAULT-ZOE-BATTERY.h b/Software/RENAULT-ZOE-BATTERY.h index b743d231..483fb96d 100644 --- a/Software/RENAULT-ZOE-BATTERY.h +++ b/Software/RENAULT-ZOE-BATTERY.h @@ -2,13 +2,10 @@ #define RENAULT_ZOE_BATTERY_H #include #include "ESP32CAN.h" +#include "USER_SETTINGS.h" -#define BATTERY_WH_MAX 22000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger batteries but do set value over 60000 #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 MAXPERCENTAGE_ZOE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached) -#define MINPERCENTAGE_ZOE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached) -static byte printValues = 1; //Should modbus values be printed to serial output? // These parameters need to be mapped for the Gen24 extern uint16_t SOC; diff --git a/Software/SOLAX-CAN.cpp b/Software/SOLAX-CAN.cpp index 16581bf2..fee7c026 100644 --- a/Software/SOLAX-CAN.cpp +++ b/Software/SOLAX-CAN.cpp @@ -30,7 +30,7 @@ CAN_frame_t SOLAX_100A001 = {.FIR = {.B = {.DLC = 0,.FF = CAN_frame_ext,}},.MsgI void CAN_WriteFrame(CAN_frame_t* tx_frame) { -if(dual_can){ + #ifdef DUAL_CAN CANMessage MCP2515Frame; //Struct with ACAN2515 library format, needed to use the MCP2515 library MCP2515Frame.id = tx_frame->MsgID; MCP2515Frame.ext = tx_frame->FIR.B.FF; @@ -39,10 +39,9 @@ if(dual_can){ MCP2515Frame.data[i] = tx_frame->data.u8[i]; } can.tryToSend(MCP2515Frame); - } - else{ + #else ESP32Can.CANWriteFrame(tx_frame); - } + #endif } void update_values_can_solax() diff --git a/Software/SOLAX-CAN.h b/Software/SOLAX-CAN.h index 81e2dfa3..fd62123a 100644 --- a/Software/SOLAX-CAN.h +++ b/Software/SOLAX-CAN.h @@ -3,10 +3,10 @@ #include #include "ESP32CAN.h" #include "config.h" +#include "USER_SETTINGS.h" #include "ACAN2515.h" extern ACAN2515 can; -extern bool dual_can; extern uint16_t SOC; extern uint16_t StateOfHealth; diff --git a/Software/Software.ino b/Software/Software.ino index 9d065aff..f1daf3f2 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -1,28 +1,9 @@ -/* Select battery used */ -#define BATTERY_TYPE_LEAF // See NISSAN-LEAF-BATTERY.h for more LEAF battery settings -//#define TESLA_MODEL_3_BATTERY // See TESLA-MODEL-3-BATTERY.h for more Tesla battery settings -//#define RENAULT_ZOE_BATTERY // See RENAULT-ZOE-BATTERY.h for more Zoe battery settings -//#define BMW_I3_BATTERY // See BMW-I3-BATTERY.h for more i3 battery settings -//#define IMIEV_ION_CZERO_BATTERY // See IMIEV-CZERO-ION-BATTERY.h for more triplet battery settings -//#define KIA_HYUNDAI_64_BATTERY // See KIA-HYUNDAI-64-BATTERY.h for more battery settings -//#define CHADEMO // See CHADEMO.h for more Chademo related settings - -/* Select inverter communication protocol. See Wiki for which to use with your inverter: https://github.com/dalathegreat/BYD-Battery-Emulator-For-Gen24/wiki */ -#define MODBUS_BYD //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU -//#define CAN_BYD //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus -//#define SOLAX_CAN //Enable this line to emulate a "SolaX Triple Power LFP" over CAN bus -//#define PYLON_CAN //Enable this line to emulate a "Pylontech battery" over CAN bus - -/* Other options */ -#define CONTACTOR_CONTROL //Enable this line to have pins 25,32,33 handle precharge/contactor+/contactor- closing sequence -//#define PWM_CONTACTOR_CONTROL //Enable this line to use PWM logic for contactors, which lower power consumption and heat generation -//#define DUAL_CAN //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 controller (Needed for FoxESS inverters) - /* Do not change any code below this line unless you are sure what you are doing */ -/* Only change battery specific settings and limits in their respective .h files */ +/* Only change battery specific settings in "USER_SETTINGS.h" and limits in their respective .h files */ #include #include "HardwareSerial.h" +#include "USER_SETTINGS.h" #include "config.h" #include "Logging.h" #include "mbServerFCs.h" @@ -38,13 +19,10 @@ CAN_device_t CAN_cfg; // CAN Config const int rx_queue_size = 10; // Receive Queue size #ifdef DUAL_CAN - bool dual_can = 1; #include "ACAN2515.h" static const uint32_t QUARTZ_FREQUENCY = 8UL * 1000UL * 1000UL ; // 8 MHz ACAN2515 can(MCP2515_CS, SPI, MCP2515_INT); static ACAN2515_Buffer16 gBuffer; -#else - bool dual_can = 0; #endif //Interval settings diff --git a/Software/TESLA-MODEL-3-BATTERY.cpp b/Software/TESLA-MODEL-3-BATTERY.cpp index 277feb0a..c44b31c9 100644 --- a/Software/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/TESLA-MODEL-3-BATTERY.cpp @@ -3,17 +3,12 @@ #include "CAN_config.h" /* Do not change code below unless you are sure what you are doing */ -static unsigned long previousMillis10 = 0; // will store last time a 10ms CAN Message was send static unsigned long previousMillis30 = 0; // will store last time a 30ms CAN Message was send -static unsigned long previousMillis100 = 0; // will store last time a 100ms CAN Message was send -static const int interval10 = 10; // interval (ms) at which send CAN Messages static const int interval30 = 30; // interval (ms) at which send CAN Messages -static const int interval100 = 100; // interval (ms) at which send CAN Messages static uint8_t stillAliveCAN = 6; //counter for checking if CAN is still alive CAN_frame_t TESLA_221_1 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_std,}},.MsgID = 0x221,.data = {0x41, 0x11, 0x01, 0x00, 0x00, 0x00, 0x20, 0x96}}; CAN_frame_t TESLA_221_2 = {.FIR = {.B = {.DLC = 8,.FF = CAN_frame_std,}},.MsgID = 0x221,.data = {0x61, 0x15, 0x01, 0x00, 0x00, 0x00, 0x20, 0xBA}}; -static uint8_t alternate221 = 0; static uint32_t total_discharge = 0; static uint32_t total_charge = 0; @@ -89,23 +84,6 @@ void update_values_tesla_model_3_battery() max_target_discharge_power = max_discharge_current; max_target_charge_power = max_charge_current; - - #ifdef HVIL_OMITTED - //When HVIL is not available, battery will send 0W charge allowed. Luckily SOC% is still available, so we use this to estimate charge limits - if(SOC > 9900){ // 99% - max_target_charge_power = 0; - } - else{ - max_target_charge_power = 10000; - } - - if(SOC < 500){ // 5% - max_target_discharge_power = 0; - } - else{ - max_target_discharge_power = 10000; - } - #endif stat_batt_power = (volts * amps); //TODO, check if scaling is OK @@ -115,6 +93,8 @@ void update_values_tesla_model_3_battery() max_temp = (max_temp * 10); temperature_max = convert2unsignedint16(max_temp); + bms_status = ACTIVE; //Startout in active mode before checking if we have any faults + /* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/ if(!stillAliveCAN) { @@ -126,8 +106,7 @@ void update_values_tesla_model_3_battery() stillAliveCAN--; } - if(printValues) - { + #ifdef DEBUG_VIA_USB if (packCtrsClosingAllowed == 0) { Serial.println("Check high voltage connectors and interlock circuit! Closing contactor not allowed! Values: "); @@ -136,9 +115,6 @@ void update_values_tesla_model_3_battery() { Serial.println("Please wait for Pyro Connection check to finish, HV cables successfully seated!"); } - #ifdef HVIL_OMITTED - Serial.println("!!! High voltage interlock check skipped. Proceed with caution, limits estimated with no cell monitoring!!!"); - #endif Serial.print("Contactor: "); Serial.print(contactorText[contactor]); //Display what state the contactor is in @@ -207,7 +183,7 @@ void update_values_tesla_model_3_battery() Serial.print(temperature_max); Serial.print(" Min temperature (C): "); Serial.println(temperature_min); - } + #endif } void receive_can_tesla_model_3_battery(CAN_frame_t rx_frame) @@ -312,29 +288,13 @@ void receive_can_tesla_model_3_battery(CAN_frame_t rx_frame) void send_can_tesla_model_3_battery() { unsigned long currentMillis = millis(); - // Send 100ms CAN Message - if (currentMillis - previousMillis100 >= interval100) - { - previousMillis100 = currentMillis; - - //ESP32Can.CANWriteFrame(&message100); - - } //Send 30ms message if (currentMillis - previousMillis30 >= interval30) { previousMillis30 = currentMillis; - + if(bms_status != FAULT){ ESP32Can.CANWriteFrame(&TESLA_221_1); - ESP32Can.CANWriteFrame(&TESLA_221_2); - - } - //Send 10ms message - if (currentMillis - previousMillis10 >= interval10) - { - previousMillis10 = currentMillis; - - //ESP32Can.CANWriteFrame(&message10); + } } } diff --git a/Software/TESLA-MODEL-3-BATTERY.h b/Software/TESLA-MODEL-3-BATTERY.h index 08b1034e..754ceea7 100644 --- a/Software/TESLA-MODEL-3-BATTERY.h +++ b/Software/TESLA-MODEL-3-BATTERY.h @@ -2,19 +2,12 @@ #define TESLA_MODEL_3_BATTERY_H #include #include "ESP32CAN.h" +#include "USER_SETTINGS.h" -/* User definable settings for the Tesla Model 3 battery */ -//#define HVIL_OMITTED //Uncomment this line to allow battery to function without HVIL condition fulfilled. NOTE: Some values not available in this mode, see wiki -// NOTE: Omitting this has consequences, battery cannot request a stop incase a cell over/undercharges!!! So try to fix HVIL as soon as possible - -#define BATTERY_WH_MAX 60000 //Battery size in Wh (Maximum value Fronius accepts is 60000 [60kWh] you can use larger 65/75/90 batteries but do set value over 60000! #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 MAXPERCENTAGE 950 //95.0% , Max percentage the battery will charge to (App will show 100% once this value is reached) -#define MINPERCENTAGE 150 //15.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached) -static byte printValues = 1; //Should modbus values be printed to serial output? -// These parameters need to be mapped for the Gen24 +// These parameters need to be mapped for the Inverter extern uint16_t SOC; extern uint16_t StateOfHealth; extern uint16_t battery_voltage; diff --git a/Software/USER_SETTINGS.h b/Software/USER_SETTINGS.h new file mode 100644 index 00000000..f588f134 --- /dev/null +++ b/Software/USER_SETTINGS.h @@ -0,0 +1,35 @@ +#ifndef __USER_SETTINGS_H__ +#define __USER_SETTINGS_H__ + +/* This file contains all the user configurable settings for the Battery-Emulator software */ +/* To switch between batteries/inverters, uncomment a line to enable, comment out to disable. */ +/* There are also some options for battery limits and extra functionality */ + +/* Select battery used */ +#define BATTERY_TYPE_LEAF +//#define TESLA_MODEL_3_BATTERY +//#define RENAULT_ZOE_BATTERY +//#define BMW_I3_BATTERY +//#define IMIEV_ION_CZERO_BATTERY +//#define KIA_HYUNDAI_64_BATTERY +//#define CHADEMO + +/* Select inverter communication protocol. See Wiki for which to use with your inverter: https://github.com/dalathegreat/BYD-Battery-Emulator-For-Gen24/wiki */ +#define MODBUS_BYD //Enable this line to emulate a "BYD 11kWh HVM battery" over Modbus RTU +//#define CAN_BYD //Enable this line to emulate a "BYD Battery-Box Premium HVS" over CAN Bus +//#define SOLAX_CAN //Enable this line to emulate a "SolaX Triple Power LFP" over CAN bus +//#define PYLON_CAN //Enable this line to emulate a "Pylontech battery" over CAN bus + +/* Battery settings */ +#define BATTERY_WH_MAX 30000 //Battery size in Wh (Maximum value for most inverters is 60000 [60kWh], you can use larger batteries but do set value over 60000! +#define MAXPERCENTAGE 800 //80.0% , Max percentage the battery will charge to (App will show 100% once this value is reached) +#define MINPERCENTAGE 200 //20.0% , Min percentage the battery will discharge to (App will show 0% once this value is reached) +//define INTERLOCK_REQUIRED //Nissan LEAF specific setting, if enabled requires both high voltage conenctors to be seated before starting + +/* Other options */ +#define DEBUG_VIA_USB //Enable this line to have the USB port output serial diagnostic data while program runs +//#define CONTACTOR_CONTROL //Enable this line to have pins 25,32,33 handle automatic precharge/contactor+/contactor- closing sequence +//#define PWM_CONTACTOR_CONTROL //Enable this line to use PWM logic for contactors, which lower power consumption and heat generation +//#define DUAL_CAN //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 controller (Needed for FoxESS inverters) + +#endif \ No newline at end of file diff --git a/Software/config.h b/Software/config.h index cefc9baf..75a1a8d4 100644 --- a/Software/config.h +++ b/Software/config.h @@ -1,13 +1,17 @@ #ifndef __CONFIG_H__ #define __CONFIG_H__ -// PIN +// PIN mappings, do not change these unless you are adding on extra hardware to the PCB #define PIN_5V_EN 16 - #define CAN_TX_PIN 27 #define CAN_RX_PIN 26 #define CAN_SE_PIN 23 +#define RS485_EN_PIN 17 // 17 /RE +#define RS485_TX_PIN 22 // 21 +#define RS485_RX_PIN 21 // 22 +#define RS485_SE_PIN 19 // 22 /SHDN + #ifdef DUAL_CAN #define MCP2515_SCK 12 // SCK input of MCP2515 #define MCP2515_MOSI 5 // SDI input of MCP2515 @@ -16,11 +20,6 @@ #define MCP2515_INT 35 // INT output of MCP2515 | | Pin 35 is input only, without pullup/down resistors #endif -#define RS485_EN_PIN 17 // 17 /RE -#define RS485_TX_PIN 22 // 21 -#define RS485_RX_PIN 21 // 22 -#define RS485_SE_PIN 19 // 22 /SHDN - #ifdef CONTACTOR_CONTROL #define POSITIVE_CONTACTOR_PIN 32 #define NEGATIVE_CONTACTOR_PIN 33 @@ -31,7 +30,6 @@ #define SD_MOSI_PIN 15 #define SD_SCLK_PIN 14 #define SD_CS_PIN 13 - #define WS2812_PIN 4 #endif \ No newline at end of file