I’ve decided to try this SCT tuning voodoo, however, I’m pretty f*cking stupid when it comes to these things, so… I’m trying to write a program to do all the thinking for me. The end goal is a stand-alone executable that will generate injector pulse width, fuel tables, spark tables, enrichment parameters, VE topographies, etc etc etc for anidealhardware (engine and shit?) configuration. Load those tuning parameters, datalog the results, and then adjust a series of feedback gains and refine the tune until it’s perfect.

The executable is still in its infancy, but I’m also doing a “dumbed down” version in VBA that uses Excel to do all the heavy lifting to verify the math stuff and make sure my documentation is straight. PRP is still in the mail, so I haven’t even had the actual software in front of me. A lot of what I have is reverse-engineered Megasquirt logic and a lot of ICE theory.

A lot of the fundamentals of this is borrowed from the algorithms page on DIY EFI, a now-defunct site dedicated to building and programming GM ECMs from scratch. They word the explanations much more better-er than I can. This is the general idea… I’m looking forfeedback onmy methodology. Academically sound? Practically sound? Stupid as f*ck? Give up and go carb’d?

PW=0.67(InjTurnOn + BattComp) + AccPw +(ReqdFuel/InjFlowRate)

Where:PW= Fuel Injector Pulsewidth in microseconds.InjTurnOn= Time (in microseconds) for injector to open fully when 12 volts is applied. Typical value is 1.5 ms. User-defined.BattComp= Compensation (+ or - microseconds) to turn-on time for fact that battery voltage may not be exactly 12 volts.0.67= Factor to account for the fact that the average fuel flow rate is only ~1/3 the max rate during turn-on time. The 1/3 factor comes from F=Ma applied to a solenoid, and assuming flow is proportional to the opening of the solenoid:

TurnOn + (ReqdFuel-0.33(IFR)TurnOn)/IFR = 0.67(TurnOn) + ReqdFuel/IFR

AccPw= Temporary extension of pulsewidth (in microseconds) during acceleration. User-defined. May be left as 0.0, as there is also an acceleration enrichment term inReqdFuel, which is a function of throttle rate.InjFlowRate (IFR)= Injector flow rate at operating pressure (lbs/microsecond). User input.ReqdFuel= Total fuel required (pounds) for a particular cylinder firing:

ReqdFuel = MassAirFa(GammaEnrich/100)*(1+ PmFuel/100)

PmFuel= a +/- integer incremented/decremented by the end user. Each increment represents a 1 percent increase/decrease in the fuel/air ratio.Haven’t played with this in SCT yet, but I know it exists, so the program accounts for it.MassAirFa= Mass air (pounds per cylinder firing) for desired fuel/air ratio, also equal to the mass fuel required (exclusive of special enrichments):

MassAirFa = AirDen(CID/1728)(1/14.7(NCyl))(MAP/MAP(WOT))(VE/(AirFuel/14.7))

Where air density (in lbs/ft^3) is given by:

AirDen=0.039157(BaroPress-31.0)/((MatTemp/10)+459.7)

withBaroPress= barometric pressure in KPa * 10 (from sensor), 31 = 3.1 Kpa correction for vapor pressure, assuming a humidity of 75 percent at 85 degrees F temperature. This is arbitrary since we do not sense humidity, but should be better than assuming 0 percent relative humidity in most cases.MatTempis the intake manifold air temperature in degrees F * 10 (from sensor).Mass Air Coefficient, which is a subset of theMassAirFaequation, is given by:

VeafCorr = VE(MAP, RPM)/(AirFuel/14.7)

Ideally this entire table should be values at or below 1.0 if you’re naturally aspirated.

This is where I started to get away from the work on DIY EFI. It’s great, but the Megasquirt VE(MAP,RPM) calculations are a more accurate model. VE is derived from a couple ambient conditions, engine performance characteristics, and plotted over either a MAP vs RPM table or a Load % vs RPM table.

We’re going to use quadratic coefficients to calculate VE .

VE = A*RPM^2 + B*RPM + C

Where A, B, and C are the quadratic coefficients. Defined as:

A = (y2-y1)/((x2*x2)-(2*x1*x2)+(x1*x1))

B = -2 *A + x1

C = y1+ (A + x1*x1)

Once you’ve gotten this far, you can calculate the theoretical PulseWidth for any conditions. But, somebody somewhere once told me that “Truth is stranger than fiction… Or theory for that matter.” That’s where datalogging comes in.

I’m still working on the injector timing and spark table part, but it doesn’t look very difficult. The fuel enrichment calculations, on the other hand, are pretty convoluted, and get worse when more than one condition applies. So I might just skip them.

TL;DR, looking for feedback from people who do voodoo shit. Here's a pretty picture for attention: