Fix to low speed / small advance timing bug (CH 1/2 only)

This commit is contained in:
Josh Stewart 2015-12-09 12:13:23 +11:00
parent 756b048e5a
commit 23f10a918a
2 changed files with 15 additions and 11 deletions

View File

@ -448,7 +448,7 @@ void triggerSec_4G63()
int getRPM_4G63()
{
//During cranking, RPM is calculated 4 times per revolution, once for each rising/falling of the crank signal.
//Because these signals aren't even (Alternativing 110 and 70 degrees), this needs a special function
//Because these signals aren't even (Alternating 110 and 70 degrees), this needs a special function
if(currentStatus.RPM < configPage2.crankRPM)
{
int tempToothAngle;
@ -461,7 +461,8 @@ int getRPM_4G63()
}
else { return stdGetRPM(); }
}
int getCrankAngle_4G63(int timePerDegree)
int getCrankAngle_4G63(int timePerDegree)
{
if(!currentStatus.hasSync) { return 0;}
//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)
@ -475,11 +476,11 @@ int getRPM_4G63()
int crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle; //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was.
//Estimate the number of degrees travelled since the last tooth}
long elapsedTime = micros() - tempToothLastToothTime;
if(elapsedTime < SHRT_MAX ) { crankAngle += div((int)elapsedTime, timePerDegree).quot; } //This option is much faster, but only available for smaller values of elapsedTime
else { crankAngle += ldiv(elapsedTime, timePerDegree).quot; }
if (crankAngle >= 720) { crankAngle -= 720; }
if (crankAngle > 360) { crankAngle -= 360; }
if (crankAngle < 0) { crankAngle += 360; }

View File

@ -731,10 +731,10 @@ void loop()
//How fast are we going? Need to know how long (uS) it will take to get from one tooth to the next. We then use that to estimate how far we are between the last tooth and the next one
//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
if(secondDerivEnabled && toothHistoryIndex >= 3 && currentStatus.RPM < 2000 ) //toothHistoryIndex must be greater than or equal to 3 as we need the last 3 entries. Currently this mode only runs below 3000 rpm
if(secondDerivEnabled && toothHistoryIndex >= 3 && currentStatus.RPM < 2000) //toothHistoryIndex must be greater than or equal to 3 as we need the last 3 entries. Currently this mode only runs below 3000 rpm
{
//Only recalculate deltaV if the tooth has changed since last time (DeltaV stays the same until the next tooth)
if (deltaToothCount != toothCurrentCount)
//if (deltaToothCount != toothCurrentCount)
{
deltaToothCount = toothCurrentCount;
int angle1, angle2; //These represent the crank angles that are travelled for the last 2 pulses
@ -990,9 +990,9 @@ void loop()
//if ((ignition1StartAngle > crankAngle) == 0)
//if ((ignition1StartAngle < crankAngle))
{
long ignition1StartTime;
unsigned long ignition1StartTime = 0;
if(ignition1StartAngle > crankAngle) { ignition1StartTime = ((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree); }
else if (ignition1StartAngle < crankAngle) { ignition1StartTime = ((long)(360 - crankAngle + ignition1StartAngle) * (long)timePerDegree); }
//else if (ignition1StartAngle < crankAngle) { ignition1StartTime = ((unsigned long)(360 - crankAngle + ignition1StartAngle) * (unsigned long)timePerDegree); }
else { ignition1StartTime = 0; }
if(ignition1StartTime > 0) {
@ -1008,18 +1008,21 @@ void loop()
if( tempCrankAngle < 0) { tempCrankAngle += 360; }
tempStartAngle = ignition2StartAngle - channel2IgnDegrees;
if ( tempStartAngle < 0) { tempStartAngle += 360; }
if ( (tempStartAngle > tempCrankAngle) && ign2LastRev != startRevolutions)
//if ( (tempStartAngle > tempCrankAngle) && ign2LastRev != startRevolutions)
//if ( ign2LastRev != startRevolutions )
{
unsigned long ignition2StartTime;
long ignition2StartTime = 0;
if(tempStartAngle > tempCrankAngle) { ignition2StartTime = ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree); }
else { ignition2StartTime = ((unsigned long)(360 - tempCrankAngle + tempStartAngle) * (unsigned long)timePerDegree); }
//else if (tempStartAngle < tempCrankAngle) { ignition2StartTime = ((long)(360 - tempCrankAngle + tempStartAngle) * (long)timePerDegree); }
else { ignition2StartTime = 0; }
if(ignition2StartTime > 0) {
setIgnitionSchedule2(ign2StartFunction,
((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree),
ignition2StartTime,
currentStatus.dwell,
ign2EndFunction
);
}
}
tempCrankAngle = crankAngle - channel3IgnDegrees;