mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 10:49:42 +02:00
Rewrite max/min voltage to save memory
This commit is contained in:
parent
37c07c5c1b
commit
8c88352c5f
14 changed files with 49 additions and 61 deletions
|
@ -110,8 +110,8 @@ static long inverter_timestamp = 0;
|
|||
|
||||
void update_values_can_byd() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
//Calculate values
|
||||
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)
|
||||
charge_current =
|
||||
((max_target_charge_power * 10) / max_voltage); //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) {
|
||||
|
@ -119,7 +119,7 @@ void update_values_can_byd() { //This function maps all the values fetched from
|
|||
}
|
||||
|
||||
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)
|
||||
max_voltage); //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) {
|
||||
|
@ -131,11 +131,11 @@ void update_values_can_byd() { //This function maps all the values fetched from
|
|||
|
||||
//Map values to CAN messages
|
||||
//Maxvoltage (eg 400.0V = 4000 , 16bits long)
|
||||
BYD_110.data.u8[0] = (max_volt_byd_can >> 8);
|
||||
BYD_110.data.u8[1] = (max_volt_byd_can & 0x00FF);
|
||||
BYD_110.data.u8[0] = (max_voltage >> 8);
|
||||
BYD_110.data.u8[1] = (max_voltage & 0x00FF);
|
||||
//Minvoltage (eg 300.0V = 3000 , 16bits long)
|
||||
BYD_110.data.u8[2] = (min_volt_byd_can >> 8);
|
||||
BYD_110.data.u8[3] = (min_volt_byd_can & 0x00FF);
|
||||
BYD_110.data.u8[2] = (min_voltage >> 8);
|
||||
BYD_110.data.u8[3] = (min_voltage & 0x00FF);
|
||||
//Maximum discharge power allowed (Unit: A+1)
|
||||
BYD_110.data.u8[4] = (discharge_current >> 8);
|
||||
BYD_110.data.u8[5] = (discharge_current & 0x00FF);
|
||||
|
|
|
@ -18,8 +18,8 @@ extern uint16_t stat_batt_power;
|
|||
extern uint16_t temperature_min;
|
||||
extern uint16_t temperature_max;
|
||||
extern uint16_t CANerror;
|
||||
extern uint16_t min_volt_byd_can;
|
||||
extern uint16_t max_volt_byd_can;
|
||||
extern uint16_t min_voltage;
|
||||
extern uint16_t max_voltage;
|
||||
// Definitions for BMS status
|
||||
#define STANDBY 0
|
||||
#define INACTIVE 1
|
||||
|
|
|
@ -37,9 +37,9 @@ void handle_update_data_modbusp201_byd() {
|
|||
system_data[4] =
|
||||
(max_power); // Id.: p205 Value.: 14500 Scaled value.: 30,42kW Comment.: Max Charge/Discharge Power=10.24kW (lowest value of 204 and 205 will be enforced by Gen24)
|
||||
system_data[5] =
|
||||
(max_volt_modbus_byd); // Id.: p206 Value.: 3667 Scaled value.: 362,7VDC Comment.: Max Voltage, if higher charging is not possible (goes into forced discharge)
|
||||
(max_voltage); // Id.: p206 Value.: 3667 Scaled value.: 362,7VDC Comment.: Max Voltage, if higher charging is not possible (goes into forced discharge)
|
||||
system_data[6] =
|
||||
(min_volt_modbus_byd); // Id.: p207 Value.: 2776 Scaled value.: 277,6VDC Comment.: Min Voltage, if lower Gen24 disables battery
|
||||
(min_voltage); // Id.: p207 Value.: 2776 Scaled value.: 277,6VDC Comment.: Min Voltage, if lower Gen24 disables battery
|
||||
system_data[7] =
|
||||
53248; // Id.: p208 Value.: 53248 Scaled value.: 53248 Comment.: Always 53248 for this BYD, Peak Charge power?
|
||||
system_data[8] = 10; // Id.: p209 Value.: 10 Scaled value.: 10 Comment.: Always 10
|
||||
|
|
|
@ -25,11 +25,10 @@ extern uint16_t bms_char_dis_status;
|
|||
extern uint16_t stat_batt_power;
|
||||
extern uint16_t temperature_min;
|
||||
extern uint16_t temperature_max;
|
||||
|
||||
extern uint16_t capacity_Wh_startup;
|
||||
extern uint16_t max_power;
|
||||
extern uint16_t max_volt_modbus_byd;
|
||||
extern uint16_t min_volt_modbus_byd;
|
||||
extern uint16_t max_voltage;
|
||||
extern uint16_t min_voltage;
|
||||
|
||||
void handle_static_data_modbus_byd();
|
||||
void handle_update_data_modbusp201_byd();
|
||||
|
|
|
@ -25,11 +25,10 @@ extern uint16_t bms_char_dis_status;
|
|||
extern uint16_t stat_batt_power;
|
||||
extern uint16_t temperature_min;
|
||||
extern uint16_t temperature_max;
|
||||
|
||||
extern uint16_t capacity_Wh_startup;
|
||||
extern uint16_t max_power;
|
||||
extern uint16_t max_volt_modbus_byd;
|
||||
extern uint16_t min_volt_modbus_byd;
|
||||
extern uint16_t max_voltage;
|
||||
extern uint16_t min_voltage;
|
||||
|
||||
void update_modbus_registers_luna2000();
|
||||
void handle_update_data_modbus32051();
|
||||
|
|
|
@ -200,16 +200,16 @@ void update_values_can_pylon() { //This function maps all the values fetched fr
|
|||
PYLON_4211.data.u8[7] = (StateOfHealth * 0.01);
|
||||
|
||||
//Minvoltage (eg 300.0V = 3000 , 16bits long) Charge Cutoff Voltage
|
||||
PYLON_4220.data.u8[0] = (min_volt_pylon_can >> 8);
|
||||
PYLON_4220.data.u8[1] = (min_volt_pylon_can & 0x00FF);
|
||||
PYLON_4221.data.u8[0] = (min_volt_pylon_can >> 8);
|
||||
PYLON_4221.data.u8[1] = (min_volt_pylon_can & 0x00FF);
|
||||
PYLON_4220.data.u8[0] = (min_voltage >> 8);
|
||||
PYLON_4220.data.u8[1] = (min_voltage & 0x00FF);
|
||||
PYLON_4221.data.u8[0] = (min_voltage >> 8);
|
||||
PYLON_4221.data.u8[1] = (min_voltage & 0x00FF);
|
||||
|
||||
//Maxvoltage (eg 400.0V = 4000 , 16bits long) Discharge Cutoff Voltage
|
||||
PYLON_4220.data.u8[2] = (max_volt_pylon_can >> 8);
|
||||
PYLON_4220.data.u8[3] = (max_volt_pylon_can & 0x00FF);
|
||||
PYLON_4221.data.u8[2] = (max_volt_pylon_can >> 8);
|
||||
PYLON_4221.data.u8[3] = (max_volt_pylon_can & 0x00FF);
|
||||
PYLON_4220.data.u8[2] = (max_voltage >> 8);
|
||||
PYLON_4220.data.u8[3] = (max_voltage & 0x00FF);
|
||||
PYLON_4221.data.u8[2] = (max_voltage >> 8);
|
||||
PYLON_4221.data.u8[3] = (max_voltage & 0x00FF);
|
||||
|
||||
//In case we run into any errors/faults, we can set charge / discharge forbidden
|
||||
if (bms_status == FAULT) {
|
||||
|
|
|
@ -18,8 +18,8 @@ extern uint16_t stat_batt_power;
|
|||
extern uint16_t temperature_min;
|
||||
extern uint16_t temperature_max;
|
||||
extern uint16_t CANerror;
|
||||
extern uint16_t min_volt_pylon_can;
|
||||
extern uint16_t max_volt_pylon_can;
|
||||
extern uint16_t min_voltage;
|
||||
extern uint16_t max_voltage;
|
||||
// Definitions for BMS status
|
||||
#define STANDBY 0
|
||||
#define INACTIVE 1
|
||||
|
|
|
@ -125,13 +125,13 @@ static int ampere_hours_remaining = 0;
|
|||
|
||||
void update_values_can_sma() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
//Calculate values
|
||||
charge_current = ((max_target_charge_power * 10) /
|
||||
max_volt_sma_can); //Charge power in W , max volt in V+1decimal (P=UI, solve for I)
|
||||
charge_current =
|
||||
((max_target_charge_power * 10) / max_voltage); //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)
|
||||
|
||||
discharge_current = ((max_target_discharge_power * 10) /
|
||||
max_volt_sma_can); //Charge power in W , max volt in V+1decimal (P=UI, solve for I)
|
||||
max_voltage); //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)
|
||||
|
||||
|
@ -142,11 +142,11 @@ void update_values_can_sma() { //This function maps all the values fetched from
|
|||
|
||||
//Map values to CAN messages
|
||||
//Maxvoltage (eg 400.0V = 4000 , 16bits long)
|
||||
SMA_358.data.u8[0] = (max_volt_sma_can >> 8);
|
||||
SMA_358.data.u8[1] = (max_volt_sma_can & 0x00FF);
|
||||
SMA_358.data.u8[0] = (max_voltage >> 8);
|
||||
SMA_358.data.u8[1] = (max_voltage & 0x00FF);
|
||||
//Minvoltage (eg 300.0V = 3000 , 16bits long)
|
||||
SMA_358.data.u8[2] = (min_volt_sma_can >> 8); //Minvoltage behaves strange on SMA, cuts out at 56% of the set value?
|
||||
SMA_358.data.u8[3] = (min_volt_sma_can & 0x00FF);
|
||||
SMA_358.data.u8[2] = (min_voltage >> 8); //Minvoltage behaves strange on SMA, cuts out at 56% of the set value?
|
||||
SMA_358.data.u8[3] = (min_voltage & 0x00FF);
|
||||
//Discharge limited current, 500 = 50A, (0.1, A)
|
||||
SMA_358.data.u8[4] = (discharge_current >> 8);
|
||||
SMA_358.data.u8[5] = (discharge_current & 0x00FF);
|
||||
|
|
|
@ -19,8 +19,8 @@ extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 funct
|
|||
extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385)
|
||||
extern uint16_t cell_max_voltage; //mV, 0-4350
|
||||
extern uint16_t cell_min_voltage; //mV, 0-4350
|
||||
extern uint16_t min_volt_sma_can;
|
||||
extern uint16_t max_volt_sma_can;
|
||||
extern uint16_t min_voltage;
|
||||
extern uint16_t max_voltage;
|
||||
extern uint8_t LEDcolor; //Enum, 0-2
|
||||
// Definitions for BMS status
|
||||
#define STANDBY 0
|
||||
|
|
|
@ -281,15 +281,15 @@ CAN_frame_t SOFAR_7C0 = {.FIR = {.B =
|
|||
void update_values_can_sofar() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
|
||||
//Maxvoltage (eg 400.0V = 4000 , 16bits long) Charge Cutoff Voltage
|
||||
SOFAR_351.data.u8[0] = (max_volt_sofar_can >> 8);
|
||||
SOFAR_351.data.u8[1] = (max_volt_sofar_can & 0x00FF);
|
||||
SOFAR_351.data.u8[0] = (max_voltage >> 8);
|
||||
SOFAR_351.data.u8[1] = (max_voltage & 0x00FF);
|
||||
//SOFAR_351.data.u8[2] = DC charge current limitation (Default 25.0A)
|
||||
//SOFAR_351.data.u8[3] = DC charge current limitation
|
||||
//SOFAR_351.data.u8[4] = DC discharge current limitation (Default 25.0A)
|
||||
//SOFAR_351.data.u8[5] = DC discharge current limitation
|
||||
//Minvoltage (eg 300.0V = 3000 , 16bits long) Discharge Cutoff Voltage
|
||||
SOFAR_351.data.u8[6] = (min_volt_sofar_can >> 8);
|
||||
SOFAR_351.data.u8[7] = (min_volt_sofar_can & 0x00FF);
|
||||
SOFAR_351.data.u8[6] = (min_voltage >> 8);
|
||||
SOFAR_351.data.u8[7] = (min_voltage & 0x00FF);
|
||||
|
||||
//SOC
|
||||
SOFAR_355.data.u8[0] = (SOC / 100);
|
||||
|
|
|
@ -22,8 +22,8 @@ extern uint16_t cell_max_voltage; //mV, 0-4350
|
|||
extern uint16_t cell_min_voltage; //mV, 0-4350
|
||||
extern uint8_t batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||
extern uint8_t LEDcolor; //Enum, 0-2
|
||||
extern uint16_t min_volt_sofar_can;
|
||||
extern uint16_t max_volt_sofar_can;
|
||||
extern uint16_t min_voltage;
|
||||
extern uint16_t max_voltage;
|
||||
// Definitions for BMS status
|
||||
#define STANDBY 0
|
||||
#define INACTIVE 1
|
||||
|
|
|
@ -150,10 +150,10 @@ void update_values_can_solax() { //This function maps all the values fetched fr
|
|||
|
||||
//Put the values into the CAN messages
|
||||
//BMS_Limits
|
||||
SOLAX_1872.data.u8[0] = (uint8_t)max_volt_solax_can; //Todo, scaling OK?
|
||||
SOLAX_1872.data.u8[1] = (max_volt_solax_can >> 8);
|
||||
SOLAX_1872.data.u8[2] = (uint8_t)min_volt_solax_can; //Todo, scaling OK?
|
||||
SOLAX_1872.data.u8[3] = (min_volt_solax_can >> 8);
|
||||
SOLAX_1872.data.u8[0] = (uint8_t)max_voltage; //Todo, scaling OK?
|
||||
SOLAX_1872.data.u8[1] = (max_voltage >> 8);
|
||||
SOLAX_1872.data.u8[2] = (uint8_t)min_voltage; //Todo, scaling OK?
|
||||
SOLAX_1872.data.u8[3] = (min_voltage >> 8);
|
||||
SOLAX_1872.data.u8[4] = (uint8_t)(max_charge_rate_amp * 10); //Todo, scaling OK?
|
||||
SOLAX_1872.data.u8[5] = ((max_charge_rate_amp * 10) >> 8);
|
||||
SOLAX_1872.data.u8[6] = (uint8_t)(max_discharge_rate_amp * 10); //Todo, scaling OK?
|
||||
|
|
|
@ -22,8 +22,8 @@ extern uint16_t stat_batt_power;
|
|||
extern uint16_t temperature_min;
|
||||
extern uint16_t temperature_max;
|
||||
extern uint16_t CANerror;
|
||||
extern uint16_t min_volt_solax_can;
|
||||
extern uint16_t max_volt_solax_can;
|
||||
extern uint16_t min_voltage;
|
||||
extern uint16_t max_voltage;
|
||||
extern uint16_t cell_max_voltage;
|
||||
extern uint16_t cell_min_voltage;
|
||||
extern uint8_t inverterAllowsContactorClosing;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue