Tuning

Flashing utilities
You need some way to read and write files to the ECU. Some options are:
 * eBay USB VAG KKL cable and the Nefmoto Free ECU Flashing Software - The easiest and best supported method. Does not rely on boot mode, but will not flash bricked ECUs.
 * Galletto 1260 cable and included software - Useful in an emergency to recover a bricked ECU. You will have to put your ECU into boot mode for it to work.
 * KWP2000+ OBD cable and KWP2000+ flashing software

The most popular combination is a cheap eBay USB VAG KKL cable used with the Nefmoto Free ECU Flashing Software. However, it is good to have a Galletto 1260 cable to rescue a "bricked" ECU in boot mode.

One downside to using the Galletto cable or other boot mode flasher is that it cannot clear the "Error is P0601- Internal Control Module - Memory Checksum error." DTC. You MUST use flashing software that uses the VAG programming protocol, such as the Nefmoto flashing software, to clear this code.

Tuning your ECU
You will need:
 * 1) A map editor
 * 2) * TunerPro
 * 3) An XDF definition file so that the map editor can locate maps.
 * 4) * You'll need one specific to the ECU you are using. If you wish to use a different version software than your car came with, read this carefully.
 * 5) * XDF for M-box (most popular).
 * 6) Checksum correction
 * 7) * Modifying data in the ECU file will invalidate the internal checksum values. These will need to be updated or your car will not start. More info.
 * 8) * MTX Electronics sells a €10 checksum correction plugin for TunerPro.
 * 9) * ME7Check is a free executable that will tell you whether the checksums in a file are valid or not. It does not correct them but is sometimes useful.
 * 10) * ECUFix - $150 - Stand alone checksums correction utility

Logging utilities

 * 1) Ross-Tech's VCDS (aka VAG-COM)
 * 2) APR's ECUx (no longer supported)
 * 3) setzi's ME7 Logger (pure awesome)
 * 4) A wide-band O2 sensor if you are not using stock fueling. A tailpipe sniffer is fine, as long as you have test-pipes and no pre-cats in your downpipes.
 * 5) ECUxPlot to graph logs. Also has a HP/TQ calculator and various other tools.

Terminology
The acronyms are Bosch's Motronic map names from the Funktionsrahmen. If noted, map locations are for the M-box.

Fueling
Always start with this first. If you get fueling wrong, you will likely break something. Get this right, and do not try pushing the envelope in any tables until you are confident your fueling is where you want it. Always use a wideband sensor. Do not skimp on this. The stock narrow bands do not provide you with accurate enough readings. For stage 1-2+, adjusting fueling isn't technically necessary; however, a bit of extra fuel via KFLBTS isn't such a bad idea if you are running pump gas and a bunch of extra boost.

Primary

 * KRKTE - primary fueling

A good ballpark starting value for KRKTE is 34.125/(injector flow in cc/min). If you are using stock injectors and fuel pump, you should not have to touch this. Note that the factor is wrong (should be 0.000111) on many of my old .XDF map packs. For those, you will need to fix the factor so it is 0.000111 and not 0.000167.

Now, scale your MAF:
 * MLHFM - compensate for MAF housing diameter
 * MLOFS - MAF offset. For Bosch MAFs, it should be 200. For Hitachi, 0.

Scale MLHFM (constant throughout scale vs stock!) to get your idle and partial short term fuel trims (STFT) near zero and your WOT AFR to roughly match your requested AFR. Note: when you are tuning according to STFT, *make sure* you regularly clear your DTCs to reset the LTFTs to zero, or disable LTFTs altogether using VCDS:


 * 099 -> switch basic settings ON -> LR off

Some argue that using a different MAF housing (to extend the functional metered flow range) requires you to fix this so that measured load is "correct". The upside is that all of Motronic's tables that are based on load are probably still good. The downside is that you may hit the hard limit of load, and you'll go lean at high loads because the ECU can't tell how much air the motor is ingesting. That's obviously very bad. If that's the case, you'll want to scale back the MAF readings some, and go back and tweak KRKTE accordingly. Even if you don't ride the hard MAF limit, you'll also run off the end of the load axis in the timing tables (and everywhere else). Some say this isn't so much of an issue. By and large, keeping your max load (at torque peak) under 191 is probably a good idea.

