From 4191e6e86580c990d9226dedaaa03ab927d98fc0 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Wed, 4 Nov 2015 21:49:37 +1100 Subject: [PATCH] Actually return a value when using the higher resolution cranking RPM --- decoders.h | 2 +- decoders.ino | 19 +++++++++++-------- speeduino.ino | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/decoders.h b/decoders.h index da140441..7495506f 100644 --- a/decoders.h +++ b/decoders.h @@ -13,7 +13,7 @@ volatile unsigned long toothOneTime = 0; //The time (micros()) that tooth 1 last volatile unsigned long toothOneMinusOneTime = 0; //The 2nd to last time (micros()) that tooth 1 last triggered volatile unsigned int toothHistory[TOOTH_LOG_BUFFER]; volatile unsigned int toothHistoryIndex = 0; -volatile long toothDeltaV; //Represents the change in time taken between the last 2 teeth compared to the previous 2. Positive value represents accleration, negative = deccleration +volatile long toothDeltaT; //Represents the change in time taken between the last 2 teeth compared to the previous 2. Positive value represents accleration, negative = deccleration volatile byte secondaryToothCount; //Used for identifying the current secondary (Usually cam) tooth for patterns with multiple secondary teeth volatile unsigned long secondaryLastToothTime = 0; //The time (micros()) that the last tooth was registered (Cam input) diff --git a/decoders.ino b/decoders.ino index 7d9ec04a..2e7021eb 100644 --- a/decoders.ino +++ b/decoders.ino @@ -96,7 +96,7 @@ void triggerPri_missingTooth() startRevolutions++; //Counter } - toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration + toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } @@ -160,7 +160,7 @@ void triggerPri_DualWheel() addToothLogEntry(curGap); - toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration + toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } @@ -239,14 +239,14 @@ void triggerPri_BasicDistributor() addToothLogEntry(curGap); - toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime -toothLastToothTime); //Positive value = accleration, Negative = decceleration + toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime -toothLastToothTime); //Positive value = accleration, Negative = decceleration toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } void triggerSec_BasicDistributor() { return; } //Not required int getRPM_BasicDistributor() { - if(currentStatus.RPM < configPage2.crankRPM) { crankingGetRPM((configPage1.nCylinders >> 1)); } + if(currentStatus.RPM < configPage2.crankRPM) { return crankingGetRPM((configPage1.nCylinders >> 1)); } else { return stdGetRPM(); } } int getCrankAngle_BasicDistributor(int timePerDegree) @@ -307,7 +307,7 @@ void triggerPri_GM7X() } } - toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration + toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } @@ -399,7 +399,10 @@ void triggerPri_4G63() addToothLogEntry(curGap); - toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration + //Whilst this is an uneven tooth pattern, if the specific angle between the last 2 teeth is specified, 1st deriv prediction can be used + if(toothCurrentCount == 1 || toothCurrentCount == 3) { triggerToothAngle = 70; } + else { triggerToothAngle = 110; } + toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } @@ -427,7 +430,7 @@ void triggerSec_4G63() int getRPM_4G63() { - if(currentStatus.RPM < configPage2.crankRPM) { crankingGetRPM(2); } + if(currentStatus.RPM < configPage2.crankRPM) { return crankingGetRPM(2); } else { return stdGetRPM(); } } int getCrankAngle_4G63(int timePerDegree) @@ -589,7 +592,7 @@ void triggerPri_Jeep2000() addToothLogEntry(curGap); - toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration + toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } diff --git a/speeduino.ino b/speeduino.ino index e2f9d633..686ad57a 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -730,7 +730,7 @@ void loop() //Any decoder that has uneven spacing has its triggerToothAngle set to 0 if(triggerToothAngle > 0) { - long toothAccel = toothDeltaV / triggerToothAngle; //An amount represengint the current acceleration or decceleration of the crank in degrees per uS per uS + long toothAccel = toothDeltaT / triggerToothAngle; //An amount represengint the current acceleration or decceleration of the crank in degrees per uS per uS timePerDegree = ldiv( 166666L, currentStatus.RPM ).quot + (toothAccel * (micros() - toothLastToothTime)); //There is a small amount of rounding in this calculation, however it is less than 0.001 of a uS (Faster as ldiv than / ) } else