EFI project

hello, ive been working on converting a small engine into EFI. i have 95% of the circuits working. and they all work with the arduino on their own. im now trying to put them all together into 1 sketch.
the basic idea of the program, my crank position sensor is hooked up to an interrupt pin. the interrupt will record the run time (mils) and compare it to the last time the interrupt was triggered, there is also a threshold to reset the counter, because ill have a few teeth on the crank wheel filled in, providing a longer pulse to mark the end of each cycle. if the time is below the threshold, it will just increment the counter by 1. the interrupt should also flip 2 variable between true and false depending on the counter. these must be timed accurately, because they are for the ignition events and the fuel injection command. i was hoping someone could take a look at my code and either point out some mistakes or maybe ideas of a different way to approach this problem. all help is appreciated.

//  **** ISR  ****  //
bool INJcmd = false;
bool IGNcmd = false;
volatile byte CPC = 0;
// ****  INPUT  ****  //
byte TPS = A0;
byte CKP = 2;
//  **** OUTPUT  ****  //
byte INJ = 6;
byte IGN = 5;

void setup(){
  pinMode(INJ, OUTPUT);
  pinMode(IGN, OUTPUT);
  digitalWrite(IGN, HIGH);
  pinMode(TPS, INPUT);
  pinMode(CKP,INPUT);
  attachInterrupt(digitalPinToInterrupt(CKP), CrankInterrupt, RISING);
  long historyMills = 0;
  long time = 0;
  long compaireTime = 0;
  long CThreshold = 0;
   
}

void loop(){
  while (IGNcmd = true){ ignition();}
  while (INJcmd = true){ injector();} 
  digitalWrite(IGN, HIGH);
  analogWrite(INJ, 0);
}
  void injector(){
  digitalWrite(INJ, HIGH);
  }
  void ignition(){
  digitalWrite(IGN, LOW);
  }

void CrankInterrupt(){
  long historyMills;
  long currentMills = millis();            // records current time
  long compaireTime = currentMills - historyMills;  // compaires current time to history time
  long CThreshold = compaireTime * 2.5;
  if (compaireTime >= CThreshold){
      CPC = 0;                            //RESET
    }
    else{
      CPC++;
      if (CPC = 13){IGNcmd = !IGNcmd;}
      if (CPC >= 6 && CPC < 10){INJcmd = !INJcmd;}
      }
     historyMills = currentMills;
     currentMills = 0;
     compaireTime = 0;
     CThreshold = 0;
}

thx in advanced !

variables you declare inside your functions don't hang around. You declare 'historyMills' in setup() [among others] and then never use them.

You declare these variables again inside CrankInterupt() but they won't retain their values for the next interrupt. You need to declare them globally - outside a function definition, usually near the top of the program.

millis() related variables need to be 'unsigned long'

This if statement

      if (CPC = 13){IGNcmd = !IGNcmd;}

Is an assignment, not a comparison

You have some "while" statements that have problems similar to the "if" statement.

okay so if im understanding this right, i just need to store those variables outside the interrupt.
but the reason i wanted to used the “if” and “while” statements like i did, was so that after i have everything running. i would be able to replace the numbers in the code and replace them with variables that could be modified through the serial monitor, and have different “while” statements to have a different “tune” for the engine, ie. changing those same variable with a push of a button. to a “tune” thats stored in memory. but for now im just trying to get it all working… i didnt want to have a loop full of “if” statements. is there another way of structuring this ?
thx the help !

= is assignment. == is comparison.

Doing assignment inside of an "if" or a "while" is permissible but rare. Unless you are a professional, just don't do it!

... and in your code, it is the wrong thing to do.