From 22d2b4e38e795cf6626c8a0d781976b8439f6ff6 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 23 Nov 2022 16:15:01 +1100 Subject: [PATCH] Add delay to oil pressure engine protection --- reference/speeduino.ini | 6 +++++- speeduino/engineProtection.ino | 20 +++++++++++++++++--- speeduino/globals.h | 4 +++- speeduino/updates.ino | 3 +++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/reference/speeduino.ini b/reference/speeduino.ini index 925f2699..66bebc0c 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -1252,7 +1252,9 @@ page = 10 spark2InputPolarity = bits , U08, 189, [6:6], "LOW", "HIGH" spark2InputPullup = bits , U08, 189, [7:7], "No", "Yes" - unused11_190_191 = array, U08, 190, [2], "RPM", 100.0, 0.0, 100, 25500, 0 + oilPressureProtTime = scalar, U08, 190, "seconds", 0.1, 0.0, 0.0, 25, 1 + + unused11_190_191 = array, U08, 191, [1], "RPM", 100.0, 0.0, 100, 25500, 0 ;Page 11 is the fuel map and axis bins only page = 11 @@ -2131,6 +2133,7 @@ menuDialog = main #endif afrProtectCutTime = "Time delay before activating AFR protection when all conditions has been fulfilled" afrProtectReactivationTPS = "Going below this throttle position (%) will deactivate this protection" + oilPressureProtTime = "Time delay before activating oil pressure protection when all conditions has been fulfilled" fuel2InputPin = "The Arduino pin that is being used to trigger the second fuel table to be active" fuel2InputPolarity = "Whether the 2nd fuel table should be active when input is high or low. This should be LOW for a typical ground switching input" @@ -2992,6 +2995,7 @@ menuDialog = main dialog = oilPressureProtection, "Oil Pressure" field = "Oil Pressure Protection", oilPressureProtEnbl, { oilPressureEnable } + field = "Oil Pressure cut delay", oilPressureProtTime, { oilPressureEnable && oilPressureProtEnbl } panel = oil_pressure_prot_curve, { oilPressureEnable && oilPressureProtEnbl } ; AFR engine protection dialog diff --git a/speeduino/engineProtection.ino b/speeduino/engineProtection.ino index a23740f3..ee2f0807 100644 --- a/speeduino/engineProtection.ino +++ b/speeduino/engineProtection.ino @@ -2,6 +2,8 @@ #include "globals.h" #include "engineProtection.h" +byte oilProtStartTime = 0; + byte checkEngineProtect(void) { byte protectActive = 0; @@ -93,17 +95,29 @@ byte checkBoostLimit(void) byte checkOilPressureLimit(void) { byte oilProtectActive = 0; + static constexpr char X100_MULTIPLIER = 100; + bool alreadyActive = BIT_CHECK(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_OIL); BIT_CLEAR(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_OIL); //Will be set true below if required - if (configPage6.engineProtectType != PROTECT_CUT_OFF) { + if (configPage6.engineProtectType != PROTECT_CUT_OFF) + { if( (configPage10.oilPressureProtEnbl == true) && (configPage10.oilPressureEnable == true) ) { byte oilLimit = table2D_getValue(&oilPressureProtectTable, currentStatus.RPMdiv100); if(currentStatus.oilPressure < oilLimit) { - BIT_SET(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_OIL); - oilProtectActive = 1; + //Check if this is the first time we've been below the limit + if(oilProtStartTime == 0) { oilProtStartTime = (millis() / 100); } + + /* Check if countdown has reached its target, if so then instruct to cut */ + if( (uint8_t(millis()/100) >= (uint16_t(oilProtStartTime + configPage10.oilPressureProtTime)) ) || (alreadyActive > 0) ) + { + BIT_SET(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_OIL); + oilProtectActive = 1; + } + } + else { oilProtStartTime = 0; } //Reset the timer } } diff --git a/speeduino/globals.h b/speeduino/globals.h index 173980e7..4b8d1dcb 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -1376,7 +1376,9 @@ struct config10 { byte spark2InputPolarity : 1; byte spark2InputPullup : 1; - byte unused11_187_191[2]; //Bytes 187-191 + byte oilPressureProtTime; + + byte unused11_191_191; //Bytes 187-191 #if defined(CORE_AVR) }; diff --git a/speeduino/updates.ino b/speeduino/updates.ino index 1b87a6e3..7ea3c030 100644 --- a/speeduino/updates.ino +++ b/speeduino/updates.ino @@ -683,6 +683,9 @@ void doUpdates(void) //Set A/C default values - these line up with the ini file defaults configPage15.airConEnable = 0; + //Oil Pressure protection delay added. Set to 0 to match existing behaviour + configPage10.oilPressureProtTime = 0; + writeAllConfig(); storeEEPROMVersion(21); }