updated to fix resync and improve sync fail reporting (#1047)
Fixes #801
This commit is contained in:
parent
9a1c3e30c3
commit
d89cd532f9
|
@ -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)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
//If no teeth have passed, we can't do anything
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
if(toothCurrentCount > 13) //can't have more than 12 teeth so have lost sync
|
||||||
//Can't do anything with a single pulse from the cam either (We need either 2 or 3 pulses)
|
{
|
||||||
secondaryToothCount = 0;
|
toothCurrentCount = 0;
|
||||||
break;
|
currentStatus.hasSync = false;
|
||||||
|
currentStatus.syncLossCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
case 2:
|
//Sync is determined by counting the number of cam teeth that have passed between the crank teeth
|
||||||
toothCurrentCount = 8;
|
switch(secondaryToothCount)
|
||||||
//currentStatus.hasSync = true;
|
{
|
||||||
secondaryToothCount = 0;
|
case 0:
|
||||||
break;
|
//If no teeth have passed, we can't do anything
|
||||||
|
break;
|
||||||
|
|
||||||
case 3:
|
case 1:
|
||||||
//toothCurrentCount = 2;
|
//Can't do anything with a single pulse from the cam either (We need either 2 or 3 pulses)
|
||||||
if( toothCurrentCount == 2)
|
if(toothCurrentCount == 5 || toothCurrentCount == 11)
|
||||||
{
|
{ currentStatus.hasSync = true; }
|
||||||
currentStatus.hasSync = true;
|
else
|
||||||
}
|
|
||||||
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(); }
|
currentStatus.hasSync = false;
|
||||||
else if( (toothCurrentCount == 4) || (toothCurrentCount == 10) ) { endCoil2Charge(); endCoil4Charge(); }
|
currentStatus.syncLossCounter++;
|
||||||
|
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%
|
||||||
}
|
}
|
||||||
|
secondaryToothCount = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
if ( toothCurrentCount > 12 ) //2 complete crank revolutions
|
case 2:
|
||||||
|
if (toothCurrentCount == 8)
|
||||||
|
{ currentStatus.hasSync = true; }
|
||||||
|
else
|
||||||
{
|
{
|
||||||
toothCurrentCount = 1;
|
currentStatus.hasSync = false;
|
||||||
toothOneMinusOneTime = toothOneTime;
|
currentStatus.syncLossCounter++;
|
||||||
toothOneTime = curTime;
|
toothCurrentCount = 8;
|
||||||
currentStatus.startRevolutions++; //Counter
|
|
||||||
}
|
}
|
||||||
|
secondaryToothCount = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
//Set the last angle between teeth for better calc accuracy
|
case 3:
|
||||||
if(toothCurrentCount == 1) { triggerToothAngle = 55; } //Special case for tooth 1
|
if( toothCurrentCount == 2)
|
||||||
else if(toothCurrentCount == 2) { triggerToothAngle = 93; } //Special case for tooth 2
|
{ currentStatus.hasSync = true; }
|
||||||
else { triggerToothAngle = toothAngles[(toothCurrentCount-1)] - toothAngles[(toothCurrentCount-2)]; }
|
else
|
||||||
BIT_SET(decoderState, BIT_DECODER_TOOTH_ANG_CORRECT);
|
|
||||||
|
|
||||||
|
|
||||||
//NEW IGNITION MODE
|
|
||||||
if( (configPage2.perToothIgn == true) && (!BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) )
|
|
||||||
{
|
{
|
||||||
int16_t crankAngle = toothAngles[(toothCurrentCount - 1)] + configPage4.triggerAngle;
|
currentStatus.hasSync = false;
|
||||||
if( (configPage4.sparkMode != IGN_MODE_SEQUENTIAL) )
|
currentStatus.syncLossCounter++;
|
||||||
{
|
toothCurrentCount = 2;
|
||||||
crankAngle = ignitionLimits( toothAngles[(toothCurrentCount-1)] );
|
|
||||||
|
|
||||||
//Handle non-sequential tooth counts
|
|
||||||
if( (configPage4.sparkMode != IGN_MODE_SEQUENTIAL) && (toothCurrentCount > 6) ) { checkPerToothTiming(crankAngle, (toothCurrentCount-6) ); }
|
|
||||||
else { checkPerToothTiming(crankAngle, toothCurrentCount); }
|
|
||||||
}
|
|
||||||
else{ checkPerToothTiming(crankAngle, toothCurrentCount); }
|
|
||||||
}
|
}
|
||||||
//Recalc the new filter value
|
secondaryToothCount = 0;
|
||||||
//setFilter(curGap);
|
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(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
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) )
|
||||||
|
{
|
||||||
|
crankAngle = ignitionLimits( toothAngles[(toothCurrentCount-1)] );
|
||||||
|
|
||||||
|
//Handle non-sequential tooth counts
|
||||||
|
if( (configPage4.sparkMode != IGN_MODE_SEQUENTIAL) && (toothCurrentCount > 6) ) { checkPerToothTiming(crankAngle, (toothCurrentCount-6) ); }
|
||||||
|
else { checkPerToothTiming(crankAngle, toothCurrentCount); }
|
||||||
|
}
|
||||||
|
else{ checkPerToothTiming(crankAngle, toothCurrentCount); }
|
||||||
|
}
|
||||||
|
//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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue