diff --git a/Software/src/battery/TESLA-BATTERY.cpp b/Software/src/battery/TESLA-BATTERY.cpp
index 8644405b..70dbbdb2 100644
--- a/Software/src/battery/TESLA-BATTERY.cpp
+++ b/Software/src/battery/TESLA-BATTERY.cpp
@@ -901,6 +901,15 @@ void update_values_battery() { //This function maps all the values fetched via
datalayer.battery.info.min_cell_voltage_mV = MIN_CELL_VOLTAGE_NCA_NCM;
datalayer.battery.info.max_cell_voltage_deviation_mV = MAX_CELL_DEVIATION_NCA_NCM;
}
+
+ // During forced balancing request via webserver, we allow the battery to exceed normal safety parameters
+ if (datalayer.battery.settings.user_requests_balancing) {
+ datalayer.battery.info.max_design_voltage_dV = datalayer.battery.settings.balancing_max_pack_voltage_dV;
+ datalayer.battery.info.max_cell_voltage_mV = datalayer.battery.settings.balancing_max_cell_voltage_mV;
+ datalayer.battery.info.max_cell_voltage_deviation_mV =
+ datalayer.battery.settings.balancing_max_deviation_cell_voltage_mV;
+ datalayer.battery.status.max_charge_power_W = datalayer.battery.settings.balancing_float_power_W;
+ }
#endif // TESLA_MODEL_3Y_BATTERY
// Update webserver datalayer
diff --git a/Software/src/battery/TESLA-BATTERY.h b/Software/src/battery/TESLA-BATTERY.h
index 817ca1f6..4a843838 100644
--- a/Software/src/battery/TESLA-BATTERY.h
+++ b/Software/src/battery/TESLA-BATTERY.h
@@ -10,10 +10,11 @@
#define MAXDISCHARGEPOWERALLOWED 60000 // 60000W we use a define since the value supplied by Tesla is always 0
/* Do not change the defines below */
-#define RAMPDOWN_SOC 900 // 90.0 SOC% to start ramping down from max charge power towards 0 at 100.00%
-#define RAMPDOWNPOWERALLOWED 15000 // What power we ramp down from towards top balancing
-#define FLOAT_MAX_POWER_W 200 // W, what power to allow for top balancing battery
-#define FLOAT_START_MV 20 // mV, how many mV under overvoltage to start float charging
+#define RAMPDOWN_SOC 900 // 90.0 SOC% to start ramping down from max charge power towards 0 at 100.00%
+#define RAMPDOWNPOWERALLOWED \
+ 15000 // What power we ramp down from towards top balancing (usually same as MAXCHARGEPOWERALLOWED)
+#define FLOAT_MAX_POWER_W 200 // W, what power to allow for top balancing battery
+#define FLOAT_START_MV 20 // mV, how many mV under overvoltage to start float charging
#define MAX_PACK_VOLTAGE_SX_NCMA 4600 // V+1, if pack voltage goes over this, charge stops
#define MIN_PACK_VOLTAGE_SX_NCMA 3100 // V+1, if pack voltage goes over this, charge stops
diff --git a/Software/src/datalayer/datalayer.h b/Software/src/datalayer/datalayer.h
index 6064aa15..9a484a7a 100644
--- a/Software/src/datalayer/datalayer.h
+++ b/Software/src/datalayer/datalayer.h
@@ -121,6 +121,21 @@ typedef struct {
/** The user specified maximum allowed discharge voltage, in deciVolt. 3000 = 300.0 V */
uint16_t max_user_set_discharge_voltage_dV = BATTERY_MAX_DISCHARGE_VOLTAGE;
+ /** Tesla specific settings that are edited on the fly when manually forcing a balance charge for LFP chemistry */
+ /* Bool for specifying if user has requested manual balancing */
+ bool user_requests_balancing = false;
+ /* Forced balancing max time & start timestamp */
+ uint32_t balancing_time_ms = 3600000; //1h default, (60min*60sec*1000ms)
+ uint32_t balancing_start_time_ms = 0; //For keeping track when balancing started
+ /* Max cell voltage during forced balancing */
+ uint16_t balancing_max_cell_voltage_mV = 3650;
+ /* Max cell deviation allowed during forced balancing */
+ uint16_t balancing_max_deviation_cell_voltage_mV = 400;
+ /* Float max power during forced balancing */
+ uint16_t balancing_float_power_W = 1000;
+ /* Maximum voltage for entire battery pack during forced balancing */
+ uint16_t balancing_max_pack_voltage_dV = 3940;
+
} DATALAYER_BATTERY_SETTINGS_TYPE;
typedef struct {
diff --git a/Software/src/devboard/safety/safety.cpp b/Software/src/devboard/safety/safety.cpp
index f662adfe..35d28579 100644
--- a/Software/src/devboard/safety/safety.cpp
+++ b/Software/src/devboard/safety/safety.cpp
@@ -238,6 +238,22 @@ void update_machineryprotection() {
if (datalayer.battery.status.max_charge_power_W == 0) {
datalayer.battery.status.max_charge_current_dA = 0;
}
+
+ //Decrement the forced balancing timer incase user requested it
+ if (datalayer.battery.settings.user_requests_balancing) {
+ // If this is the start of the balancing period, capture the current time
+ if (datalayer.battery.settings.balancing_start_time_ms == 0) {
+ datalayer.battery.settings.balancing_start_time_ms = millis();
+ //TODO, raise info event? Forced balancing starting!
+ }
+
+ // Check if the elapsed time exceeds the balancing time
+ if (millis() - datalayer.battery.settings.balancing_start_time_ms >= datalayer.battery.settings.balancing_time_ms) {
+ datalayer.battery.settings.user_requests_balancing = false;
+ datalayer.battery.settings.balancing_start_time_ms = 0; // Reset the start time
+ //TODO, raise info event? Balancing time elapsed. Turning off...
+ }
+ }
}
//battery pause status begin
diff --git a/Software/src/devboard/webserver/settings_html.cpp b/Software/src/devboard/webserver/settings_html.cpp
index e21ec722..a576ef38 100644
--- a/Software/src/devboard/webserver/settings_html.cpp
+++ b/Software/src/devboard/webserver/settings_html.cpp
@@ -97,6 +97,42 @@ String settings_processor(const String& var) {
content += "";
#endif
+#ifdef TESLA_MODEL_3Y_BATTERY
+
+ // Start a new block with grey background color
+ content += "