EGO Correction PID Setup
How to configure closed-loop EGO (oxygen sensor) correction with PID tuning on Megasquirt 3 for optimal air-fuel ratio control.
What is EGO Correction?
EGO (Exhaust Gas Oxygen) correction is a closed-loop fuel control system. It reads the oxygen sensor (lambda/wideband) and automatically adjusts fuel delivery to match your target AFR (Air-Fuel Ratio).
Without EGO correction, your engine runs purely on the VE table — any errors in the table result in a rich or lean condition. With EGO correction enabled, the ECU constantly fine-tunes the fuel to hit the target.
Prerequisites
- A wideband O2 sensor (e.g., Bosch LSU 4.9) with a wideband controller
- The wideband controller connected to an analog input on the MS3
- A properly calibrated wideband input in TunerStudio
Step 1: Configure the Wideband Input
- Go to Fuel → AFR/EGO Control → EGO Sensor Settings
- Select your wideband controller type (e.g., AEM, Innovate, PLX, or generic 0-5V)
- Set the correct input pin (typically AD6 or AD7)
- Verify the AFR reading matches your wideband gauge
Step 2: Set Up the AFR Target Table
- Go to Fuel → AFR/EGO Control → AFR Target Table
- This 2D table maps RPM × Load to target AFR
- Typical values:
- Idle (700-1000 RPM): 14.7:1 (stoichiometric)
- Cruise (1500-3000 RPM, low load): 14.7:1 to 15.0:1
- Full load / WOT: 12.5:1 to 11.5:1 (rich for safety)
- Deceleration: 16.0:1 or disable correction
Step 3: Configure PID Parameters
The PID controller determines how aggressively the ECU corrects fuel based on the error (difference between target and actual AFR).
Go to Fuel → AFR/EGO Control → EGO PID Settings:
Starting Point Values
| Parameter | Value | Description | |-----------|-------|-------------| | P (Proportional) | 25 | How hard to react to current error | | I (Integral) | 15 | How much to accumulate past errors | | D (Derivative) | 5 | How much to react to error rate of change | | Authority | ±15% | Maximum correction allowed | | Step size | 1% | Maximum change per control loop | | Update rate | 10 Hz | How often the PID runs |
Tuning the PID
- Start with P only — set I=0, D=0, P=25
- Watch the AFR gauge — if it oscillates around the target, reduce P
- Add I gradually — increase I to eliminate steady-state error (AFR offset)
- Add D if needed — only if AFR overshoots significantly during transitions
- Adjust Authority — increase to ±20% if correction hits the limit frequently
Common Issues
- AFR oscillates rapidly → P is too high, reduce it
- AFR is consistently off-target → I is too low, increase it
- Slow response to throttle changes → increase update rate or P
- Correction is maxed out at ±15% → your VE table needs work, don't just increase authority
Step 4: Enable EGO Correction
- Set EGO Correction to Enabled
- Set Active Above to your normal operating coolant temperature (e.g., 65°C / 150°F)
- Set Active Above RPM to 600 RPM (above cranking)
- Set Delay After Start to 30 seconds (let the sensor warm up)
Best Practices
- Fix the VE table first — EGO correction is for fine-tuning, not for compensating a bad VE table
- Log everything — record datalogs while tuning and review the EGO correction percentage
- If correction is consistently >10% in a zone, adjust the VE table in that zone instead
- Disable during WOT tuning — tune WOT enrichment manually, then re-enable EGO