If you do scale your MAF, you may throw a "MAF too high" code. You'll have to increase:
 * KFMLDMX - maximum load

Finally:
 * KFKHFM - fix up individual rich/lean areas, and WOT fueling issues.

Open loop AFR
When requested lambda is <1 (richer than stoichiometric), the fueling system will go "open loop". This means that the ECU will no longer use the narrow band O2 sensors to regulate fueling in closed loop (feedback). It will use ONLY the MAF signal to guess how much fuel should be added to the mix based on how much O2 is being detected in the intake.

There are three ways to adjust WOT (open loop) requested AFR


 * 1) LAMFAW: enrichment based on pedal position. Does not relate to actual loads.
 * 2) LAMFAWKR: enrichment based on knock recognition
 * 3) LAMBTS: enrichment triggered by calculated EGTS passing a threshold

Fueling within the entire system will follow the richest set point coming from each of these three components.

LAMFAW
Driver requested AFR:


 * LAMFA - requested lambda. Not very flexible for high load enrichment, uses requested load instead of actual load. Also, the stock LAMFA load axis is restricted to 0-1%. You will have to change it to full range (0-100%) to use LAMFA, otherwise, the 1% column will be used at ALL requested load points!

The result is "lamfaw"

LAMFAWKR
Knock recognition based enrichment:


 * CWLAMFAW - when bit zero is set to 0, don't allow dzwwl to advance dzwlamfaw. If you leave bit zero set to 1, dzwlamfaw will likely stay near zero (since DZWWL can counteract WKRMA), and you won't get much knock based enrichment.


 * KFLAMKRL - enrichment based on load and dzwlamfaw
 * DLAMTANS - additive correction to KFLAMKRL based on intake temp
 * KFLAMKR - enrichment correction factor based on rpm and load

They are combined like this: $$1 - (1 - (KFLAMKRL+DLAMTANS)*KFLAMKR)$$

Which is equivalent to: $$(KFLAMKRL+DLAMTANS)*KFLAMKR$$

The result is "lamfawkr"

LAMBTS
EGT enrichment tables:


 * KFLBTS_0_A - requested lambda for component protection when calculated EGT is above TABGBTS, scaled by FBSTABGM. Note that lambts also modified by [KF]DLBTS and KFFDLBTS: lambts = KFLBTS + ([KF]DLBTS * KFFDLBTS). Therefore, setting KFLBTS to 1 where you don't need it won't disable bts, you also have to set KFFDLBTS = 0 to disable bts completely. Note that Mbox has DLBTS (2D), not KFDLBTS (3D).


 * TABGBTS - Threshold for KFLBTS. Unless calculated EGTs are above this threshold, KFLBTS is ignored, and LAMFA controls requested AFR if it is lower than lambts. You may have to lower TABGBTS if you have a scaled MAF, since calculated EGTs will be artificially low.


 * FBSTABGM - KFLBTS multiplier. Make sure you change the axis properly to represent your lowered TABGBTS. Again, not necessary if you have a properly scaled MAF.

The result is "lambts"

Result
The lowest value of the three (lamfaw, lamfawkr, lambts) become your requested AFR.

Thus, you can use the combination of LAMFA, BTS, and KFLAMKR to tailor your AFR. In particular, pre-emptive rich fueling at low actual loads (but high requested load) may inhibit knock sooner than the KR approach. You can use BTS to do further enrichment when EGTs get dangerously high, unless you have BTS activate at very low actual loads (and/or calculated EGTs). The latter may be undesirable for fuel economy reasons; it is more fuel efficient to have BTS activate much later, let LAMFA handle pre-emptive, high load request (but low actual load) enrichment, and let KR handle real time knock inhibition.

Note that on tunes for low octane gasoline, it is likely that your target AFR is so low (to prevent knock) that additional BTS fueling is unlikely to protect against anything, unless your fuel system is severely under-delivering fuel do to injector/fpr/fuel pump malfunction.

Part throttle LTFT
Once you get your WOT AFR right, you may notice that your LTFTs are way out of whack. If they get too far out, you'll throw a code and possibly go into limp mode.


 * KFKHFM - Correction map for MAF. Log STFTs at various part throttle positions, RPMs, inclines, and gears to determine where the MAF readings need tweaking. If you are using the stock MAF and intake system, you should not have to touch this.

