Skip to content

Commit

Permalink
Communication Speed improvement (#63)
Browse files Browse the repository at this point in the history
* Baud rate changes

* Update DIYBMSServer.cpp

* Update default.htm

* Update platformio.ini
  • Loading branch information
stuartpittaway authored Nov 9, 2021
1 parent 019382f commit 61a7bf6
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 7 deletions.
25 changes: 24 additions & 1 deletion ATTINYCellModule/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions ESPController/include/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
26 changes: 26 additions & 0 deletions ESPController/src/DIYBMSServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
{
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions ESPController/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,6 @@ void SetupOTA()
ArduinoOTA.begin();
}



void onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info)
{

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down
11 changes: 8 additions & 3 deletions ESPController/web_src/default.htm
Original file line number Diff line number Diff line change
Expand Up @@ -1005,10 +1005,9 @@ <h1>Controller Settings</h1>
<div class="region">
<h2 id="mb1">Modules &amp; Banks</h2>
<p id="mb2">DIYBMS supports up to <span id='labelMaxModules'>X</span> modules in total. These modules can be
split into banks to support
parallel
configurations.</p>
split into banks to support parallel configurations.</p>
<p id="mb3">Example: You have 16 cells configured as 8 in series and 2 in parallel (8S2P).</p>
<p id="mb4">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.</p>
<form id="banksForm" method="POST" action="savebankconfig.json" autocomplete="off">
<div class="settings">
<div>
Expand All @@ -1021,6 +1020,12 @@ <h2 id="mb1">Modules &amp; Banks</h2>
<select name="totalBanks" id="totalBanks">
</select>
</div>
<div>
<label for="baudrate">Communication speed</label>
<select name="baudrate" id="baudrate">
</select>
</div>

<button type="submit">Save module &amp; bank settings</button>
</div>
</form>
Expand Down
12 changes: 12 additions & 0 deletions ESPController/web_src/pagecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<option>' + n + '</option>')
}
Expand Down Expand Up @@ -1061,6 +1062,17 @@ $(function () {
$("#totalSeriesModules").val(data.settings.totalseriesmodules);
$("#totalBanks").val(data.settings.totalnumberofbanks);

$("#baudrate").empty();
$("#baudrate").append('<option value="2400">Standard</option>')

if (data.settings.supportSpeedChange) {
$("#baudrate").append('<option value="5000">5K</option>')
$("#baudrate").append('<option value="9600">9K6</option>')
}

$("#baudrate").val(data.settings.baudrate);


$("#banksForm").show();
}).fail(function () { }
);
Expand Down

0 comments on commit 61a7bf6

Please sign in to comment.