From 61a7bf6e3491319b62e9f097b6fe805dae014f40 Mon Sep 17 00:00:00 2001 From: Stuart Pittaway <1201909+stuartpittaway@users.noreply.github.com> Date: Tue, 9 Nov 2021 17:38:50 +0000 Subject: [PATCH] Communication Speed improvement (#63) * Baud rate changes * Update DIYBMSServer.cpp * Update default.htm * Update platformio.ini --- ATTINYCellModule/platformio.ini | 25 ++++++++++++++++++++++++- ESPController/include/defines.h | 1 + ESPController/src/DIYBMSServer.cpp | 26 ++++++++++++++++++++++++++ ESPController/src/main.cpp | 6 +++--- ESPController/web_src/default.htm | 11 ++++++++--- ESPController/web_src/pagecode.js | 12 ++++++++++++ 6 files changed, 74 insertions(+), 7 deletions(-) diff --git a/ATTINYCellModule/platformio.ini b/ATTINYCellModule/platformio.ini index dde82956..519cd1d4 100644 --- a/ATTINYCellModule/platformio.ini +++ b/ATTINYCellModule/platformio.ini @@ -28,7 +28,7 @@ ; [Blue LED removed, resetable fuse fitted] ;** DO NOT FLASH V430 TO AN OLDER BOARD - THE ATTINY WILL BECOME UNUSABLE ** [platformio] -default_envs = V400, V410, V420, V420_SWAPR19R20, V421, V421_LTO, V440 +default_envs = V400, V410, V420, V420_SWAPR19R20, V421, V421_LTO, V440, V440_COMMS_5K, V440_COMMS_9K6 description=DIYBMS Cell monitoring module code [env] @@ -112,3 +112,26 @@ upload_flags = -Ulfuse:w:0b01101100:m -Uhfuse:w:0b11010110:m -Uefuse:w:0b11110100:m + + +[env:V440_COMMS_5K] +build_flags=-DDIYBMSMODULEVERSION=440 -DMV_PER_ADC=2.00 -DINT_BCOEFFICIENT=3950 -DEXT_BCOEFFICIENT=3950 -DLOAD_RESISTANCE=3.30 -DBAUD=5000 -DSAMPLEAVERAGING=5 +board_fuses.lfuse = 0b01101100 +board_fuses.hfuse = 0b11010110 +board_fuses.efuse = 0b11110100 +upload_flags = + -Pusb + -Ulfuse:w:0b01101100:m + -Uhfuse:w:0b11010110:m + -Uefuse:w:0b11110100:m + +[env:V440_COMMS_9K6] +build_flags=-DDIYBMSMODULEVERSION=440 -DMV_PER_ADC=2.00 -DINT_BCOEFFICIENT=3950 -DEXT_BCOEFFICIENT=3950 -DLOAD_RESISTANCE=3.30 -DBAUD=9600 -DSAMPLEAVERAGING=5 +board_fuses.lfuse = 0b01101100 +board_fuses.hfuse = 0b11010110 +board_fuses.efuse = 0b11110100 +upload_flags = + -Pusb + -Ulfuse:w:0b01101100:m + -Uhfuse:w:0b11010110:m + -Uefuse:w:0b11110100:m diff --git a/ESPController/include/defines.h b/ESPController/include/defines.h index 39ea1301..faa91fab 100644 --- a/ESPController/include/defines.h +++ b/ESPController/include/defines.h @@ -96,6 +96,7 @@ struct diybms_eeprom_settings { uint8_t totalNumberOfBanks; uint8_t totalNumberOfSeriesModules; + uint16_t baudRate; uint32_t rulevalue[RELAY_RULES]; uint32_t rulehysteresis[RELAY_RULES]; diff --git a/ESPController/src/DIYBMSServer.cpp b/ESPController/src/DIYBMSServer.cpp index c8ef5109..79cc8a07 100644 --- a/ESPController/src/DIYBMSServer.cpp +++ b/ESPController/src/DIYBMSServer.cpp @@ -190,6 +190,7 @@ void DIYBMSServer::saveConfigurationToSDCard(AsyncWebServerRequest *request) root["totalNumberOfBanks"] = _mysettings->totalNumberOfBanks; root["totalNumberOfSeriesModules"] = _mysettings->totalNumberOfSeriesModules; + root["baudRate"] = _mysettings->baudRate; root["graph_voltagehigh"] = _mysettings->graph_voltagehigh; root["graph_voltagelow"] = _mysettings->graph_voltagelow; @@ -1128,6 +1129,7 @@ void DIYBMSServer::saveBankConfiguration(AsyncWebServerRequest *request) uint8_t totalSeriesModules = 1; uint8_t totalBanks = 1; + uint16_t baudrate = COMMS_BAUD_RATE; if (request->hasParam("totalSeriesModules", true)) { @@ -1141,10 +1143,17 @@ void DIYBMSServer::saveBankConfiguration(AsyncWebServerRequest *request) totalBanks = p1->value().toInt(); } + if (request->hasParam("baudrate", true)) + { + AsyncWebParameter *p1 = request->getParam("baudrate", true); + baudrate = p1->value().toInt(); + } + if (totalSeriesModules * totalBanks <= maximum_controller_cell_modules) { _mysettings->totalNumberOfSeriesModules = totalSeriesModules; _mysettings->totalNumberOfBanks = totalBanks; + _mysettings->baudRate = baudrate; saveConfiguration(); SendSuccess(request); @@ -1427,6 +1436,23 @@ void DIYBMSServer::settings(AsyncWebServerRequest *request) settings["totalnumberofbanks"] = _mysettings->totalNumberOfBanks; settings["totalseriesmodules"] = _mysettings->totalNumberOfSeriesModules; + settings["baudrate"] = _mysettings->baudRate; + + uint8_t numberOfV440OrNewer = 0; + uint8_t totalModules = _mysettings->totalNumberOfBanks * _mysettings->totalNumberOfSeriesModules; + for (uint8_t i = 0; i < totalModules; i++) + { + if (cmi[i].valid) + { + //Count of v440 or newer modules + if (cmi[i].BoardVersionNumber >= 440) + { + numberOfV440OrNewer++; + } + } + } + //Only true if all modules have communicated and are all v440 or newer + settings["supportSpeedChange"] = numberOfV440OrNewer == totalModules; settings["bypassthreshold"] = _mysettings->BypassThresholdmV; settings["bypassovertemp"] = _mysettings->BypassOverTempShutdown; diff --git a/ESPController/src/main.cpp b/ESPController/src/main.cpp index 2ef0c79f..c46daf50 100644 --- a/ESPController/src/main.cpp +++ b/ESPController/src/main.cpp @@ -1503,8 +1503,6 @@ void SetupOTA() ArduinoOTA.begin(); } - - void onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info) { @@ -2775,6 +2773,8 @@ void LoadConfiguration() //Default to a single module mysettings.totalNumberOfBanks = 1; mysettings.totalNumberOfSeriesModules = 1; + //Default serial port speed + mysettings.baudRate = COMMS_BAUD_RATE; mysettings.BypassOverTempShutdown = 65; //4.10V bypass mysettings.BypassThresholdmV = 4100; @@ -3352,7 +3352,7 @@ void setup() ESP_LOGI("Config loaded"); //Receive is IO2 which means the RX1 plug must be disconnected for programming to work! - SERIAL_DATA.begin(COMMS_BAUD_RATE, SERIAL_8N1, 2, 32); // Serial for comms to modules + SERIAL_DATA.begin(mysettings.baudRate, SERIAL_8N1, 2, 32); // Serial for comms to modules myPacketSerial.begin(&SERIAL_DATA, &onPacketReceived, sizeof(PacketStruct), SerialPacketReceiveBuffer, sizeof(SerialPacketReceiveBuffer)); diff --git a/ESPController/web_src/default.htm b/ESPController/web_src/default.htm index 33918a78..bbe59dda 100644 --- a/ESPController/web_src/default.htm +++ b/ESPController/web_src/default.htm @@ -1005,10 +1005,9 @@

Controller Settings

Modules & Banks

DIYBMS supports up to X modules in total. These modules can be - split into banks to support - parallel - configurations.

+ split into banks to support parallel configurations.

Example: You have 16 cells configured as 8 in series and 2 in parallel (8S2P).

+

Only hardware module version 4.4 or newer support faster communication speeds. You will need to reboot the controller manually if you change the speed.

@@ -1021,6 +1020,12 @@

Modules & Banks

+
+ + +
+
diff --git a/ESPController/web_src/pagecode.js b/ESPController/web_src/pagecode.js index de48d7b9..87514bce 100644 --- a/ESPController/web_src/pagecode.js +++ b/ESPController/web_src/pagecode.js @@ -946,6 +946,7 @@ $(function () { $("#labelMaxModules").text(MAXIMUM_NUMBER_OF_SERIES_MODULES); + for (var n = 1; n <= MAXIMUM_NUMBER_OF_SERIES_MODULES; n++) { $("#totalSeriesModules").append('') } @@ -1061,6 +1062,17 @@ $(function () { $("#totalSeriesModules").val(data.settings.totalseriesmodules); $("#totalBanks").val(data.settings.totalnumberofbanks); + $("#baudrate").empty(); + $("#baudrate").append('') + + if (data.settings.supportSpeedChange) { + $("#baudrate").append('') + $("#baudrate").append('') + } + + $("#baudrate").val(data.settings.baudrate); + + $("#banksForm").show(); }).fail(function () { } );