Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/byd can amp #81

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Software/USER_SETTINGS.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
//#define SOLAX_CAN //Enable this line to emulate a "SolaX Triple Power LFP" 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 BATTERY_WH_MAX 30000 //Battery size in Wh (Maximum value for most inverters is 60000 [60kWh], you can use larger batteries but do not 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 MAXCHARGEAMP 300 //30.0A , BYD CAN specific setting, Max charge speed in Amp (Some inverters needs to be artificially limited)
#define MAXDISCHARGEAMP 300 //30.0A , BYD CAN specific setting, Max discharge speed in Amp (Some inverters needs to be artificially limited)
//define INTERLOCK_REQUIRED //Nissan LEAF specific setting, if enabled requires both high voltage conenctors to be seated before starting

/* Other options */
Expand Down
60 changes: 32 additions & 28 deletions Software/src/inverter/BYD-CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ void update_values_can_byd()
charge_current = ((max_target_charge_power*10)/max_volt_byd_can); //Charge power in W , max volt in V+1decimal (P=UI, solve for I)
//The above calculation results in (30 000*10)/3700=81A
charge_current = (charge_current*10); //Value needs a decimal before getting sent to inverter (81.0A)
if(charge_current > MAXCHARGEAMP)
{
charge_current = MAXCHARGEAMP; //Cap the value to the max allowed Amp. Some inverters cannot handle large values.
}

discharge_current = ((max_target_discharge_power*10)/max_volt_byd_can); //Charge power in W , max volt in V+1decimal (P=UI, solve for I)
//The above calculation results in (30 000*10)/3700=81A
discharge_current = (discharge_current*10); //Value needs a decimal before getting sent to inverter (81.0A)
if(discharge_current > MAXDISCHARGEAMP)
{
discharge_current = MAXDISCHARGEAMP; //Cap the value to the max allowed Amp. Some inverters cannot handle large values.
}

temperature_average = ((temperature_max + temperature_min)/2);


//Map values to CAN messages
//Maxvoltage (eg 400.0V = 4000 , 16bits long)
BYD_110.data.u8[0] = (max_volt_byd_can >> 8);
Expand Down Expand Up @@ -127,33 +134,30 @@ void send_can_byd()
initialDataSent = 1;
}

if(bms_status != FAULT)
{ // Send CAN messages towards inverter if battery is OK
// Send 2s CAN Message
if (currentMillis - previousMillis2s >= interval2s)
{
previousMillis2s = currentMillis;

ESP32Can.CANWriteFrame(&BYD_110);
}
// Send 10s CAN Message
if (currentMillis - previousMillis10s >= interval10s)
{
previousMillis10s = currentMillis;

ESP32Can.CANWriteFrame(&BYD_150);
ESP32Can.CANWriteFrame(&BYD_1D0);
ESP32Can.CANWriteFrame(&BYD_210);
//Serial.println("CAN 10s done");
}
//Send 60s message
if (currentMillis - previousMillis60s >= interval60s)
{
previousMillis60s = currentMillis;

ESP32Can.CANWriteFrame(&BYD_190);
//Serial.println("CAN 60s done");
}
// Send 2s CAN Message
if (currentMillis - previousMillis2s >= interval2s)
{
previousMillis2s = currentMillis;

ESP32Can.CANWriteFrame(&BYD_110);
}
// Send 10s CAN Message
if (currentMillis - previousMillis10s >= interval10s)
{
previousMillis10s = currentMillis;

ESP32Can.CANWriteFrame(&BYD_150);
ESP32Can.CANWriteFrame(&BYD_1D0);
ESP32Can.CANWriteFrame(&BYD_210);
//Serial.println("CAN 10s done");
}
//Send 60s message
if (currentMillis - previousMillis60s >= interval60s)
{
previousMillis60s = currentMillis;

ESP32Can.CANWriteFrame(&BYD_190);
//Serial.println("CAN 60s done");
}
}

Expand Down