diff --git a/speeduino/decoders.h b/speeduino/decoders.h index ba1b7bb7..139d5889 100644 --- a/speeduino/decoders.h +++ b/speeduino/decoders.h @@ -192,14 +192,14 @@ extern unsigned long lastCrankAngleCalc; extern int16_t lastToothCalcAdvance; //Invalid value here forces calculation of this on first main loop extern unsigned long lastVVTtime; //The time between the vvt reference pulse and the last crank pulse -extern int16_t ignition1EndTooth; -extern int16_t ignition2EndTooth; -extern int16_t ignition3EndTooth; -extern int16_t ignition4EndTooth; -extern int16_t ignition5EndTooth; -extern int16_t ignition6EndTooth; -extern int16_t ignition7EndTooth; -extern int16_t ignition8EndTooth; +extern uint16_t ignition1EndTooth; +extern uint16_t ignition2EndTooth; +extern uint16_t ignition3EndTooth; +extern uint16_t ignition4EndTooth; +extern uint16_t ignition5EndTooth; +extern uint16_t ignition6EndTooth; +extern uint16_t ignition7EndTooth; +extern uint16_t ignition8EndTooth; extern int16_t toothAngles[24]; //An array for storing fixed tooth angles. Currently sized at 24 for the GM 24X decoder, but may grow later if there are other decoders that use this style diff --git a/speeduino/decoders.ino b/speeduino/decoders.ino index ac5159a2..edb52637 100644 --- a/speeduino/decoders.ino +++ b/speeduino/decoders.ino @@ -78,14 +78,14 @@ unsigned long lastCrankAngleCalc; int16_t lastToothCalcAdvance = 99; //Invalid value here forces calculation of this on first main loop unsigned long lastVVTtime; //The time between the vvt reference pulse and the last crank pulse -int16_t ignition1EndTooth = 0; -int16_t ignition2EndTooth = 0; -int16_t ignition3EndTooth = 0; -int16_t ignition4EndTooth = 0; -int16_t ignition5EndTooth = 0; -int16_t ignition6EndTooth = 0; -int16_t ignition7EndTooth = 0; -int16_t ignition8EndTooth = 0; +uint16_t ignition1EndTooth = 0; +uint16_t ignition2EndTooth = 0; +uint16_t ignition3EndTooth = 0; +uint16_t ignition4EndTooth = 0; +uint16_t ignition5EndTooth = 0; +uint16_t ignition6EndTooth = 0; +uint16_t ignition7EndTooth = 0; +uint16_t ignition8EndTooth = 0; int16_t toothAngles[24]; //An array for storing fixed tooth angles. Currently sized at 24 for the GM 24X decoder, but may grow later if there are other decoders that use this style @@ -282,13 +282,11 @@ If it's the correct tooth, but the schedule is not yet started, calculate and an if( (ignitionSchedule1.Status == RUNNING) ) { IGN1_COMPARE = IGN1_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition1EndAngle - crankAngle) ) ) ); } \ else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) { ignitionSchedule1.endCompare = IGN1_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition1EndAngle - crankAngle) ) ) ); ignitionSchedule1.endScheduleSetByDecoder = true; } \ } \ - \ else if ( (currentTooth == ignition2EndTooth) ) \ { \ if( (ignitionSchedule2.Status == RUNNING) ) { IGN2_COMPARE = IGN2_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition2EndAngle - crankAngle) ) ) ); } \ else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) { ignitionSchedule2.endCompare = IGN2_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition2EndAngle - crankAngle) ) ) ); ignitionSchedule2.endScheduleSetByDecoder = true; } \ } \ - \ else if ( (currentTooth == ignition3EndTooth) ) \ { \ if( (ignitionSchedule3.Status == RUNNING) ) { IGN3_COMPARE = IGN3_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition3EndAngle - crankAngle) ) ) ); } \ @@ -299,6 +297,26 @@ If it's the correct tooth, but the schedule is not yet started, calculate and an if( (ignitionSchedule4.Status == RUNNING) ) { IGN4_COMPARE = IGN4_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition4EndAngle - crankAngle) ) ) ); } \ else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) { ignitionSchedule4.endCompare = IGN4_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition4EndAngle - crankAngle) ) ) ); ignitionSchedule4.endScheduleSetByDecoder = true; } \ } \ + else if ( (currentTooth == ignition5EndTooth) ) \ + { \ + if( (ignitionSchedule5.Status == RUNNING) ) { IGN5_COMPARE = IGN5_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition5EndAngle - crankAngle) ) ) ); } \ + else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) { ignitionSchedule5.endCompare = IGN5_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition5EndAngle - crankAngle) ) ) ); ignitionSchedule5.endScheduleSetByDecoder = true; } \ + } \ + else if ( (currentTooth == ignition6EndTooth) ) \ + { \ + if( (ignitionSchedule6.Status == RUNNING) ) { IGN6_COMPARE = IGN6_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition6EndAngle - crankAngle) ) ) ); } \ + else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) { ignitionSchedule6.endCompare = IGN6_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition6EndAngle - crankAngle) ) ) ); ignitionSchedule6.endScheduleSetByDecoder = true; } \ + } \ + else if ( (currentTooth == ignition7EndTooth) ) \ + { \ + if( (ignitionSchedule7.Status == RUNNING) ) { IGN7_COMPARE = IGN7_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition7EndAngle - crankAngle) ) ) ); } \ + else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) { ignitionSchedule7.endCompare = IGN7_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition7EndAngle - crankAngle) ) ) ); ignitionSchedule7.endScheduleSetByDecoder = true; } \ + } \ + else if ( (currentTooth == ignition8EndTooth) ) \ + { \ + if( (ignitionSchedule8.Status == RUNNING) ) { IGN8_COMPARE = IGN8_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition8EndAngle - crankAngle) ) ) ); } \ + else if(currentStatus.startRevolutions > MIN_CYCLES_FOR_ENDCOMPARE) { ignitionSchedule8.endCompare = IGN8_COUNTER + uS_TO_TIMER_COMPARE( fastDegreesToUS( ignitionLimits( (ignition8EndAngle - crankAngle) ) ) ); ignitionSchedule8.endScheduleSetByDecoder = true; } \ + } \ } \ } @@ -569,15 +587,37 @@ void triggerSetEndTeeth_missingTooth() if((uint16_t)tempIgnition4EndTooth > (triggerActualTeeth + toothAdder)) { tempIgnition4EndTooth = (triggerActualTeeth + toothAdder); } ignition4EndTooth = tempIgnition4EndTooth; - ignition5EndTooth = ( (ignition5EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1; - if(ignition5EndTooth > (configPage4.triggerTeeth + toothAdder)) { ignition5EndTooth -= (configPage4.triggerTeeth + toothAdder); } - if(ignition5EndTooth <= 0) { ignition5EndTooth += configPage4.triggerTeeth; } - if(ignition5EndTooth > (triggerActualTeeth + toothAdder)) { ignition5EndTooth = (triggerActualTeeth + toothAdder); } - - ignition6EndTooth = ( (ignition6EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1; - if(ignition6EndTooth > (configPage4.triggerTeeth + toothAdder)) { ignition6EndTooth -= (configPage4.triggerTeeth + toothAdder); } - if(ignition6EndTooth <= 0) { ignition6EndTooth += configPage4.triggerTeeth; } - if(ignition6EndTooth > (triggerActualTeeth + toothAdder)) { ignition6EndTooth = (triggerActualTeeth + toothAdder); } + int16_t tempIgnition5EndTooth; + tempIgnition5EndTooth = ( (ignition5EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1; + if(tempIgnition5EndTooth > (configPage4.triggerTeeth + toothAdder)) { tempIgnition5EndTooth -= (configPage4.triggerTeeth + toothAdder); } + if(tempIgnition5EndTooth <= 0) { tempIgnition5EndTooth += (configPage4.triggerTeeth + toothAdder); } + if((uint16_t)tempIgnition5EndTooth > (triggerActualTeeth + toothAdder)) { tempIgnition5EndTooth = (triggerActualTeeth + toothAdder); } + ignition5EndTooth = tempIgnition5EndTooth; + +#if IGN_CHANNELS >= 6 + int16_t tempIgnition6EndTooth; + tempIgnition6EndTooth = ( (ignition6EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1; + if(tempIgnition6EndTooth > (configPage4.triggerTeeth + toothAdder)) { tempIgnition6EndTooth -= (configPage4.triggerTeeth + toothAdder); } + if(tempIgnition6EndTooth <= 0) { tempIgnition6EndTooth += (configPage4.triggerTeeth + toothAdder); } + if((uint16_t)tempIgnition6EndTooth > (triggerActualTeeth + toothAdder)) { tempIgnition6EndTooth = (triggerActualTeeth + toothAdder); } + ignition6EndTooth = tempIgnition6EndTooth; +#endif +#if IGN_CHANNELS >= 7 + int16_t tempIgnition7EndTooth; + tempIgnition7EndTooth = ( (ignition7EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1; + if(tempIgnition7EndTooth > (configPage4.triggerTeeth + toothAdder)) { tempIgnition7EndTooth -= (configPage4.triggerTeeth + toothAdder); } + if(tempIgnition7EndTooth <= 0) { tempIgnition7EndTooth += (configPage4.triggerTeeth + toothAdder); } + if((uint16_t)tempIgnition7EndTooth > (triggerActualTeeth + toothAdder)) { tempIgnition7EndTooth = (triggerActualTeeth + toothAdder); } + ignition7EndTooth = tempIgnition7EndTooth; +#endif +#if IGN_CHANNELS >= 8 + int16_t tempIgnition8EndTooth; + tempIgnition8EndTooth = ( (ignition8EndAngle - configPage4.triggerAngle) / (int16_t)(triggerToothAngle) ) - 1; + if(tempIgnition8EndTooth > (configPage4.triggerTeeth + toothAdder)) { tempIgnition8EndTooth -= (configPage4.triggerTeeth + toothAdder); } + if(tempIgnition8EndTooth <= 0) { tempIgnition8EndTooth += (configPage4.triggerTeeth + toothAdder); } + if((uint16_t)tempIgnition8EndTooth > (triggerActualTeeth + toothAdder)) { tempIgnition8EndTooth = (triggerActualTeeth + toothAdder); } + ignition8EndTooth = tempIgnition8EndTooth; +#endif lastToothCalcAdvance = currentStatus.advance; } diff --git a/speeduino/init.ino b/speeduino/init.ino index 2c144c90..6da4a226 100644 --- a/speeduino/init.ino +++ b/speeduino/init.ino @@ -350,6 +350,9 @@ void initialiseAll() ignition3EndAngle = 0; ignition4EndAngle = 0; ignition5EndAngle = 0; + ignition6EndAngle = 0; + ignition7EndAngle = 0; + ignition8EndAngle = 0; if(configPage2.strokes == FOUR_STROKE) { CRANK_ANGLE_MAX_INJ = 720 / currentStatus.nSquirts; } else { CRANK_ANGLE_MAX_INJ = 360 / currentStatus.nSquirts; }