Copyright: MegaTune v2.25


Warmup Wizard

The Warmup Wizard was developed by Steve Herz and Marc Piccioni.  It helps you tune your afterstart enrichment (ASE), warmup enrichment (WUE) and cranking pulsewidths.  For full details on the enrichment fields and their meaning, see the enrichments help; this section details the specifics of using the wizard and not what the values mean.  (The default configuration for MegaTune is to display temperatures in Fahrenheit, but you can change this to Celsius by editing megatune.ini.)

Usage

As usual, this is a short primer, for complete details read the MegaManual tuning section.

You must have your base VE table tuned before you attempt to tune warmup enrichments, otherwise you are just wasting time.  The WUE factor is multiplied by other enrichment factors to compute the total enrichment correction; if the base pulse width is incorrect, you are not going to be doing anything useful by changing WUE values.

Similarly, ASE should not be tuned until the base VE is under control.  The values can be modified in this wizard for convenience only, as I don’t have any good algorithm for a starting point other than to say, “Read the MegaManual.”

Cranking pulsewidth, on the other hand, can and should be tuned as soon as possible, as it is completely independent of the VE table tuning. ??? Figure out how pw = warm idle pw * nSquirts /nIgnition events…

Indicators

When the engine coolant temperature is in the warmup mode, you will see big arrowheads to the right of the enrichment bin or bins that are participating in the warmup calculations (you will see no arrowheads when your engine is fully warmed up and WUE is no longer engaged).

You will see either one or two arrowheads, depending on how close the coolant temperature is to those bin’s selection value.  For example, if the coolant temperature is 42 F, then there will be a single arrowhead to the right of the 40 F bin, but if the coolant temperature is 52 F, then there will be arrows next to both the 40 F and 60 F bins.

When you invoke either the increment or decrement operations, all of the indicated bins will be modified.  If you see two arrowheads, both of those bins will be incremented at the same time.

Keystrokes

The two special keystrokes used by the Warmup Wizard match the tuning screen so as to reduce confusion.

Shift-Up = richen the active warmup bins by 1% (this is the same as clicking the Inc button).

Shift-Down = lean the active bins by 1% (same as clicking the Dec button).

Buttons

“Inc” increments the active bins by 1%, “Dec” decrements them by 1%.


Communications

MegaTune v.1.51 (dated 20 APR 2002) or later reads and saves the com port in a file named megatune.cfg.  This file will be created in the same directory as the megatune.exe executable, if it does not exist.

Port

The communications port number should correspond to the port to which the MS controller is attached.  Usually you will select port 1 or 2, but some machines force you up to higher numbers (for instance, we’ve seen com5 as the default on some IBM Thinkpad laptops).

Timer Interval (ms)

The timer interval dictates how frequently the runtime and tuning displays are updated.  An interrupt is generated at the specified interval, and the real time data is pulled down from the MS controller.  Use 100-200 ms to start; you can try to smaller values if your computer is fast enough (I use 50 ms without problems on a P2 233 mHz laptop).

Serial Data Rate

The data rate is hard coded into your MegaSquirt embedded code, and if you have not modified the assembly code, then YOU MUST USE 9600!  If you change this value from 9600, nothing will work and you will spend a lot of time trying to figure out what is wrong.

Verify ECU Communications

Click this button to attempt communications with the MegaSquirt controller.  Success will be reported.


Topic Name

You can blah blah blah…


Setting The Constants

Required Fuel - One Cylinder (ms)

