updated to fix resync and improve sync fail reporting (#1047)

Fixes #801
This commit is contained in:
mike501 2023-05-13 06:54:05 +01:00 committed by GitHub
parent 9a1c3e30c3
commit d89cd532f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 107 additions and 83 deletions

View File

@ -2848,105 +2848,126 @@ void triggerSetup_Subaru67(void)
void triggerPri_Subaru67(void) void triggerPri_Subaru67(void)
{ {
curTime = micros(); curTime = micros();
//curGap = curTime - toothLastToothTime; curGap = curTime - toothLastToothTime;
//if ( curGap < triggerFilterTime ) { return; } if ( curGap < triggerFilterTime )
toothCurrentCount++; //Increment the tooth counter { return; }
toothSystemCount++; //Used to count the number of primary pulses that have occurred since the last secondary. Is part of the noise filtering system.
BIT_SET(decoderState, BIT_DECODER_VALID_TRIGGER); //Flag this pulse as being a valid trigger (ie that it passed filters)
toothLastMinusOneToothTime = toothLastToothTime; toothCurrentCount++; //Increment the tooth counter
toothLastToothTime = curTime; toothSystemCount++; //Used to count the number of primary pulses that have occurred since the last secondary. Is part of the noise filtering system.
BIT_SET(decoderState, BIT_DECODER_VALID_TRIGGER); //Flag this pulse as being a valid trigger (ie that it passed filters)
if ( (currentStatus.hasSync == false) || (configPage4.useResync == true) ) toothLastMinusOneToothTime = toothLastToothTime;
{ toothLastToothTime = curTime;
if(toothCurrentCount > 12) { toothCurrentCount = toothCurrentCount % 12; } //Because toothCurrentCount is not being reset when hitting tooth 1, we manually loop it here.
//Sync is determined by counting the number of cam teeth that have passed between the crank teeth
switch(secondaryToothCount) if(toothCurrentCount > 13) //can't have more than 12 teeth so have lost sync
{ {
case 0: toothCurrentCount = 0;
//If no teeth have passed, we can't do anything currentStatus.hasSync = false;
break; currentStatus.syncLossCounter++;
}
case 1: //Sync is determined by counting the number of cam teeth that have passed between the crank teeth
//Can't do anything with a single pulse from the cam either (We need either 2 or 3 pulses) switch(secondaryToothCount)
secondaryToothCount = 0; {
break; case 0:
//If no teeth have passed, we can't do anything
break;
case 2: case 1:
toothCurrentCount = 8; //Can't do anything with a single pulse from the cam either (We need either 2 or 3 pulses)
//currentStatus.hasSync = true; if(toothCurrentCount == 5 || toothCurrentCount == 11)
secondaryToothCount = 0; { currentStatus.hasSync = true; }
break; else
{
case 3: currentStatus.hasSync = false;
//toothCurrentCount = 2; currentStatus.syncLossCounter++;
if( toothCurrentCount == 2) toothCurrentCount = 5; // we don't know if its 5 or 11, but we'll be right 50% of the time and speed up geting sync 50%
{
currentStatus.hasSync = true;
}
secondaryToothCount = 0;
break;
default:
//Almost certainly due to noise or cranking stop/start
currentStatus.hasSync = false;
BIT_CLEAR(decoderState, BIT_DECODER_TOOTH_ANG_CORRECT);
currentStatus.syncLossCounter++;
secondaryToothCount = 0;
break;
}
}
//Check sync again
if ( currentStatus.hasSync == true )
{
//Locked timing during cranking. This is fixed at 10* BTDC.
if ( BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) && configPage4.ignCranklock)
{
if( (toothCurrentCount == 1) || (toothCurrentCount == 7) ) { endCoil1Charge(); endCoil3Charge(); }
else if( (toothCurrentCount == 4) || (toothCurrentCount == 10) ) { endCoil2Charge(); endCoil4Charge(); }
} }
secondaryToothCount = 0;
break;
if ( toothCurrentCount > 12 ) //2 complete crank revolutions case 2:
{ if (toothCurrentCount == 8)
toothCurrentCount = 1; { currentStatus.hasSync = true; }
toothOneMinusOneTime = toothOneTime; else
toothOneTime = curTime; {
currentStatus.startRevolutions++; //Counter currentStatus.hasSync = false;
currentStatus.syncLossCounter++;
toothCurrentCount = 8;
}
secondaryToothCount = 0;
break;
case 3:
if( toothCurrentCount == 2)
{ currentStatus.hasSync = true; }
else
{
currentStatus.hasSync = false;
currentStatus.syncLossCounter++;
toothCurrentCount = 2;
} }
secondaryToothCount = 0;
break;
//Set the last angle between teeth for better calc accuracy default:
if(toothCurrentCount == 1) { triggerToothAngle = 55; } //Special case for tooth 1 //Almost certainly due to noise or cranking stop/start
else if(toothCurrentCount == 2) { triggerToothAngle = 93; } //Special case for tooth 2 currentStatus.hasSync = false;
else { triggerToothAngle = toothAngles[(toothCurrentCount-1)] - toothAngles[(toothCurrentCount-2)]; } BIT_CLEAR(decoderState, BIT_DECODER_TOOTH_ANG_CORRECT);
BIT_SET(decoderState, BIT_DECODER_TOOTH_ANG_CORRECT); currentStatus.syncLossCounter++;
secondaryToothCount = 0;
break;
}
//Check sync again
if ( currentStatus.hasSync == true )
{
//Locked timing during cranking. This is fixed at 10* BTDC.
if ( BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) && configPage4.ignCranklock)
{
if( (toothCurrentCount == 1) || (toothCurrentCount == 7) ) { endCoil1Charge(); endCoil3Charge(); }
else if( (toothCurrentCount == 4) || (toothCurrentCount == 10) ) { endCoil2Charge(); endCoil4Charge(); }
}
if ( toothCurrentCount > 12 ) // done 720 degrees so increment rotation
{
toothCurrentCount = 1;
toothOneMinusOneTime = toothOneTime;
toothOneTime = curTime;
currentStatus.startRevolutions++; //Counter
}
//Set the last angle between teeth for better calc accuracy
if(toothCurrentCount == 1) { triggerToothAngle = 55; } //Special case for tooth 1
else if(toothCurrentCount == 2) { triggerToothAngle = 93; } //Special case for tooth 2
else { triggerToothAngle = toothAngles[(toothCurrentCount-1)] - toothAngles[(toothCurrentCount-2)]; }
BIT_SET(decoderState, BIT_DECODER_TOOTH_ANG_CORRECT);
//NEW IGNITION MODE //NEW IGNITION MODE
if( (configPage2.perToothIgn == true) && (!BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) ) if( (configPage2.perToothIgn == true) && (!BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) )
{
int16_t crankAngle = toothAngles[(toothCurrentCount - 1)] + configPage4.triggerAngle;
if( (configPage4.sparkMode != IGN_MODE_SEQUENTIAL) )
{ {
int16_t crankAngle = toothAngles[(toothCurrentCount - 1)] + configPage4.triggerAngle; crankAngle = ignitionLimits( toothAngles[(toothCurrentCount-1)] );
if( (configPage4.sparkMode != IGN_MODE_SEQUENTIAL) )
{
crankAngle = ignitionLimits( toothAngles[(toothCurrentCount-1)] );
//Handle non-sequential tooth counts //Handle non-sequential tooth counts
if( (configPage4.sparkMode != IGN_MODE_SEQUENTIAL) && (toothCurrentCount > 6) ) { checkPerToothTiming(crankAngle, (toothCurrentCount-6) ); } if( (configPage4.sparkMode != IGN_MODE_SEQUENTIAL) && (toothCurrentCount > 6) ) { checkPerToothTiming(crankAngle, (toothCurrentCount-6) ); }
else { checkPerToothTiming(crankAngle, toothCurrentCount); } else { checkPerToothTiming(crankAngle, toothCurrentCount); }
}
else{ checkPerToothTiming(crankAngle, toothCurrentCount); }
} }
//Recalc the new filter value else{ checkPerToothTiming(crankAngle, toothCurrentCount); }
//setFilter(curGap); }
} //Recalc the new filter value
//setFilter(curGap);
}
} }
void triggerSec_Subaru67(void) void triggerSec_Subaru67(void)
{ {
if( (toothSystemCount == 0) || (toothSystemCount == 3) ) if( ((toothSystemCount == 0) || (toothSystemCount == 3)) )
{ {
curTime2 = micros(); curTime2 = micros();
curGap2 = curTime2 - toothLastSecToothTime; curGap2 = curTime2 - toothLastSecToothTime;
@ -2956,14 +2977,14 @@ void triggerSec_Subaru67(void)
toothLastSecToothTime = curTime2; toothLastSecToothTime = curTime2;
secondaryToothCount++; secondaryToothCount++;
toothSystemCount = 0; toothSystemCount = 0;
if(secondaryToothCount > 1) if(secondaryToothCount > 1)
{ {
//Set filter at 25% of the current speed //Set filter at 25% of the current speed
//Note that this can only be set on the 2nd or 3rd cam tooth in each set. //Note that this can only be set on the 2nd or 3rd cam tooth in each set.
triggerSecFilterTime = curGap2 >> 2; triggerSecFilterTime = curGap2 >> 2;
} }
else { triggerSecFilterTime = 0; } //Filter disabled else { triggerSecFilterTime = 0; } //Filter disabled
} }
} }
@ -2974,7 +2995,10 @@ void triggerSec_Subaru67(void)
{ {
toothSystemCount = 0; toothSystemCount = 0;
secondaryToothCount = 1; secondaryToothCount = 1;
currentStatus.hasSync = false; // impossible to have more than 3 crank teeth between cam teeth - must have noise but can't have sync
currentStatus.syncLossCounter++;
} }
secondaryToothCount = 0;
} }
} }