From 049f3081b1daf76e2de64aa43be7a3debf363296 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Mon, 28 Nov 2016 20:37:24 +1100 Subject: [PATCH] Complete fuel correction for flex --- comms.ino | 2 +- corrections.h | 1 + corrections.ino | 15 +++++++++++++++ globals.h | 5 ++--- reference/speeduino.ini | 25 ++++++++++--------------- speeduino.ino | 2 +- timers.ino | 8 ++++---- 7 files changed, 34 insertions(+), 24 deletions(-) diff --git a/comms.ino b/comms.ino index fd9ca7e..4264896 100644 --- a/comms.ino +++ b/comms.ino @@ -257,7 +257,7 @@ void sendValues(int packetlength, byte portNum) response[31] = lowByte(currentStatus.rpmDOT); response[32] = highByte(currentStatus.rpmDOT); - response[33] = currentStatus.flex; //Flex sensor value (or 0 if not used) + response[33] = currentStatus.ethanolPct; //Flex sensor value (or 0 if not used) response[34] = getNextError(); //cli(); diff --git a/corrections.h b/corrections.h index 134a731..bd5c32b 100644 --- a/corrections.h +++ b/corrections.h @@ -13,5 +13,6 @@ byte correctionASE(); //After Start Enrichment byte correctionAccel(); //Acceleration Enrichment byte correctionsFloodClear(); //Check for flood clear on cranking byte correctionsAFRClosedLoop(); //Closed loop AFR adjustment +byte correctionsFlex(); //Flex fuel adjustment #endif // CORRECTIONS_H diff --git a/corrections.ino b/corrections.ino index c6e567c..131ba6a 100644 --- a/corrections.ino +++ b/corrections.ino @@ -64,6 +64,10 @@ byte correctionsTotal() currentStatus.iatCorrection = correctionsIATDensity(); if (currentStatus.iatCorrection != 100) { sumCorrections = (sumCorrections * currentStatus.iatCorrection); activeCorrections++; } if (activeCorrections == 3) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } + + currentStatus.flexCorrection = correctionsFlex(); + if (currentStatus.flexCorrection != 100) { sumCorrections = (sumCorrections * currentStatus.flexCorrection); activeCorrections++; } + if (activeCorrections == 3) { sumCorrections = sumCorrections / powint(100,activeCorrections); activeCorrections = 0; } currentStatus.launchCorrection = correctionsLaunch(); if (currentStatus.launchCorrection != 100) { sumCorrections = (sumCorrections * currentStatus.launchCorrection); activeCorrections++; } @@ -219,6 +223,17 @@ bool correctionsDFCO() else { return ( currentStatus.RPM > ( (configPage2.dfcoRPM * 10) + configPage2.dfcoHyster) ) && ( currentStatus.TPS < configPage2.dfcoTPSThresh ); } } +/* + * Flex fuel adjustment to vary fuel based on ethanol content + * The amount of extra fuel required is a linear relationship based on the % of ethanol. +*/ +byte correctionsFlex() +{ + if(!configPage1.flexEnabled) { return 100; } //Check for flex being enabled + byte flexRange = configPage1.flexFuelHigh - configPage1.flexFuelLow; + return percentage(currentStatus.ethanolPct, flexRange) + 100; +} + /* Lookup the AFR target table and perform either a simple or PID adjustment based on this diff --git a/globals.h b/globals.h index 31f6f20..1005c29 100644 --- a/globals.h +++ b/globals.h @@ -142,10 +142,11 @@ struct statuses { byte batCorrection; //The amount of battery voltage enrichment currently being applied byte iatCorrection; //The amount of inlet air temperature adjustment currently being applied 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 byte afrTarget; byte idleDuty; bool fanOn; //Whether or not the fan is turned on - byte flex; //Ethanol reading (if enabled). 0 = No ethanol, 100 = pure ethanol. Eg E85 = 85. + byte ethanolPct; //Ethanol reading (if enabled). 0 = No ethanol, 100 = pure ethanol. Eg E85 = 85. unsigned long TAEEndTime; //The target end time used whenever TAE is turned on volatile byte squirt; volatile byte spark; @@ -247,8 +248,6 @@ struct config1 { unsigned int oddfire2; //The ATDC angle of channel 2 for oddfire unsigned int oddfire3; //The ATDC angle of channel 3 for oddfire unsigned int oddfire4; //The ATDC angle of channel 4 for oddfire - byte flexEthPctLow; //Ethanol % represented by flexFreqLow - byte flexEthPctHigh; //Ethanol % represented by flexFreqHigh byte flexFuelLow; //Fuel % to be used for the lowest ethanol reading (Typically 100%) byte flexFuelHigh; //Fuel % to be used for the highest ethanol reading (Typically 163%) byte flexAdvLow; //Additional advance (in degrees) at lowest ethanol reading (Typically 0) diff --git a/reference/speeduino.ini b/reference/speeduino.ini index 0dff4aa..7d33d7c 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -208,14 +208,14 @@ page = 2 oddfire2 = scalar, U16, 51, "deg", 1.0, 0.0, 0.0, 720, 0 ; * ( 2 byte) oddfire3 = scalar, U16, 53, "deg", 1.0, 0.0, 0.0, 720, 0 ; * ( 2 byte) oddfire4 = scalar, U16, 55, "deg", 1.0, 0.0, 0.0, 720, 0 ; * ( 2 byte) - - flexEthPctLow = scalar, U08, 57, "%", 1.0, 0.0, 0.0, 250.0, 0 - flexEthPctHigh= scalar, U08, 58, "%", 1.0, 0.0, 0.0, 250.0, 0 - flexFuelLow = scalar, U08, 59, "%", 1.0, 0.0, 0.0, 250.0, 0 - flexFuelHigh = scalar, U08, 60, "%", 1.0, 0.0, 0.0, 250.0, 0 - flexAdvLow = scalar, U08, 61, "Deg", 1.0, 0.0, 0.0, 250.0, 0 - flexAdvHigh = scalar, U08, 62, "Deg", 1.0, 0.0, 0.0, 250.0, 0 - unused2-63 = scalar, U08, 63, "RPM", 100.0, 0.0, 100, 25500, 0 + + flexFuelLow = scalar, U08, 57, "%", 1.0, 0.0, 0.0, 250.0, 0 + flexFuelHigh = scalar, U08, 58, "%", 1.0, 0.0, 0.0, 250.0, 0 + flexAdvLow = scalar, U08, 59, "Deg", 1.0, 0.0, 0.0, 250.0, 0 + flexAdvHigh = scalar, U08, 60, "Deg", 1.0, 0.0, 0.0, 250.0, 0 + unused2-61 = scalar, U08, 61, "RPM", 100.0, 0.0, 100, 25500, 0 + unused2-62 = scalar, U08, 62, "RPM", 100.0, 0.0, 100, 25500, 0 + unused2-63 = scalar, U08, 63, "RPM", 100.0, 0.0, 100, 25500, 0 ;-------------------------------------------------- ;Start Ignition table (Page 3) @@ -737,10 +737,8 @@ menuDialog = main includeAFR = "When enabled, the current AFR reading is incorporated directly in the pulsewidth calculation as a percentage of the current target ratio. VE table must be retuned when this value is changed. " flexEnabled = "Turns on readings from the Flex sensor and enables the below adjustments" - flexFreqLow = "The lowest valid frequency of the sensor (50Hz for standard GM/Continental sensor)" - flexFreqHigh = "The highest valid frequency of the sensor (150Hz for standard GM/Continental sensor)" - flexEthPctLow = "Ethanol % represented by Low frequency above (0% for GM Sensors)" - flexEthPctHigh = "Ethanol % represented by High frequency above (100% for GM Sensors)" + flexFreqLow = "The frequency of the sensor at 0% ethanol (50Hz for standard GM/Continental sensor)" + flexFreqHigh = "The frequency of the sensor at 100% ethanol (150Hz for standard GM/Continental sensor)" flexFuelLow = "Fuel % to be used for the lowest ethanol reading (Typically 100%. ie No adjustment)" flexFuelHigh = "Fuel % to be used for the highest ethanol reading (Typically 163% for 100% ethanol)" flexAdvLow = "Additional advance (in degrees) at lowest ethanol reading (Typically 0)" @@ -797,7 +795,6 @@ menuDialog = main dialog = flexn, "" field = "#Spark/Fuel" field = "Sensor Frequency" - field = "Ethanol Mix" field = "Fuel Multiplier%" field = "Additional advance" #field = "#Temp Sense" @@ -807,7 +804,6 @@ menuDialog = main dialog = flexl, "" field = "Low" field = "", flexFreqLow, { flexEnabled } - field = "", flexEthPctLow, { flexEnabled } field = "", flexFuelLow, { flexEnabled } field = "", flexAdvLow, { flexEnabled } #field = "Low" @@ -817,7 +813,6 @@ menuDialog = main dialog = flexh, "" field = "High" field = "", flexFreqHigh, { flexEnabled } - field = "", flexEthPctHigh, { flexEnabled } field = "", flexFuelHigh, { flexEnabled } field = "", flexAdvHigh, { flexEnabled } #field = "High" diff --git a/speeduino.ino b/speeduino.ino index f7e8f9c..af9845e 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -259,7 +259,7 @@ void setup() if(configPage1.flexEnabled) { attachInterrupt(digitalPinToInterrupt(pinFlex), flexPulse, RISING); - currentStatus.flex = 0; + currentStatus.ethanolPct = 0; } //Once the configs have been loaded, a number of one time calculations can be completed diff --git a/timers.ino b/timers.ino index f090129..a93cfc1 100644 --- a/timers.ino +++ b/timers.ino @@ -113,7 +113,7 @@ unsigned long targetTachoPulseTime; { if(flexCounter < 50) { - currentStatus.flex = 0; //Standard GM Continental sensor reads from 50Hz (0 ethanol) to 150Hz (Pure ethanol). Subtracting 50 from the frequency therefore gives the ethanol percentage. + currentStatus.ethanolPct = 0; //Standard GM Continental sensor reads from 50Hz (0 ethanol) to 150Hz (Pure ethanol). Subtracting 50 from the frequency therefore gives the ethanol percentage. flexCounter = 0; } else if (flexCounter > 151) //1 pulse buffer @@ -121,19 +121,19 @@ unsigned long targetTachoPulseTime; if(flexCounter < 169) { - currentStatus.flex = 100; //Standard GM Continental sensor reads from 50Hz (0 ethanol) to 150Hz (Pure ethanol). Subtracting 50 from the frequency therefore gives the ethanol percentage. + currentStatus.ethanolPct = 100; flexCounter = 0; } else { //This indicates an error condition. Spec of the sensor is that errors are above 170Hz) - currentStatus.flex = 0; + currentStatus.ethanolPct = 0; flexCounter = 0; } } else { - currentStatus.flex = flexCounter - 50; //Standard GM Continental sensor reads from 50Hz (0 ethanol) to 150Hz (Pure ethanol). Subtracting 50 from the frequency therefore gives the ethanol percentage. + currentStatus.ethanolPct = flexCounter - 50; //Standard GM Continental sensor reads from 50Hz (0 ethanol) to 150Hz (Pure ethanol). Subtracting 50 from the frequency therefore gives the ethanol percentage. flexCounter = 0; }