Fix for sequential ignition timing issue (No spark under some conditions)

This commit is contained in:
Josh Stewart 2016-11-21 22:06:41 +11:00
parent 4bfab2e479
commit 8b551e6506
3 changed files with 16 additions and 16 deletions

View File

@ -171,7 +171,7 @@ int getCrankAngle_missingTooth(int timePerDegree)
if (crankAngle >= 720) { crankAngle -= 720; }
else if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; }
if (crankAngle < 0) { crankAngle += 360; }
if (crankAngle < 0) { crankAngle += CRANK_ANGLE_MAX; }
return crankAngle;
}
@ -274,7 +274,7 @@ int getCrankAngle_DualWheel(int timePerDegree)
if (crankAngle >= 720) { crankAngle -= 720; }
if (crankAngle > CRANK_ANGLE_MAX) { crankAngle -= CRANK_ANGLE_MAX; }
if (crankAngle < 0) { crankAngle += 360; }
if (crankAngle < 0) { crankAngle += CRANK_ANGLE_MAX; }
return crankAngle;
}

View File

@ -237,13 +237,14 @@ void setIgnitionSchedule1(void (*startCallback)(), unsigned long timeout, unsign
ignitionSchedule1.duration = duration;
//As the timer is ticking every 4uS (Time per Tick = (Prescale)*(1/Frequency))
if (timeout > 262140) { timeout = 262100; } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
if (timeout > 262140) { timeout = 262100; } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65535), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
noInterrupts();
ignitionSchedule1.startCompare = IGN1_COUNTER + (timeout >> 2); //As there is a tick every 4uS, there are timeout/4 ticks until the interrupt should be triggered ( >>2 divides by 4)
ignitionSchedule1.endCompare = ignitionSchedule1.startCompare + (duration >> 2);
IGN1_COMPARE = ignitionSchedule1.startCompare;
ignitionSchedule1.Status = PENDING; //Turn this schedule on
ignitionSchedule1.schedulesSet++;
interrupts();
IGN1_TIMER_ENABLE();
}
@ -263,6 +264,7 @@ void setIgnitionSchedule2(void (*startCallback)(), unsigned long timeout, unsign
ignitionSchedule2.endCompare = ignitionSchedule2.startCompare + (duration >> 2);
IGN2_COMPARE = ignitionSchedule2.startCompare;
ignitionSchedule2.Status = PENDING; //Turn this schedule on
ignitionSchedule2.schedulesSet++;
interrupts();
IGN2_TIMER_ENABLE();
}
@ -282,6 +284,7 @@ void setIgnitionSchedule3(void (*startCallback)(), unsigned long timeout, unsign
ignitionSchedule3.endCompare = ignitionSchedule3.startCompare + (duration >> 2);
IGN3_COMPARE = ignitionSchedule3.startCompare;
ignitionSchedule3.Status = PENDING; //Turn this schedule on
ignitionSchedule3.schedulesSet++;
interrupts();
IGN3_TIMER_ENABLE();
}
@ -302,6 +305,7 @@ void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsign
ignitionSchedule4.endCompare = ignitionSchedule4.startCompare + (duration >> 4);
IGN4_COMPARE = ignitionSchedule4.startCompare;
ignitionSchedule4.Status = PENDING; //Turn this schedule on
ignitionSchedule4.schedulesSet++;
interrupts();
IGN4_TIMER_ENABLE();
}
@ -430,8 +434,9 @@ void timer5compareAinterrupt() //Most ARM chips can simply call a function
}
else if (ignitionSchedule1.Status == RUNNING)
{
ignitionSchedule1.Status = OFF; //Turn off the schedule
ignitionSchedule1.EndCallback();
ignitionSchedule1.Status = OFF; //Turn off the schedule
ignitionSchedule1.schedulesSet = 0;
ignitionCount += 1; //Increment the igintion counter
IGN1_TIMER_DISABLE();
}
@ -455,6 +460,7 @@ void timer5compareBinterrupt() //Most ARM chips can simply call a function
{
ignitionSchedule2.Status = OFF; //Turn off the schedule
ignitionSchedule2.EndCallback();
ignitionSchedule2.schedulesSet = 0;
ignitionCount += 1; //Increment the igintion counter
IGN2_TIMER_DISABLE();
}
@ -478,6 +484,7 @@ void timer5compareCinterrupt() //Most ARM chips can simply call a function
{
ignitionSchedule3.Status = OFF; //Turn off the schedule
ignitionSchedule3.EndCallback();
ignitionSchedule3.schedulesSet = 0;
ignitionCount += 1; //Increment the igintion counter
IGN3_TIMER_DISABLE();
}
@ -501,6 +508,7 @@ void timer4compareAinterrupt() //Most ARM chips can simply call a function
{
ignitionSchedule4.Status = OFF; //Turn off the schedule
ignitionSchedule4.EndCallback();
ignitionSchedule4.schedulesSet = 0;
ignitionCount += 1; //Increment the igintion counter
IGN4_TIMER_DISABLE();
}

View File

@ -1330,22 +1330,14 @@ void loop()
if(ignitionOn && !currentStatus.launchingHard && !BIT_CHECK(currentStatus.spark, BIT_SPARK_BOOSTCUT) && !BIT_CHECK(currentStatus.spark, BIT_SPARK_HRDLIM))
{
//if ( (ignition1StartAngle > crankAngle))// && ign1LastRev != startRevolutions)
//if ((ignition1StartAngle > crankAngle) == 0)
//if ((ignition1StartAngle < crankAngle))
//if (ignition1StartAngle <= crankAngle && ignition1.schedulesSet == 0) { ignition1StartAngle += CRANK_ANGLE_MAX_IGN; }
if (ignition1StartAngle > crankAngle)
{
unsigned long ignition1StartTime = 0;
if(ignition1StartAngle > crankAngle) { ignition1StartTime = ((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree); }
//else if (ignition1StartAngle < crankAngle) { ignition1StartTime = ((unsigned long)(360 - crankAngle + ignition1StartAngle) * (unsigned long)timePerDegree); }
else { ignition1StartTime = 0; }
if(ignition1StartTime > 0) {
setIgnitionSchedule1(ign1StartFunction,
ignition1StartTime,
((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree),
currentStatus.dwell + fixedCrankingOverride,
ign1EndFunction
);
}
}
tempCrankAngle = crankAngle - channel2IgnDegrees;