Move toothDeltaT out of interrupts

This commit is contained in:
Josh Stewart 2015-11-08 22:56:54 +11:00
parent 48c5350d63
commit 2517d97555
3 changed files with 5 additions and 10 deletions

View File

@ -13,7 +13,6 @@ 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 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)

View File

@ -24,7 +24,7 @@ toothLastToothTime - The time (In uS) that the last primary tooth was 'seen'
inline void addToothLogEntry(unsigned long time)
{
//High speed tooth logging history
toothHistory[toothHistoryIndex] = curGap;
toothHistory[toothHistoryIndex] = time;
if(toothHistoryIndex == (TOOTH_LOG_BUFFER-1))
{ toothHistoryIndex = 0; BIT_CLEAR(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); } //The tooth log ready bit is cleared to ensure that we only get a set of concurrent values.
else
@ -96,7 +96,6 @@ void triggerPri_missingTooth()
startRevolutions++; //Counter
}
toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
}
@ -160,7 +159,6 @@ void triggerPri_DualWheel()
addToothLogEntry(curGap);
toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
}
@ -240,7 +238,6 @@ void triggerPri_BasicDistributor()
addToothLogEntry(curGap);
toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime -toothLastToothTime); //Positive value = accleration, Negative = decceleration
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
}
@ -308,7 +305,6 @@ void triggerPri_GM7X()
}
}
toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
}
@ -396,7 +392,7 @@ void triggerPri_4G63()
//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;
}
@ -595,7 +591,6 @@ void triggerPri_Jeep2000()
addToothLogEntry(curGap);
toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
}

View File

@ -730,12 +730,13 @@ 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(triggerToothAngle > 0)
if(triggerToothAngle > 0 && toothHistoryIndex >= 3) //toothHistoryIndex must be greater than or equal to 3 as we need the last 3 entries
{
long toothDeltaT = toothHistory[toothHistoryIndex-1] - toothHistory[toothHistoryIndex]; //Positive value = accleration, Negative = decceleration
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 */
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 / )
}