how-to: control closed loop AFR with your wideband O2 system
I too would be interested in being able to log & control cruise AFR's based on my wideband output. What would be involved to get this implemented on the the various V7 roms available?
Thread Starter
EvoM Guru
iTrader: (50)
Joined: Mar 2006
Posts: 9,675
Likes: 132
From: Tri-Cities, WA // Portland, OR
Thread Starter
EvoM Guru
iTrader: (50)
Joined: Mar 2006
Posts: 9,675
Likes: 132
From: Tri-Cities, WA // Portland, OR

But seriously, family and work always take priority over random folks on the Internet. Don't worry about it, we'll still be here when you get a little more free time.
Actually, since I have a little time on my hands...mrfred, given how long ago you'd done this patch, do you have any concerns about how it was done, now that you've spent more quality time with the fuel routines? Are you still running this yourself?
Looking at the source, the ADC hook at C250 in 8859 looks like it's at A8F8 in 9653, and the AFRMAP hook at 182E4 in 8859 appears to be at 14DB4 in 9653, so this looks like it would be a pretty straightforward port: just a matter of fixing up some addresses.
Looking at the source, the ADC hook at C250 in 8859 looks like it's at A8F8 in 9653, and the AFRMAP hook at 182E4 in 8859 appears to be at 14DB4 in 9653, so this looks like it would be a pretty straightforward port: just a matter of fixing up some addresses.
Thread Starter
EvoM Guru
iTrader: (50)
Joined: Mar 2006
Posts: 9,675
Likes: 132
From: Tri-Cities, WA // Portland, OR
Actually, since I have a little time on my hands...mrfred, given how long ago you'd done this patch, do you have any concerns about how it was done, now that you've spent more quality time with the fuel routines? Are you still running this yourself?
Looking at the source, the ADC hook at C250 in 8859 looks like it's at A8F8 in 9653, and the AFRMAP hook at 182E4 in 8859 appears to be at 14DB4 in 9653, so this looks like it would be a pretty straightforward port: just a matter of fixing up some addresses.
Looking at the source, the ADC hook at C250 in 8859 looks like it's at A8F8 in 9653, and the AFRMAP hook at 182E4 in 8859 appears to be at 14DB4 in 9653, so this looks like it would be a pretty straightforward port: just a matter of fixing up some addresses.
Yep, I still run the closed loop wideband patch, but have not carefully tested whether it gets me better gas mileage. The closed-loop wideband subroutine is well-written. I wouldn't change a thing with it. Along with the subroutine, some of the original ROM code needs to be modified to make the hook and allow the ECU to read the fuel table even when in closed loop. If you like, I can send you the source code to allow you to make a more informed decision on whether you'd want to port it over to those ROMs.
Actually, you already posted the source in the second post of the thread, so I've been going off of that along with a simple diff between 8859 and your modified version. (I think I've finally found a good use-case for my python disassembler: doing quick diffs between stock and modified ROMs.
)
I've already found the two main hooks (ADC and AFRMAP, as posted above), I just need to run through any memory addresses you're working with and make note of them. The rest looks like a no-brainer; I'd planned on finishing up porting it to 96530006 this afternoon, but my actual paying job got in the way.
3gEclipseTurbo, I might have something to play with tomorrow or sometime this weekend, if you're feeling up to testing.
)I've already found the two main hooks (ADC and AFRMAP, as posted above), I just need to run through any memory addresses you're working with and make note of them. The rest looks like a no-brainer; I'd planned on finishing up porting it to 96530006 this afternoon, but my actual paying job got in the way.

