From a8e7066b41c40ac10f089958dc9dd98c8ac1f0fc Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Tue, 17 Feb 2015 16:31:26 +1100 Subject: [PATCH] Fixes and performance improvements to TAE --- corrections.h | 2 -- corrections.ino | 16 ++++++++++------ globals.h | 2 ++ reference/speeduino 0.2.ini | 6 +++--- speeduino.ino | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/corrections.h b/corrections.h index 0fd54ba8..53442572 100644 --- a/corrections.h +++ b/corrections.h @@ -5,8 +5,6 @@ All functions in the gamma file return #ifndef CORRECTIONS_H #define CORRECTIONS_H -//static byte numCorrections = 2; - byte correctionsTotal(); byte correctionWUE(); //Warmup enrichment byte correctionASE(); //After Start Enrichment diff --git a/corrections.ino b/corrections.ino index 78dcbc6b..f244dec2 100644 --- a/corrections.ino +++ b/corrections.ino @@ -97,17 +97,21 @@ byte correctionAccel() return 100; } //Enrichment still needs to keep running. Simply return the total TAE amount - return 100 + currentStatus.TAEamount; + return currentStatus.TAEamount; } - //If TAE isn't currently turned on, need to check whether it needs to be turned on - int rateOfChange = ldiv(1000000, (currentLoopTime - previousLoopTime)).quot * (currentStatus.TPS - currentStatus.TPSlast); //This is the % per second that the TPS has moved - currentStatus.tpsDOT = divs10(rateOfChange); //The TAE bins are divided by 10 in order to allow them to be stored in a byte. + //Check for deceleration (Deceleration adjustment not yet supported) + if (currentStatus.TPS < currentStatus.TPSlast) { return 100; } - if (currentStatus.tpsDOT > (configPage1.tpsThresh * 10)) + //If TAE isn't currently turned on, need to check whether it needs to be turned on + int rateOfChange = ldiv(1000000, (currentStatus.TPS_time - currentStatus.TPSlast_time)).quot * (currentStatus.TPS - currentStatus.TPSlast); //This is the % per second that the TPS has moved + //currentStatus.tpsDOT = divs10(rateOfChange); //The TAE bins are divided by 10 in order to allow them to be stored in a byte. + currentStatus.tpsDOT = rateOfChange / 10; + + if (rateOfChange > configPage1.tpsThresh) { BIT_SET(currentStatus.engine, BIT_ENGINE_ACC); //Mark accleration enrichment as active. - currentStatus.TAEEndTime = micros() + (configPage1.taeTime * 100); //Set the time in the future where the enrichment will be turned off. taeTime is stored as mS * 10, so multiply it by 100 to get it in uS + currentStatus.TAEEndTime = micros() + ((unsigned long)configPage1.taeTime * 10000); //Set the time in the future where the enrichment will be turned off. taeTime is stored as mS / 10, so multiply it by 100 to get it in uS return 100 + table2D_getValue(taeTable, currentStatus.tpsDOT); } diff --git a/globals.h b/globals.h index a6d6207c..9bbadadf 100644 --- a/globals.h +++ b/globals.h @@ -48,6 +48,8 @@ struct statuses { byte MAP; byte TPS; //The current TPS reading (0% - 100%) byte TPSlast; //The previous TPS reading + unsigned long TPS_time; //The time the TPS sample was taken + unsigned long TPSlast_time; //The time the previous TPS sample was taken byte tpsADC; //0-255 byte representation of the TPS byte tpsDOT; byte VE; diff --git a/reference/speeduino 0.2.ini b/reference/speeduino 0.2.ini index d851b71f..4f9588a6 100644 --- a/reference/speeduino 0.2.ini +++ b/reference/speeduino 0.2.ini @@ -96,7 +96,7 @@ page = 1 unused97 = scalar, U08, 97, "ms", 0.1, 0.0, 0.0, 25.5, 1 taeColdA = scalar, U08, 98, "ms", 0.1, 0.0, 0.0, 25.5, 1 tpsThresh = scalar, U08, 99, "%/s", 1.0, 0.0, 0.0, 255, 0 - taeTime = scalar, U08, 100, "ms", 0.1, 0.0, 0.0, 25.5, 1 + taeTime = scalar, U08, 100, "ms", 10, 0.0, 0.0, 2550, 0 tdePct = scalar, U08, 101, "%", 1.0, 0.0, 0.0, 255, 0 unused102 = scalar, U08, 102, "ms", 0.1, 0.0, 0.0, 25.5, 1 unused103 = scalar, U08, 103, "ms", 0.1, 0.0, 0.0, 25.5, 1 @@ -902,7 +902,7 @@ help = helpEnrichments, "Enrichments Help" afrTarget = scalar, U08, 19 "O2", 0.100, 0.000 #blank2 = scalar, U08, 20 pulseWidth = scalar, U08, 20, "ms", 0.2, 0.000 - TPSdot = scalar, U08, 21, "%/s", 0.100, 0.000 + TPSdot = scalar, U08, 21, "%/s", 10.00, 0.000 advance = scalar, U08, 22, "deg", 1.000, 0.000 tps = scalar, U08, 23, "%", 1.000, 0.000 loopsPerSecond = scalar, S16, 24, "loops", 1.000, 0.000 @@ -998,7 +998,7 @@ help = helpEnrichments, "Enrichments Help" entry = warmupEnrich, "Gwarm", int, "%d" entry = baroCorrection, "Gbaro", int, "%d" entry = gammaEnrich, "Gammae", int, "%d" - entry = accDecEnrich, "TPSacc", int, "%d" + entry = accelEnrich, "TPSacc", int, "%d" entry = veCurr, "VE", int, "%d" entry = pulseWidth, "PW", float, "%.1f" entry = afrTarget, "AFR Target", int, "%d" diff --git a/speeduino.ino b/speeduino.ino index 1d50049f..21b32298 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -277,7 +277,7 @@ void loop() currentStatus.MAP = map(analogRead(pinMAP), 0, 1023, 10, 255); //Get the current MAP value //TPS setting to be performed every 16 loops (any faster and it can upset the TPSdot sampling time) - if ((mainLoopCount & 15) == 1) + if ((mainLoopCount & 31) == 1) { currentStatus.TPSlast = currentStatus.TPS; currentStatus.TPSlast_time = currentStatus.TPS_time;