Ensure already scheduled events are stopped when rolling cut goes active

This commit is contained in:
Josh Stewart 2023-08-22 14:38:17 +10:00
parent ee807bb243
commit d13c7d0ab5
3 changed files with 82 additions and 2 deletions

View File

@ -110,6 +110,9 @@ void setIgnitionSchedule6(void (*startCallback)(), unsigned long timeout, unsign
void setIgnitionSchedule7(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)());
void setIgnitionSchedule8(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)());
void disablePendingFuelSchedule(byte channel);
void disablePendingIgnSchedule(byte channel);
inline void refreshIgnitionSchedule1(unsigned long timeToEnd) __attribute__((always_inline));
//The ARM cores use separate functions for their ISRs

View File

@ -1547,3 +1547,64 @@ inline void ignitionSchedule8Interrupt(void)
}
}
#endif
void disablePendingFuelSchedule(byte channel)
{
switch(channel)
{
case 1:
if(fuelSchedule1.Status == PENDING) { fuelSchedule1.Status = OFF; }
break;
case 2:
if(fuelSchedule2.Status == PENDING) { fuelSchedule2.Status = OFF; }
break;
case 3:
if(fuelSchedule3.Status == PENDING) { fuelSchedule3.Status = OFF; }
break;
case 4:
if(fuelSchedule4.Status == PENDING) { fuelSchedule4.Status = OFF; }
break;
case 5:
if(fuelSchedule5.Status == PENDING) { fuelSchedule5.Status = OFF; }
break;
case 6:
if(fuelSchedule6.Status == PENDING) { fuelSchedule6.Status = OFF; }
break;
case 7:
if(fuelSchedule7.Status == PENDING) { fuelSchedule7.Status = OFF; }
break;
case 8:
if(fuelSchedule8.Status == PENDING) { fuelSchedule8.Status = OFF; }
break;
}
}
void disablePendingIgnSchedule(byte channel)
{
switch(channel)
{
case 1:
if(ignitionSchedule1.Status == PENDING) { ignitionSchedule1.Status = OFF; }
break;
case 2:
if(ignitionSchedule2.Status == PENDING) { ignitionSchedule2.Status = OFF; }
break;
case 3:
if(ignitionSchedule3.Status == PENDING) { ignitionSchedule3.Status = OFF; }
break;
case 4:
if(ignitionSchedule4.Status == PENDING) { ignitionSchedule4.Status = OFF; }
break;
case 5:
if(ignitionSchedule5.Status == PENDING) { ignitionSchedule5.Status = OFF; }
break;
case 6:
if(ignitionSchedule6.Status == PENDING) { ignitionSchedule6.Status = OFF; }
break;
case 7:
if(ignitionSchedule7.Status == PENDING) { ignitionSchedule7.Status = OFF; }
break;
case 8:
if(ignitionSchedule8.Status == PENDING) { ignitionSchedule8.Status = OFF; }
break;
}
}

View File

@ -803,7 +803,7 @@ void loop(void)
{
uint8_t revolutionsToCut = 1;
if(configPage2.strokes == FOUR_STROKE) { revolutionsToCut *= 2; } //4 stroke needs to cut for at least 2 revolutions
//if( (configPage4.sparkMode != IGN_MODE_SEQUENTIAL) || (configPage2.injLayout != INJ_SEQUENTIAL) ) { revolutionsToCut *= 2; } //4 stroke and non-sequential will cut for 4 revolutions minimum. This is to ensure no half fuel ignition cycles take place
if( (configPage4.sparkMode != IGN_MODE_SEQUENTIAL) || (configPage2.injLayout != INJ_SEQUENTIAL) ) { revolutionsToCut *= 2; } //4 stroke and non-sequential will cut for 4 revolutions minimum. This is to ensure no half fuel ignition cycles take place
if(rollingCutLastRev == 0) { rollingCutLastRev = currentStatus.startRevolutions; } //First time check
if ( (currentStatus.startRevolutions >= (rollingCutLastRev + revolutionsToCut)) || (currentStatus.RPM > maxAllowedRPM) ) //If current RPM is over the max allowed RPM always cure, otherwise check if the required number of revolutions have passed since the last cut
@ -816,19 +816,28 @@ void loop(void)
for(uint8_t x=0; x<max(maxIgnOutputs, maxInjOutputs); x++)
{
if( (configPage6.engineProtectType != PROTECT_CUT_OFF) && ( (cutPercent == 100) || (random1to100() < cutPercent) ) )
if( (cutPercent == 100) || (random1to100() < cutPercent) )
{
switch(configPage6.engineProtectType)
{
case PROTECT_CUT_OFF:
//Make sure all channels are turned on
ignitionChannelsOn = 0xFF;
fuelChannelsOn = 0xFF;
break;
case PROTECT_CUT_IGN:
BIT_CLEAR(ignitionChannelsOn, x); //Turn off this ignition channel
disablePendingIgnSchedule(x);
break;
case PROTECT_CUT_FUEL:
BIT_CLEAR(fuelChannelsOn, x); //Turn off this fuel channel
disablePendingFuelSchedule(x);
break;
case PROTECT_CUT_BOTH:
BIT_CLEAR(ignitionChannelsOn, x); //Turn off this ignition channel
BIT_CLEAR(fuelChannelsOn, x); //Turn off this fuel channel
disablePendingFuelSchedule(x);
disablePendingIgnSchedule(x);
break;
default:
BIT_CLEAR(ignitionChannelsOn, x); //Turn off this ignition channel
@ -838,6 +847,13 @@ void loop(void)
}
else
{
/*
//Special case for non-sequential, 4-stroke where both fuel and ignition are cut. The ignition pulses should wait 1 cycle after the fuel channels are turned back on before firing again
if( (revolutionsToCut == 4) && //4 stroke and non-sequential
(BIT_CHECK(fuelChannelsOn, x) == false) && //Fuel on this channel is currently off, meaning it is the first revolution after a cut
(configPage6.engineProtectType == PROTECT_CUT_BOTH) //Both fuel and ignition are cut
)
*/
BIT_SET(ignitionChannelsOn, x); //Turn on this ignition channel
BIT_SET(fuelChannelsOn, x); //Turn on this fuel channel
}