Minor optimizations

This commit is contained in:
Daniel 2024-03-28 22:46:29 +02:00
parent fd85a9ebb2
commit a51c53edff
5 changed files with 7 additions and 21 deletions

View file

@ -28,8 +28,7 @@ Preferences settings; // Store user settings
const char* version_number = "5.6.dev"; const char* version_number = "5.6.dev";
// Interval settings // Interval settings
int intervalUpdateValues = 4800; // Interval at which to update inverter values / Modbus registers uint16_t intervalUpdateValues = INTERVAL_5_S; // Interval at which to update inverter values / Modbus registers
const int interval10 = 10; // Interval for 10ms tasks
unsigned long previousMillis10ms = 50; unsigned long previousMillis10ms = 50;
unsigned long previousMillisUpdateVal = 0; unsigned long previousMillisUpdateVal = 0;
@ -174,7 +173,7 @@ void loop() {
#endif #endif
// Process // Process
if (millis() - previousMillis10ms >= interval10) // Every 10ms if (millis() - previousMillis10ms >= INTERVAL_10_MS) // Every 10ms
{ {
previousMillis10ms = millis(); previousMillis10ms = millis();
handle_LED_state(); // Set the LED color according to state handle_LED_state(); // Set the LED color according to state
@ -183,7 +182,7 @@ void loop() {
#endif #endif
} }
if (millis() - previousMillisUpdateVal >= intervalUpdateValues) // Every 4.8s if (millis() - previousMillisUpdateVal >= intervalUpdateValues) // Every 5s normally
{ {
previousMillisUpdateVal = millis(); previousMillisUpdateVal = millis();
update_SOC(); // Check if real or calculated SOC% value should be sent update_SOC(); // Check if real or calculated SOC% value should be sent

View file

@ -15,7 +15,6 @@ static unsigned long previousMillis10s = 0; // will store last time a 1s CAN Me
static uint16_t CANerror = 0; //counter on how many CAN errors encountered static uint16_t CANerror = 0; //counter on how many CAN errors encountered
#define MAX_CAN_FAILURES 5000 //Amount of malformed CAN messages to allow before raising a warning #define MAX_CAN_FAILURES 5000 //Amount of malformed CAN messages to allow before raising a warning
static uint8_t CANstillAlive = 12; //counter for checking if CAN is still alive static uint8_t CANstillAlive = 12; //counter for checking if CAN is still alive
static uint8_t errorCode = 0; //stores if we have an error code active from battery control logic
static uint8_t mprun10r = 0; //counter 0-20 for 0x1F2 message static uint8_t mprun10r = 0; //counter 0-20 for 0x1F2 message
static uint8_t mprun10 = 0; //counter 0-3 static uint8_t mprun10 = 0; //counter 0-3
static uint8_t mprun100 = 0; //counter 0-3 static uint8_t mprun100 = 0; //counter 0-3
@ -268,7 +267,6 @@ void update_values_battery() { /* This function maps all the values fetched via
Serial.println("Battery requesting immediate shutdown and contactors to be opened!"); Serial.println("Battery requesting immediate shutdown and contactors to be opened!");
#endif #endif
//Note, this is sometimes triggered during the night while idle, and the BMS recovers after a while. Removed latching from this scenario //Note, this is sometimes triggered during the night while idle, and the BMS recovers after a while. Removed latching from this scenario
errorCode = 1;
system_max_discharge_power_W = 0; system_max_discharge_power_W = 0;
system_max_charge_power_W = 0; system_max_charge_power_W = 0;
} }
@ -296,17 +294,14 @@ void update_values_battery() { /* This function maps all the values fetched via
break; break;
case (5): case (5):
//Caution Lamp Request & Normal Stop Request //Caution Lamp Request & Normal Stop Request
errorCode = 2;
set_event(EVENT_BATTERY_DISCHG_STOP_REQ, 0); set_event(EVENT_BATTERY_DISCHG_STOP_REQ, 0);
break; break;
case (6): case (6):
//Caution Lamp Request & Charging Mode Stop Request //Caution Lamp Request & Charging Mode Stop Request
errorCode = 3;
set_event(EVENT_BATTERY_CHG_STOP_REQ, 0); set_event(EVENT_BATTERY_CHG_STOP_REQ, 0);
break; break;
case (7): case (7):
//Caution Lamp Request & Charging Mode Stop Request & Normal Stop Request //Caution Lamp Request & Charging Mode Stop Request & Normal Stop Request
errorCode = 4;
set_event(EVENT_BATTERY_CHG_DISCHG_STOP_REQ, 0); set_event(EVENT_BATTERY_CHG_DISCHG_STOP_REQ, 0);
break; break;
default: default:
@ -320,7 +315,6 @@ void update_values_battery() { /* This function maps all the values fetched via
if (LB_StateOfHealth < 25) { //Battery is extremely degraded, not fit for secondlifestorage. Zero it all out. if (LB_StateOfHealth < 25) { //Battery is extremely degraded, not fit for secondlifestorage. Zero it all out.
if (LB_StateOfHealth != 0) { //Extra check to see that we actually have a SOH Value available if (LB_StateOfHealth != 0) { //Extra check to see that we actually have a SOH Value available
errorCode = 5;
set_event(EVENT_LOW_SOH, LB_StateOfHealth); set_event(EVENT_LOW_SOH, LB_StateOfHealth);
} else { } else {
clear_event(EVENT_LOW_SOH); clear_event(EVENT_LOW_SOH);
@ -330,7 +324,6 @@ void update_values_battery() { /* This function maps all the values fetched via
#ifdef INTERLOCK_REQUIRED #ifdef INTERLOCK_REQUIRED
if (!LB_Interlock) { if (!LB_Interlock) {
set_event(EVENT_HVIL_FAILURE, 0); set_event(EVENT_HVIL_FAILURE, 0);
errorCode = 6;
} else { } else {
clear_event(EVENT_HVIL_FAILURE); clear_event(EVENT_HVIL_FAILURE);
} }
@ -338,7 +331,6 @@ void update_values_battery() { /* This function maps all the values fetched via
/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/ /* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
if (!CANstillAlive) { if (!CANstillAlive) {
errorCode = 7;
set_event(EVENT_CAN_RX_FAILURE, 0); set_event(EVENT_CAN_RX_FAILURE, 0);
} else { } else {
CANstillAlive--; CANstillAlive--;
@ -347,7 +339,6 @@ void update_values_battery() { /* This function maps all the values fetched via
if (CANerror > if (CANerror >
MAX_CAN_FAILURES) //Also check if we have recieved too many malformed CAN messages. If so, signal via LED MAX_CAN_FAILURES) //Also check if we have recieved too many malformed CAN messages. If so, signal via LED
{ {
errorCode = 10;
set_event(EVENT_CAN_RX_WARNING, 0); set_event(EVENT_CAN_RX_WARNING, 0);
} }
@ -358,10 +349,6 @@ void update_values_battery() { /* This function maps all the values fetched via
/*Finally print out values to serial if configured to do so*/ /*Finally print out values to serial if configured to do so*/
#ifdef DEBUG_VIA_USB #ifdef DEBUG_VIA_USB
if (errorCode > 0) {
Serial.print("ERROR CODE ACTIVE IN SYSTEM. NUMBER: ");
Serial.println(errorCode);
}
Serial.println("Values going to inverter"); Serial.println("Values going to inverter");
print_with_units("SOH%: ", (system_SOH_pptt * 0.01), "% "); print_with_units("SOH%: ", (system_SOH_pptt * 0.01), "% ");
print_with_units(", SOC% scaled: ", (system_scaled_SOC_pptt * 0.01), "% "); print_with_units(", SOC% scaled: ", (system_scaled_SOC_pptt * 0.01), "% ");
@ -576,11 +563,9 @@ void receive_can_battery(CAN_frame_t rx_frame) {
} }
if (min_max_voltage[1] >= MAX_CELL_VOLTAGE) { if (min_max_voltage[1] >= MAX_CELL_VOLTAGE) {
errorCode = 8;
set_event(EVENT_CELL_OVER_VOLTAGE, 0); set_event(EVENT_CELL_OVER_VOLTAGE, 0);
} }
if (min_max_voltage[0] <= MIN_CELL_VOLTAGE) { if (min_max_voltage[0] <= MIN_CELL_VOLTAGE) {
errorCode = 9;
set_event(EVENT_CELL_UNDER_VOLTAGE, 0); set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
} }
break; break;

View file

@ -2,6 +2,7 @@
#define CHEVYVOLT_CHARGER_H #define CHEVYVOLT_CHARGER_H
#include <Arduino.h> #include <Arduino.h>
#include "../../USER_SETTINGS.h" #include "../../USER_SETTINGS.h"
#include "../devboard/config.h" // Needed for all defines
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
/* Charger hardware limits /* Charger hardware limits

View file

@ -2,6 +2,7 @@
#define NISSANLEAF_CHARGER_H #define NISSANLEAF_CHARGER_H
#include <Arduino.h> #include <Arduino.h>
#include "../../USER_SETTINGS.h" #include "../../USER_SETTINGS.h"
#include "../devboard/config.h" // Needed for all defines
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
extern uint16_t system_battery_voltage_dV; //V+1, 0-500.0 (0-5000) extern uint16_t system_battery_voltage_dV; //V+1, 0-500.0 (0-5000)

View file

@ -583,8 +583,8 @@ String processor(const String& var) {
#endif #endif
#ifdef NISSANLEAF_CHARGER #ifdef NISSANLEAF_CHARGER
float chgPwrDC = static_cast<float>(charger_stat_HVcur * 100); float chgPwrDC = static_cast<float>(charger_stat_HVcur * 100);
charger_stat_HVcur = chgPwrDC / (battery_voltage / 10); // P/U=I charger_stat_HVcur = chgPwrDC / (system_battery_voltage_dV / 10); // P/U=I
charger_stat_HVvol = static_cast<float>(battery_voltage / 10); charger_stat_HVvol = static_cast<float>(system_battery_voltage_dV / 10);
float ACvol = charger_stat_ACvol; float ACvol = charger_stat_ACvol;
float HVvol = charger_stat_HVvol; float HVvol = charger_stat_HVvol;
float HVcur = charger_stat_HVcur; float HVcur = charger_stat_HVcur;