This field of the Constants dialog should contain the injector pulse width, in milliseconds, required to supply the fuel for a single injection event at stoichiometric combustion and 100% volumetric efficiency.  In order to come up with this value, MegaTune provides a calculator that will suffice for 99% of applications (those for which it won't work generally require changes to the MS controller code itself, and that is beyond the scope of this help file).

Given this value, it is then fairly easy to see how the MegaSquirt controller does its job.  When you are running at 50% VE, MS cuts this required fuel value in half; if you require warmup enrichment of 30%, MS will multiply it by 1.30 and so on.

Click the Required Fuel button to invoke the calculator.

Injector Characteristics

Injector Opening Time (ms)

The amount of time required for the injector to go from a fully closed state to a fully opened state when a 13.2 v signal is applied.  Since fuel injectors are electro-mechanical devices with mass, they have latency between the time a signal is applied and the time they are in steady-state spraying mode.

Set Injector Opening Time to 1.0 ms and leave it there unless you are an expert and have information that indicates otherwise.

It is usually assumed that injector opening is linear with respect to the amount of fuel delivered, so it is easy to compute the amount of fuel delivered (rate * opening_time / 2).  So, if you deviate too much from the correct value for opening time, this assumption is incorrect; for instance, if you set the opening time to 5.0 ms when it is really 1.2 ms, then too much fuel will be injected with respect to the computed value.  The current MS controller code makes the simplifying assumption that zero fuel is injected during the opening (and closing) phases, so making this value larger will enrich the mix and will have a much greater effect at low pulse widths.  MS also uses this value as an additive constant in pulse width calculation, thus making this the lower limit for pulse width.

Opening time is also dependent on the voltage applied to the injector coil, which is where the next value (Battery Voltage Correction) comes into play.

Battery Voltage Correction (ms/v)

The decay rate of the Injector Open Time with respect to battery voltage.  When the system voltage deviates from the nominal voltage, the injector will take more or less time to open, this value corrects for this variation.

Set the Battery Voltage Correction rate to 0.1 ms/v and do not change it unless you are an expert and have specific data on your injector to the contrary.

Injector Current Control

In order to minimize injector opening time, some injectors have very low impedance coils and require specialized drivers.  The low impedance coil allows it to produce a lot more "horsepower" when opening the injector, but it produces so much power that it would burn up if left at full current for the duration of the injector pulse.  Therefore, the drivers for these injectors must give an initial full-current pulse to get the injector open, then after a certain amount of time, drop the current to some lower "hold" value to keep it open for the duration of the pulse (for this reason, low impedance injectors are also called "peak and hold" injectors).  The two phases of operation are called the opening phase and the current limit phase (current limit mode is when the MegaSquirt controller is driving the injector in the current limit phase).

MegaSquirt implements a "software" solution to the problem of driving these injectors, rather than a hardware one (this makes MS adaptable to virtually any type of injector available, another one of it's many strong points).  The hardware drivers (the big transistors bolted to the end case) are able to turn on and off very rapidly (much more rapidly than the injector can respond).  So, when the initial full current pulse time has expired, and the "hold" or current limiting phase is to begin, MS toggles the driver on and off at 15 kHz, which makes it look to the slower-responding injector as if the current available has dropped, and voila, current limit mode.

This scheme is called Pulse Width Modulation or PWM.  In a PWM circuit, you keep the frequency constant, but vary the width of (modulate) the "on" time by making the on and off parts of the signal different widths (i.e., from "on" to next "on" might always be 1 second, but the "on" part can vary from 0-1 second, with the "off" part always being 1.0-"on" seconds long).  The amount of time that the signal is on is called its duty cycle and is expressed as a percentage (0% duty cycle means off all the time and 100% means on all the time).  In MS, the PWM frequency is 15 kHz, and you adjust the duty cycle of the signal to control the “hold” current to the injector.

There are two settings controlling current to the injectors - one is the time after which the injector drive switches from full current to PWM current-limit mode, call PWM Time Threshold.  If you don’t know the actual characteristics of your low impedance injectors, try 1.0 ms for this, and once things are running you can adjust this time.  You can either calculate the charging current in your injector setup using theory (i.e., the charging equation for a solenoid, for which you will need the inductance value), or you can use the empirical method (start shortening the time until you notice a difference in idle, then back it off and lengthen it by, say, 0.1 to 0.5 ms or so).

The second setting is PW Current Limit, which controls the current after the injector opening period.  When you set this value, you are adjusting the duty cycle. This one is real easy to compute - take the battery voltage and divide by the DC resistance of an injector - this will give you the maximum current. Then you choose a desired hold current (usually somewhere around 1 amp or so for each injector), and set your duty cycle from this.

Choosing PWM Values for V1.01 Boards

The following discussion deals with V1.01 MS boards without the flyback modification.

For example, let say your injectors have a DC resistance of 2 ohms and have a 1 amp hold current.  First, calculate the DC current flow:

   12 v / 2 Ù = 6 A

Then, calculate the percentage of full current required:

   1 A / 6 A = 0.1666 = 17%

Round this up 5-10% and use the result, say 25% in this case.

Choosing PWM Values for V2.2 Boards

When using a V2.2 MS board or a V1.01 with flyback mods, you will have to substantially increase the PWM Current Limit percentage from the above calculations.  Typically you should start at 75% and work down from there.  Leave the time threshold value at small values, around 1.0 ms!  If you set it too high, you will melt your injectors.

With either setup, if you are converting an existing EFI system with resistor packs on P&H injectors, you can keep the resistor pack, and then you do not need the PWM mode, so set the current limit to 100%.  If you get rid of the resistor pack, then you will need to turn on PWM current limiting.

PWM Time Threshold (ms)

When running peak and hold injectors, set this value to the time your injectors require full current.  A typical value for the full-current time might be 1.0 ms.  When the injector has received a full-current pulse of this duration, the signal is modulated at the lower current for the rest of the pulse.

PWM Current Limit (percent)

For high impedance injectors, set this value to 100%.  For low impedance injectors, set this value to determine the hold current, as described above for your particular hardware.

Fast Idle Control

Fast Idle Threshold (degrees F)

Enter the temperature below which you wish to turn on the fast idle solenoid.  This is independent of any warmup enrichment.  A typical value is 145 Fahrenheit.

Correction Factors

Barometric Correction

Enabling barometric correction causes an additional multiplicative factor to be used when computing injector pulse width.  The correction factor is 100% at 30 in/Hg (101.6 kPa), varying as described by the table contained in barofactor.inc.  See the archives for several debates as to the merits and necessity of barometric correction, most people are leaving it off with no ill effects.

Injector Control

Control Algorithm

Depending upon your engine’s characteristics you may choose either Speed Density (or SD, which is preferred in almost all cases) or Alpha-N as the algorithm for computing injector pulse width.  Speed Density uses RPM (the speed part) and manifold pressure (MAP, the density part) as the primary inputs to estimate flow into the engine.  Alpha-N uses throttle position (also called Alpha) instead of MAP in the flow equation, and can only be used for normally aspirated engines.  Alpha-N should only be used in situations where the vacuum signal to the MAP sensor is so poor that it is impossible to tune with SD, such as might be found with very long duration cams with individual intake runners.

Injections per Engine Cycle

Set the number of squirts you want per engine cycle.  This is the total injector events that you wish to occur for every engine cycle (360 degrees for two stroke engines and 720 for four strokes).

Injector Staging

Values for injector staging are simultaneous or alternating.  If you wish for all your injectors to fire at once, select simultaneous.  More likely you will choose alternating, as this helps even out the pressure fluctuations in the fuel rail.  If you use too many squirts per cycle, you might run out of time for all the injection events, since each one has the overhead of injector opening and closing.  Likewise, raising the number of squirts effectively reduces the size of your injectors, since more time must be dedicated to the less-than-full-flow injector opening time.

Two squirts alternating is the same as one squirt simultaneous, except that the injector banks are fired out of phase.

Engine Stroke

Values for engine stroke type are two or four.  MS uses engine stroke to determine how many degrees are in an engine cycle.

Number of Cylinders

Count the cylinders on your engine.  If you are unsure how many cylinders your engine has, you shouldn’t be installing MegaSquirt on it.  This value is actually the number if ignition events per cycle sent to the ignition input on the controller (so my initial Audi installation, which took the ignition signal from a single-window Hall sensor in the distributor, was set up as a 1-cylinder motor rather than a 5-cylinder).

Injector Port Type

Select the type of injector that you are using, throttle body or multi-port.

MAP Type

Values for this may be selected from the option menu, and are either 115 kPa or 250 kPa.  This should be auto-detected from MS, but in case it is not, then select the right one and hit "Send to ECU" right away.

Engine Type

Even fire engines have evenly spaced ignition events, say every 90 or 180 degrees of crank angle.  Odd fire engines (like 45 V-twins) will fire with a different interval between each spark (135 and 225 degrees, for example).  The odd fire code was not implemented in either of the V1 or V2 controller code, so just leave this at even fire.  If you have an odd fire engine, ask about this at http://www.msefi.com/ and someone may be able to help you.


Enrichments

Priming Pulse

The duration in milliseconds of a priming pulse that is applied when the MS controller is powered up.  If you don’t want a priming pulse, set this field to zero.  (Only available for version 2.0 and later of MegaSquirt controller code.)

Cranking Pulsewidth

Cranking pulse width determines how long the injector will be open in milliseconds for each pulse while the engine is cranking (i.e., the RPM is below 300).  The actual pulse width is determined by performing linear interpolation on the line described by the end points you enter for the "-40 degrees F" and "170 degrees F" values.  For instance, if you enter 10.0 ms as the pulse width at -40 F and 2.0 ms at 170 F, the pulse width will be 6.0 ms when you start your engine at 65 F.

Note: Cranking pulse occur at every ignition event, while running pulses only occur at the interval specified on the constants page; if you have a 4 cylinder engine and are taking the tachometer signal from the coil, then you will get four (4) cranking pulses per cycle and depending on settings one injection per cycle while running.

The MS variables "CWU" and "CWH" hold the low temperature and high temperature pulse widths, respectively.

Afterstart Enrichment

The afterstart enrichment is one that decays from its max value (specified in the "Enrichment (percent)" field) to zero in a linear fashion over a period defined in "Number of Ignition Cycles."  If you specify 20% enrichment over 250 ignition cycles, then the first pulse is enriched by 20%, the 125th pulse is enriched by 10% and the 250th (and later) by zero percent (this assumes 1 event per cycle, or a 1 cylinder engine; divide by the number of ignition events per cycle to get the specific behavior for your motor).

MS stores these values in the flash constants called "AWC" (Afterstart Warmup Count) and "AWEV" (Afterstart Warmup Enrichment Value).

Exhaust Gas Oxygen Sensor Parameters

These parameters define the closed loop behavior of MS.  You must have a narrow band O2 sensor hooked up for this mode to work in v.1.0 controller code; either a narrow band or wide band will work with v.2.0 of controller code.  To disable closed loop operation altogether, set the EGO Step value to zero.

EGO Sensor Type

Specify either a narrow band sensor or wide band sensor.  Functionally this merely sets the direction sense of the sensor voltage.  For narrow band sensors, the voltage rises as the mixture is richening and drops as the mixture becomes lean.  The wide band setting corresponds to the opposite sense, i.e., voltage drops to indicate enrichment (this is how the DIY-WB operates, not necessarily all WB sensors!).  (Available in v 2.0 controller code.)

EGO Switch Point (v)

This is the switching point voltage that indicates stoichiometric combustion (approximately 14.7:1 with gasoline).  For narrow band sensors this is 0.5 v*; for the DIY-WB wideband sensor it is 2.5 v (for other wideband sensors this voltage may be quite different).  (This value is only active in v 2.0 controller code.)

*This is true for zirconia NB sensors, which are used almost exclusively in modern vehicles.  The titania NB sensor has a different voltage range (1-5 v), but is rarely used.

Coolant Temp Activation (°F)

This is the temperature below which closed loop operation is disabled.  If this value is too low, then closed loop will try to lean out the warmup enrichments and you may experience rough running.  Typical value is 160 F and should somewhat above the point at which warmup enrichment stops (see the Warmup Enrichment Bins settings and find the lowest on which contains 100).

The MS value "EGOTEMP" stores this quantity.

Ignition Events Per Step

This value determines the rate at which the closed loop algorithm applies correction.  The default value of 32, when used on a four cylinder engine with four ignition events per cycle, tells MS to wait for 8 cycles before changing the current correction factor.

EGO Step (percent)

Once the closed loop algorithm has decided to change the correction factor, it adds or subtracts this percentage from the current value.  This should move slowly to avoid unstable response, so make sure it is small, 1% being the default.

EGO   Limit (%)

Closed loop operation should not be substituted for proper tuning!  This value limits the correction that can be made by the closed loop algorithm, the default of 10% indicates the correction factor cannot go outside the range 90-110%.

EGO Active Above RPM

This value specifies the lower limit above which closed loop operation occurs.  Typically, your engine will idle best when it is richer than stoich, so turning off closed loop for low RPMs allows this to happen. The default value for the RPM limit is 1200.  (Available only in v 2.0 MS, older versions have a fixed 1200 RPM value in the controller code.)

Warmup Enrichment Bins

Warmup enrichment is based on coolant temperature.  Since warmup enrichment requirements are usually non-linear, several bins are provided to specify different rates in different temperature domains.

Place values in the "-40" through "160 degrees F" fields, typically running from about 120 at -40 F to 100 at 100 F; make sure the values are all 100 or greater.

The MS array "WWU" contains these enrichment values.

Acceleration Enrichment

Acceleration enrichment (AE) occurs when you open the throttle "rapidly" to avoid bogging the engine.  In v.1.01 MS, this is done solely based upon the rate of change in the throttle position sensor (also called TPSDOT).

TPSDOT Thresh

This is the threshold in v/sec below which no acceleration enrichment will occur (you can move the throttle from idle to full open without acceleration enrichment, if you open it slowly enough).  Depends grossly upon the range of your TPS, a typical value might be 1.2 v/sec.

Tuning Note:  While you are tuning the VE table you should set this threshold artificially high (maybe 40.0) to disable acceleration enrichment completely.  After the VE table is fairly well-defined, set this back to 1.2 and begin tuning AE.

MS stores this value in the "TPSTHRESH" variable.

Accel Time (sec)

This value indicates how long the acceleration enrichment "squirt" will last.  Typical values are around 1.0 second.  MS stores this value in the variable "TPSACLK."

Cold Accel Enrichment (ms)

The acceleration enrichment pulse also varies depending upon coolant temperature.  The value specified here is the pulse width added to the value from the bin calculations at -40 F.  The Cold Acceleration Enrichment amount is linearly interpolated from full amount at -40 F down to zero at 165 F.  A typical value might be 2.0 ms.

This value is stored in the "TPSACOLD" variable in MS.

Cold Accel Multiplier (%)

Another means for increasing the amount of fuel delivered by the acceleration enrichment pulse is supplied by this value; it is likewise interpolated from the full specified amount at –40F down to zero at 165 F.  Before the Cold Acceleration Enrichment value is added to the base acceleration enrichment pulsewidth, it is multiplied by this value.

Total AE = Base AE * CAM + CAE

The difference between the two types of AE cold modify can be easily seen with a few examples:

1)	Assume we have a calculated AE pulse of 5.0 ms.  Say our coolant temperature is 40 F,  giving a CAE pulse of 2.0 ms and CAM is turned off (100%).  The result is 5.0+2.0 = 7.0 ms.

2)	Assume same base AE and temperature, but now we turn off CAE (0.0 ms) and set CAM to give 140%.  The result is the same, we get 5.0*1.4 = 7.0 ms.

