diff --git a/reference/speeduino.ini b/reference/speeduino.ini index e18c301e..d1a2017d 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -431,14 +431,19 @@ page = 4 #else cltAdvBins = array, U08, 71, [ 6], "F", 1.8, -22.23, -40, 215.0, 0 ; No -40 degree offset here #endif - cltAdvValues = array, S08, 77, [ 6], "deg", 1.0, -15, -15, 15, 0 + cltAdvValues = array, S08, 77, [ 6], "deg", 1.0, -15, -15, 15, 0 ;MAP based acceleration enrichment maeBins = array, U08, 83, [ 4], "kpa/s", 10.0, 0.0, 0.00, 2550.0, 0 maeRates = array, U08, 87, [ 4], "%", 1.0, 0.0, 0.00, 255.0, 0 ; 4 bytes batVoltCorrect = scalar, S08, 91, "v", 0.1, 0.0, -2, 2, 1 ;Battery reading calibration value. Note: Signed value - unused4-92 = array, U08, 92, [36], "%", 1.0, 0.0, 0.0, 255, 0 + +;Baro fuel correction + baroFuelBins = array, U08, 92, [8], "kPa", 1.0, 0, 80, 120, 0 ; Bins for the Baro correction curve + baroFuelValues = array, U08, 100, [8], "%", 1.0, 0, 0, 255, 0 ; % Values for same + + unused4-92 = array, U08, 108,[20], "%", 1.0, 0.0, 0.0, 255, 0 ;-------------------------------------------------- ;Start AFR page @@ -1206,6 +1211,7 @@ menuDialog = main subMenu = triggerSettings, "Trigger Setup" ;subMenu = OLED, "OLED Setup" subMenu = airdensity_curve, "IAT Density" + subMenu = baroFuel_curve, "Barometric Correction" subMenu = reset_control, "Reset Control" @@ -2800,6 +2806,14 @@ cmdtestspk450dc = "E\x03\x0C" xBins = airDenBins, iat yBins = airDenRates +; Correction curve for Barometric pressure fuel adjustment + curve = baroFuel_curve, "Baro fuel correction" + columnLabel = "Baro Pressure", "Fuel Amount" + xAxis = 70, 130, 6 + yAxis = 0, 255, 6 + xBins = baroFuelBins, baro + yBins = baroFuelValues + ; IAT based ignition timing retard curve = iat_retard_curve, "IAT timing retard" columnLabel = "Inlet Air Temp", "Retard" diff --git a/speeduino/corrections.h b/speeduino/corrections.h index 75c6f9f9..9cd647a8 100644 --- a/speeduino/corrections.h +++ b/speeduino/corrections.h @@ -17,6 +17,7 @@ static inline byte correctionAFRClosedLoop() __attribute__((always_inline)); //C static inline byte correctionFlex() __attribute__((always_inline)); //Flex fuel adjustment static inline byte correctionBatVoltage() __attribute__((always_inline)); //Battery voltage correction static inline byte correctionIATDensity() __attribute__((always_inline)); //Inlet temp density correction +static inline byte correctionBaro() __attribute__((always_inline)); //Inlet temp density correction static inline byte correctionLaunch() __attribute__((always_inline)); //Launch control correction static inline bool correctionDFCO() __attribute__((always_inline)); //Decelleration fuel cutoff @@ -25,6 +26,7 @@ static inline int8_t correctionFixedTiming(int8_t); static inline int8_t correctionCrankingFixedTiming(int8_t); static inline int8_t correctionFlexTiming(int8_t); static inline int8_t correctionIATretard(int8_t); +static inline int8_t correctionBaro(int8_t); static inline int8_t correctionCLTadvance(int8_t); static inline int8_t correctionSoftRevLimit(int8_t); static inline int8_t correctionNitrous(int8_t); diff --git a/speeduino/corrections.ino b/speeduino/corrections.ino index 92263e5a..6578e95d 100644 --- a/speeduino/corrections.ino +++ b/speeduino/corrections.ino @@ -38,7 +38,8 @@ This is the only function that should be called from anywhere outside the file */ static inline byte correctionsFuel() { - unsigned long sumCorrections = 100; + #define MAX_CORRECTIONS 3 //The maximum number of corrections allowed before the sum is reprocessed + uint32_t sumCorrections = 100; byte activeCorrections = 0; byte result; //temporary variable to store the result of each corrections function @@ -51,31 +52,35 @@ static inline byte correctionsFuel() result = correctionCranking(); if (result != 100) { sumCorrections = (sumCorrections * result); activeCorrections++; } - if (activeCorrections == 3) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } // Need to check this to ensure that sumCorrections doesn't overflow. Can occur when the number of corrections is greater than 3 (Which is 100^4) as 100^5 can overflow + if (activeCorrections == MAX_CORRECTIONS) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } // Need to check this to ensure that sumCorrections doesn't overflow. Can occur when the number of corrections is greater than 3 (Which is 100^4) as 100^5 can overflow currentStatus.AEamount = correctionAccel(); if (currentStatus.AEamount != 100) { sumCorrections = (sumCorrections * currentStatus.AEamount); activeCorrections++; } - if (activeCorrections == 3) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } + if (activeCorrections == MAX_CORRECTIONS) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } result = correctionFloodClear(); if (result != 100) { sumCorrections = (sumCorrections * result); activeCorrections++; } - if (activeCorrections == 3) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } + if (activeCorrections == MAX_CORRECTIONS) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } currentStatus.egoCorrection = correctionAFRClosedLoop(); if (currentStatus.egoCorrection != 100) { sumCorrections = (sumCorrections * currentStatus.egoCorrection); activeCorrections++; } - if (activeCorrections == 3) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } + if (activeCorrections == MAX_CORRECTIONS) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } currentStatus.batCorrection = correctionBatVoltage(); if (currentStatus.batCorrection != 100) { sumCorrections = (sumCorrections * currentStatus.batCorrection); activeCorrections++; } - if (activeCorrections == 3) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } + if (activeCorrections == MAX_CORRECTIONS) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } currentStatus.iatCorrection = correctionIATDensity(); if (currentStatus.iatCorrection != 100) { sumCorrections = (sumCorrections * currentStatus.iatCorrection); activeCorrections++; } - if (activeCorrections == 3) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } + if (activeCorrections == MAX_CORRECTIONS) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } + + currentStatus.baroCorrection = correctionBaro(); + if (currentStatus.baroCorrection != 100) { sumCorrections = (sumCorrections * currentStatus.baroCorrection); activeCorrections++; } + if (activeCorrections == MAX_CORRECTIONS) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } currentStatus.flexCorrection = correctionFlex(); if (currentStatus.flexCorrection != 100) { sumCorrections = (sumCorrections * currentStatus.flexCorrection); activeCorrections++; } - if (activeCorrections == 3) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } + if (activeCorrections == MAX_CORRECTIONS) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } currentStatus.launchCorrection = correctionLaunch(); if (currentStatus.launchCorrection != 100) { sumCorrections = (sumCorrections * currentStatus.launchCorrection); activeCorrections++; } @@ -322,6 +327,18 @@ static inline byte correctionIATDensity() return IATValue; } +/** + * @brief + * + */ +static inline byte correctionBaro() +{ + byte baroValue = 100; + baroValue = table2D_getValue(&baroFuelTable, currentStatus.baro); + + return baroValue; +} + /* Launch control has a setting to increase the fuel load to assist in bringing up boost This simple check applies the extra fuel if we're currently launching diff --git a/speeduino/globals.h b/speeduino/globals.h index 0f7c9fee..03d7407f 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -278,6 +278,7 @@ struct table2D crankingEnrichTable; //4 bin cranking Enrichment map (2D) struct table2D dwellVCorrectionTable; //6 bin dwell voltage correction (2D) struct table2D injectorVCorrectionTable; //6 bin injector voltage correction (2D) struct table2D IATDensityCorrectionTable; //9 bin inlet air temperature density correction (2D) +struct table2D baroFuelTable; //8 bin baro correction curve (2D) struct table2D IATRetardTable; //6 bin ignition adjustment based on inlet air temperature (2D) struct table2D IDLEAdvanceTable; //6 bin idle advance adjustment table based on RPM difference (2D) struct table2D CLTAdvanceTable; //6 bin ignition adjustment based on coolant temperature (2D) @@ -425,6 +426,7 @@ struct statuses { byte wueCorrection; /**< The amount of warmup enrichment currently being applied */ byte batCorrection; /**< The amount of battery voltage enrichment currently being applied */ byte iatCorrection; /**< The amount of inlet air temperature adjustment currently being applied */ + byte baroCorrection; /**< The amount of correction being applied for the current baro reading */ byte launchCorrection; /**< The amount of correction being applied if launch control is active */ byte flexCorrection; /**< Amount of correction being applied to compensate for ethanol content */ int8_t flexIgnCorrection; /**< Amount of additional advance being applied based on flex. Note the type as this allows for negative values */ @@ -678,7 +680,11 @@ struct config4 { byte maeRates[4]; /**< MAP based AE values */ int8_t batVoltCorrect; /**< Battery voltage calibration offset */ - byte unused2_91[36]; + + byte baroFuelBins[8]; + byte baroFuelValues[8]; + + byte unused2_91[20]; #if defined(CORE_AVR) }; diff --git a/speeduino/init.ino b/speeduino/init.ino index 3bb52328..6d2016f5 100644 --- a/speeduino/init.ino +++ b/speeduino/init.ino @@ -107,6 +107,11 @@ void initialiseAll() IATDensityCorrectionTable.xSize = 9; IATDensityCorrectionTable.values = configPage6.airDenRates; IATDensityCorrectionTable.axisX = configPage6.airDenBins; + baroFuelTable.valueSize = SIZE_BYTE; + baroFuelTable.axisSize = SIZE_BYTE; + baroFuelTable.xSize = 8; + baroFuelTable.values = configPage4.baroFuelValues; + baroFuelTable.axisX = configPage4.baroFuelBins; IATRetardTable.valueSize = SIZE_BYTE; IATRetardTable.axisSize = SIZE_BYTE; //Set this table to use byte axis bins IATRetardTable.xSize = 6;