Initial groundwork for 5 cylinder support

This commit is contained in:
Josh Stewart 2016-07-24 19:32:26 +10:00
parent ab4429c2d2
commit 01d9578523
4 changed files with 131 additions and 16 deletions

View File

@ -76,6 +76,8 @@ volatile byte *inj3_pin_port;
volatile byte inj3_pin_mask;
volatile byte *inj4_pin_port;
volatile byte inj4_pin_mask;
volatile byte *inj5_pin_port;
volatile byte inj5_pin_mask;
volatile byte *ign1_pin_port;
volatile byte ign1_pin_mask;
@ -85,6 +87,8 @@ volatile byte *ign3_pin_port;
volatile byte ign3_pin_mask;
volatile byte *ign4_pin_port;
volatile byte ign4_pin_mask;
volatile byte *ign5_pin_port;
volatile byte ign5_pin_mask;
//The status struct contains the current values for all 'live' variables
//In current version this is 64 bytes
@ -392,6 +396,10 @@ byte pinCoil1; //Pin for coil 1
byte pinCoil2; //Pin for coil 2
byte pinCoil3; //Pin for coil 3
byte pinCoil4; //Pin for coil 4
byte pinCoil5; //Pin for coil 4
byte pinCoil6; //Pin for coil 4
byte pinCoil7; //Pin for coil 4
byte pinCoil8; //Pin for coil 4
byte pinTrigger; //The CAS pin
byte pinTrigger2; //The Cam Sensor pin
byte pinTrigger3; //the 2nd cam sensor pin

View File

@ -212,6 +212,20 @@ void setIgnitionSchedule4(void (*startCallback)(), unsigned long timeout, unsign
ignitionSchedule4.Status = PENDING; //Turn this schedule on
TIMSK4 |= (1 << OCIE4A); //Turn on the A compare unit (ie turn on the interrupt)
}
void setIgnitionSchedule5(void (*startCallback)(), unsigned long timeout, unsigned long duration, void(*endCallback)())
{
if(ignitionSchedule1.Status == RUNNING) { return; } //Check that we're not already part way through a schedule
//As the timer is ticking every 4uS (Time per Tick = (Prescale)*(1/Frequency))
if (timeout > 262140) { return; } // If the timeout is >4x (Each tick represents 4uS) the maximum allowed value of unsigned int (65525), the timer compare value will overflow when appliedcausing erratic behaviour such as erroneous sparking.
OCR5A = TCNT5 + (timeout >> 2); //As there is a tick every 4uS, there are timeout/4 ticks until the interrupt should be triggered ( >>2 divides by 4)
ignitionSchedule5.duration = duration;
ignitionSchedule5.StartCallback = startCallback; //Name the start callback function
ignitionSchedule5.EndCallback = endCallback; //Name the start callback function
ignitionSchedule5.Status = PENDING; //Turn this schedule on
TIMSK5 |= (1 << OCIE5A); //Turn on the A compare unit (ie turn on the interrupt)
}

View File