3)	Take the first case, but hit the accelerator faster, giving 8.0 ms base AE pulse.  We now have a result of 8.0+2.0 = 10.0 ms.

4)	Take case 2, but with the higher base AE pulse, giving 8.0*1.4 = 11.2 ms.

The bottom line is that the CAE modifier is constant and independent of the base pulse, where on the other hand, the CAM modifier has a proportional effect on the AE, bigger base pulse means bigger result.

This value is stored in the “ACMULT” variable in MS.

Decel Fuel Amount (%)

When you let off the throttle rapidly (that is the closing rate exceeds TPSDOT Thresh) and the engine is turning faster than 1500 RPM, then deceleration fuel cutoff is performed by MS.  Deceleration fuel amount is multiplied by the "normal" pulse width, that is, if the calculated pulse is 12.0 ms and you have 20% decel amount, then the resulting pulse width is 2.4 ms.  A value of 100% causes the fuel to remain at its calculated value, and can cure bucking on deceleration in vehicles with manual transmissions; those with automatic transmissions may benefit in fuel economy by using values below 100%.

The MS variable "TPSDQ" holds this value as a percentage.

Acceleration Enrichment Bins (ms)

These bins specify the actual enrichment in terms of pulse width.  They are linearly interpolated to determine a value that is ultimately added to the computed pulse width.

The array of values is called "TPSAQ" as stored in MS.


Expressions

MegaTune allows you to compute values from MegaSquirt’s output channel data or from constants and settings in the database.

Data types:

Int - signed 32-bit integer.

Double - double precision floating point numbers.

String - dynamic length collection of characters.

Boolean - results derived from comparisons or directly from above values, with 0, 0.0 and "" being false and all other values being true.

Operators in order of descending precedence:

() grouping

!  logical NOT

~  bitwise NOT

-  unary minus = negation

*  multiplication

/  division

%  modulus

+  addition

-  subtraction

<< left shift

>> right shift

<  less than

<= less than or equal to

== equal to

>  greater than

>= greater than or equal to

!= not equal to

&  bitwise AND

^  bitwise XOR

|  bitwise OR

&& logical AND

|| logical OR

?: conditional

Built-in math functions and constants:

PI

acos(x)

asin(x)

atan(x)

atan2

ceil(x)

cos(x)

exp(x)

fabs(x)

floor(x)

fmod(x,y)

log(x)

log10(x)

pow(x,y)

sin(x)

sqrt(x)

tan(x)

MS-specific functions:

const(addr) - Returns the integer value of MegaSquirt's memory at the specified address.  Look in your assembler output and find the offset of the variables in the constant section.  For example, in the standard B&G v 3.0 code, EGO enable temperature is stored at offset 86 as degrees F minus 40, so “const(86)” will fetch that value.

itable(value, "filename") – “Inverse” table, causes the table to be read on the first invocation.  Returns the index of the table entry nearest the “value” parameter.  Table files may contain an arbitrary number of 16-bit signed or unsigned quantities.  A good example of use is to feed a throttle position percentage into this function, and get back the raw ADC value corresponding to that value.

table(idx, "filename") – Table lookup causes the table to be read on the first invocation.  Indexes into the table and returns the value contained at the specified location.  Table files may contain an arbitrary number of 16-bit signed or unsigned quantities.

tempCvt(x) - Converts Fahrenheit temperature to user-selected units.  Does nothing if temperature units are already set to F.

timeNow - Parameterless function returning the current count of seconds since MegaTune started.  Seems to be accurate to about 1 ms on modern laptops.

