Skip to content

Commit

Permalink
Merge pull request #176 from stuartpittaway/post-valentines-fixes
Browse files Browse the repository at this point in the history
Additional changes for #175 - Victron don't use zero volt for CVL
  • Loading branch information
stuartpittaway authored Feb 21, 2023
2 parents 5202c6b + b4601d4 commit 7780f30
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
10 changes: 5 additions & 5 deletions ESPController/include/Rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Rules
// Number of TRUE values in array rule_outcome
uint8_t active_rule_count;

// Actual bank voltage reported by the modules (sum of voltage reported by modules)
// Actual bank voltage reported by the modules (sum of voltage reported by modules) (millivolts)
uint32_t bankvoltage[maximum_number_of_banks];
// As above, but each voltage reading limited to "cellmaxmv" setting (used for charge voltage calc)
uint32_t limitedbankvoltage[maximum_number_of_banks];
Expand All @@ -83,14 +83,14 @@ class Rules
// Number of modules who have reported zero volts (bad!)
uint8_t zeroVoltageModuleCount;

// Highest pack voltage
// Highest pack voltage (millivolts)
uint32_t highestBankVoltage;
// Lowest pack voltage
// Lowest pack voltage (millivolts)
uint32_t lowestBankVoltage;

// Highest cell voltage in the whole system
// Highest cell voltage in the whole system (millivolts)
uint16_t highestCellVoltage;
// Lowest cell voltage in the whole system
// Lowest cell voltage in the whole system (millivolts)
uint16_t lowestCellVoltage;

// Highest cell voltage range (mV) across all banks
Expand Down
1 change: 1 addition & 0 deletions ESPController/include/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ struct diybms_eeprom_settings
// Maximum charge current - scale 0.1
uint16_t chargecurrent;
uint16_t dischargecurrent;
// Scale 0.1
uint16_t dischargevolt;
int16_t cellminmv;
int16_t cellmaxmv;
Expand Down
30 changes: 17 additions & 13 deletions ESPController/src/victron_canbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
)(_) )_)(_ \ / ) _ < ) ( \__ \
(____/(____) (__) (____/(_/\/\_)(___/
(c) 2021 Stuart Pittaway
(c) 2021-2023 Stuart Pittaway
This code communicates with VICTRON CERBO GX style devices using CANBUS @ 500kbps and 11 bit addresses.
The code supports the VICTRON CAN BUS BMS style messages.
*/

#define USE_ESP_IDF_LOG 1
Expand Down Expand Up @@ -127,29 +126,31 @@ void victron_message_351()

struct data351
{
// CVL
// CVL - 0.1V scale
uint16_t chargevoltagelimit;
// CCL
// CCL - 0.1A scale
int16_t maxchargecurrent;
// DCL
// DCL - 0.1A scale
int16_t maxdischargecurrent;
// Not currently used by Victron
// 0.1V scale
uint16_t dischargevoltage;
};

data351 data;


// Defaults (do nothing)
data.chargevoltagelimit = 0;
// Defaults (do nothing)
// Don't use zero for voltage - this indicates to Victron an over voltage situation, and Victron gear attempts to dump
// the whole battery contents! (feedback from end users)
data.chargevoltagelimit = rules.lowestBankVoltage / 100;
data.maxchargecurrent = 0;

if (rules.IsChargeAllowed(&mysettings))
{
if (rules.numberOfBalancingModules > 0 && mysettings.stopchargebalance == true)
{
// Balancing, stop charge, allow discharge
data.chargevoltagelimit = 0;
// Balancing, stop charge
data.chargevoltagelimit = rules.lowestBankVoltage / 100;
data.maxchargecurrent = 0;
}
else
Expand All @@ -160,6 +161,7 @@ void victron_message_351()
}
}

// Discharge settings....
data.maxdischargecurrent = 0;
data.dischargevoltage = mysettings.dischargevolt;

Expand Down Expand Up @@ -206,6 +208,7 @@ void victron_message_356()
data356 data;

// Use highest bank voltage calculated by controller and modules
// Scale 0.01V
data.voltage = rules.highestBankVoltage / 10;

// If current shunt is installed, use the voltage from that as it should be more accurate
Expand All @@ -218,10 +221,11 @@ void victron_message_356()
// If current shunt is installed, use it
if (mysettings.currentMonitoringEnabled && currentMonitor.validReadings)
{
// Scale 0.1A
data.current = currentMonitor.modbus.current * 10;
}

// Temperature 0.1 C using external temperature sensor
// Temperature 0.1C using external temperature sensor
if (rules.moduleHasExternalTempSensor)
{
data.temperature = (int16_t)rules.highestExternalTemp * (int16_t)10;
Expand Down Expand Up @@ -361,8 +365,8 @@ void victron_message_35a()
// ESP_LOGI(TAG, "numberOfBalancingModules=%u", rules.numberOfBalancingModules);

// 7 (bit 0+1) Cell imbalance warning
//data.byte7 |= (rules.numberOfBalancingModules > 0 ? BIT01_ALARM : BIT01_OK);
// data.byte7 |= (rules.numberOfBalancingModules > 0 ? BIT01_ALARM : BIT01_OK);

// 7 (bit 2+3) System status (online/offline) [1]
data.byte7 |= ((_controller_state != ControllerState::Running) ? BIT23_ALARM : BIT23_OK);
// 7 (rest) Reserved
Expand Down

0 comments on commit 7780f30

Please sign in to comment.