Final sequential fixes/tweaks

This commit is contained in:
Josh Stewart 2016-11-09 12:57:04 +11:00
parent de3ee45f7f
commit 1afb70d1da
3 changed files with 15 additions and 7 deletions

View File

@ -91,7 +91,7 @@ void triggerSetup_missingTooth()
triggerFilterTime = (int)(1000000 / (MAX_RPM / 60 * configPage2.triggerTeeth)); //Trigger filter time is the shortest possible time (in uS) that there can be between crank teeth (ie at max RPM). Any pulses that occur faster than this time will be disgarded as noise
secondDerivEnabled = false;
decoderIsSequential = false;
checkSyncToothCount = (configPage2.triggerTeeth * 3) >> 1; //50% of the total teeth.
checkSyncToothCount = (configPage2.triggerTeeth) >> 1; //50% of the total teeth.
MAX_STALL_TIME = (3333UL * triggerToothAngle * (configPage2.triggerMissingTeeth + 1)); //Minimum 50rpm. (3333uS is the time per degree at 50rpm)
}
@ -107,7 +107,7 @@ void triggerPri_missingTooth()
addToothLogEntry(curGap);
if(toothCurrentCount > checkSyncToothCount || !currentStatus.hasSync)
//if(toothCurrentCount > checkSyncToothCount || !currentStatus.hasSync)
{
//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
@ -138,7 +138,8 @@ void triggerPri_missingTooth()
void triggerSec_missingTooth()
{
if(!currentStatus.hasSync) { revolutionOne = 0; } //Sequential revolution reset
//TODO: This should really have filtering enabled on the secondary input.
revolutionOne = 1;
}
int getRPM_missingTooth()
@ -151,10 +152,12 @@ int getCrankAngle_missingTooth(int timePerDegree)
//This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees)
unsigned long tempToothLastToothTime;
int tempToothCurrentCount;
bool tempRevolutionOne;
//Grab some variables that are used in the trigger code and assign them to temp variables.
noInterrupts();
tempToothCurrentCount = toothCurrentCount;
tempToothLastToothTime = toothLastToothTime;
tempRevolutionOne = revolutionOne;
interrupts();
int crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle + configPage2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth.
@ -164,7 +167,7 @@ int getCrankAngle_missingTooth(int timePerDegree)
else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; }
//Sequential check (simply sets whether we're on the first or 2nd revoltuion of the cycle)
if (revolutionOne) { crankAngle += 360; }
if (tempRevolutionOne) { crankAngle += 360; }
if (crankAngle >= 720) { crankAngle -= 720; }
else if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; }
@ -234,7 +237,7 @@ void triggerSec_DualWheel()
currentStatus.hasSync = true;
}
if(!currentStatus.hasSync) { revolutionOne = 0; } //Sequential revolution reset
revolutionOne = 1; //Sequential revolution reset
}
int getRPM_DualWheel()
@ -249,10 +252,12 @@ int getCrankAngle_DualWheel(int timePerDegree)
//This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees)
unsigned long tempToothLastToothTime;
int tempToothCurrentCount;
bool tempRevolutionOne;
//Grab some variables that are used in the trigger code and assign them to temp variables.
noInterrupts();
tempToothCurrentCount = toothCurrentCount;
tempToothLastToothTime = toothLastToothTime;
tempRevolutionOne = revolutionOne;
interrupts();
//Handle case where the secondary tooth was the last one seen
@ -265,7 +270,7 @@ int getCrankAngle_DualWheel(int timePerDegree)
else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; }
//Sequential check (simply sets whether we're on the first or 2nd revoltuion of the cycle)
if (revolutionOne) { crankAngle += 360; }
if (tempRevolutionOne) { crankAngle += 360; }
if (crankAngle >= 720) { crankAngle -= 720; }
if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; }

View File

@ -328,6 +328,7 @@ void setup()
if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering)
else { attachInterrupt(triggerInterrupt, trigger, FALLING); }
attachInterrupt(triggerInterrupt2, triggerSec_missingTooth, RISING);
break;
case 1:
@ -1056,6 +1057,7 @@ void loop()
int PWdivTimerPerDegree = div(currentStatus.PW1, timePerDegree).quot; //How many crank degrees the calculated PW will take at the current speed
injector1StartAngle = configPage1.inj1Ang - ( PWdivTimerPerDegree ); //This is a little primitive, but is based on the idea that all fuel needs to be delivered before the inlet valve opens. See http://www.extraefi.co.uk/sequential_fuel.html for more detail
if(injector1StartAngle < 0) {injector1StartAngle += CRANK_ANGLE_MAX_INJ;}
//Repeat the above for each cylinder
switch (configPage1.nCylinders)
{
@ -1332,7 +1334,7 @@ void loop()
if (crankAngle > CRANK_ANGLE_MAX_IGN ) { crankAngle -= 360; }
//fixedCrankingOverride is used to extend the dwell during cranking so that the decoder can trigger the spark upon seeing a certain tooth. Currently only available on the basic distributor and 4g63 decoders.
if ( configPage2.ignCranklock && BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) { fixedCrankingOverride = currentStatus.dwell; }
if ( configPage2.ignCranklock && BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK)) { fixedCrankingOverride = currentStatus.dwell * 2; }
else { fixedCrankingOverride = 0; }
//Perform an initial check to see if the ignition is turned on (Ignition only turns on after a preset number of cranking revolutions and:

View File

@ -45,6 +45,7 @@ void oneMSInterval() //Most ARM chips can simply call a function
//Increment Loop Counters
loop250ms++;
loopSec++;
//Overdwell check
targetOverdwellTime = micros() - (1000 * configPage2.dwellLimit); //Set a target time in the past that all coil charging must have begun after. If the coil charge began before this time, it's been running too long