From 153aa32fb448532dec50a70178713953e1074139 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Fri, 27 Jan 2017 22:20:38 +1100 Subject: [PATCH] Faster 2nd derive prediction on RPM / crank angle --- globals.h | 4 ++-- speeduino.ino | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/globals.h b/globals.h index 7663f51..5c62cd5 100644 --- a/globals.h +++ b/globals.h @@ -145,7 +145,7 @@ struct statuses { long longRPM; int mapADC; long MAP; //Has to be a long for PID calcs (Boost control) - int baro; //Barometric pressure is simply the inital MAP reading, taken before the engine is running + byte baro; //Barometric pressure is simply the inital MAP reading, taken before the engine is running 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 @@ -197,7 +197,7 @@ struct statuses { int freeRAM; unsigned int clutchEngagedRPM; bool flatShiftingHard; - volatile byte startRevolutions = 0; //A counter for how many revolutions have been completed since sync was achieved. + volatile byte startRevolutions; //A counter for how many revolutions have been completed since sync was achieved. //Helpful bitwise operations: //Useful reference: http://playground.arduino.cc/Code/BitMath diff --git a/speeduino.ino b/speeduino.ino index 718068d..5eb253d 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -252,6 +252,7 @@ void setup() currentStatus.hasSync = false; currentStatus.runSecs = 0; currentStatus.secl = 0; + currentStatus.startRevolutions = 0; currentStatus.flatShiftingHard = false; currentStatus.launchingHard = false; triggerFilterTime = 0; //Trigger filter time is the shortest possible time (in uS) that there can be between crank teeth (ie at max RPM). Any pulses that occur faster than this time will be disgarded as noise. This is simply a default value, the actual values are set in the setup() functinos of each decoder @@ -978,6 +979,7 @@ void loop() //We use a 1st Deriv accleration prediction, but only when there is an even spacing between primary sensor teeth //Any decoder that has uneven spacing has its triggerToothAngle set to 0 if(secondDerivEnabled && toothHistoryIndex >= 3 && currentStatus.RPM < 2000) //toothHistoryIndex must be greater than or equal to 3 as we need the last 3 entries. Currently this mode only runs below 3000 rpm + //if(true) { //Only recalculate deltaV if the tooth has changed since last time (DeltaV stays the same until the next tooth) //if (deltaToothCount != toothCurrentCount) @@ -1012,7 +1014,8 @@ void loop() } else { - timePerDegree = ldiv( 166666L, currentStatus.RPM ).quot; //There is a small amount of rounding in this calculation, however it is less than 0.001 of a uS (Faster as ldiv than / ) + long rpm_adjust = ((long)(micros() - toothOneTime) * (long)currentStatus.rpmDOT) / 1000000; //Take into account any likely accleration that has occurred since the last full revolution completed + timePerDegree = ldiv( 166666L, currentStatus.RPM + rpm_adjust).quot; //There is a small amount of rounding in this calculation, however it is less than 0.001 of a uS (Faster as ldiv than / ) } //Check that the duty cycle of the chosen pulsewidth isn't too high. This is disabled at cranking @@ -1334,8 +1337,16 @@ void loop() //if (ignition1StartAngle <= crankAngle && ignition1.schedulesSet == 0) { ignition1StartAngle += CRANK_ANGLE_MAX_IGN; } if (ignition1StartAngle > crankAngle) { + /* + long some_time = ((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree); + long newRPM = (long)(some_time * currentStatus.rpmDOT) / 1000000L; + newRPM = currentStatus.RPM + (newRPM/2); + unsigned long timePerDegree_1 = ldiv( 166666L, newRPM).quot;*/ + setIgnitionSchedule1(ign1StartFunction, ((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree), + //some_time -some_accel, + //((unsigned long)((unsigned long)currentStatus.dwell* currentStatus.RPM) / newRPM) + fixedCrankingOverride, currentStatus.dwell + fixedCrankingOverride, ign1EndFunction );