vexInterp(speed, load, page, "filename") – Reads a VEX file on first invocation, and returns an interpolated value from the specified page from the file (page numbers are zero-based, so the first page is numbered zero).  The speed and load values are typically rpm100 and map, corresponding to the values in the VEX file.


Gauge Configuration

You can reconfigure the gauges


Gauge Frames

You can relocate and resize the gauges


Memory Editor

Memory editing has two components, the table editor and the memory viewer.  The table editor works with all known versions of the MS code (V1, V2 and dual table), and allows you to edit the raw data contained in the constants section of the controller.  For B&G code you can edit 125 bytes of data, including the unused bytes that you cannot otherwise change through the fancy interfaces of PCC or MT.  With dual table code, you can edit a full 256-byte page of flash memory.

Note that the table editor modifies RAM directly on the MS controller as soon as you change a value on the screen, but it does not burn those changes to FLASH.


Initialization Files

Before you see the front page of MegaTune it reads several files.

Transfer Functions

MegaSquirt reports many real-time data values as raw ADC (analog-to-digital converter) values.  These are commonly called “counts” because of the way the ADC hardware computes the digital value (typically by accumulating a charge, while counting how long it takes the charge to reach a certain level).  Because an ADC count of 133 means little to the engine tuner, MegaTune converts this value into 74° Fahrenheit so that you can make sense of it.  This conversion is performed by use of transfer functions encoded in tables 256 entries long.  Since one byte of data (one byte being the size of the ADC counts on the MC68HC908 MCU in MegaSquirt) can take on 256 values from zero to 255, the construction of this table is pretty simple with the ADC count indexing into the table thus producing a value in engineering terms.

The following files are delivered with MegaTune, and work with the sensors indicated.  You can change these files easily if you use different sensors, and EasyTherm generates appropriate ones for use with MegaTune.

•	airdenfactor.inc – turns ADC counts into air density correction factors; for use with GM “standard” MAT sensor.

•	barofactor.inc – turns ADC counts into barometric correction factors; two copies come with MegaTune, for the Motorola MPX4115 and MPX4250 MAP sensors.

•	kpafactor.inc – turns ADC into kPa; paired with barofactor.inc, using the same sensors.

•	matfactor.inc – turns ADC into degrees F-40; for use with GM MAT sensors.

•	thermfactor.inc – turns ADC into degrees F-40; use with GM CLT sensors.

•	throttlefactor.inc – generated on the fly by MegaTune, see Tools->Calibrate TPS…

The transfer function tables are found by file name, not by the label in the file (which is actually ignored).

Configuration File

The configuration file megatune.ini contains information regarding your preferences for the interface.  It allows you to specify whether temperature is displayed as Celsius or Fahrenheit, what the RPM range is on tachometers, where the redline should be on the tachs, and other similar things.

Gauges can have either two or three values, the first is the lower gauge value and the second is the upper limit.  If the third is present, it is the “redline” for that gauge (i.e., the gauge arc will be drawn in red at and above that value).  If the gauge has a warning LED, then it will come on when the gauge value exceeds the redline value.

Settings for “bar gauges” have two values, the lower and upper limit for that bar.

The temperature setting is a single character, either C or F.

All temperature values in this file are in degrees F, and are converted when used as limits on the gauges and bars.

[MegaTune]

defaultVersion=2.0

[Units]

temperature=F

[FrontPage]

rpmGauge=0,8000,6700

mapGauge=0,255,200

throttleGauge=0,100,100

pulseWidthGauge=0,25.5,25.5

dutyCycleGauge=0,100,85

[RunTime]

egoBar=0,1.0

coolantBar=-40,215

batteryBar=6,15

throttleBar=0,100

gammaEBar=0,200

mapBar=0,255

matBar=-40,215

rpmBar=0,8000

pulseWidthBar=0,25.5

dutyCycleBar=0,100

egoCorrBar=0,200

baroCorrBar=0,200

warmupCorrBar=0,200

airdenCorrBar=0,200

veCorrBar=0,200

accCorrBar=0,100

[Tuning]

rpmGauge=0,8000,6700

mapGauge=0,255,200

throttleGauge=0,100

; Set ego range about switch point and last value to switch point.

egoGauge=0,1.0,0.5

warmupGauge=0,200,100

veGauge=0,120

acceGauge=0,200

veBar=0,120


Datalog Options

You can specify optional text be recorded in any datalog generated by MegaTune.  If you wish for some user-defined text to be included at the top of the datalog, then write some text into the edit window of the options dialog, where you see the label “Log file comments:”.

If you select “Prefix log with dump,” then every datalog in this session will have a MegaTune dump of the controller configuration at the front of the log file.  This dump is contained in quoted strings, so you can still read the file into MSLVV and MSTweak correctly, and the dump appears as text if you open it in Excel.

Likewise, if you select “Suffix log with dump,” then the datalog will contain a dump at the end.  If you have changed your configuration between starting the log and finishing it, then you will be able to compare the two and see these differences.  This suffix dump is written out automatically if MegaTune is terminated, so you needn’t manually terminate logging.


Using MegaTune

MegaTune is the Windows 95 and later configuration editor for the MegaSquirt EFI controller.  It allows all of the parameters to be modified and has a real-time VE table editor, which allows a vehicle passenger to tune the engine while driving.

See Getting Started for some tips on setting up MegaTune for your engine and tuning it.  If you can’t find what you are looking for in this help, ask on the http://www.msefi.com/ forum/e-mail list or read the online documentation at http://www.megasquirt.info/.  This help file is sketchy, since I develop the code faster than I write help files.

Gauges

The front page shows eight gauges, the left four of which are the major inputs to MegaSquirt and the last four are the output pulse width and resulting duty cycle for the two injector banks.

Pulse width is the measure in milliseconds of how long the injector is opened for each pulse, regardless of how many times it is opened in a cycle.  Duty cycle gives the percentage of time the injector is open irrespective of individual pulse duration.

The bar gauge across the bottom of the window shows the oxygen sensor reading.  The scale is determined by egoGauge value in the Tuning section of the megatune.ini file.  This same setting controls the analog and bar gauges on the tuning screen.  The first value of this setting controls the lowest voltage displayed on the gauges, the second number controls the highest and the optional third value specifies the “alert” value, above which the LEDs are red.

Gauge Modification

The gauges in MegaTune are fully configurable and you can read about the related topics in the following sections:

1.	Expressions – defining output channel data.

2.	Gauge configuration – defining a gauge’s data source, limits and colors.

3.	Gauge frames – defining where on which page a gauge will appear.

File Menu

MegaTune allows you to save and restore configurations as disk files.  Use the Open, Save and Save As entries to do this.

Datalogging

Datalogging allows you to turn on the logging of realtime variables.  Once you’ve enabled datalogging, MegaTune polls the MS controller when any of the front page, runtime display or tuning screen are active, and writes this data to a file.  The file has a comma-separated value format and defaults to having an extension of “xls”, so Microsoft Excel will open them automatically.

There are three datalog formats: classic, full and raw.  The classic format is useful for interfacing to other programs (old versions of MST3k require this format).  The full format is the most useful for examining values manually and for making plots and such (it is the only format with a continuous real-time clock).  The raw format is simply that, the exact 8-bit values returned from MS; these values are raw ADC counts and internal values, so don’t expect to see kPa values or voltages in a raw log.

The classic datalog may be used as input to the MSTweak3000 program to automatically correct your VE table.  See the MSTweak folder at http://www.msefi.com/.  MST3k release 1.1.22 or later will process either classic or full datalogs, automatically detecting which type of log is being read and acting accordingly.

Classic Data Log Format

The data log contains a header line indicating the contents of each column.  These values are as follows:

