Fix for potential miss on trailing spark of FC rotary mode at high RPM

This commit is contained in:
Josh Stewart 2017-08-31 12:09:13 +10:00
parent 6aebf7e068
commit 0ccab57e61
3 changed files with 48 additions and 6 deletions

View File

@ -478,7 +478,7 @@ uint16_t correctionsDwell(uint16_t dwell)
uint16_t dwellPerRevolution = tempDwell + (uint16_t)(configPage2.sparkDur * 100); //Spark duration is in mS*10. Multiple it by 100 to get spark duration in uS
int8_t pulsesPerRevolution = 1;
//Single channel spark mode is the only time there will be more than 1 pulse per revolution on any given output
if( (configPage2.sparkMode == IGN_MODE_SINGLE) && (configPage1.nCylinders > 1) ) //No point in running this for 1 cylinder engines
if( ( (configPage2.sparkMode == IGN_MODE_SINGLE) || (configPage2.sparkMode == IGN_MODE_ROTARY) ) && (configPage1.nCylinders > 1) ) //No point in running this for 1 cylinder engines
{
pulsesPerRevolution = (configPage1.nCylinders >> 1);
dwellPerRevolution = dwellPerRevolution * pulsesPerRevolution;

View File

@ -445,6 +445,14 @@ void setIgnitionSchedule3(void (*startCallback)(), unsigned long timeout, unsign
interrupts();
IGN3_TIMER_ENABLE();
}
else
{
//If the schedule is already running, we can set the next schedule so it is ready to go
//This is required in cases of high rpm and high DC where there otherwise would not be enough time to set the schedule
ignitionSchedule3.nextStartCompare = IGN3_COUNTER + uS_TO_TIMER_COMPARE(timeout);
ignitionSchedule3.nextEndCompare = ignitionSchedule3.nextStartCompare + uS_TO_TIMER_COMPARE(duration);
ignitionSchedule3.hasNextSchedule = true;
}
}
void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)())
{
@ -469,6 +477,14 @@ void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsign
interrupts();
IGN4_TIMER_ENABLE();
}
else
{
//If the schedule is already running, we can set the next schedule so it is ready to go
//This is required in cases of high rpm and high DC where there otherwise would not be enough time to set the schedule
ignitionSchedule4.nextStartCompare = IGN4_COUNTER + uS_TO_TIMER_COMPARE_SLOW(timeout);
ignitionSchedule4.nextEndCompare = ignitionSchedule4.nextStartCompare + uS_TO_TIMER_COMPARE_SLOW(duration);
ignitionSchedule4.hasNextSchedule = true;
}
}
void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)())
{
@ -707,7 +723,17 @@ static inline void ignitionSchedule3Interrupt() //Most ARM chips can simply call
ignitionSchedule3.EndCallback();
ignitionSchedule3.schedulesSet = 0;
ignitionCount += 1; //Increment the igintion counter
IGN3_TIMER_DISABLE();
//If there is a next schedule queued up, activate it
if(ignitionSchedule3.hasNextSchedule == true)
{
IGN3_COMPARE = ignitionSchedule3.nextStartCompare;
ignitionSchedule3.endCompare = ignitionSchedule3.nextEndCompare;
ignitionSchedule3.Status = PENDING;
ignitionSchedule3.schedulesSet = 1;
ignitionSchedule3.hasNextSchedule = false;
}
else { IGN3_TIMER_DISABLE(); }
}
}
@ -730,7 +756,17 @@ static inline void ignitionSchedule4Interrupt() //Most ARM chips can simply call
ignitionSchedule4.EndCallback();
ignitionSchedule4.schedulesSet = 0;
ignitionCount += 1; //Increment the igintion counter
IGN4_TIMER_DISABLE();
//If there is a next schedule queued up, activate it
if(ignitionSchedule4.hasNextSchedule == true)
{
IGN4_COMPARE = ignitionSchedule4.nextStartCompare;
ignitionSchedule4.endCompare = ignitionSchedule4.nextEndCompare;
ignitionSchedule4.Status = PENDING;
ignitionSchedule4.schedulesSet = 1;
ignitionSchedule4.hasNextSchedule = false;
}
else { IGN4_TIMER_DISABLE(); }
}
}

View File

@ -400,6 +400,12 @@ void setup()
CRANK_ANGLE_MAX_IGN = 720;
}
else if(configPage2.sparkMode == IGN_MODE_ROTARY)
{
//Rotary uses the ign 3 and 4 schedules for the trailing spark. They are offset from the ign 1 and 2 channels respectively and so use the same degrees as them
channel3IgnDegrees = 0;
channel4IgnDegrees = 180;
}
}
else
{
@ -931,9 +937,9 @@ void loop()
int injector5StartAngle = 0; //For 5 cylinder testing
int ignition1StartAngle = 0;
int ignition2StartAngle = 0;
int ignition3StartAngle = 0; //Currently used for 3 cylinder only
int ignition4StartAngle = 0; //Not used until sequential or 4+ cylinders support gets written
int ignition5StartAngle = 0; //Not used until sequential or 4+ cylinders support gets written
int ignition3StartAngle = 0;
int ignition4StartAngle = 0;
int ignition5StartAngle = 0;
//These are used for comparisons on channels above 1 where the starting angle (for injectors or ignition) can be less than a single loop time
//(Don't ask why this is needed, it will break your head)
int tempCrankAngle;