@ -117,15 +117,18 @@ int channel1IgnDegrees; //The number of crank degrees until cylinder 1 is at TDC
int channel2IgnDegrees; //The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC
int channel3IgnDegrees; //The number of crank degrees until cylinder 3 (and 5/6/7/8) is at TDC
int channel4IgnDegrees; //The number of crank degrees until cylinder 4 (and 5/6/7/8) is at TDC
int channel5IgnDegrees; //The number of crank degrees until cylinder 5 is at TDC
int channel1InjDegrees; //The number of crank degrees until cylinder 1 is at TDC (This is obviously 0 for virtually ALL engines, but there's some weird ones)
int channel2InjDegrees; //The number of crank degrees until cylinder 2 (and 5/6/7/8) is at TDC
int channel3InjDegrees; //The number of crank degrees until cylinder 3 (and 5/6/7/8) is at TDC
int channel4InjDegrees; //The number of crank degrees until cylinder 4 (and 5/6/7/8) is at TDC
int channel5InjDegrees; //The number of crank degrees until cylinder 5 is at TDC
bool channel1InjEnabled;
bool channel2InjEnabled;
bool channel3InjEnabled;
bool channel4InjEnabled;
bool channel1InjEnabled = true;
bool channel2InjEnabled = false;
bool channel3InjEnabled = false;
bool channel4InjEnabled = false;
bool channel5InjEnabled = false;
//These are the functions the get called to begin and end the ignition coil charging. They are required for the various spark output modes
void (*ign1StartFunction)();
@ -136,6 +139,8 @@ void (*ign3StartFunction)();
void (*ign3EndFunction)();
void (*ign4StartFunction)();
void (*ign4EndFunction)();
void (*ign5StartFunction)();
void (*ign5EndFunction)();
int timePerDegree;
byte degreesPerLoop; //The number of crank degrees that pass for each mainloop of the program
@ -206,12 +211,14 @@ void setup()
digitalWrite(pinCoil2, coilLOW);
digitalWrite(pinCoil3, coilLOW);
digitalWrite(pinCoil4, coilLOW);
digitalWrite(pinCoil5, coilLOW);
//Similar for injectors, make sure they're turned off
digitalWrite(pinInjector1, LOW);
digitalWrite(pinInjector2, LOW);
digitalWrite(pinInjector3, LOW);
digitalWrite(pinInjector4, LOW);
digitalWrite(pinInjector5, LOW);
//Set the tacho output default state
digitalWrite(pinTachOut, HIGH);
@ -470,9 +477,6 @@ void setup()
channel1InjDegrees = 0;
channel1InjEnabled = true;
channel2InjEnabled = false;
channel3InjEnabled = false;
channel4InjEnabled = false;
break;
case 2:
channel1IgnDegrees = 0;
@ -488,8 +492,6 @@ void setup()
channel1InjEnabled = true;
channel2InjEnabled = true;
channel3InjEnabled = false;
channel4InjEnabled = false;
break;
case 3:
channel1IgnDegrees = 0;
@ -514,7 +516,6 @@ void setup()
channel1InjEnabled = true;
channel2InjEnabled = true;
channel3InjEnabled = true;
channel4InjEnabled = false;
break;
case 4:
channel1IgnDegrees = 0;
@ -543,8 +544,46 @@ void setup()
channel1InjEnabled = true;
channel2InjEnabled = true;
channel3InjEnabled = false;
channel4InjEnabled = false;
break;
case 5:
channel1IgnDegrees = 0;
channel2IgnDegrees = 72;
channel3IgnDegrees = 144;
channel4IgnDegrees = 216;
channel5IgnDegrees = 288;
if(useSequentialIgnition)
{
channel2IgnDegrees = 144;
channel3IgnDegrees = 288;
channel4IgnDegrees = 432;
channel5IgnDegrees = 576;
}
//For alternatiing injection, the squirt occurs at different times for each channel
if(configPage1.injTiming == INJ_SEMISEQUENTIAL)
{
channel1InjDegrees = 0;
channel2InjDegrees = 72;
channel3InjDegrees = 144;
channel4InjDegrees = 216;
channel5InjDegrees = 288;
}
else if (useSequentialFuel)
{
channel1InjDegrees = 0;
channel2InjDegrees = 144;
channel3InjDegrees = 288;
channel4InjDegrees = 432;
channel5InjDegrees = 576;
}
else { channel1InjDegrees = channel2InjDegrees = channel3InjDegrees = channel4InjDegrees = channel5InjDegrees = 0; } //For simultaneous, all squirts happen at the same time
channel1InjEnabled = true;
channel2InjEnabled = true;
channel3InjEnabled = true;
channel4InjEnabled = true;
channel5InjEnabled = true;
break;
case 6:
channel1IgnDegrees = 0;
@ -565,7 +604,6 @@ void setup()
channel1InjEnabled = true;
channel2InjEnabled = true;
channel3InjEnabled = true;
channel4InjEnabled = false;
break;
case 8:
channel1IgnDegrees = 0;
@ -608,6 +646,8 @@ void setup()
ign3EndFunction = endCoil3Charge;
ign4StartFunction = beginCoil4Charge;
ign4EndFunction = endCoil4Charge;
ign5StartFunction = beginCoil5Charge;
ign5EndFunction = endCoil5Charge;
break;
case 1:
@ -620,6 +660,8 @@ void setup()
ign3EndFunction = endCoil1Charge;
ign4StartFunction = beginCoil1Charge;
ign4EndFunction = endCoil1Charge;
ign5StartFunction = beginCoil1Charge;
ign5EndFunction = endCoil1Charge;
break;
case 2:
@ -648,6 +690,8 @@ void setup()
ign3EndFunction = endCoil3Charge;
ign4StartFunction = beginCoil4Charge;
ign4EndFunction = endCoil4Charge;
ign5StartFunction = beginCoil5Charge;
ign5EndFunction = endCoil5Charge;
}
break;
@ -661,6 +705,8 @@ void setup()
ign3EndFunction = endCoil3Charge;
ign4StartFunction = beginCoil4Charge;
ign4EndFunction = endCoil4Charge;
ign5StartFunction = beginCoil5Charge;
ign5EndFunction = endCoil5Charge;
break;
}
@ -843,10 +889,12 @@ void loop()
int injector2StartAngle = 0;
int injector3StartAngle = 0; //Currently used for 3 cylinder only
int injector4StartAngle = 0; //Not used until sequential gets written
int injector5StartAngle = 0; //For 5 cylinder testing
int ignition1StartAngle = 0;
int ignition2StartAngle = 0;
int ignition3StartAngle = 0; //Not used until sequential or 4+ cylinders support gets written
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
//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;
@ -1202,6 +1250,27 @@ void loop()
);
}
}
tempCrankAngle = crankAngle - channel5IgnDegrees;
if( tempCrankAngle < 0) { tempCrankAngle += CRANK_ANGLE_MAX; }
tempStartAngle = ignition5StartAngle - channel5IgnDegrees;
if ( tempStartAngle < 0) { tempStartAngle += CRANK_ANGLE_MAX; }
//if (tempStartAngle > tempCrankAngle)
{
long ignition5StartTime = 0;
if(tempStartAngle > tempCrankAngle) { ignition5StartTime = ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree); }
//else if (tempStartAngle < tempCrankAngle) { ignition4StartTime = ((long)(360 - tempCrankAngle + tempStartAngle) * (long)timePerDegree); }
else { ignition5StartTime = 0; }
if(ignition5StartTime > 0) {
setIgnitionSchedule5(ign5StartFunction,
ignition5StartTime,
currentStatus.dwell + fixedCrankingOverride,
ign5EndFunction
);
}
}
}
@ -1263,6 +1332,11 @@ void loop()
inline void beginCoil4Charge() { digitalWrite(pinCoil4, coilHIGH); digitalWrite(pinTachOut, LOW); }
inline void endCoil4Charge() { digitalWrite(pinCoil4, coilLOW); }
inline void openInjector5() { digitalWrite(pinInjector5, HIGH); }
inline void closeInjector5() { digitalWrite(pinInjector5, LOW); }
inline void beginCoil5Charge() { digitalWrite(pinCoil5, coilHIGH); digitalWrite(pinTachOut, LOW); }
inline void endCoil5Charge() { digitalWrite(pinCoil5, coilLOW); }
//#endif