Seconds - The seconds part of MS's internal clock.  Since this is a one byte value, it wraps around at 256.

RPM - The engine speed in RPM, to the nearest 100 RPM (you will never see anything but zero for the last two digits).

MAP - The calculated MAP sensor pressure in kPa.  The correct value for this uses the transfer function embedded in MegaTune (or preferably read from your kpafactor.inc file).

O2 - The O2 sensor value in volts.

EngineBit - A bit string containing the following fields:

Running (bit 1) a value of zero means the engine is not yet running, 1 means it is running.

Cranking (bit 2) 0 = engine not cranking, 1 = engine cranking.

Startup Enrichment (bit 3) 0 = not in startup warmup, 1 = in warmup enrichment.

Warmup Enrichment (bit 4) 0 = not in warmup phase, 1 = in warmup.

TPS Acceleration Enrichment (bit 5) 0 = not in TPS acceleration mode, 1 = TPS acceleration mode.

TPS Deceleration Enrichment (bit 6) 0 = not in deacceleration mode, 1 = in deacceleration mode.

In Excel, you can use a formula like this to extract a given bit:

   =MOD(INT(E10/4),2)

which extracts the 3rd (warmup enrichment) bit.  The divisor (in this case 4), is computed by using 2**(bit number-1), so 4 came from 2**(3-1) == 2**2.

Gego - The EGO gamma in percent.

Gair - The air density correction gamma in percent.

Gwarm - The warmup enrichment gamma in percent.

Gbaro - The barometric correction factor gamma in percent.

Gve - The current VE as computed inside MS.

Gammae -The total gamma enrichment in percent.

PW – The pulse width in milliseconds.

Status Bar

The bottom of the front page contains a status bar.  The current file name (used for Save operations) is displayed in the left part of the status bar, followed by “saved” status.  When the memory image has been modified since the last Open or Save operation, this entry shows “SAVED” in bold face.

When datalogging is enabled, the second status box contains a bold “LOGGING” indicator.

The rightmost indicator contains either grayed-out “CONNECTED”, meaning that MT is not communicating with MS, dark “CONNECTED”, indicating that MT and MS communications is working properly, or dark “RESET n”, indicating that the MS controller has been erroneously re-booted n times since MT started talking to it.


MegaTune Mini-Terminal

MegaTune has a built-in terminal emulator, under Communications -> Mini-Terminal.  It allows you to do loop-back testing during MS board assembly, check error status on with various firmware versions and check firmware types, among other things.

Assembly-Time Communication Checks

While you are soldering up your MegaSquirt board, you will need to do some testing.  The “loop-back” testing described in the assembly instructions can be accomplished using HyperTerm or any other terminal emulator, but if you use MT’s Mini-Term to do them, then you know that not only is the MS hardware working, but that it indeed is talking to MT properly and you have your settings specified correctly.

To run the loop-back tests, follow the instructions for installing the jumper or jumpers on your main board, then start typing characters into Mini-Term.  Since Mini-Term implements a local echo of all characters sent, you should see the characters you type appear twice, first the local echo and then the character that comes back on the communications loop.  For instance, if you type "test", then you should see "tteesstt" on the screen.

Remember that the baud rate for MS-I is 9600 and MS-II is 115200; you will probably need to change the comm port setting to find out which is correct on your PC.

MSnS-Extra Error Reporting

The MSnS-Extra firmware contains some very nice built-in diagnostics that check for configuration conflicts at startup.  For instance, I set my test box to use HEI Ignition, but left LED19 set to display acceleration enrichment.  Upon power up, the stimulator LEDs flashed indicating an error (injector LEDs black, the fuel pump LED flashing every second or so), and this error message came up in the Mini-Term window.

In HEI7 mode you must have LED19 set as a spark output for the bypass signal

In order for you to see these messages from the MSnS-Extra code, you will need to have Mini-Term displayed, and then power cycle the MegaSquirt.  The messages are sent once at power up, so if you don’t see them the first time, you may need power cycle the MS several times.

Checking Firmware Versions

Virtually all MS firmwares will report their version number or other version information if you send them the proper command.  Various version use either upper or lower case “S”, “Q” or “T” to get back this information.  Often you can get two pieces of information from the firmware, both its “interface” version and its “feature” version.  The interface defines the memory footprint that the firmware defines, and the feature version can tell you about the bug fix levels

For example, my test MS-II responds to both “S” and “Q”.  Sending “Q” produces MS-II’s interface version string:

MSII Rev 2.30000

While sending an “S” produces its feature version, which differs in the revision number (all of the 2.3x code versions shared the same memory layout, but the later ones had bug fixes and features added):

** V2.32Embedded Code by B&G **

So, when you get a response to “T”, don’t just stop there, try the other commands and see if they report something different.


Creating and Selecting New Projects

MegaTune allows you to manage data for multiple MegaSquirt installations.  First you must use the installer to build yourself a default setup.  Once you have a basic MegaTune setup, make a copy of the "car1" directory for each new project, so your installation directory looks like this:

   c:\Program Files\MegaSquirt\
      MegaTuneN.NN\
      car1\ - created by installer, cut'n'paste it, then rename it.
         copy any .msq and .log files for this engine here...
         mtCfg\
            custom.ini from c:\Program Files\MegaSquirt\MegaTuneXXX\mtCfg\
            copy any install specific .inc files here...
      car2\
         same as above, make sure it contains at least mtCfg\custom.ini
      ...
      carN\
         mtCfg\
            custom.ini

In the MegaTuneN.NN directory you can find all the files for that specific version of MegaTune, including executables, help files, readme, and basic configuration files.

Instead of "carN", use a real name, my two are "MaxQ" and "Rocco" for my two cars (the actual names are of no significance, just make sure each car directory contains an mtCfg subdirectory).

Once you've got the directory structure in place, copy any old log or msq files you may have into the places noted in the little diagram (wherever it says "copy").  You also need to move any special include files, such as those created by EasyTherm, into that engine’s mtCfg directory.  If you have customized init files for that MegaSquirt, say maybe you are running dual table code on it, then you would put all your customizations into custom.ini in the mtCfg directory, too.

Where you have only a single car directory, MegaTune assumes that you want to use that one, so starts there automatically.  When you have more than one, MegaTune will present you with a list of choices at startup, so you can work on the correct one.  By typing the initial letters of the project name, you can jump down the select list to the desired one quite quickly.  Once you have the desired project highlighted, just hit the enter key or use the mouse to click “Ok.”


Required Fuel

Engine Displacement

The total swept displacement of your engine (more precisely, the air that your engine would pump in a single cycle at 100% VE).  Nothing tricky here, just tell MegaTune how big your engine is.

Number of Cylinders

This is the number of cylinders in your engine, used to divide the engine displacement above to compute mass of air per cylinder at 100% VE.  If you have set the number of cylinders in the Constants window, then this value will be copied into the Required Fuel dialog.  If you have not set it in the Constants, then the value you set here will be copied from Required Fuel dialog to the Constants dialog.

Injector Flow

The nominal flow rate of your injectors at the fuel pressure that you will run.  If you have a flow rating in cc/min divide it by 10.5 to get lbs/hr (this assumes a specific gravity of 0.70 for the fuel).  If your flow rating is at a different pressure (say they are rated at 43.5 psi and you will be running 50 psi), use the following equation to compute the flow rate at the new pressure:

   newRate = oldRate * sqrt(newPressure/oldPressure)

So for our example, assume we have 550 cc/min@43.5 psi injectors we wish to run at 50 psi:

   550 * sqrt(50/43.5) = 589 cc/min

Air Fuel Ratio

