Performance optimisation on the missing tooth decoder

This commit is contained in:
Josh Stewart 2019-11-12 15:28:43 +11:00
parent 554f58eb28
commit 3dd92b15fe
1 changed files with 85 additions and 71 deletions

View File

@ -279,6 +279,17 @@ void triggerPri_missingTooth()
//if(toothCurrentCount > checkSyncToothCount || currentStatus.hasSync == false)
if( (toothLastToothTime > 0) && (toothLastMinusOneToothTime > 0) )
{
bool isMissingTooth = false;
/*
Performance Optimisation:
Only need to try and detect the missing tooth if:
1. WE don't have sync yet
2. We have sync and are in the 2nd half of the wheel (Missing tooth will/should never occur in the first have)
3. RPM is under 2000. This is to ensure that we don't interfer with strange timing when cranking or idling. Optimisation not really required at these speeds anyway
*/
if( (currentStatus.hasSync == false) || (currentStatus.RPM < 2000) || (toothCurrentCount >= (triggerActualTeeth >> 1)) )
{
//Begin the missing tooth detection
//If the time between the current tooth and the last is greater than 1.5x the time between the last tooth and the tooth before that, we make the assertion that we must be at the first tooth after the gap
@ -290,6 +301,7 @@ void triggerPri_missingTooth()
if ( (curGap > targetGap) || (toothCurrentCount > triggerActualTeeth) )
{
//Missing tooth detected
isMissingTooth = true;
if( (toothCurrentCount < triggerActualTeeth) && (currentStatus.hasSync == true) )
{
//This occurs when we're at tooth #1, but haven't seen all the other teeth. This indicates a signal issue so we flag lost sync so this will attempt to resync on the next revolution.
@ -330,18 +342,20 @@ void triggerPri_missingTooth()
triggerToothAngleIsCorrect = false; //The tooth angle is double at this point
}
}
else
}
if(isMissingTooth == false)
{
//Filter can only be recalc'd for the regular teeth, not the missing one.
//Regular (non-missing) tooth
setFilter(curGap);
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
triggerToothAngleIsCorrect = true;
}
}
else
{
//We fall here on initial startup when enough teeth have not yet been seen
toothLastMinusOneToothTime = toothLastToothTime;
toothLastToothTime = curTime;
}