From edd323110286cab8d9144e5244927bd0a38d82fb Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Thu, 18 Jan 2024 18:03:46 +1100 Subject: [PATCH] Use the faster div100 function in PW() --- speeduino/speeduino.ino | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index 532d4555..21b0c4f9 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -262,7 +262,7 @@ void loop(void) #endif readO2(); readO2_2(); - + #ifdef SD_LOGGING if(configPage13.onboard_log_file_rate == LOGGER_RATE_30HZ) { writeSDLogEntry(); } #endif @@ -1208,11 +1208,12 @@ uint16_t PW(int REQ_FUEL, byte VE, long MAP, uint16_t corrections, int injOpen) if (corrections > 511 ) { bitShift = 6; } if (corrections > 1023) { bitShift = 5; } - iVE = ((unsigned int)VE << 7) / 100; - //iVE = divu100(((unsigned int)VE << 7)); + //iVE = ((unsigned int)VE << 7) / 100; + iVE = div100(((unsigned int)VE << 7)); //Check whether either of the multiply MAP modes is turned on - if ( configPage2.multiplyMAP == MULTIPLY_MAP_MODE_100) { iMAP = ((unsigned int)MAP << 7) / 100; } + //if ( configPage2.multiplyMAP == MULTIPLY_MAP_MODE_100) { iMAP = ((unsigned int)MAP << 7) / 100; } + if ( configPage2.multiplyMAP == MULTIPLY_MAP_MODE_100) { iMAP = div100( ((uint16_t)MAP << 7U) ); } else if( configPage2.multiplyMAP == MULTIPLY_MAP_MODE_BARO) { iMAP = ((unsigned int)MAP << 7) / currentStatus.baro; } if ( (configPage2.includeAFR == true) && (configPage6.egoType == EGO_TYPE_WIDE) && (currentStatus.runSecs > configPage6.ego_sdelay) ) { @@ -1221,8 +1222,8 @@ uint16_t PW(int REQ_FUEL, byte VE, long MAP, uint16_t corrections, int injOpen) if ( (configPage2.incorporateAFR == true) && (configPage2.includeAFR == false) ) { iAFR = ((unsigned int)configPage2.stoich << 7) / currentStatus.afrTarget; //Incorporate stoich vs target AFR, if enabled. } - iCorrections = (corrections << bitShift) / 100; - //iCorrections = divu100((corrections << bitShift)); + //iCorrections = (corrections << bitShift) / 100; + iCorrections = div100((corrections << bitShift)); uint32_t intermediate = ((uint32_t)REQ_FUEL * (uint32_t)iVE) >> 7; //Need to use an intermediate value to avoid overflowing the long @@ -1251,9 +1252,9 @@ uint16_t PW(int REQ_FUEL, byte VE, long MAP, uint16_t corrections, int injOpen) } } - if ( intermediate > 65535) + if ( intermediate > UINT16_MAX) { - intermediate = 65535; //Make sure this won't overflow when we convert to uInt. This means the maximum pulsewidth possible is 65.535mS + intermediate = UINT16_MAX; //Make sure this won't overflow when we convert to uInt. This means the maximum pulsewidth possible is 65.535mS } } return (unsigned int)(intermediate);