Add WUP signal GPIO output

This commit is contained in:
Daniel 2024-02-12 19:36:39 +02:00
parent 27f4d3b347
commit 7c7ddd30cc
4 changed files with 41 additions and 4 deletions

View file

@ -349,6 +349,12 @@ void inform_user_on_battery() {
// Inform user what battery is used
#ifdef BMW_I3_BATTERY
Serial.println("BMW i3 battery selected");
pinMode(WUP_PIN, OUTPUT); //This pin used for WUP relay
digitalWrite(WUP_PIN, LOW);
#ifdef CONTACTOR_CONTROL
// Contactor control cannot be used when WUP signal is sent on GPIO pins
#error CONTACTOR CONTROL CANNOT BE USED ON BMW i3
#endif
#endif
#ifdef CHADEMO_BATTERY
Serial.println("Chademo battery selected");

View file

@ -8,7 +8,7 @@
/* To edit battery specific limits, see also the USER_SETTINGS.cpp file*/
/* Select battery used */
//#define BMW_I3_BATTERY
#define BMW_I3_BATTERY
//#define CHADEMO_BATTERY
//#define IMIEV_CZERO_ION_BATTERY
//#define KIA_HYUNDAI_64_BATTERY

View file

@ -33,10 +33,16 @@ static const int interval5000 = 5000; // interval (ms) at which send CA
static const int interval10000 = 10000; // interval (ms) at which send CAN Messages
static uint8_t CANstillAlive = 12; //counter for checking if CAN is still alive
static const uint16_t WUPonDuration = 477; // in milliseconds how long WUP should be ON after poweron
static const uint16_t WUPoffDuration = 105; // in milliseconds how long WUP should be OFF after on pulse
unsigned long lastChangeTime; // Variables to store timestamps
unsigned long turnOnTime; // Variables to store timestamps
enum State { POWERON, STATE_ON, STATE_OFF, STATE_STAY_ON };
static State WUPState = POWERON;
#define LB_MAX_SOC 1000 //BMS never goes over this value. We use this info to rescale SOC% sent to Inverter
#define LB_MIN_SOC 0 //BMS never goes below this value. We use this info to rescale SOC% sent to Inverter
CAN_frame_t BMW_000 = {.FIR = {.B =
{
.DLC = 4,
@ -755,6 +761,27 @@ void receive_can_i3_battery(CAN_frame_t rx_frame) {
}
void send_can_i3_battery() {
unsigned long currentMillis = millis();
//Handle WUP signal
if (WUPState == POWERON) {
digitalWrite(WUP_PIN, HIGH);
turnOnTime = currentMillis;
WUPState = STATE_ON;
}
// Check if it's time to change state
if (WUPState == STATE_ON && currentMillis - turnOnTime >= WUPonDuration) {
WUPState = STATE_OFF;
digitalWrite(WUP_PIN, LOW); // Turn off
lastChangeTime = currentMillis;
} else if (WUPState == STATE_OFF && currentMillis - lastChangeTime >= WUPoffDuration) {
WUPState = STATE_STAY_ON;
digitalWrite(WUP_PIN, HIGH); // Turn on and stay on
lastChangeTime = currentMillis;
} else if (WUPState == STATE_STAY_ON) {
// Do nothing, stay in this state forever
}
//Send 10ms message
if (currentMillis - previousMillis10 >= interval10) {
previousMillis10 = currentMillis;

View file

@ -26,6 +26,10 @@
#define PRECHARGE_PIN 25
#endif
#ifdef BMW_I3_BATTERY
#define WUP_PIN 25
#endif
#define SD_MISO_PIN 2
#define SD_MOSI_PIN 15
#define SD_SCLK_PIN 14