mirror of https://github.com/rusefi/speeduino.git
Move toothDeltaT out of interrupts
This commit is contained in:
parent
48c5350d63
commit
2517d97555
|
@ -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 long toothOneMinusOneTime = 0; //The 2nd to last time (micros()) that tooth 1 last triggered
|
||||||
volatile unsigned int toothHistory[TOOTH_LOG_BUFFER];
|
volatile unsigned int toothHistory[TOOTH_LOG_BUFFER];
|
||||||
volatile unsigned int toothHistoryIndex = 0;
|
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 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)
|
volatile unsigned long secondaryLastToothTime = 0; //The time (micros()) that the last tooth was registered (Cam input)
|
||||||
|
|
|
@ -24,7 +24,7 @@ toothLastToothTime - The time (In uS) that the last primary tooth was 'seen'
|
||||||
inline void addToothLogEntry(unsigned long time)
|
inline void addToothLogEntry(unsigned long time)
|
||||||
{
|
{
|
||||||
//High speed tooth logging history
|
//High speed tooth logging history
|
||||||
toothHistory[toothHistoryIndex] = curGap;
|
toothHistory[toothHistoryIndex] = time;
|
||||||
if(toothHistoryIndex == (TOOTH_LOG_BUFFER-1))
|
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.
|
{ 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
|
else
|
||||||
|
@ -96,7 +96,6 @@ void triggerPri_missingTooth()
|
||||||
startRevolutions++; //Counter
|
startRevolutions++; //Counter
|
||||||
}
|
}
|
||||||
|
|
||||||
toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration
|
|
||||||
toothLastMinusOneToothTime = toothLastToothTime;
|
toothLastMinusOneToothTime = toothLastToothTime;
|
||||||
toothLastToothTime = curTime;
|
toothLastToothTime = curTime;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +159,6 @@ void triggerPri_DualWheel()
|
||||||
|
|
||||||
addToothLogEntry(curGap);
|
addToothLogEntry(curGap);
|
||||||
|
|
||||||
toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration
|
|
||||||
toothLastMinusOneToothTime = toothLastToothTime;
|
toothLastMinusOneToothTime = toothLastToothTime;
|
||||||
toothLastToothTime = curTime;
|
toothLastToothTime = curTime;
|
||||||
}
|
}
|
||||||
|
@ -240,7 +238,6 @@ void triggerPri_BasicDistributor()
|
||||||
|
|
||||||
addToothLogEntry(curGap);
|
addToothLogEntry(curGap);
|
||||||
|
|
||||||
toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime -toothLastToothTime); //Positive value = accleration, Negative = decceleration
|
|
||||||
toothLastMinusOneToothTime = toothLastToothTime;
|
toothLastMinusOneToothTime = toothLastToothTime;
|
||||||
toothLastToothTime = curTime;
|
toothLastToothTime = curTime;
|
||||||
}
|
}
|
||||||
|
@ -308,7 +305,6 @@ void triggerPri_GM7X()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration
|
|
||||||
toothLastMinusOneToothTime = toothLastToothTime;
|
toothLastMinusOneToothTime = toothLastToothTime;
|
||||||
toothLastToothTime = curTime;
|
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
|
//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; }
|
if(toothCurrentCount == 1 || toothCurrentCount == 3) { triggerToothAngle = 70; }
|
||||||
else { triggerToothAngle = 110; }
|
else { triggerToothAngle = 110; }
|
||||||
toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration
|
|
||||||
toothLastMinusOneToothTime = toothLastToothTime;
|
toothLastMinusOneToothTime = toothLastToothTime;
|
||||||
toothLastToothTime = curTime;
|
toothLastToothTime = curTime;
|
||||||
}
|
}
|
||||||
|
@ -595,7 +591,6 @@ void triggerPri_Jeep2000()
|
||||||
|
|
||||||
addToothLogEntry(curGap);
|
addToothLogEntry(curGap);
|
||||||
|
|
||||||
toothDeltaT = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration
|
|
||||||
toothLastMinusOneToothTime = toothLastToothTime;
|
toothLastMinusOneToothTime = toothLastToothTime;
|
||||||
toothLastToothTime = curTime;
|
toothLastToothTime = curTime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -730,8 +730,9 @@ void loop()
|
||||||
//We use a 1st Deriv accleration prediction, but only when there is an even spacing between primary sensor teeth
|
//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
|
//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
|
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 / )
|
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 / )
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue