6&8 cyl sequential ignition (#323)
* Required changes done Needs testing * Additions * 8cyl changes for mega 2560 * Decoder fixes
This commit is contained in:
parent
1add450cf5
commit
3529f6a2f7
|
@ -165,6 +165,7 @@ extern volatile unsigned long toothLastMinusOneToothTime; //The time (micros())
|
|||
extern volatile unsigned long toothLastMinusOneSecToothTime; //The time (micros()) that the tooth before the last tooth was registered on secondary input
|
||||
extern volatile unsigned long targetGap2;
|
||||
#endif
|
||||
|
||||
extern volatile unsigned long toothOneTime; //The time (micros()) that tooth 1 last triggered
|
||||
extern volatile unsigned long toothOneMinusOneTime; //The 2nd to last time (micros()) that tooth 1 last triggered
|
||||
extern volatile bool revolutionOne; // For sequential operation, this tracks whether the current revolution is 1 or 2 (not 1)
|
||||
|
@ -191,10 +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 uint16_t ignition1EndTooth;
|
||||
extern uint16_t ignition2EndTooth;
|
||||
extern uint16_t ignition3EndTooth;
|
||||
extern uint16_t ignition4EndTooth;
|
||||
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 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
|
||||
|
||||
|
|
|
@ -78,10 +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
|
||||
|
||||
uint16_t ignition1EndTooth = 0;
|
||||
uint16_t ignition2EndTooth = 0;
|
||||
uint16_t ignition3EndTooth = 0;
|
||||
uint16_t ignition4EndTooth = 0;
|
||||
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;
|
||||
|
||||
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
|
||||
|
||||
|
@ -565,6 +569,16 @@ 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); }
|
||||
|
||||
lastToothCalcAdvance = currentStatus.advance;
|
||||
}
|
||||
|
||||
|
@ -726,6 +740,16 @@ void triggerSetEndTeeth_DualWheel()
|
|||
if(ignition4EndTooth > (configPage4.triggerTeeth + toothAdder)) { ignition4EndTooth -= (configPage4.triggerTeeth + toothAdder); }
|
||||
if(ignition4EndTooth <= 0) { ignition4EndTooth += configPage4.triggerTeeth; }
|
||||
if(ignition4EndTooth > (triggerActualTeeth + toothAdder)) { ignition4EndTooth = (triggerActualTeeth + toothAdder); }
|
||||
|
||||
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); }
|
||||
|
||||
lastToothCalcAdvance = currentStatus.advance;
|
||||
|
||||
|
|
|
@ -362,6 +362,10 @@ extern int ignition2EndAngle;
|
|||
extern int ignition3EndAngle;
|
||||
extern int ignition4EndAngle;
|
||||
extern int ignition5EndAngle;
|
||||
extern int ignition6EndAngle;
|
||||
extern int ignition7EndAngle;
|
||||
extern int ignition8EndAngle;
|
||||
|
||||
extern int ignition1StartAngle;
|
||||
extern int ignition2StartAngle;
|
||||
extern int ignition3StartAngle;
|
||||
|
@ -404,7 +408,7 @@ extern volatile byte LOOP_TIMER;
|
|||
|
||||
//These functions all do checks on a pin to determine if it is already in use by another (higher importance) function
|
||||
#define pinIsInjector(pin) ( ((pin) == pinInjector1) || ((pin) == pinInjector2) || ((pin) == pinInjector3) || ((pin) == pinInjector4) )
|
||||
#define pinIsIgnition(pin) ( ((pin) == pinCoil1) || ((pin) == pinCoil2) || ((pin) == pinCoil3) || ((pin) == pinCoil4) )
|
||||
#define pinIsIgnition(pin) ( ((pin) == pinCoil1) || ((pin) == pinCoil2) || ((pin) == pinCoil3) || ((pin) == pinCoil4) || ((pin) == pinCoil5) || ((pin) == pinCoil6) || ((pin) == pinCoil7) || ((pin) == pinCoil8) )
|
||||
#define pinIsSensor(pin) ( ((pin) == pinCLT) || ((pin) == pinIAT) || ((pin) == pinMAP) || ((pin) == pinTPS) || ((pin) == pinO2) || ((pin) == pinBat) )
|
||||
#define pinIsUsed(pin) ( pinIsInjector((pin)) || pinIsIgnition((pin)) || pinIsSensor((pin)) )
|
||||
#define pinIsOutput(pin) ( ((pin) == pinFuelPump) || ((pin) == pinFan) || ((pin) == pinVVT_1) || ((pin) == pinVVT_2) || ((pin) == pinBoost) || ((pin) == pinIdle1) || ((pin) == pinIdle2) || ((pin) == pinTachOut) )
|
||||
|
|
|
@ -98,6 +98,9 @@ int ignition2EndAngle = 0;
|
|||
int ignition3EndAngle = 0;
|
||||
int ignition4EndAngle = 0;
|
||||
int ignition5EndAngle = 0;
|
||||
int ignition6EndAngle = 0;
|
||||
int ignition7EndAngle = 0;
|
||||
int ignition8EndAngle = 0;
|
||||
|
||||
//These are variables used across multiple files
|
||||
bool initialisationComplete = false; //Tracks whether the setup() function has run completely
|
||||
|
|
|
@ -626,6 +626,17 @@ void initialiseAll()
|
|||
channel3InjDegrees = 240;
|
||||
maxIgnOutputs = 3;
|
||||
|
||||
#if IGN_CHANNELS >= 6
|
||||
if( (configPage4.sparkMode == IGN_MODE_SEQUENTIAL))
|
||||
{
|
||||
channel4IgnDegrees = 360;
|
||||
channel5IgnDegrees = 480;
|
||||
channel6IgnDegrees = 600;
|
||||
CRANK_ANGLE_MAX_IGN = 720;
|
||||
maxIgnOutputs = 6;
|
||||
}
|
||||
#endif
|
||||
|
||||
//Adjust the injection angles based on the number of squirts
|
||||
if (currentStatus.nSquirts > 2)
|
||||
{
|
||||
|
@ -673,6 +684,18 @@ void initialiseAll()
|
|||
channel3IgnDegrees = channel3InjDegrees = 180;
|
||||
channel4IgnDegrees = channel4InjDegrees = 270;
|
||||
|
||||
#if IGN_CHANNELS >= 8
|
||||
if( (configPage4.sparkMode == IGN_MODE_SEQUENTIAL))
|
||||
{
|
||||
channel5IgnDegrees = 360;
|
||||
channel6IgnDegrees = 450;
|
||||
channel7IgnDegrees = 540;
|
||||
channel8IgnDegrees = 630;
|
||||
maxIgnOutputs = 8;
|
||||
CRANK_ANGLE_MAX_IGN = 720;
|
||||
}
|
||||
#endif
|
||||
|
||||
//Adjust the injection angles based on the number of squirts
|
||||
if (currentStatus.nSquirts > 2)
|
||||
{
|
||||
|
@ -2143,11 +2166,17 @@ void setPinMapping(byte boardID)
|
|||
pinMode(pinCoil3, OUTPUT);
|
||||
pinMode(pinCoil4, OUTPUT);
|
||||
pinMode(pinCoil5, OUTPUT);
|
||||
pinMode(pinCoil6, OUTPUT);
|
||||
pinMode(pinCoil7, OUTPUT);
|
||||
pinMode(pinCoil8, OUTPUT);
|
||||
pinMode(pinInjector1, OUTPUT);
|
||||
pinMode(pinInjector2, OUTPUT);
|
||||
pinMode(pinInjector3, OUTPUT);
|
||||
pinMode(pinInjector4, OUTPUT);
|
||||
pinMode(pinInjector5, OUTPUT);
|
||||
pinMode(pinInjector6, OUTPUT);
|
||||
pinMode(pinInjector7, OUTPUT);
|
||||
pinMode(pinInjector8, OUTPUT);
|
||||
|
||||
inj1_pin_port = portOutputRegister(digitalPinToPort(pinInjector1));
|
||||
inj1_pin_mask = digitalPinToBitMask(pinInjector1);
|
||||
|
|
|
@ -61,6 +61,10 @@ void initialiseSchedulers()
|
|||
IGN2_TIMER_ENABLE();
|
||||
IGN3_TIMER_ENABLE();
|
||||
IGN4_TIMER_ENABLE();
|
||||
IGN5_TIMER_ENABLE();
|
||||
IGN6_TIMER_ENABLE();
|
||||
IGN7_TIMER_ENABLE();
|
||||
IGN8_TIMER_ENABLE();
|
||||
|
||||
ignitionSchedule1.schedulesSet = 0;
|
||||
ignitionSchedule2.schedulesSet = 0;
|
||||
|
@ -721,6 +725,7 @@ void setIgnitionSchedule8(void (*startCallback)(), unsigned long timeout, unsign
|
|||
//This calls the relevant callback function (startCallback or endCallback) depending on the status of the schedule.
|
||||
//If the startCallback function is called, we put the scheduler into RUNNING state
|
||||
//Timer3A (fuel schedule 1) Compare Vector
|
||||
#if (INJ_CHANNELS >= 1)
|
||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
|
||||
ISR(TIMER3_COMPA_vect) //fuelSchedules 1 and 5
|
||||
#else
|
||||
|
@ -757,7 +762,9 @@ static inline void fuelSchedule1Interrupt() //Most ARM chips can simply call a f
|
|||
}
|
||||
else if (fuelSchedule1.Status == OFF) { FUEL1_TIMER_DISABLE(); } //Safety check. Turn off this output compare unit and return without performing any action
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (INJ_CHANNELS >= 2)
|
||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
|
||||
ISR(TIMER3_COMPB_vect) //fuelSchedule2
|
||||
#else
|
||||
|
@ -792,7 +799,9 @@ static inline void fuelSchedule2Interrupt() //Most ARM chips can simply call a f
|
|||
else { FUEL2_TIMER_DISABLE(); }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (INJ_CHANNELS >= 3)
|
||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
|
||||
ISR(TIMER3_COMPC_vect) //fuelSchedule3
|
||||
#else
|
||||
|
@ -829,7 +838,9 @@ static inline void fuelSchedule3Interrupt() //Most ARM chips can simply call a f
|
|||
else { FUEL3_TIMER_DISABLE(); }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (INJ_CHANNELS >= 4)
|
||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this
|
||||
ISR(TIMER4_COMPB_vect) //fuelSchedule4
|
||||
#else
|
||||
|
@ -862,6 +873,7 @@ static inline void fuelSchedule4Interrupt() //Most ARM chips can simply call a f
|
|||
else { FUEL4_TIMER_DISABLE(); }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (INJ_CHANNELS >= 5)
|
||||
#if defined(CORE_AVR) //AVR chips use the ISR for this
|
||||
|
@ -1204,7 +1216,7 @@ static inline void ignitionSchedule5Interrupt() //Most ARM chips can simply call
|
|||
|
||||
#if IGN_CHANNELS >= 6
|
||||
#if defined(CORE_AVR) //AVR chips use the ISR for this
|
||||
ISR(TIMER4_COMPC_vect) //ignitionSchedule6 NOT CORRECT!!!
|
||||
ISR(TIMER4_COMPB_vect) //ignitionSchedule6
|
||||
#else
|
||||
static inline void ignitionSchedule6Interrupt() //Most ARM chips can simply call a function
|
||||
#endif
|
||||
|
@ -1244,7 +1256,7 @@ static inline void ignitionSchedule6Interrupt() //Most ARM chips can simply call
|
|||
|
||||
#if IGN_CHANNELS >= 7
|
||||
#if defined(CORE_AVR) //AVR chips use the ISR for this
|
||||
ISR(TIMER4_COMPC_vect) //ignitionSchedule6 NOT CORRECT!!!
|
||||
ISR(TIMER3_COMPC_vect) //ignitionSchedule6
|
||||
#else
|
||||
static inline void ignitionSchedule7Interrupt() //Most ARM chips can simply call a function
|
||||
#endif
|
||||
|
@ -1284,7 +1296,7 @@ static inline void ignitionSchedule7Interrupt() //Most ARM chips can simply call
|
|||
|
||||
#if IGN_CHANNELS >= 8
|
||||
#if defined(CORE_AVR) //AVR chips use the ISR for this
|
||||
ISR(TIMER4_COMPC_vect) //ignitionSchedule8 NOT CORRECT!!!
|
||||
ISR(TIMER3_COMPB_vect) //ignitionSchedule8
|
||||
#else
|
||||
static inline void ignitionSchedule8Interrupt() //Most ARM chips can simply call a function
|
||||
#endif
|
||||
|
|
|
@ -446,6 +446,7 @@ void loop()
|
|||
uint16_t injector2StartAngle = 0;
|
||||
uint16_t injector3StartAngle = 0;
|
||||
uint16_t injector4StartAngle = 0;
|
||||
|
||||
#if INJ_CHANNELS >= 5
|
||||
uint16_t injector5StartAngle = 0; //For 5 cylinder testing
|
||||
#endif
|
||||
|
@ -1399,6 +1400,25 @@ void calculateIgnitionAngles(int dwellAngle)
|
|||
if(ignition3EndAngle > CRANK_ANGLE_MAX_IGN) {ignition3EndAngle -= CRANK_ANGLE_MAX_IGN;}
|
||||
ignition3StartAngle = ignition3EndAngle - dwellAngle;
|
||||
if(ignition3StartAngle < 0) {ignition3StartAngle += CRANK_ANGLE_MAX_IGN;}
|
||||
#if IGN_CHANNELS >= 6
|
||||
if(configPage4.sparkMode == IGN_MODE_SEQUENTIAL)
|
||||
{
|
||||
ignition4EndAngle = channel4IgnDegrees - currentStatus.advance;
|
||||
if(ignition4EndAngle > CRANK_ANGLE_MAX_IGN) {ignition4EndAngle -= CRANK_ANGLE_MAX_IGN;}
|
||||
ignition4StartAngle = ignition4EndAngle - dwellAngle;
|
||||
if(ignition4StartAngle < 0) {ignition4StartAngle += CRANK_ANGLE_MAX_IGN;}
|
||||
|
||||
ignition5EndAngle = channel5IgnDegrees - currentStatus.advance;
|
||||
if(ignition5EndAngle > CRANK_ANGLE_MAX_IGN) {ignition5EndAngle -= CRANK_ANGLE_MAX_IGN;}
|
||||
ignition5StartAngle = ignition5EndAngle - dwellAngle;
|
||||
if(ignition5StartAngle < 0) {ignition5StartAngle += CRANK_ANGLE_MAX_IGN;}
|
||||
|
||||
ignition6EndAngle = channel6IgnDegrees - currentStatus.advance;
|
||||
if(ignition6EndAngle > CRANK_ANGLE_MAX_IGN) {ignition6EndAngle -= CRANK_ANGLE_MAX_IGN;}
|
||||
ignition6StartAngle = ignition6EndAngle - dwellAngle;
|
||||
if(ignition6StartAngle < 0) {ignition6StartAngle += CRANK_ANGLE_MAX_IGN;}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
//8 cylinders
|
||||
case 8:
|
||||
|
@ -1416,6 +1436,30 @@ void calculateIgnitionAngles(int dwellAngle)
|
|||
if(ignition4EndAngle > CRANK_ANGLE_MAX_IGN) {ignition4EndAngle -= CRANK_ANGLE_MAX_IGN;}
|
||||
ignition4StartAngle = ignition4EndAngle - dwellAngle;
|
||||
if(ignition4StartAngle < 0) {ignition4StartAngle += CRANK_ANGLE_MAX_IGN;}
|
||||
#if IGN_CHANNELS >= 8
|
||||
if(configPage4.sparkMode == IGN_MODE_SEQUENTIAL)
|
||||
{
|
||||
ignition5EndAngle = channel5IgnDegrees - currentStatus.advance;
|
||||
if(ignition3EndAngle > CRANK_ANGLE_MAX_IGN) {ignition5EndAngle -= CRANK_ANGLE_MAX_IGN;}
|
||||
ignition5StartAngle = ignition5EndAngle - dwellAngle;
|
||||
if(ignition5StartAngle < 0) {ignition5StartAngle += CRANK_ANGLE_MAX_IGN;}
|
||||
|
||||
ignition6EndAngle = channel6IgnDegrees - currentStatus.advance;
|
||||
if(ignition6EndAngle > CRANK_ANGLE_MAX_IGN) {ignition6EndAngle -= CRANK_ANGLE_MAX_IGN;}
|
||||
ignition6StartAngle = ignition6EndAngle - dwellAngle;
|
||||
if(ignition6StartAngle < 0) {ignition6StartAngle += CRANK_ANGLE_MAX_IGN;}
|
||||
|
||||
ignition7EndAngle = channel7IgnDegrees - currentStatus.advance;
|
||||
if(ignition7EndAngle > CRANK_ANGLE_MAX_IGN) {ignition7EndAngle -= CRANK_ANGLE_MAX_IGN;}
|
||||
ignition7StartAngle = ignition7EndAngle - dwellAngle;
|
||||
if(ignition7StartAngle < 0) {ignition7StartAngle += CRANK_ANGLE_MAX_IGN;}
|
||||
|
||||
ignition8EndAngle = channel8IgnDegrees - currentStatus.advance;
|
||||
if(ignition8EndAngle > CRANK_ANGLE_MAX_IGN) {ignition8EndAngle -= CRANK_ANGLE_MAX_IGN;}
|
||||
ignition8StartAngle = ignition8EndAngle - dwellAngle;
|
||||
if(ignition8StartAngle < 0) {ignition8StartAngle += CRANK_ANGLE_MAX_IGN;}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
//Will hit the default case on 1 cylinder or >8 cylinders. Do nothing in these cases
|
||||
|
|
Loading…
Reference in New Issue