The stoichiometric mass ratio for the fuel you plan to use with the MegaSquirt controller.  For gasoline, this should be 14.7:1.  Stoichiometric mass ratios for other fuels are given in the table below, but be aware that they all have very different density than gasoline, so the injector flow rate will be different, too.

Fuel	AFR

Methanol	6.4

Ethanol	9.0

Gasohol (10% ethanol)	14.2

Gasoline	14.7

Propane	15.7

See http://www.faqs.org/faqs/autos/gasoline-faq/part2/section-1.html for more.


Runtime Display

Realtime Variables

This display shows the values inside the MS controller in real time.

Time (s)

Time in seconds since MS last booted (MS "secl").  This value is derived from the 8-bit seconds value in the internal MS clock, and will therefore only display values from 0 to 255 (it wraps around when it hits 255).

Barometer (kPa and in/Hg)

The barometric pressure as measured by MS.  Currently this is a static value determined at startup.  Returned by MS in "baro" as a raw ADC count.

O2 (v)

This is the voltage detected on the EGO sensor if on is installed.  For narrow band sensors this ranges from 0-1 v and typical wideband sensors have a voltage range of 0-5 v.

Coolant (F)

The value reported by the coolant temperature sensor (returned by MS in "cts" as a raw ADC count).  Don't be alarmed if it seems to be stuck at 215 F when your dash gauge is reading higher.  Due to 8-bit software constraints this is the maximum value that MS knows about.

NOTE

Version 1.00 of MegaTune had hard-coded transfer functions from ADC count to temperature.  If you used a non-GM CTS and changed the THERMFACTOR table in your MS, then MegaTune would show you "wrong" values for coolant temperature.

Batt (v)

Current battery voltage as measured inside MS.  If this number looks lower than actual battery voltage (probably 14.0 v or higher), then you may not have big enough wires running to MS; put a voltmeter across the wires from the board to their source in your vehicle's wiring loom (should be less that 1 v, a lot less).  Returned from MS as a raw ADC count in "batt."

TPS (v)

Throttle position in volts.  Most TPSs don't range from 0 to 5 v, so don't be alarmed if yours only goes from 1.5 to 4.4 v as this is normal.  The nominal TPS value itself is not interpreted in any absolute way, but rather the rate of change in TPS is what is used for acceleration enrichment.  (Well, that's not exactly true as the value of 3.0 volts is used to denote "flood clear" mode; i.e., if you hold the throttle down past the 3v mark when cranking, the pulse width is cut back to 1.0 ms.

Hmm, now that I peruse the code a little closer I also see 3.5v being used as the threshold above which O2 closed loop mode is disabled.)  Returned from MS as "tps" as a raw ADC count.

GammaE

Gamma is the total enrichment factor, computed by MS taking into account all of warmup, acceleration/deceleration, barometric, manifold air temperature and EGO sensor correction factors.  (See Corrections/Enrichments, below.)  Returned from MS as a percentage value in "gammae."

MAP (kPa)

The manifold absolute pressure as seen by MS in kiloPascals.  Returned in MS "map" as a raw ADC count, converted in MegaTune using a hard-coded transfer function.

MAT (F)

The raw temperature of the air at the Manifold Air Temperature sensor.  Used in conjunction with MAP to compute manifold air density.  (See note on Coolant temp, above.)  Returned by MS in "mat" as a raw ADC count.

RPM

Engine speed in RPM.  If this is jumping around in an unpredictable manner, you probably have a poor ignition signal input to MS.  It is returned from MS as RPM/100 in the variable "rpm."

Pulse Width (ms)

The injector pulse width being used by MS to squirt fuel into your motor.  Reported as 10xPulse width in the MS variable "pw."

Duty Cycle (%)

The duty cycle of the injectors indicates the total percentage of time that the injectors are opened.  This value should almost always stay below 85-90%, unless you really know what you are doing.

Corrections/Enrichments (percent)

This part of the realtime display shows all the individual correction factors used to compute gamma and the resulting pulse width.

EGO

This is the correction factor computed from O2 sensor readings.  Returned as a percentage by MS in "egocorr."  See "Exhaust Gas Oxygen" on the Enrichments page, below, for parameters to modify MS's computation of this factor.

Barometer

A barometric correction is applied, based on the initial MAP sensor reading.  Returned in "barocor" by MS.

Warmup

The warmup correction factor applied due to startup and coolant temperature status.  Returned in "warmocor" by MS.  See "Warmup Enrichment Bins" to modify the computation of this factor.

Air Density

Air density correction is computed from MAT.  This value is returned from MS in "aircor."

Volumetric Efficiency

The current computed VE value determined by look up in the VETABLE using RPM and MAP.  Reported in "vecurr" by MS.

Acceleration

Unlike all the other corrections here, the acceleration enrichment is an additive factor; take the result of all the above multiplied through, then add this one on.  Returned from MS in "tpsaccel."

Runtime Messages

This message is a decoded version of the MS engine status variable "engine."  Possible status values are (these are their names in the controller code megasquirt.h and megasquirt.asm):

Connected – MegaTune is communicating with the MegaSquirt controller.

Cranking - whether the engine is cranking (i.e., RPM is less than 300).

Running - whether the engine is considered to be running or not.

Warmup - indicates that the engine is in warmup due to coolant temperature.  You can change the TPSaen behavior by changing the "Warmup Enrichment Bins," below.

Afterstart - indicates if after-start warmup enrichment is being done (see Afterstart Enrichment in the next section).

ACCEL - tells us if MS is applying acceleration enrichment.  Change the acceleration enrichment by modifying the values on the "Enrichments" page, below.

DECEL - indicates any acceleration enleanment (de-enrichment).


Getting Started

If you have a MegaSquirt stimulator, use it a lot before you try to install the controller on your engine.  You can run MegaTune against the stimulator and become very familiar with both it and MegaSquirt in the comfort of your living room, and learn all the little tricks and surprises before you hit the road.

Make sure you read all the online documentation at http://www.megasquirt.info/ before you try to anything with MegaSquirt or its derivatives.

TPS Calibration

One of the first things you should do after installing MegaTune is set up the throttle position file.  This is pretty simple, you need to turn on the MegaSquirt (don’t start the engine!), go to the Tools menu and select Calibrate TPS…  Leave the throttle closed and pick the Get Current button for closed position, push the pedal to the floor (this is why the engine isn’t running) and pick on the Get Current button for wide open throttle.  Click OK and you’re done.  Whenever you change the TPS or mess with the throttle body, just go through this procedure again.

Injector Setup

Read the Constant section well and characterize your injectors to the best of you ability.  For high impedance (saturated) injectors, this is pretty easy, but for low impedance (peak & hold) injectors, this might take some experimentation.

Do not set the opening time too high (over, say 1.5 ms), as this sets a lower limit on pulse width (actual pulse width is opening time + all that other stuff).


Throttle Position Calibration

Calibration of the throttle position in MegaTune is actually only an aesthetic adjustment; it has no affect on the operation of your MegaSquirt.  The calibration merely generates a file that MegaTune will use to display values from 0 to 100%, but since MegaSquirt uses its raw TPS ADC values internally, this really does nothing for you.

The calibration procedure is pretty simple.

1.	Turn on the MegaSquirt (don’t start the engine!).

2.	Go to the Tools menu and select Calibrate TPS…

3.	Leave the throttle closed and pick the “Get Current” button for closed position.

4.	Push the pedal to the floor (this is why the engine isn’t running) and pick on the “Get Current” button for wide open throttle.

5.	Click OK and you’re done.

Whenever you change the TPS position, just go through this procedure again.

Diagnostic Notes

