Miata Turbo Forum - Boost cars, acquire cats.

Miata Turbo Forum - Boost cars, acquire cats. (https://www.miataturbo.net/)
-   Link (https://www.miataturbo.net/link-130/)
-   -   Using Math Blocks and GP Outputs. AFR Safety Example (https://www.miataturbo.net/link-130/using-math-blocks-gp-outputs-afr-safety-example-109979/)

redursidae Nov 18, 2024 03:59 PM

Using Math Blocks and GP Outputs. AFR Safety Example
 
One of my favorite features of the Link ECUs are the Math Blocks and General Purpose Outputs. These allow you to create any logical gate to activate ECU functionality, or create a virtual output that enables another function. A useful example would be an AFR Safety mechanism, since it isn't a named function like in TunerStudio/Megasquirt.

There are multiple approaches to achieve an AFR safety in the G4X, but this one shows how the above functions work.

The process is:
1. Create a Math Block that calculates the percentage of error between Lambda Target and Lambda Average.
2. Use the output of the Math Block to feed a General Purpose Output that decides if AFRs are out of threshold.
3. Use the General Purpose Output in an RPM Limit table to perform a fuel or ignition cut.

Creating the match channel:
Go to ECU Settings > Math > and select a free Math Block
1. Name the label, such as "Lambda Error %"
2. Set Parameter a to "AFR/Lambda Target"
3. Set parameter b to "Lambda 1" or "Lambda Avg"
4. I suggest 1 decimal place
5. Set the Equation to (a-b)*100 . The parenthesis is important for order of operations. You could also remove the "*100" and change the comparison below to be -0.05 instead of -5
Settings example:
https://i.imgur.com/ywzsZNU.png


Next go to Auxiliary Outputs > GP Output > Select a free GP Output
1. Name the Output: "AFR Warning"
2. Select an output. A Virtual Aux or a CAN Aux will do the job.
3. Set the switch logic to "Cond 1 and Cond 2"
4. On Delay to 0.5 (or your preferred delay). You could also set this to 0, and have a delay in the RPM Limit table instead.
5. Off Delay to 0.5 (or your preferred delay)
6. SW Parameter 1: Set to the Math Block created above, "Lambda Error %"
7. Set SW Cond 1 to "<"
8. Set Math Block output to the maximum percentage of lean mixture you want to allow. I use -5. Positive is rich with the Math Block above
9. SW Parameter 2: Set to a condition you want to verify against. For example "TPS (Main)", or "MGP"
10. Set SW Cond 2 to ">="
11. Set Math Block output to a value where you want the logic to function. For example, 30% TPS, or 10 kPa of boost
Settings example:

https://i.imgur.com/m3bMNLp.png

The last step is to create the RPM Limiter. Link provides 4 RPM Limit tables that can be enabled. The RPM Limit function can have a dual table switch, and then 2 General Purpose RPM Limit tables can be enabled. For this guide, we will use a General Purpose Table.

1. Go to Engine Protection > GP RPM Limit 1
Limit Mode: Fuel %Cut
Startup Lockout: 2s
Activation Delay: 0.5s

https://i.imgur.com/dzylepe.png

2. Then go to Engine Protection > GP RPM Limit 1 Table
3. Press "X" to open the axis editor, or right click the table and select "Axis Setup"
4. Set one of the axis to the GP Output made above, "AFR Warning"
5. Set two breakpoints, 0 and 1, and click OK (You can also click "Init axis" to get a starting point).
6. Now in the table, set 0 to 10000, and 1 to the RPM to limit the engine to when AFR is lean. Something like 4000 will work

https://i.imgur.com/7J7KBv3.png

https://i.imgur.com/UXy7bOD.png

And now anytime the engine runs 5% lean for 1 second at greater than 30% throttle we get a 4000 RPM fuel cut to tell us. As a note, 10000 in this table doesn't mean that is the RPM Limit set for the engine. The ECU will use the lowest limiter of all the tables (RPM, MAP, or GP). Additionally, note that the RPM Limit table is a 3D table. So you can have another Math Block or GP Output that combines various errors into this table and have other safety systems do a fuel or ignition cut.

This same process can also be applied to almost all functions of the ECU, such as latching a gate for launch control if you hold the throttle open and press the clutch for 5 seconds with the engine off. Or having a button latch a state that overrides the fan control. Or have the CEL turn on when the AFR Warning or Knock is detected. You could even calculate a estimated HP based on Mass Airflow Estimate. Let your imagination run wild.


All times are GMT -4. The time now is 03:51 AM.


© 2026 MH Sub I, LLC dba Internet Brands