Megasquirt-3 Idle Control Setup
Guide to setting up the idle air control (IAC) valve on Megasquirt-3: control algorithms, PID tuning, and troubleshooting
Megasquirt-3 Idle Control Setup
The idle air control (IAC) valve is responsible for maintaining stable engine RPM when the throttle pedal is released. Proper idle control setup is one of the key tasks when tuning with Megasquirt-3. This article covers all aspects of the setup: from selecting the valve type to fine-tuning the PID controller.
Types of Idle Air Control Valves
Megasquirt-3 supports three main types of idle air control valves. The choice of type is determined by which valve is installed on your engine.
Solenoid (PWM Valve)
A PWM valve is controlled by duty cycle (in percent). The higher the duty cycle percentage, the more air bypasses the throttle plate through the valve. Typical examples include two-wire GM and Ford valves.
- Control range: 0-100% duty cycle
- PWM signal frequency is configured in TunerStudio (usually 500-1000 Hz, depending on the specific valve)
- Simple installation: two wires — power and control signal from the ECU
Stepper Motor
A stepper motor is controlled by discrete steps (usually 0-255). Each step corresponds to a specific displacement of the valve element, changing the cross-sectional area of the air bypass channel. The most common example is the four-wire GM IAC valve.
- Control range: 0-255 steps
- Requires four control wires
- When the ignition is turned on, the motor performs a homing procedure, fully closing the valve and then opening it to the initial number of steps
- More precise control compared to a PWM valve
On/Off Valve
The simplest type — a valve with two states: fully open or fully closed. Rarely used, mainly on older or budget systems.
- No intermediate regulation
- Suitable only for the simplest applications where noticeable RPM fluctuations are acceptable
- Setup comes down to selecting the on/off threshold based on RPM or temperature
Idle Control Modes
Megasquirt-3 offers two main control modes: open-loop and closed-loop with a PID controller. The correct setup order is to configure open-loop first, then transition to closed-loop.
Open-Loop
In open-loop mode, the idle valve position is determined solely by a table linked to coolant temperature (CLT). The ECU does not analyze the current RPM and does not make corrections — it simply sets the specified duty value (for PWM) or step count (for stepper motor) according to the table.
Warmup curve principle:
The curve is built on a simple principle — the colder the engine, the more air needs to bypass the throttle plate to maintain elevated warmup RPM:
- At -20...-10 C — maximum value (e.g., 60-80% duty or 150-200 steps)
- At 0...+20 C — medium value (40-60% duty or 80-120 steps)
- At +40...+60 C — gradual reduction (25-40% duty or 40-70 steps)
- At +80...+95 C (operating temperature) — minimum value to maintain stable idle (15-25% duty or 20-40 steps)
The specific values depend on the engine and the valve's flow capacity. Your task is to shape the curve so that RPM decreases smoothly as the engine warms up to the target values at operating temperature.
Crank-to-Run (position during cranking):
A separate parameter sets the initial valve position during cranking. This is usually an elevated value that provides sufficient airflow for confident starting. After transitioning from cranking to run mode, the valve switches to the value from the warmup curve.
Tips for open-loop setup:
- Start at operating temperature (+80...+90 C). Warm up the engine and find the duty/step value that produces stable RPM of 800-900
- Then start the engine at different temperatures (a morning cold start is the ideal opportunity) and adjust the values in the table
- The curve should be smooth, without sharp jumps between adjacent points
Closed-Loop (PID Controller)
In closed-loop mode, the ECU actively monitors the current engine RPM and compares it with the target value. When a deviation occurs, the PID controller adjusts the valve position, attempting to bring the RPM back to the target.
Target RPM curve:
Target RPM is also defined by a curve based on coolant temperature:
- Cold engine (-20...0 C): 1200-1500 RPM
- Warmup (+20...+60 C): 900-1100 RPM
- Operating temperature (+80...+95 C): 800-900 RPM
The curve should provide a smooth decrease in target RPM as the engine warms up.
PID controller tuning:
The PID controller consists of three components: proportional (P), integral (I), and derivative (D). Each plays its own role in maintaining stable RPM.
Critically important: before tuning the idle PID, you must first properly tune the VE table (volumetric efficiency table) in the idle zone! If the VE table is incorrectly tuned in this range, the mixture will be wrong, and no PID controller will be able to provide stable idle.
Recommended order for tuning PID parameters:
Step 1: Tune I (integral component)
The integral component eliminates the steady-state error (offset) between the current and target RPM. This is the primary component of idle control.
- Set P = 0, D = 0
- Start with a small I value (e.g., 0.005)
- Gradually increase I while observing RPM behavior
- RPM should smoothly return to the target value after disturbances (turning on headlights, turning the steering wheel on a car with power steering)
- Increase I until slow oscillations appear (RPM begins to slowly swing around the target)
- Once oscillations appear — reduce I by 20-30%
Step 2: Tune P (proportional component)
The proportional component responds to the current magnitude of deviation. It provides a fast response to sudden load changes.
- Start with a small P value (e.g., 1.0)
- Gradually increase it, checking the response to turning the air conditioning on and off and other loads
- P should provide a fast initial response without causing jerking or oscillations
- If RPM starts oscillating rapidly — P is too high, reduce it
Step 3: Tune D (derivative component)
The derivative component responds to the rate of change of the error. In most cases, it is not needed for idle control.
- Usually D is left at zero
- If used, keep values very small
- D heavily dampens system response — if the value is too high, the valve will respond to changes too slowly
- Use D only if you cannot achieve stability with P and I alone
Warmup Steps/Duty (Warmup Curve)
The warmup curve defines the base valve position at different engine temperatures. It works both in open-loop (determines all behavior) and in closed-loop (sets the starting point from which the PID begins its corrections).
Key principles:
- The curve should smoothly decrease from maximum on a cold engine to minimum on a hot engine
- Do not allow sharp jumps between points — this will cause RPM jerks during warmup
- Use the "RPM with valve opened" and "RPM with valve closed" parameters to calibrate valve response. These values help the ECU understand what RPM range corresponds to the fully open and fully closed valve
Additional Settings
Fan On / AC On Compensation (Load Compensation)
When the cooling fan or air conditioning turns on, an additional load is placed on the engine and RPM tends to drop. To compensate, Megasquirt-3 allows you to set an additive value of steps or duty percentage.
- Fan on adder: addition when the electric cooling fan turns on (usually 3-8% duty or 5-15 steps)
- AC on adder: addition when the AC compressor engages (usually 5-12% duty or 10-25 steps)
- Values are selected experimentally: turn on the load and assess how much RPM dropped, then add the corresponding compensation
- In closed-loop mode, the PID will also correct RPM, but the compensation helps it by providing feedforward correction before RPM has a chance to noticeably drop
Dashpot (Anti-Stall on Throttle Release)
The dashpot function ensures a smooth RPM decrease when the throttle pedal is suddenly released. Without it, RPM can sharply drop below idle and even cause the engine to stall, especially on vehicles with a manual transmission.
- Dashpot rate: valve closing speed (the lower the value, the smoother the transition)
- Dashpot RPM: RPM threshold below which the function activates
- Adjust so that when the throttle is suddenly released, RPM smoothly decreases to idle without stalling and without hanging at elevated RPM for too long
Idle Advance Timing (Ignition Timing at Idle)
Ignition timing directly affects idle stability. Megasquirt-3 allows you to use a separate table or algorithm to control ignition timing specifically at idle.
The basic principle: reducing the advance angle (retarding ignition) makes idle more stable, but the engine requires more air to maintain the same RPM. Conversely, increasing the advance angle makes the engine more efficient but can make idle less stable.
- Typical idle values: 10-18 degrees BTDC (depends on the engine)
- Idle timing can be used as an additional stabilization tool: the ECU slightly retards timing at elevated RPM and advances it at lower RPM
- This feature is especially useful in combination with closed-loop valve control
Practical Setup Tips
General Workflow
-
Start with open-loop. Configure the warmup curve so the engine idles stably at any temperature. Do not rush to switch to closed-loop — make sure the base curve provides acceptable RPM across the entire temperature range.
-
Tune the VE table in the idle zone. Use autotune or manual correction to ensure the AFR (air/fuel ratio) at idle matches the target value. Stable idle is impossible without a correct mixture.
-
Switch to closed-loop only after the VE table is tuned and open-loop provides stable operation. When switching, use the duty/step values from open-loop as the starting point for the warmup curve in closed-loop mode — this way the PID controller will not need to make large corrections.
-
Tune the PID using the method described above: first I, then P, and D if necessary.
-
Add compensations for the fan and air conditioning. Test the dashpot function.
Target RPM
Recommended target RPM values (may vary depending on the engine):
- Hot engine: 750-900 RPM (for most 4-cylinder and 6-cylinder engines)
- Cold engine: 1200-1500 RPM
- Do not set RPM too low when cold — an engine with cold oil and increased clearances needs elevated RPM for stable operation
Common Problems and Solutions
- RPM hunting (oscillating): P or I coefficient is too high in the PID controller. Reduce the values. Also check for vacuum leaks.
- RPM takes too long to return to target: I is too small. Increase the integral component.
- Engine stalls on throttle release: adjust the dashpot, increase compensation, or check whether the valve is open enough at operating temperature.
- RPM stays high when hot and won't come down: check that the valve physically closes (no sticking). Make sure the CLT sensor shows the correct temperature. Reduce the duty/step value for operating temperature.
- Unstable idle despite tuned PID: go back to the VE table. Check that the AFR at idle is stable and matches the target (usually 14.2-14.7 for gasoline).
A properly tuned idle is a sign of quality ECU calibration. Do not skip this step and give it sufficient time.