If the closed throttle ADC count is higher than the full throttle ADC count, then you have the TPS installed backwards and need to swap the ground and Vref lines.

If the closed throttle value is over 150, then the MegaSqirt will be put into flood clear mode when cranking, and your engine will never start.  This may due to improper wiring, or because of a very strange TPS, but in any case, you’ll need to get this fixed.


Trigger Wizard

You use the ignition trigger wizard to set the Trigger Offset value.  In order to do so, you need a timing light connected to cylinder 1 on your engine.  Simply watch the timing light value and click the + and – buttons on the wizard until the two values match.


Tuning

Tuning Point

The "tuning point" is the red cross on the graph on the right half of the screen.  The three coordinate values corresponding to the current tuning point position are displayed in the status window in the same color as the cursor.

Spot

The “spot” is the green dot specifying current engine operating position in the graph.  The numeric values corresponding to the spot are displayed in green in the status window.

Keystrokes

Arrows move the tuning point to a different vertex on the graph.

Shift-Up = increase the value at the tuning point on the graph.

Shift-Down = decrease the value at the tuning point.

Ctrl-Shift-Up = increase the value by a “lot” (5 internal units).

Ctrl-Shift-Down = reduce the value by a lot.

F = find and place the tuning point on the graph vertex nearest the spot.

G = Goto spot; behaves as a continuous “F” mode.

Z = zoom between a 2D and 3D display of the VE graph.  2D mode makes it much easier to see where the spot is with respect to the tuning point, but 3D mode allows you to easily see when you have vertices that are out of agreement with the rest of the table.

M and N = rotate the 3D view, display new “gridOrient” so you can past the values into your custom.ini file.

S = save current state (i.e., burn flash on the MS).

X = eXit from the tuning dialog.

To navigate the graph on the right of the Tuning screen, use the arrow keys to move the tuning point, up moves up on the Y axis of the grid and down moves to a lower Y bin.  If you know VI, then you can alternatively use the standard motion keys from that editor; use "k" to go up, "j" to go down, "h" to go left and "l" to go right.  Left and right arrow keys move to the higher and lower X-axis bins, respectively.

For example, when the tuning dialog is being used to edit a VE table, the shifted up and down arrow keys enrich or lean the VE table value at the tuning point.  Alternatively, the "q" key richens the currently selected bin and "w" leans it.  Whenever you change a value in MegaTune, it is immediately changed in the MegaSquirt controller's RAM.  These changes will go away when you turn off the engine if you do not save them into flash memory by typing "b" for “burn to flash.”

Gauges

If the Engine MAP gauge appears to be reading at about half of what you expect and you are running an MPX4250 sensor, then MS is using the wrong transfer function table for your sensor.  This could be because you either told MS you have the other sensor, or because MegaTune read the wrong kpafactor.inc file.  Run the MegaTune Configurator and see what configuration is selected.

The operation of the gauges should be self evident, with the exception of the VE gauge.

VE Gauge

The VE gauge on the tuning screen represents the VE table value corresponding to the cursor placement on the right-hand side, not the runtime VE value.  The tuning screen allows one to access a particular VE table entry easily, by moving the cursor to one of 64 positions (up/down by 8 and left/right by 8), and the VE gauge represents the VE table entry.  If you hit the richen VE key, the gauge will go up by 1% for each hit, down for 1% lower - this is also transmitted to the ECU and it responds immediately.

So, lets say you want to set your VE value at idle.  Get the engine running, and bring the RPMs down to idle.  The "dot" on the screen follows the MAP and RPM, just like the ECU does internally to determine VE.  Move the cursor to a VE table point close to where the "dot" is, and then hit the richen (q) or lean (w) keys - the engine will react.  It takes only a few minutes to get used to the setup, and it takes a few seconds to dial in a VE table entry.

One thing to remember - if you like what you have adjusted, then you must hit the save (s) key in order for the setting to be stored in flash, otherwise the values will be erased when you shut off the key.  This allows you to play around with VE table values any time you like, and if you like what you did with the VE values then you can save them, otherwise go back to the old settings the next time you start the car.

The 15 Minute Tune

Rough tuning your engine is pretty straight forward if you have a narrow-band oxygen sensor wired into your MegaSquirt.  If you plan on tuning on the road (as opposed to on a dyno), then you will need an assistant.

The first step is setting the ReqFuel constant to an appropriate value.  If you know your injector flow rate, then use the calculator on the constants screen.  If you don’t know the flow rate, make a rough guess, then set all the values in the VE table around the expected idle MAP and RPM to 15-20%.  Start your engine and let it warm up, then tweak the ReqFuel value on the Tuning dialog while the engine idles.  Make the idle as smooth and strong as you can, it will probably be rich when idling, but this is ok.

Go to the Enrichments dialog and turn off acceleration enrichment by setting the TPSdot Threshold to some large value like 50 and turn off the EGO closed-loop mode by setting the EGO Step value to 0.

Now you are ready to rough tune the rest of the table.  While one of your team drives the vehicle, the other member will tune specific points in the table.  If you are the driver, you will need to hold a steady vacuum and RPM at each of the vertices on the tuning screen; the green dot will reside at the intersection of two lines.

If you are the tuner, you will be watching the Exhaust Gas Oxygen gauge and trying to get it to hover around its mid-point (0.5 volts).  Do this by moving the cursor to the vertex of interest (type”F”) and then use shift-up and shift-down arrows to raise or lower the VE at that point (all of VE, fuel delivered and narrow band Exhaust Gas Oxygen move in the same direction, so if the EGO is below center, use shift-up to raise it).

Once you have the engine running reasonably well, start using datalogs and MSTweak3000 to do the rest of the table.


User-Defined Data Editor

Not all memory locations in the MegaSquirt’s tables are accessible from the standard dialog boxes.  In order to allow you to edit these values, the User-Defined Data Editor lets you customize what values are changed and what they are called.

I assume that you know what you are doing, and can figure out the offset of the values in the MS tables from the assembly language listings.  Once you know the offsets, modify the UserDefined section of the megatune.ini file following this example.

[UserDefined]

;lineN  Label                      Offset

line1 = “Dual table Cranking RPM”, 255  ; First two are legitimate

line3 = “Dual table Launch Limit”, 252

line4 = “”,                        123  ; Fake for example

line5 = “No field”,                -1

You can have from entries from “line1” to “line15”, indicating where in the generated dialog box the entry appears.  If you skip a line, that entry remains blank in the dialog.  If you use a blank label, the label is not displayed but the edit field is shown.  If you have a label, but the offset is outside the valid range 0-255, then the label is displayed but no field is shown.  All values are displayed as their integer values, so any voltages will have to be converted in your head.

NOTE: If you are using standard B&G embedded code, then you should keep those offset values in the range 0-127, as memory above that is not under control of the flash burning routines (dual table code and its derivatives can burn anything from 0-255).


VE Table Generator

Lance Gardiner developed this VE table generator, and originally implemented it in Javascript as a page in the on-line MegaManual, I turned it into C++ and incorporated it here as one of the basic tuning tools in MegaTune.

WARNING!   WARNING!   WARNING!

The VE tables generated are only estimates, sometimes very poor estimates, and unthinking use of the table can destroy your engine!  You must tune your engine after generating the VE table, especially up in the high load parts of the table, to make sure your engine has sufficient fuel that it does not detonate or go lean and burn some pistons.  Every effort was made to assure that this generator produces rich conditions, but that is not guaranteed.  Note also that it generates a VE table for speed-density mode, not for alpha-N mode.

This is a tool for establishing a baseline VE table for your tuning efforts with MegaSquirt, MegaSquirt II and UltraMegaSquirt.  The VE curve is assumed to follow the torque curve (which is not quite right, but close enough for a first approximation). This calculator is based on modeling your engine's wide-open-throttle VE with a quadratic equation of the form

