Your Cart(0)

Maximizing Accuracy between Spartan 2 and Megasquirt

There is a companion video available here

In this article I will be discussing and demonstrating how to maximize accuracy (or minimizing errors) when interfacing your Spartan Lambda Controller 2 to your MegaSquirt ECU. I will be utilizing the Output Sequencer feature on Spartan 2 to achieve maximium accuracy, this article is applicable to any of my lambda controllers which have the Output Sequencer feature, this includes Spartan1, Spartan2, and SLC Gauge.

Spartan 2 like most other Wideband Oxygen Controllers will interface to Megasquirt via a 0 to 5 volt analog output. The output on Spartan 2’s linear output is a standard 0 to 5 volt signal, 0 volt @ 10 AFR linear to 5 volts @ 20 AFR. Interfacing an analog signal to Megasquirt leaves alot of room for errors to manifest itself and reduce the accuracy of the AFR data as seen by MegaSquirt.

On any electronic system that measures things (AFR, Pressure, temperature, etc...) there are 3 general types of errors; offset, linear, and non-linear errors. Non-linear errors are generally the smallest of the 3 types of errors by an order of magnitude, and usually it is a very involved process to begin to even try to zero or compensate for non-linear errors. Utilizing the Output Sequencer feature will only compensate for offset and linear errors, it will not compensate for non-linear errors.

In a typical application, an example of offset error is ground offsets. Ground offsets occur when there is a potential, or voltage, difference between the Spartan 2's ground and the MegaSquirt ground. This ground offset is usually caused by high currents flowing through the ground connections and is greatly magnified by poor ground locations. There are other sources of offset errors, but offset errors can be added together via the superposition principle, and in this article offset errors are compensated for in aggregate. This means that by using the Output Sequencer feature you can zero out the sum of all offset errors, so classification of each and every source of offset error is not required.

Linear errors are usually the dominate error in most electronic measurement systems, a good example of a linear error is due to the tolerance of the 5 volt regulators on Spartan 2 and MegaSquirt. All electronic components have an associated tolerance, on Spartan 2 the 5 volt regulator has a 1% tolerance, I am not sure of the tolerance of the 5 volt regulator on MegaSquirt but let us assume that it is also a 1% tolerance. Suppose on Spartan 2 the 5 volt regulator operates at the upper range of it's tolerance, 5.05 volts, and the 5 volt regulator on MegaSquirt operates at the lower range of it's tolerance, 4.95v. Suppose Spartan 2 is trying to output 2.5 volts, because the 5 volt regulator is at 5.05 volts, Spartan 2 will end up outputting 2.525 (2.5*1.01) volts. When Megasquirt measures the 2.525 volts from Spartan 2, it will see the 2.525 volts as 2.550 (2.5*1.01*1.01) volts. In this case the linear errors of the voltage regulators are in opposite direction and the linear errors multiply together, if both regulators have the same error (both are say 5.05v or both are say 4.95v) the errors would cancel each other out. There are other sources of linear errors, but like offset errors, linear errors can be grouped together via the superposition principle and the linear errors will be compensated for in aggregate. This means that by using the Output Sequencer feature you can zero out the sum (product is the correct term) of all linear errors, so classification of each and every source of each linear error is not required.

To summarize the above paragraphs; non-linear errors are typically very small and that is a good thing because it is very hard to compensate for non-linear errors, all offset errors can be grouped together and the sum of all the offset errors can be compensated for, all linear errors can be grouped together and the sum (product is the correct term) of all linear errors can be compensated for.

The process to compensate for offset and linear errors is a 2 step process. The first step is to properly install Spartan 2 and in Tuner Studio for MegaSquirt the default settings will be used. The 2nd step is to use the AFR read by MS as shown by Tuner Studio to calculate new settings which are then entered into Tuner Studio. Once the 2nd step is complete then the offset and linear errors associated with AFR read by MegaSquirt will be compensated for and the result is that Megasquirt will read AFR from Spartan 2 with total error of 1/10th of an AFR.

Install and wire up spartan 2 according to the user manual here, On my MicroSquirt unit wire #34 (pink wire) connects to Spartan 2's linear output (green wire). Grounding is very important, Spartan 2's black wire (electronics ground) should be grounded where the MegaSquirt ECU is grounded, Spartan 2's white wire (Wideband Sensor Heater Ground) should be grounded to the chassis far away from where the black wire is grounded. The white wire carries upto 3 Amps and if grounds are not properly chosen, it can cause very large ground offset errors. The first line of defense against offset errors is proper installation and proper grounds, there may still be small offset errors present which we can easily compensate for in the next steps.

In Tuner Studio,  tools->Calibrate AFR Table->EGO Sensor select "Custom Linear WB", enter the values shown in the picture below and write changes to MegaSquirt.

 

Later on we will change the Custom Linear WB settings to account for offset and linear errors.

During powerup Spartan 2's Output Sequencer will be triggered, the Output Sequencer will output 2 distinct calibration voltages on the Linear Output, 1.666 volts for the first 5 seconds then 3.333 volts the next 5 seconds, after 10 seconds has passed; the Linear Output will function normally. When a wideband controller is first powered up, it will take about 30 seconds to 1 minute for the Wideband Oxygen Sensor to heat up, while the sensor is heating up the Wideband Sensor is unable to read the AFR of the exhaust gas composition, only when the sensor is heated up will the AFR of the exhaust gas composition be correct. Spartan 2's Output sequencer takes advantage of this heatup time when the AFR data is not correct to output calibration voltages that we will use to generate new Tuner Studio settings to compensate for offset and linear errors.

While Tuner Studio connected to MS and is actively displaying AFR data, cycle power to Spartan 2 and write down the 2 AFRs shown by tuner studio during the first 5 seconds and then during the next 5-10 seconds. For this example lets use 13 AFR and 17.1 AFR. Now if there were no offset or linear errors present; the first 5 seconds AFR should be 13.328 AFR and the 5-10 seconds AFR should be 16.666 AFR.

Now download and open this Microsoft excel worksheet here 

Assuming that the first 5 seconds AFR shown by Tuner Studio is 13 AFR and the 5-10 seconds AFR shown by tuner studio is 17.1 AFR, you would enter 13 and 17.1 into the excel worksheet like the above picture, of course instead of 13 AFR and 17.1 AFR you would enter the AFR shown by your Tuner studio. Once those two AFRs are entered, the settings in the green box will be calculated to compensate for offset and linear errors, this calculated setting you will enter into Tuner Studio and your MegaSquirt will be able to  read AFRs from Spartan 2 with an accuracy of 1/10th of an AFR.

In Tuner Studio,  tools->Calibrate AFR Table->EGO Sensor select "Custom Linear WB", enter the values shown in green excel worksheet  and write changes to MegaSquirt. In my example where the first 5 seconds AFR is 13 AFR and the 5-10 AFR is 17.1 AFR, my calculated new tuner studio settings is 10.89 AFR @ 0 volts and 19.02 AFR @ 5 volts.

 

Now if everything was done correctly then now your Megasquirt will be able to read AFR with 1/10th AFR accuracy. Cycle power to Spartan 2 again and now the first 5 seconds AFR should be 13.3 +/- 0.1 AFR and the 5-10 seconds AFR should be 16.7 AFR +/- 0.1 AFR. Because Megasquirt uses only upto the first decimal place to represent AFR, the best you can do is +/- 0.1 AFR accuracy.

Share

1237 Shaw Street Toronto, Ontario M6G3N9 Canada 416-273-5409

We Accept...

We Accept Visa We Accept PayPal