Use the faster div100 function in PW()

This commit is contained in:
Josh Stewart 2024-01-18 18:03:46 +11:00
parent 1439750731
commit edd3231102
1 changed files with 9 additions and 8 deletions

View File

@ -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);