Oh ok, sorry @Robin2 will not do.
Yeah @blh64 i ment that i understod that the Serial.print lines takes time, not the comment. just badly formulated from me. 
And yes, dont really see what i intended with this line. it quite weird..
if (digitalPinToInterrupt(crankshaftReferencePin), CHANGE)
Went through the code again with a rubberduck, Notic i also connected one led-circuit wrong.
Got the reading side to work like intended with RISING like you said.
const byte IGTPin = 2; //Interrupt pin for IGT signal from ECU (pin3)
const byte crankPin = 3; //Interrupt pin for crankshaft reference pin (pin2)
volatile boolean syncAchieved = 0; //Set this to true if sync has been achieved
volatile byte cylinderCounter = 0; //Sequence which cylinder should fire (0-1-2-3)
const byte fireOrder[] = { //Table containing the fireorder (1-3-4-2)
B00000001, // cylinder 1-4
B00000010, // cylinder 2-3
B00000001, // cylinder 1-4
B00000010 // cylinder 2-3
};
void setup() {
Serial.begin(19200); //for debug
pinMode(crankPin, INPUT_PULLUP); //Interrupt pin for crankshaft position Use pullup to get rid of dangerous wire break situation
pinMode(IGTPin, INPUT_PULLUP);
DDRB = 0b00000011; //Set the first 2 pins on the B register to outputs.
attachInterrupt(digitalPinToInterrupt(crankPin), ISR0, RISING);
Serial.println("Startup");
}
void loop() {
// put your main code here, to run repeatedly:
while (syncAchieved == 1) { //Start sequencing ignition outputs when sync has occured. Otherwise just wait until engine starts rotating.
PORTB = fireOrder[cylinderCounter];
}
}
void ISR0()
{
detachInterrupt(digitalPinToInterrupt(crankPin)); //If sync is achieved, we immedeatly disable keeping track of the position pin permanently
syncAchieved = 1; //Set variable used to start ignition and disable unnecessary measuring of position pin
Serial.println("Sync Achieved"); //Add when troubleshooting
attachInterrupt(digitalPinToInterrupt(IGTPin), ISR1, RISING); //We no longer keep track of change state once synced. Now we locate rising change on the ref pin.
}
void ISR1()
{
if (syncAchieved == 1) { //If we have achieved sync, do only this part of the interrupt
if (digitalRead(IGTPin) == HIGH) { //This is an "unneeded if". It filters out spark EMI, incorrect pulses will be counted otherwise.
cylinderCounter++; //we sequence the next cylinder that should fire
Serial.println(cylinderCounter); //debug line to see that the right cylinder are shooting
if (cylinderCounter > 3) {
cylinderCounter = 0; //This a reset for the cylinder firing sequencer. We have 4 cylinders, so we reset after we reached the final one.
}
}
}
}
For the detach line my intention is to use the syncing pin for the crank once to get it to fire in the right order, i dont think i need to check it again if the rest works correctly. But since a faulty spark can blow my engine up i might be good to check it every revolution?
Now the big question for me is the outputs, that i have set to port B?
I want them to send out a high signal. So when sync is achived i want cylinderCounter for 1 to be high, and after the IGT signal i want it to be low and cylinderCounter for 2 high.
How do i do that? since i got it to rotate correctly for the cylinder, the outputs dont become high.
The high signal of the output will go to a mosfet that awaits the IGT signal and then do the real switching between cylinders.
So from a risk analytic standpoint, do you guys se something in the code or am i missing something that would prevent blowing the engine?
All i have done is INPUT_PULLUP to get rid of a broken/loose connection from the sensors.
//Thanks