VE = A*RPM2 + B*RPM + C

where

A, B, & C are constants.

These constants are derived from the:

•	Peak torque@RPM,

•	Peak horsepower@RPM,

•	The assumption that the peak torque occurs at the VE curve's maximum (i.e., the first derivative with respect to RPM is zero).

An assumption has been made about the VE required to produced 1 lb·ft/ci as well as 1 hp/ci.  A further assumption has been made that compressor efficiency=60% for kPa > 100.  Finally, a scaling factor has been used to adjust the wide-open throttle VE for lower MAP values. The factor is derived from examples of working VE tables.

A limit of 5% per RPM bin drop in VE has been applied to prevent the extreme drop-offs that can occur at high RPM & kPa when VE is modeled in this way. As well, all VEs are restricted to be not less than 25% of the highest VE, to prevent unusable idle values.

This calculator has not been tested on all possible engine combinations and operating parameters.
Use it at your own risk.

1. Inputs

Fill in all of the values (use your best estimate if you don't have measured numbers, but remember your table will only be as good as your estimates, and sometimes quite a bit worse).

•	Engine Displacement
The total swept displacement of your engine (more precisely, the air that your engine would pump in a single cycle at 100% VE).  Nothing tricky here, just tell MegaTune how big your engine is.

•	Idle Characterstics
These values define the lower left corner of the VE table, so put in the values that you want as the lower bound for both RPM and MAP.

•	Peak Torque
Enter your best estimate for peak torque in lb-ft in the “Value” field, the RPM and expected MAP for that torque peak.  Now if you are dealing with a naturally aspirated engine, use 100 kPa for the MAP, but if you super- or turbocharging and have good numbers for a similar motor use the torque, RPM and boost at which that torque was produced, irrespective of your intended actual boost pressure.

•	Peak HP
Enter you best estimate for peak crankshaft HP and the RPM and MAP corresponding to that HP.  Again, if you have a boosted application, use the HP, RPM and MAP corresponding to on another.

•	Redline Characteristics
Enter the RPM and MAP values you want to see in the upper right corner of the VE table.  If these values are different (either higher or lower) the table will still be interpolated over the range defined by the Idle and Redline ranges.

2. Generate The Table

When you click “Ok”, the table is generated and sent down to the MegaSquirt controller.

3. Verify

•	Pop up the VE table, Settings->VE Table, and verify that the VE numbers and MAP/RPM bins look reasonable for your engine.

•	Remember that the table generated is only a starting point for tuning. Using the generated table as a 'final' table under severe operating conditions can destroy your engine. Be sure to follow the tuning guide, and get professional assistance whenever you are not sure.


VE Table

All interpolation in MS uses table end points (NOT extrapolation) when the indexing value exceeds the limits of the table, but that fact is especially important when considering the computations of volumetric efficiency from the VE table.  This means that if your biggest MAP bin contains 100%, then any MAP value over this will produce 100% (for a given RPM).

This does NOT mean that the pulse width will be the same for MAP readings of 100 kPa and 200 kPa, the MAP value is used to scale the pulse width accordingly, so for this example you will get twice as much fuel.

To clarify how all these factors are used, I'll give you an ideal form of the pulse width calculation (containing no enrichments or any other fluff).

   PW = nominalPW * airDensity * VE

In MegaTune, the nominal pulse width is called Required Fuel.  This number gives a value (in milliseconds) that provides exactly the correct amount of fuel for stoichiometric combustion when the temperature is 70 F, the atmospheric pressure is 100 kPa and the engine is operating at 100% volumetric efficiency.

Air density is calculated from MAP and air temperature.

Volumetric efficiency is a function of many factors (intake and exhaust tract design, camshaft lobe shape, and so on) but can be characterized very well for a given engine by MAP and RPM.  I could go on about resonance and laminar flow, but it is sufficient to say that at low MAP (30 kPa), the VE is typically very poor due to turbulence effects, so VE is low (maybe 10-30%).  At the MAP values 100 kPa and higher, the torque curve is a close reflection of the VE curve, so expect the VE values to peak at about the same point.

Very Important Note

The VE values in MS do not reflect the true VE in your engine, since you usually do not want to run stoichiometric combustion in all operating regimes!  They are a combined value giving the VE multiplied by any enrichments or enleanments that you desire.  When your turbo motor is running at 250 kPa and has a true VE of 100% at 14.7:1 AFR, you would enter 111% to get 13.2:1 AFR.

?????????????????

Table Entries

Remember that Required Fuel value that you entered (or computed) on the first field of the Constants page?  That value determines the ideal pulse width at 100% VE.  The entries in this table scale that value to determine the actual pulse width (neglecting all correction factors and enrichments).  As such, both the required fuel and the VE table entries are more or less arbitrary, but it is useful to make them as close to correct as possible.

In other words, if your required fuel value is 15.0 ms and the VE table entry being used is 100%, you could achieve the same pulse width with 10.0 ms and 150%, respectively.

It is also important to understand that these VE values do not indicate the amount of fuel delivered over time.  For example, if you have a row in the table that is 100% across the board, then fuel delivered is proportional to RPM.  Say that the engine is running at 2500 RPM and the pulse width is 12.0 ms.  If you speed the engine up to 5000 RPM the pulse width will remain at 12.0 ms, but this delivers twice as much fuel because there will be twice as many injection events in a given time interval.

MAP Bins

The MAP bins define the range over which you can vary the VE values used for pulse width calculations.  These values are in kPa (absolute) and can vary from 0 to 255 kPa; usually 0 to 100 for a NA motor and 0 to max boost on a turbo- or supercharged one.

The biggest value might be 100%, even for a turbo motor, IF you want the fuel at boost to be linearly proportional to MAP.  Typically, though, you want some values above the 100 kPa value to add fuel as coolant when boosting.

This might result in a table that looks like this:

MAP	VE (%)

...

100	80

150	100

200	100

250	120

4000 RPM

to ensure that extra fuel is delivered when boost is applied.

I've got no good way to determine spacing of the bin values, as I do for RPM bins, but read below and you can probably rationalize something.

The MAP bins must be ordered from top to bottom in strictly ascending order (i.e., small ones on top, big ones on the bottom).  The low value should be around 20 kPa and the top value should be around the maximum pressure that you expect your engine to see (100 kPa for NA motors, somewhat over max boost on a turbo- or supercharged motor to give yourself some headroom).

The MAP bin values are stored in MS as "KPARANGEVE."

RPM Bins

The RPM bins define the range over which you can adjust VE based on engine speed.

If you have a representative torque curve for a motor like yours (ideally from a dyno run, but probably nearly as good from one of the many engine simulation packages available), you can set the spacing of these values from that.  Find the places on the graph where the curve is "bending" the fastest (i.e., has big second derivatives; usually from idle to up near the torque peak) and use smaller RPM intervals over these.  For long stretches where the curve is straight, but not necessarily horizontal, you can use bigger gaps in the bins.

??? need a picture here.

The reason for this is that the algorithm is going to do linear interpolation between these points (that is, it is going to play connect-the-dots), so you will have smaller error between bin points if you choose them well.

It is usual to have the low end of the torque curve well represented, down to idle, and the top end should be somewhere near your redline value.  For a street engine, the torque curve is usually dropping rapidly at redline, dictating that you have that top value up near redline.  On a race motor, you are much nearer the torque peak, so will probably group the RPM bin values more tightly up there for finer control over the range of interest.

The RPM bin values are stored in MS as "RPMRANGEVE."