From 856bcfb24275906b3fc8be68698bb50b03f3ac5c Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Tue, 4 Jul 2023 15:26:56 +1000 Subject: [PATCH] Fix rolling limiter not working with coolant based RPM limit --- speeduino/engineProtection.ino | 11 +++++------ speeduino/speeduino.ino | 11 +++-------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/speeduino/engineProtection.ino b/speeduino/engineProtection.ino index 454f77a8..e6c406aa 100644 --- a/speeduino/engineProtection.ino +++ b/speeduino/engineProtection.ino @@ -18,7 +18,7 @@ byte checkEngineProtect(void) byte checkRevLimit(void) { //Hardcut RPM limit - byte revLimiterActive = 0; + byte currentLimitRPM = 255; //Default to no limit (In case PROTECT_CUT_OFF is selected) BIT_CLEAR(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_RPM); BIT_CLEAR(currentStatus.spark, BIT_SPARK_HRDLIM); BIT_CLEAR(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_COOLANT); @@ -27,28 +27,27 @@ byte checkRevLimit(void) { if(configPage9.hardRevMode == HARD_REV_FIXED) { + currentLimitRPM = configPage4.HardRevLim; if ( (currentStatus.RPMdiv100 >= configPage4.HardRevLim) || ((softLimitTime > configPage4.SoftLimMax) && (currentStatus.RPMdiv100 >= configPage4.SoftRevLim)) ) { BIT_SET(currentStatus.spark, BIT_SPARK_HRDLIM); //Legacy and likely to be removed at some point BIT_SET(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_RPM); - revLimiterActive = 1; } else { BIT_CLEAR(currentStatus.spark, BIT_SPARK_HRDLIM); } } else if(configPage9.hardRevMode == HARD_REV_COOLANT ) { - int8_t coolantLimit = (int16_t)(table2D_getValue(&coolantProtectTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET)); - if(currentStatus.RPMdiv100 > coolantLimit) + currentLimitRPM = (int16_t)(table2D_getValue(&coolantProtectTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET)); + if(currentStatus.RPMdiv100 > currentLimitRPM) { BIT_SET(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_COOLANT); BIT_SET(currentStatus.spark, BIT_SPARK_HRDLIM); //Legacy and likely to be removed at some point BIT_SET(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_RPM); - revLimiterActive = 1; } } } - return revLimiterActive; + return currentLimitRPM; } byte checkBoostLimit(void) diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index d9ca1a76..337a4cbd 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -54,9 +54,6 @@ uint16_t inj_opentime_uS = 0; uint8_t ignitionChannelsOn; /**< The current state of the ignition system (on or off) */ uint8_t fuelChannelsOn; /**< The current state of the fuel system (on or off) */ - -//byte curRollingCut = 0; /**< Rolling rev limiter, current ignition channel being cut */ -//byte rollingCutCounter = 0; /**< how many times (revolutions) the ignition has been cut in a row */ uint32_t rollingCutLastRev = 0; /**< Tracks whether we're on the same or a different rev for the rolling cut */ uint16_t staged_req_fuel_mult_pri = 0; @@ -793,9 +790,8 @@ void loop(void) // } //Check for any of the engine protections or rev limiters being turned on - int16_t maxAllowedRPM = configPage4.HardRevLim; //The maximum RPM allowed by all the potential limiters (Engine protection, 2-step, flat shift etc). Divided by 100. Use RPM hard limit as the default as it's the highest that is ever permitted + uint16_t maxAllowedRPM = checkRevLimit(); //The maximum RPM allowed by all the potential limiters (Engine protection, 2-step, flat shift etc). Divided by 100. `checkRevLimit()` returns the current maximum RPM allow (divided by 100) based on either the fixed hard limit or the current coolant temp //Check each of the functions that has an RPM limit. Update the max allowed RPM if the function is active and has a lower RPM than already set - checkRevLimit(); if( checkEngineProtect() && (configPage4.engineProtectMaxRPM < maxAllowedRPM)) { maxAllowedRPM = configPage4.engineProtectMaxRPM; } if ( (currentStatus.launchingHard == true) && (configPage6.lnchHardLim < maxAllowedRPM) ) { maxAllowedRPM = configPage6.lnchHardLim; } if ( (currentStatus.flatShiftingHard == true) && (configPage6.flatSArm < maxAllowedRPM) ) { maxAllowedRPM = configPage6.flatSArm; } @@ -835,15 +831,14 @@ void loop(void) //if( (configPage4.sparkMode != IGN_MODE_SEQUENTIAL) || (configPage2.injLayout != INJ_SEQUENTIAL) ) { revolutionsToCut *= 2; } //4 stroke and non-sequential will cut for 4 revolutions minimum. This is to ensure no half fuel ignition cycles take place if(rollingCutLastRev == 0) { rollingCutLastRev = currentStatus.startRevolutions; } //First time check - if (currentStatus.startRevolutions > (rollingCutLastRev + revolutionsToCut) ) + if (currentStatus.startRevolutions >= (rollingCutLastRev + revolutionsToCut) ) { uint8_t cutPercent = 0; int16_t rpmDelta = currentStatus.RPM - maxAllowedRPM; if(rpmDelta >= 0) { cutPercent = 100; } //If the current RPM is over the max allowed RPM then cut is full (100%) else { cutPercent = table2D_getValue(&rollingCutTable, (rpmDelta / 10) ); } // - //max(maxIgnOutputs, maxInjOutputs) - for(uint8_t x=0; x<8; x++) + for(uint8_t x=0; x