View File

@ -27,10 +27,12 @@ void setPinMapping(byte boardID)
pinInjector2 = 9; //Output pin injector 2 is on
pinInjector3 = 11; //Output pin injector 3 is on
pinInjector4 = 10; //Output pin injector 4 is on
pinInjector5 = 12; //Output pin injector 5 is on
pinCoil1 = 6; //Pin for coil 1
pinCoil2 = 7; //Pin for coil 2
pinCoil3 = 12; //Pin for coil 3
pinCoil4 = 13; //Pin for coil 4
pinCoil5 = 14; //Pin for coil 5
pinTrigger = 2; //The CAS pin
pinTrigger2 = 3; //The CAS pin
pinTPS = A0; //TPS input pin
@ -53,10 +55,12 @@ void setPinMapping(byte boardID)
pinInjector2 = 9; //Output pin injector 2 is on
pinInjector3 = 10; //Output pin injector 3 is on
pinInjector4 = 11; //Output pin injector 4 is on
pinInjector5 = 12; //Output pin injector 5 is on
pinCoil1 = 28; //Pin for coil 1
pinCoil2 = 24; //Pin for coil 2
pinCoil3 = 40; //Pin for coil 3
pinCoil4 = 36; //Pin for coil 4
pinCoil5 = 34; //Pin for coil 5 PLACEHOLDER value for now
pinTrigger = 20; //The CAS pin
pinTrigger2 = 21; //The Cam Sensor pin
pinTPS = A2; //TPS input pin
@ -81,10 +85,12 @@ void setPinMapping(byte boardID)
pinInjector2 = 9; //Output pin injector 2 is on
pinInjector3 = 10; //Output pin injector 3 is on
pinInjector4 = 11; //Output pin injector 4 is on
pinInjector5 = 12; //Output pin injector 5 is on
pinCoil1 = 28; //Pin for coil 1
pinCoil2 = 24; //Pin for coil 2
pinCoil3 = 40; //Pin for coil 3
pinCoil4 = 36; //Pin for coil 4
pinCoil5 = 34; //Pin for coil 5 PLACEHOLDER value for now
pinTrigger = 19; //The CAS pin
pinTrigger2 = 18; //The Cam Sensor pin
pinTPS = A2;//TPS input pin
@ -111,10 +117,12 @@ void setPinMapping(byte boardID)
pinInjector2 = 9; //Output pin injector 2 is on
pinInjector3 = 10; //Output pin injector 3 is on
pinInjector4 = 11; //Output pin injector 4 is on
pinInjector5 = 12; //Output pin injector 5 is on
pinCoil1 = 40; //Pin for coil 1
pinCoil2 = 38; //Pin for coil 2
pinCoil3 = 52; //Pin for coil 3
pinCoil4 = 50; //Pin for coil 4
pinCoil5 = 34; //Pin for coil 5 PLACEHOLDER value for now
pinTrigger = 19; //The CAS pin
pinTrigger2 = 18; //The Cam Sensor pin
pinTPS = A2;//TPS input pin
@ -149,6 +157,7 @@ void setPinMapping(byte boardID)
pinCoil2 = 28; //Pin for coil 2
pinCoil3 = 36; //Pin for coil 3
pinCoil4 = 40; //Pin for coil 4
pinCoil5 = 34; //Pin for coil 5 PLACEHOLDER value for now
pinTrigger = 18; //The CAS pin
pinTrigger2 = 19; //The Cam Sensor pin
pinTPS = A2;//TPS input pin
@ -174,10 +183,12 @@ void setPinMapping(byte boardID)
pinInjector2 = 9; //Output pin injector 2 is on
pinInjector3 = 10; //Output pin injector 3 is on
pinInjector4 = 11; //Output pin injector 4 is on
pinInjector5 = 12; //Output pin injector 5 is on
pinCoil1 = 28; //Pin for coil 1
pinCoil2 = 24; //Pin for coil 2
pinCoil3 = 40; //Pin for coil 3
pinCoil4 = 36; //Pin for coil 4
pinCoil5 = 34; //Pin for coil 5 PLACEHOLDER value for now
pinSpareOut1 = 4; //Spare LSD Output 1(PWM)
pinSpareOut2 = 5; //Spare LSD Output 2(PWM)
pinSpareOut3 = 6; //Spare LSD Output 3(PWM)
@ -204,12 +215,12 @@ void setPinMapping(byte boardID)
pinInjector2 = 9; //Output pin injector 2 is on
pinInjector3 = 10; //Output pin injector 3 is on
pinInjector4 = 11; //Output pin injector 4 is on
//pinInjector5 = 12; //Placeholder only - NOT USED
//pinInjector6 = 13; //Placeholder only - NOT USED
pinInjector5 = 12; //Output pin injector 5 is on
pinCoil1 = 40; //Pin for coil 1
pinCoil2 = 38; //Pin for coil 2
pinCoil3 = 50; //Pin for coil 3
pinCoil4 = 52; //Pin for coil 4
pinCoil5 = 34; //Pin for coil 5 PLACEHOLDER value for now
pinTrigger = 19; //The CAS pin
pinTrigger2 = 18; //The Cam Sensor pin
pinTrigger3 = 17; // cam sensor 2 pin
@ -241,10 +252,12 @@ void setPinMapping(byte boardID)
pinInjector2 = 9; //Output pin injector 2 is on
pinInjector3 = 10; //Output pin injector 3 is on
pinInjector4 = 11; //Output pin injector 4 is on
pinInjector5 = 12; //Output pin injector 5 is on
pinCoil1 = 28; //Pin for coil 1
pinCoil2 = 24; //Pin for coil 2
pinCoil3 = 40; //Pin for coil 3
pinCoil4 = 36; //Pin for coil 4
pinCoil5 = 34; //Pin for coil 5 PLACEHOLDER value for now
pinTrigger = 20; //The CAS pin
pinTrigger2 = 21; //The Cam Sensor pin
pinTPS = A2; //TPS input pin
@ -270,10 +283,12 @@ void setPinMapping(byte boardID)
pinMode(pinCoil2, OUTPUT);
pinMode(pinCoil3, OUTPUT);
pinMode(pinCoil4, OUTPUT);
pinMode(pinCoil5, OUTPUT);
pinMode(pinInjector1, OUTPUT);
pinMode(pinInjector2, OUTPUT);
pinMode(pinInjector3, OUTPUT);
pinMode(pinInjector4, OUTPUT);
pinMode(pinInjector5, OUTPUT);
pinMode(pinTachOut, OUTPUT);
pinMode(pinIdle1, OUTPUT);
pinMode(pinIdle2, OUTPUT);
@ -288,6 +303,8 @@ void setPinMapping(byte boardID)
inj3_pin_mask = digitalPinToBitMask(pinInjector3);
inj4_pin_port = portOutputRegister(digitalPinToPort(pinInjector4));
inj4_pin_mask = digitalPinToBitMask(pinInjector4);
inj5_pin_port = portOutputRegister(digitalPinToPort(pinInjector5));
inj5_pin_mask = digitalPinToBitMask(pinInjector5);
ign1_pin_port = portOutputRegister(digitalPinToPort(pinCoil1));
ign1_pin_mask = digitalPinToBitMask(pinCoil1);
@ -297,6 +314,8 @@ void setPinMapping(byte boardID)
ign3_pin_mask = digitalPinToBitMask(pinCoil3);
ign4_pin_port = portOutputRegister(digitalPinToPort(pinCoil4));
ign4_pin_mask = digitalPinToBitMask(pinCoil4);
ign5_pin_port = portOutputRegister(digitalPinToPort(pinCoil5));
ign5_pin_mask = digitalPinToBitMask(pinCoil5);
//And for inputs
pinMode(pinMAP, INPUT);