Fix rolling limiter not working with coolant based RPM limit

This commit is contained in:
Josh Stewart 2023-07-04 15:26:56 +10:00
parent 572d1b274b
commit 856bcfb242
2 changed files with 8 additions and 14 deletions

View File

@ -18,7 +18,7 @@ byte checkEngineProtect(void)
byte checkRevLimit(void) byte checkRevLimit(void)
{ {
//Hardcut RPM limit //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.engineProtectStatus, ENGINE_PROTECT_BIT_RPM);
BIT_CLEAR(currentStatus.spark, BIT_SPARK_HRDLIM); BIT_CLEAR(currentStatus.spark, BIT_SPARK_HRDLIM);
BIT_CLEAR(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_COOLANT); BIT_CLEAR(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_COOLANT);
@ -27,28 +27,27 @@ byte checkRevLimit(void)
{ {
if(configPage9.hardRevMode == HARD_REV_FIXED) if(configPage9.hardRevMode == HARD_REV_FIXED)
{ {
currentLimitRPM = configPage4.HardRevLim;
if ( (currentStatus.RPMdiv100 >= configPage4.HardRevLim) || ((softLimitTime > configPage4.SoftLimMax) && (currentStatus.RPMdiv100 >= configPage4.SoftRevLim)) ) 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.spark, BIT_SPARK_HRDLIM); //Legacy and likely to be removed at some point
BIT_SET(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_RPM); BIT_SET(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_RPM);
revLimiterActive = 1;
} }
else { BIT_CLEAR(currentStatus.spark, BIT_SPARK_HRDLIM); } else { BIT_CLEAR(currentStatus.spark, BIT_SPARK_HRDLIM); }
} }
else if(configPage9.hardRevMode == HARD_REV_COOLANT ) else if(configPage9.hardRevMode == HARD_REV_COOLANT )
{ {
int8_t coolantLimit = (int16_t)(table2D_getValue(&coolantProtectTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET)); currentLimitRPM = (int16_t)(table2D_getValue(&coolantProtectTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET));
if(currentStatus.RPMdiv100 > coolantLimit) if(currentStatus.RPMdiv100 > currentLimitRPM)
{ {
BIT_SET(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_COOLANT); 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.spark, BIT_SPARK_HRDLIM); //Legacy and likely to be removed at some point
BIT_SET(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_RPM); BIT_SET(currentStatus.engineProtectStatus, ENGINE_PROTECT_BIT_RPM);
revLimiterActive = 1;
} }
} }
} }
return revLimiterActive; return currentLimitRPM;
} }
byte checkBoostLimit(void) byte checkBoostLimit(void)

View File

@ -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 ignitionChannelsOn; /**< The current state of the ignition system (on or off) */
uint8_t fuelChannelsOn; /**< The current state of the fuel 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 */ 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; 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 //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 //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( checkEngineProtect() && (configPage4.engineProtectMaxRPM < maxAllowedRPM)) { maxAllowedRPM = configPage4.engineProtectMaxRPM; }
if ( (currentStatus.launchingHard == true) && (configPage6.lnchHardLim < maxAllowedRPM) ) { maxAllowedRPM = configPage6.lnchHardLim; } if ( (currentStatus.launchingHard == true) && (configPage6.lnchHardLim < maxAllowedRPM) ) { maxAllowedRPM = configPage6.lnchHardLim; }
if ( (currentStatus.flatShiftingHard == true) && (configPage6.flatSArm < maxAllowedRPM) ) { maxAllowedRPM = configPage6.flatSArm; } 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( (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(rollingCutLastRev == 0) { rollingCutLastRev = currentStatus.startRevolutions; } //First time check
if (currentStatus.startRevolutions > (rollingCutLastRev + revolutionsToCut) ) if (currentStatus.startRevolutions >= (rollingCutLastRev + revolutionsToCut) )
{ {
uint8_t cutPercent = 0; uint8_t cutPercent = 0;
int16_t rpmDelta = currentStatus.RPM - maxAllowedRPM; 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%) 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) ); } // else { cutPercent = table2D_getValue(&rollingCutTable, (rpmDelta / 10) ); } //
//max(maxIgnOutputs, maxInjOutputs) for(uint8_t x=0; x<max(maxIgnOutputs, maxInjOutputs); x++)
for(uint8_t x=0; x<8; x++)
{ {
if( (configPage6.engineProtectType != PROTECT_CUT_OFF) && ( (cutPercent == 100) || (random1to100() < cutPercent) ) ) if( (configPage6.engineProtectType != PROTECT_CUT_OFF) && ( (cutPercent == 100) || (random1to100() < cutPercent) ) )
{ {