3gEclipseTurbo, I might have something to play with tomorrow or sometime this weekend, if you're feeling up to testing.
Ya just let me know, my email is thegamefgunit@aol.com.
I would be interested on this also as I have been waiting for this! I have a 2005 evo and would love to control AFR on closed loop. I am still using 96940011 but I will be willing to change to this rom if I can control close loop AFR.
Last edited by pupo; May 14, 2010 at 06:15 AM. Reason: add info.
first cut of 9653 support
Edited 5/20/2010: Uploaded v2, which changed "Cold Engine Closed Loop AFR" to a much more reasonable 14.7.
----
Cool, I actually found a few minutes this afternoon to tackle this.
Here's a completely untested 96530006 patch, based on mrfred's original code. I've run it through a disassembler and it looks correct, but I can't stress this enough: I haven't even loaded this on my own car yet, so if something breaks, you get to keep both pieces. If something goes wrong, turn the car off and flash it back to your old ROM, and post here about what happened.
I tried to take care to avoid collisions, so this should work with at both a stock 96530006, as well as with v5.10 and v7 of tephra's ROMs (including the SD- and DMA-patched versions of v7).
Download a patched 96530006 here (you don't actually flash this to your car; you only copy stuff from it): http://evoecu.logic.net/mirror/patch...oop_AFR-v2.hex
Add this XML to 96530006.xml in your rommetadata directory:
All the rest of mrfred's instructions apply, including EvoScan changes.
(For the geeks: I used FFFF8906 and FFFF890A for rear/front O2 RAM locations, as they appeared to be unused. Any other differences should just be accounting for different RAM and ROM locations in 9653, and most should be obvious from the XML.)
----
Cool, I actually found a few minutes this afternoon to tackle this.
Here's a completely untested 96530006 patch, based on mrfred's original code. I've run it through a disassembler and it looks correct, but I can't stress this enough: I haven't even loaded this on my own car yet, so if something breaks, you get to keep both pieces. If something goes wrong, turn the car off and flash it back to your old ROM, and post here about what happened.

I tried to take care to avoid collisions, so this should work with at both a stock 96530006, as well as with v5.10 and v7 of tephra's ROMs (including the SD- and DMA-patched versions of v7).
Download a patched 96530006 here (you don't actually flash this to your car; you only copy stuff from it): http://evoecu.logic.net/mirror/patch...oop_AFR-v2.hex
Add this XML to 96530006.xml in your rommetadata directory:
PHP Code:
<scaling name="AFR16" units="AFR" toexpr="14.7*128/x" frexpr="14.7*128/x" format="%.1f" min="8" max="20" inc="0.1" storagetype="uint16" endian="big"/>
<scaling name="mLinverse" units="1/mL" toexpr="x/8" frexpr="x*8" format="%.1f" min="0" max="100" inc="0.1" storagetype="uint16" endian="big"/>
<table name="Closed Loop Wideband On/Off" category="Front/Rear_02" address="7FC0" type="1D" level="1" scaling="uint8"/>
<table name="Cold Engine Closed Loop AFR" category="Front/Rear_02" address="7FC2" type="1D" level="1" scaling="AFR16"/>
<table name="Min Coolant Temp To Use AFR Table" category="Front/Rear_02" address="7FC4" type="1D" level="1" scaling="Temp"/>
<table name="Wideband AFR Correlation 1/mL Value" category="Front/Rear_02" address="7FC6" type="1D" level="1" scaling="mLinverse"/>
<table name="Wideband AFR Correlation bL/mL Value" category="Front/Rear_02" address="7FC8" type="1D" level="1" scaling="uint16"/>
<table name="AFR Table Multiplier High Word" category="Front/Rear_02" address="7FCC" type="1D" level="1" scaling="Hex16"/>
<table name="AFR Table Multiplier Low Word" category="Front/Rear_02" address="7FCE" type="1D" level="1" scaling="Hex16"/>
<table name="Front O2 (ADC 04) RAM variable" category="Front/Rear_02" address="AA0E" type="1D" level="1" scaling="Hex16"/>
<table name="Rear O2 (ADC 0A) RAM variable" category="Front/Rear_02" address="AA0A" type="1D" level="1" scaling="Hex16"/>
<table name="MUT12 Value (To Read Wideband)" category="Front/Rear_02" address="3624A" type="1D" level="1" scaling="Hex16"/>
<table name="MUT19 Value (To Read Front O2 ADC)" category="Front/Rear_02" address="36266" type="1D" level="1" scaling="Hex16"/>
<table name="ADC Value Mod Hook" category="Front/Rear_02" address="A8F8" type="3D" level="1" scaling="Hex16">
<table name="Code" type="Static X Axis" elements="1" scaling="Hex16">
<data>Hex16</data>
</table>
<table name="Address" type="Static Y Axis" elements="10">
<data>A8F8</data>
<data>A8FA</data>
<data>A8FC</data>
<data>A8FE</data>
<data>A900</data>
<data>A902</data>
<data>A904</data>
<data>A906</data>
<data>A908</data>
<data>A90A</data>
</table>
</table>
<table name="Hook For Closed Loop Pulse Control Hex" category="Front/Rear_02" address="14DB4" type="3D" level="1" scaling="Hex16">
<table name="Code" type="Static X Axis" elements="1">
<data>Hex16</data>
</table>
<table name="Address" type="Static Y Axis" elements="8">
<data>14DB4</data>
<data>14DB6</data>
<data>14DB8</data>
<data>14DBA</data>
<data>14DBC</data>
<data>14DBE</data>
<data>14DC0</data>
<data>14DC2</data>
</table>
</table>
<table name="Front/Rear 02 Sim Subroutine Part 1" category="Front/Rear_02" address="36980" type="3D" level="1" scaling="Hex16">
<table name="Code" type="Static X Axis" elements="1" scaling="Hex16">
<data>Hex16</data>
</table>
<table name="Address" type="Static Y Axis" elements="40">
<data>36980</data>
<data>36982</data>
<data>36984</data>
<data>36986</data>
<data>36988</data>
<data>3698A</data>
<data>3698C</data>
<data>3698E</data>
<data>36990</data>
<data>36992</data>
<data>36994</data>
<data>36996</data>
<data>36998</data>
<data>3699A</data>
<data>3699C</data>
<data>3699E</data>
<data>369A0</data>
<data>369A2</data>
<data>369A4</data>
<data>369A6</data>
<data>369A8</data>
<data>369AA</data>
<data>369AC</data>
<data>369AE</data>
<data>369B0</data>
<data>369B2</data>
<data>369B4</data>
<data>369B6</data>
<data>369B8</data>
<data>369BA</data>
<data>369BC</data>
<data>369BE</data>
<data>369C0</data>
<data>369C2</data>
<data>369C4</data>
<data>369C6</data>
<data>369C8</data>
<data>369CA</data>
<data>369CC</data>
<data>369CE</data>
</table>
</table>
<table name="Front/Rear 02 Sim Subroutine Part 2" category="Front/Rear_02" address="369D0" type="3D" level="1" scaling="Hex16">
<table name="Code" type="Static X Axis" elements="1">
<data>Hex16</data>
</table>
<table name="Address" type="Static Y Axis" elements="40">
<data>369D0</data>
<data>369D2</data>
<data>369D4</data>
<data>369D6</data>
<data>369D8</data>
<data>369DA</data>
<data>369DC</data>
<data>369DE</data>
<data>369E0</data>
<data>369E2</data>
<data>369E4</data>
<data>369E6</data>
<data>369E8</data>
<data>369EA</data>
<data>369EC</data>
<data>369EE</data>
<data>369F0</data>
<data>369F2</data>
<data>369F4</data>
<data>369F6</data>
<data>369F8</data>
<data>369FA</data>
<data>369FC</data>
<data>369FE</data>
<data>36A00</data>
<data>36A02</data>
<data>36A04</data>
<data>36A06</data>
<data>36A08</data>
<data>36A0A</data>
<data>36A0C</data>
<data>36A0E</data>
<data>36A10</data>
<data>36A12</data>
<data>36A14</data>
<data>36A16</data>
<data>36A18</data>
<data>36A1A</data>
<data>36A1C</data>
<data>36A1E</data>
</table>
</table>
<table name="Front/Rear 02 Sim Subroutine Part 3" category="Front/Rear_02" address="36A20" type="3D" level="1" scaling="Hex16">
<table name="Code" type="Static X Axis" elements="1">
<data>Hex16</data>
</table>
<table name="Address" type="Static Y Axis" elements="18">
<data>36A20</data>
<data>36A22</data>
<data>36A24</data>
<data>36A26</data>
<data>36A28</data>
<data>36A2A</data>
<data>36A2C</data>
<data>36A2E</data>
<data>36A30</data>
<data>36A32</data>
<data>36A34</data>
<data>36A36</data>
<data>36A38</data>
<data>36A3A</data>
<data>36A3C</data>
<data>36A3E</data>
<data>36A40</data>
<data>36A42</data>
</table>
</table>
<table name="Closed Loop Fuel Pulse Control Subroutine" category="Front/Rear_02" address="36A44" type="3D" level="1" scaling="Hex16">
<table name="Code" type="Static X Axis" elements="1">
<data>Hex16</data>
</table>
<table name="Address" type="Static Y Axis" elements="16">
<data>36A44</data>
<data>36A46</data>
<data>36A48</data>
<data>36A4A</data>
<data>36A4C</data>
<data>36A4E</data>
<data>36A50</data>
<data>36A52</data>
<data>36A54</data>
<data>36A56</data>
<data>36A58</data>
<data>36A5A</data>
<data>36A5C</data>
<data>36A5E</data>
<data>36A60</data>
<data>36A62</data>
</table>
</table>
(For the geeks: I used FFFF8906 and FFFF890A for rear/front O2 RAM locations, as they appeared to be unused. Any other differences should just be accounting for different RAM and ROM locations in 9653, and most should be obvious from the XML.)
Last edited by logic; May 20, 2010 at 07:35 AM.