Idle LTFT and idle misfires
If you have idle problems (and/or idle LTFTs you can't seem to zero out), you may have to investigate tuning for your injector latency and/or idle injection period.
 * TVUB - Injection time offset
 * FKKVS - Correction factor for fuel supply system

According to Bosch documentation, FKKVS is for compensating for pulses in returnless fuel system. This could be why it is all 1s in M-box, since S4s do not have returnless fuel systems.

If you are running really big injectors, and you are running rich no matter how much you turn down KRKTE, you may need to reduce the minimum injector on time
 * TEMIN - minimum injector on time

If you did not properly scale your MAF, and you are getting a rough idle but aren't seeing idle misfires, it could be because your load at idle is too low, inhibiting misfire detection. Scale your MAF properly, or decrease your misfire recognition load threshold.
 * RLSALUN - Load threshold for shear detection for suppression of misfire detection
 * RLSALULL - Load threshold for shear detection for suppression of misfire detection during idle

Finally, if none of this works, you may have to increase your idle RPM and/or idle torque reserve (alters idle timing)
 * NLLM - idle RPM
 * NFSM - idle RPM while in gear
 * KFMRES - idle torque reserve
 * KFMRESK - idle torque reserve while transmission decoupled (clutch in)

Consumption
Now that you have your fueling set up, you'll probably notice that your MPG readings in your cluster are totally wrong. Fill up a with a tank of gas, and reset your trip odometer and average MPG. When you are done with the tank, fill up your tank, see how much gas you used and how far you went, and check it against the new average MPG. Get a calculator out, and correct it here:


 * KVB - fuel consumption (MPG in cluster)

Standard KVB value can go only up to 776cc injector size due to reaching the maximum value it accepts.

To accommodate injectors larger than that you have to also change


 * FKVA (0x1A4D5) - Constant conversion factor for consumption display

This is a multiplier for KVB.

For reference, you may be able to derive the right value using this (although some fine trial and error tweaking is much easier):

$$TKVAG = \frac{\sum_{t=0}^{TMAIN} (rk_w+rkte_w) \times KRKTE [ms] \times FKVA \times KVB [cm^3/min] \times 1000}{Kd [mm^3/s] \times 0.0512 [ms] \times 60000}$$

Boost
ME7.1 doesn't really have a "boost" table. It does everything based on "specified load". Requested boost is roughly 10*(spec load)+300mbar.

First, make sure the 100% pedal position requests enough load:
 * KFMIRL - specified load

Specified load/boost will never exceed these limits:
 * LDRXN - maximum specified load
 * KFLDHBN - maximum requested pressure ratio

Specifically, on a full throttle pull, your boost profile will follow LDRXN. K03s and K04s have some severe flow limitations, so unlike big turbos, you will want your boost to taper (not ramp up) to redline. ECUxPlot has a pressure ratio/flow plotter that you can use to compare against your turbo's compressor map.

You will throw a 17963 Charge pressure: Maximum limit exceeded code if your boost deviation is too high:
 * KFDLULS - Delta pressure for overboost protection

If you are running significantly more boost than stock, or you have made changes to the boost PID, you may have to increase these limits. The most unsophisticated way is to simply max the entire table. Obviously, you will get better results if you spend a bit more time tuning this table to something appropriate. It is generally not a good idea to disable too many safety features, particularly when it comes to boost.

If you screw up, it is possible that specified boost is higher than the maximum possible measured boost. For obvious reasons, the PID will not like this. To prevent this, set this to zero:


 * DSLOFS - MAP pressure sensor offset

Absolute maximum measured boost is 0xffff/25.6 = 2559.96 mBar (assuming DSLOFS = 0)

Maximum spec boost is 0xff*10 = 2550 mBar

These are both hard ECU limits, and cannot be increased by simply changing sensors or internal ECU MAP scaling.

''If you plan to run closed loop boost (PID control), set DSLOFS to 0. If you are planning to run open loop boost (locked WGDC via KFLDRL) keep it stock!''

IAT effect on requested boost
ME7.1 will adjust the specified load limit depending on IATs. As IAT's go up, ME7.1 brings the max boost up a bit so that the driver can't tell that the car is slow in hot weather. It can do this because the stock boost curve is relatively conservative, and there is plenty of headroom. Also, at some point, if IATs go high enough, max specified load is pulled to prevent knock.


 * KFTARX - IAT correction for maximum specified load

However, if you are running a lot of boost, and always want maximum performance, there is no point in increasing boost when it is hot, let alone reducing boost when it is cold. Also, as IATs rise, even with a perfectly flat KFTARX and LDIATA (see below), you will see more requested boost because the ECU knows that a higher P/R is required for a given cylinder fill (PV=nRT for you thermodynamics nerds out there). It is unknown if there is a table for that calculation. To compensate, you may want to taper KFTARX across the board as IATs rise to keep your requested boost sane. In particular, be aware that the maximum requested boost is slightly above the maximum MAP reading. Readers who understand PIDs should recognize that really bad things happen when the measured output cannot reach the setpoint...

Cam changeover effect on requested boost
Motronic likes to change requested boost depending on cam position. While it may seem like a good idea in theory, in practice, abrupt changes in requested boost near the MAP limit can make the boost PID unhappy. When logging, you may see an odd notch in requested boost between 3000 and 4000 RPM. These maps are what is causing that notch
 * KFPBRK - Correction factor for combustion chamber pressure
 * KFPBRKNWS - Correction factor for combustion chamber pressure when NWS active
 * KFPRG - Internal exhaust partial pressure dependent on cam adjustment when sumode=0
 * KFURL - Conversion constant for ps->rl dependent on cam adjustment when sumode=0

Boost PID
If your actual boost is not meeting requested boost, you may have to increase the PID I limit between 2250 and 5000 RPM for 850 and 1000mBar:
 * KFLDIMX - LDR I-Regulator limit

To go along with KFTARX above, there is another IAT correction that ME7.1 uses to allow the PID to add waste-gate duty cycle at elevated IATs. You may want to zero it all out:
 * LDIATA - LDR I-Regulator limit as a function of IAT

If you aren't using K03s, you may have to tweak the PID response. Note: this is NOT used to adjust requested boost. It is used to compensate for different waste-gate responses.
 * KFLDRL - Map for linearization of boost pressure = f(TV). This is the post-PID waste-gate duty correction table.
 * LDRQ0S - LDR PID Q0 in static operation (proportional term)
 * LDRQ1ST - LDR PID Q1 in static operation (integral term)
 * KFLDRQ2 - LDR PID Q2 (differential term)

KFLDRL can also be used to get open-loop type behavior for operation past the MAP and requested boost limit by making the output duty cycle unresponsive (flat) to uncorrected duty cycle (from the PID) at various RPM/DC points. Again, if you do this, make sure to leave DSLOFS at the stock value! This way, requested boost will always be higher than measured boost, and you will stay in open loop control.

With after market or external waste-gates flat line the map at something like 25% until your turbo should be spooled and then taper off to 10% at areas if higher load and RPM. Log requested vs. actual boost to see where you need to adjust KFLDRL to line things up. The higher your after market waste-gate spring pre-load the lower the WGDC you will need to accurately control boost.

If you don't get all of this just right, and your actual boost goes too far above requested boost (by ~200mBar), you may experience overboost throttle cut, which is ME attempting to get boost back under control by temporarily closing the throttle plate.

Alternately, if your requested boost is far too high for a given load/rpm point, you may experience positive deviation (underboost) limp mode.


 * If your MAF scaling is too aggressive, your load may be reading high, which might enable positive deviation diagnosis too early during a pull. Fix this by scaling back MLHFM


 * If your requested boost ramp is too aggressive for your turbos, you may be requesting far more boost than your turbo can possibly make at low rpms. In particular, the stock K03 LDRXN is VERY aggressive. K04s (let alone bigger turbos) will never spool that fast. Consider making sure LDRXN does not allow too much spec load too soon!


 * If none of the above helps, consider tweaking NDLDRAPU and SDLDRA.

Torque limits
Torque Monitoring may interfere with your timing, or even go into limp. To mitigate this, you will need to look at
 * KFMIOP - Optimal engine torque map
 * KFMIZUOF
 * TMNSMN
 * TANSMN

On tiptronic cars, you may get Engine Torque Monitor: Control Limit Exceeded codes. This is probably for protecting the torque converter. To get around it, you will have to look at:
 * RAMPASR
 * KFMIZUFIL/KFMIZUNS
 * KFMPED_/KFMPNS_
 * RLVMXN/RLVSMXN - Maximum relative indicated torque under open throttle body

Adjust all of these with caution! Disabling or tampering with torque monitoring may prevent ME7 from protecting your motor from excessive torque in high boost applications.

Timing
When running elevated boost on pump gas, you will have to significantly cut requested timing to prevent timing retard. Keep your worst case correction factors in the single digits, and always carefully monitor your knock voltages when tuning your timing.


 * KFZW/KFZW2 - primary timing maps. ME7.1 has a two point variable cam timing system; there is a table for each cam timing state.

If you did not fully "correct" your MAF using KFKHFM, make sure you do a lot of logging to see where the various load points are and how much timing ME7.1 is pulling due to knock activity. Most likely, you will have to adjust the entire map. If you did correct your MAF, you can probably leave most of the timing table alone, except at very high load.

Speed limiter

 * VAVMX/VMAX - Speed limiter

Rev limiter

 * NMAX - RPM limit
 * NLLM - idle RPM
 * NFSM - idle RPM while in gear

Left foot braking
Set either of these to maximum to prevent throttle cut when left foot braking:


 * NWPMBBR - Minimum RPM for acc pedal value lockout on brake operation
 * VWPMBBR - Minimum speed for acc pedal value lockout on brake operation

Knock recognition
'''Adjust these maps with care. Abusing any of them can cause severe ping/knock/detonation and probable motor damage'''

Knock effect on short term retard

 * KRFKLN - Ignition retard per knock event.
 * KRALH - Load hysteresis. This adjusts how quickly timing will be restored as load changes.
 * KRANH - Engine speed hysteresis. This adjusts how quickly timing will be restored as RPM changes.
 * DWKRMSN - Delta angle offset for average retard

Requested load cut on knock detection

 * KFFLLDE - Factor for slow LDR intervention on rlmax via KR

Long term knock control adaptation
If you want your long term knock control to add timing back quicker if knock activity subsides, you may want to lower KRDWA
 * KRDWA - Knock control adaptation to differential current ZW map

Fuel enrichment on knock detection

 * KFLAMKRL - Enrichment on ignition retard

Launch control
Very rudimentary "launch" control can be added via using two RPM limits


 * VNMX (1157E) - The vehicle speed for activating the raised (normal) rev limit. We set this as low at it goes (1.25 km/h) so the launch control shuts off as soon as you start moving off the line.
 * DNMAXH (16304) - This is the RPM above rev limit when the fuel cut comes on. Tweaking this helps make more boost on the limiter. I use 50 RPM
 * ITNMXH (16308) - Dwell time under lower limit before activating the upper limit. We set this to 0 seconds
 * NMAX (1630A) - Ends up being the launch RPM. I've found 4500 RPM works well.
 * NMAXOG (16312) - This is the raised RPM limit which becomes the standard limit. Mine is set at 7100 RPM
 * TMOTNMX (16316) - Coolant temp for activating raised (normal) rev limit. We set this at -48 so that it can activate at any coolant temp.
 * TNMXH (1631A) - This is the time duration of the raised (normal) rev limit. We set this at it's maximum value of 655.3500 seconds. I haven't had a problem yet with this and have been testing for months.

Some ECU's need:
 * CWNMAXMD (CWDNMAX?) (8-bit) - Codeword Drehzahlbegrenzung (Codeword for RPM limiter). Change from 0 to 1

Example bin based on stock binary.

Unfortunately, this method is useless for building boost, since it uses a soft rev limiter (throttle plate control/fuel cut) rather than a hard limiter (cutting spark). ME7 has a hard limiter, but it apparently can't be used here. In order for it to build (and hold) boost properly, custom code has to be added to ME7.

Wheel speed sensor
If you have different wheel rolling diameters from stock, and you want to log the correct speed:
 * AIMVM (0x12A56) - Number of speed pulses per m for signal normalization v

Gear detection
The ecu computes the gear (gangi) from the quotient N/V out of nmot_w and vfzg_w. To find the current gear, the ecu uses for each possible gear a min and a max quotient to compare the actual N/v against.

You have to update these quotients in order to map with the present gearbox/wheels. The thresholds are named NVQUOT1O (upper quotient for 1st gear), NVQUOT1U (lower quotient for 1st gear) up to NVQUOT6O, NVQUOT6U for 6th gear.


 * NVQUOT1O (0x013BC2)
 * NVQUOT1U (0x013BC4)
 * NVQUOT2O (0x013BC6)
 * NVQUOT2U (0x013BC8)
 * NVQUOT3O (0x013BCA)
 * NVQUOT3U (0x013BCC)
 * NVQUOT4O (0x013BCE)
 * NVQUOT4U (0x013BD0)
 * NVQUOT5O (0x013BD2)
 * NVQUOT5U (0x013BD4)
 * NVQUOT6O (0x013BD6)
 * NVQUOT6U (0x013BD8)

Rear O2 Sensors
Set these to zero to disable rear cat DTC:
 * CDKAT - Cat diagnosis in OBDII-Mode.
 * CWDLSAHK (0x18663) - Code word for probe aging after KAT

If you want to remove your rear O2s entirely, also set these to zero:
 * CDHSH - Post cat O2 heater diagnosis
 * CDHSHE - Post cat O2 heater amplifier diagnosis
 * CDLSH - Post cat O2 sensor diagnosis
 * CDLASH - Lambda sensor aging diagnosis (SHK) in OBDII-Mode (inverse: EURO-Mode)
 * CDLSHV - Lamba sensor sensor interchange recognition
 * CLAHSH - Error Class: Bank 1 post cat O2 sensor heater
 * CLAHSH2 - Error Class: Bank 2 post cat O2 sensor heater
 * CLAHSHE - Error Class: Bank 1 post cat O2 sensor heater amplifier
 * CLAHSHE2 - Error Class: Bank 2 post cat O2 sensor heater amplifier

You may also have to change these to disable rear O2 lambda control (untested):
 * CLRHK (0x11A87) - Code word for Lambda - Control post cat on/off: set to 73 (0x49/01001001b) or 5 (00000101b) ? (original value 72 0x48/01001000b)
 * CLRHKA (0x19FCF) - Code word for Lambda - Control post cat: set to 1? (original value 0)
 * CLALSH (0x10717) - Error Class: Lambda Probe post Kat Bank 1: set to 0
 * CLALSH2 (0x10718) - Error Class: Lambda Probe Post Kat Bank 2: set to 0

You can test readiness by using VCDS/VAGCOM

EGT
If you want to remove your EGT sensors: Note that my old M-box xdf is wrong for CDATR/ATS. Please use these offsets.


 * CDATR (0x18196) - Configuration byte diagnosis exhaust gas temperature regulation
 * CDATS (0x18197) - Configuration byte diagnosis exhaust gas temperature sensor
 * CLAATR - Error class exhaust gas temperature regulation
 * CLAATR2 - Error class exhaust gas temperature regulation bank 2
 * CLAATS - Error class exhaust gas temperature sensor
 * CLAATS2 - Error class exhaust gas temperature sensor bank 2

There is anecdotal evidence that this will not allow you to completely remove the EGT sensors; keeping dead ones connected might be necessary.

Setting both of these to their maximum (1229) may help:


 * TABGSS (0x1C514) and TABGSS2 (0x1C516) - Desired exhaust gas temperature for EGT regulation

Secondary Air Injection

 * CDSLS - Eurobyte
 * CLASLVE - Plug
 * CLASLPE - Pump plug

Evaporation

 * CDTES - Eurobyte - LDP Diagnosis
 * CDLDP - Eurobyte - EVAP diagnosis
 * CLATEVE - EVAP plug
 * CLALDPE - LDP plug

Catalyst Heating

 * FKHABMN - set to 0 if you do not have cats.

Additional Reading

 * Tony@NefMoto's website - one stop shopping for real tuning discussions, without the glass bead trading game and secret handshakes.
 * Motronic abbreviations
 * VCDS
 * Lemmiwinks
 * Basic tuning guide - caution: this is only an example