intreq_fuel=((engineCapacity/engineInjectorSize)/engineCylinders/engineStoich)*100;// This doesn't seem quite correct, but I can't find why. It will be close enough to start an engine
// These aren't really configuration options, more so a description of how the hardware is setup. These are things that will be defined in the recommended hardware setup
inttriggerActualTeeth=triggerTeeth-triggerMissingTeeth;//The number of physical teeth on the wheel. Doing this here saves us a calculation each time in the interrupt
req_fuel=req_fuel/engineSquirtsPerCycle;//The req_fuel calculation above gives the total required fuel (At VE 100%) in the full cycle. If we're doing more than 1 squirt per cycle then we need to split the amount accordingly. (Note that in a non-sequential 4-stroke setup you cannot have less than 2 squirts as you cannot determine the stroke to make the single squirt on)
//Calculate the RPM based on the time between the last 2 teeth. I have no idea whether this will be accurate AT ALL, but it's fairly efficient and means there doesn't need to be another variable placed into the trigger interrupt
if(toothCurrentCount!=1)//We can't perform the RPM calculation if we're at the first tooth as the timing would be double (Well, we can, but it would need a different calculation and I don't think it's worth it, just use the last RPM value)
{
longrevolutionTime=(triggerTeeth*(toothLastToothTime-toothLastMinusOneToothTime));//The time in us that one revolution would take at current speed
rpm=US_IN_MINUTE/revolutionTime;
}
//Get the current MAP value
intMAP=1;//Placeholder
//Perform lookup into fuel map for RPM vs MAP value
intVE=getTableValue(fuelTable,rpm,MAP);
//From all of the above, calculate an injector pulsewidth
intpulseWidth=PW(req_fuel,VE,MAP,100,engineInjectorDeadTime);//The 100 here is just a placeholder for any enrichment factors (Cold start, acceleration etc). To add 10% extra fuel, this would be 110
//If the time between the current tooth and the last is greater than 1.5x the time between the last tooth and the tooth before that, we make the assertion that we must be at the first tooth after the gap