MAF implementation, ideas and discussion

Testing and development of Megasquirt 3

Moderators: jsmcortina, muythaibxr

subwoofer
Super MS/Extra'er
Posts: 884
Joined: Sat Apr 30, 2011 12:34 pm
Location: Sandefjord, Norway

Re: MAF implementation, ideas and discussion

Post by subwoofer »

Great work, Steve!

I don't know where the tables reside, but if there is enough RAM available I'd say that the user friendly solution would be to create the lookup table from the curve as part of the boot.

If it must sit in Flash due to space concerns, it should be calculated from the 64 point curve at time of download. The lookup table should never be visible to the user.

Tuning this beast will be another challenge.
Joachim
1974 Jensen-Healey
1990 VW Caravelle Syncro - running MS3+X
2014 Ford Fiesta EcoBoost
jsmcortina
Site Admin
Posts: 39617
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: MAF implementation, ideas and discussion

Post by jsmcortina »

subwoofer wrote:I don't know where the tables reside, but if there is enough RAM available I'd say that the user friendly solution would be to create the lookup table from the curve as part of the boot.
It takes 10.5 ms to do that. Quite feasible.
If it must sit in Flash due to space concerns, it should be calculated from the 64 point curve at time of download. The lookup table should never be visible to the user.
If this were done in TS then the new g/sec integration _might_ be possible on MS2 also.

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
bmwman91
MS/Extra Newbie
Posts: 30
Joined: Thu Apr 14, 2005 1:28 pm

Re: MAF implementation, ideas and discussion

Post by bmwman91 »

Hey subwoofer,
The air hose in front of your MAF might be OK. The corrugated walls might induce some vortices and whatnot that would cause some fluctuations in the MAF's accuracy, but it's a good start. It looks like the MAF and tube aren't exactly co-axial (and they can move a little relative to one another), which might not help either. The MAF sensor element assumes that it is in a laminar air stream flowing parallel with the housing walls. Is that the 0 280 218 063 MAF? Tap Plastics sells some acrylic tubing that is the same ID/OD as the MAF inlet which you could try attaching a piece of to the inlet.

Do you notice that you run a little leaner than expected at high RPMs? The RC filter on the ADC input does have some roll-off in the range of frequencies that a high-revving 4 cylinder would produce so there would be some "analog voltage averaging" occurring. The trim tables should be able to deal with it though since it is going to be consistent.
1991 BMW E30 318iS...soon to be Squirted.
subwoofer
Super MS/Extra'er
Posts: 884
Joined: Sat Apr 30, 2011 12:34 pm
Location: Sandefjord, Norway

Re: MAF implementation, ideas and discussion

Post by subwoofer »

No, it is a 0 280 218 019, it would max out at ~190bhp I believe.

I'm seeing the underestimation in the pulsating region - WOT and low revs - so bandwidth should not be an issue. There are two other explanations I can think of, dramatically different in terms of probability:

1) Incorrect transfer function (likely). It has been tuned based on the averaged voltage, there is quite some scatter in the plots. I am thinking about how to automate tuning this curve.
2) ADC input slew rate (unlikely). The signal does not swing very fast and it does not seem to have the tell-tale triangular shape of a slew rate limited signal when viewing the MAF log.
Joachim
1974 Jensen-Healey
1990 VW Caravelle Syncro - running MS3+X
2014 Ford Fiesta EcoBoost
jb007
Helpful MS/Extra'er
Posts: 139
Joined: Sat Dec 04, 2010 1:49 am
Location: Melbourne, Australia
Contact:

Re: MAF implementation, ideas and discussion

Post by jb007 »

Firstly thanks all for the discussion, I'm watching with great interest! :yeah!:

Not wishing to railroad the discussion here, but I'm in the process (after I upgrade my MS2 to a MS3) of fitting a HFM 5 (Bosh 0 280 217 123 370kg/hour) to my Mini 1275cc A series engine (maybe the only one mad enough in the world?). I've had it running reasonably well on SD for the last 5,000Ks, but feel that I'd like to try using a MAF.

With regard to the HFM 5 it has a separate temperature sensor inbuilt. Does this need to be used for the IAT, or does the MAF automatically correct for air inlet temperature and I don't need to connect any IAT sensor? :?:

Keep up the good work guys. :D

Jim
1968 Australian Morris Mini fitted with a 1310cc A+ engine
14point7 WB, TunerStudio MS Ultra & MegaLogViewer HD
My Blog: http://www.jims-blog.com
subwoofer
Super MS/Extra'er
Posts: 884
Joined: Sat Apr 30, 2011 12:34 pm
Location: Sandefjord, Norway

Re: MAF implementation, ideas and discussion

Post by subwoofer »

Knowing IAT is always nice, but the MAF sensor measures actual mass flow as long as the IAT is within reason. There is an option to enable IAT correction with MAF, but it should not be necessary.

I would (and have...) connect the IAT.
Joachim
1974 Jensen-Healey
1990 VW Caravelle Syncro - running MS3+X
2014 Ford Fiesta EcoBoost
jb007
Helpful MS/Extra'er
Posts: 139
Joined: Sat Dec 04, 2010 1:49 am
Location: Melbourne, Australia
Contact:

Re: MAF implementation, ideas and discussion

Post by jb007 »

Thanks for that. I'll connect it up using the supplied Bosch values... did you use a custom.inc or just picked three points?
1968 Australian Morris Mini fitted with a 1310cc A+ engine
14point7 WB, TunerStudio MS Ultra & MegaLogViewer HD
My Blog: http://www.jims-blog.com
subwoofer
Super MS/Extra'er
Posts: 884
Joined: Sat Apr 30, 2011 12:34 pm
Location: Sandefjord, Norway

Re: MAF implementation, ideas and discussion

Post by subwoofer »

The "Saab (Bosch)" values are correct for it, simply chose those from the Common sensor type curtain menu.
Joachim
1974 Jensen-Healey
1990 VW Caravelle Syncro - running MS3+X
2014 Ford Fiesta EcoBoost
jb007
Helpful MS/Extra'er
Posts: 139
Joined: Sat Dec 04, 2010 1:49 am
Location: Melbourne, Australia
Contact:

Re: MAF implementation, ideas and discussion

Post by jb007 »

Thanks... I'll sit back and watch your progress now! Hopefully the code will be better for us MAF guys very soon, thanks to your input and others on this thread. Maybe I'll be able to contribute my MAF tuning experiences also. :)
</end of hijack>
1968 Australian Morris Mini fitted with a 1310cc A+ engine
14point7 WB, TunerStudio MS Ultra & MegaLogViewer HD
My Blog: http://www.jims-blog.com
bmwman91
MS/Extra Newbie
Posts: 30
Joined: Thu Apr 14, 2005 1:28 pm

Re: MAF implementation, ideas and discussion

Post by bmwman91 »

subwoofer wrote:No, it is a 0 280 218 019, it would max out at ~190bhp I believe.

I'm seeing the underestimation in the pulsating region - WOT and low revs - so bandwidth should not be an issue. There are two other explanations I can think of, dramatically different in terms of probability:

1) Incorrect transfer function (likely). It has been tuned based on the averaged voltage, there is quite some scatter in the plots. I am thinking about how to automate tuning this curve.
2) ADC input slew rate (unlikely). The signal does not swing very fast and it does not seem to have the tell-tale triangular shape of a slew rate limited signal when viewing the MAF log.
Just for fun, see if you can find some tubing of the same diameter as the MAF and stick a 12" section on there. I think that you might see a slight improvement in consistency and accuracy.

1) From where did you obtain the transfer function for your sensor? I agree that this is the most plausible source if any inconsistency that you see. Even if you have the factory TF available, the hot wire does get dirty over time which might be an issue for a Pick-A-Part sensor (guessing based on the yellow writing on there).
2) The ADC should have no problem keeping up with the input signal. All of the content of interest is on the order of a few hundred Hertz, and the ADC's internal capacitive sampling buffer can handle signals of many kiloHertz. The input RC filter on the PCB is going to cause some slight signal attenuation at higher RPM's, but the pulsation seems to be much less of an issue there and the trim tables can deal with it.

As far as the MS code goes, it looks like it is more or less optimal for the application. Since it has crank position available, it can sum and average the exact amount of air coming in to the engine per each intake valve opening. If the underestimation that you are seeing in the resonance regions is in fact not due to TF error, then we'll have a real mystery on our hands.
1991 BMW E30 318iS...soon to be Squirted.
racingmini_mtl
Super MS/Extra'er
Posts: 9130
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Re: MAF implementation, ideas and discussion

Post by racingmini_mtl »

jb007 wrote:Not wishing to railroad the discussion here, but I'm in the process (after I upgrade my MS2 to a MS3) of fitting a HFM 5 (Bosh 0 280 217 123 370kg/hour) to my Mini 1275cc A series engine (maybe the only one mad enough in the world?). I've had it running reasonably well on SD for the last 5,000Ks, but feel that I'd like to try using a MAF.
TBI on a Mini engine will be much more of a limitation than whether you use SD or a MAF. You'll always have charge stealing that can't be corrected.

Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
jb007
Helpful MS/Extra'er
Posts: 139
Joined: Sat Dec 04, 2010 1:49 am
Location: Melbourne, Australia
Contact:

Re: MAF implementation, ideas and discussion

Post by jb007 »

Thanks Jean. I'm aware of the limitations of siamese port A & B series engines. I'm just hoping the MAF will make it easier for me to tune within the limitations of the engine.

Jim :D
1968 Australian Morris Mini fitted with a 1310cc A+ engine
14point7 WB, TunerStudio MS Ultra & MegaLogViewer HD
My Blog: http://www.jims-blog.com
racingmini_mtl
Super MS/Extra'er
Posts: 9130
Joined: Sun May 02, 2004 6:51 am
Location: Quebec, Canada
Contact:

Re: MAF implementation, ideas and discussion

Post by racingmini_mtl »

Jim,

Good to know that you aware of the limitations. I'm curious to see more about your implementation and I hope you post more when you have something (and with pictures).

Maybe you'll go for sequential port injection next. That would be a nice and probably unique setup with the MAF.

Jean
jbperf.com Main site . . . . . . . . . . . . . . . . . . . . . . jbperf.com Forum
Image
subwoofer
Super MS/Extra'er
Posts: 884
Joined: Sat Apr 30, 2011 12:34 pm
Location: Sandefjord, Norway

Re: MAF implementation, ideas and discussion

Post by subwoofer »

bmwman91 wrote: 1) From where did you obtain the transfer function for your sensor? I agree that this is the most plausible source if any inconsistency that you see. Even if you have the factory TF available, the hot wire does get dirty over time which might be an issue for a Pick-A-Part sensor (guessing based on the yellow writing on there).
I started off with an attempt at fitting the datapoints from the data sheet to an exponential function, it has been tweaked a lot since then. And you are indeed right, it came from a breaker's yard so I don't know how well worn it is.
bmwman91 wrote:As far as the MS code goes, it looks like it is more or less optimal for the application. Since it has crank position available, it can sum and average the exact amount of air coming in to the engine per each intake valve opening. If the underestimation that you are seeing in the resonance regions is in fact not due to TF error, then we'll have a real mystery on our hands.
I agree on that. Unless there are some ugly bugs buried somewhere the chosen solution really should work without much magic and hand waving once the correct TF is dialled in.

But I think I'll lie low for a little while now and see what comes out of the firmware process, I really appreciate the work shauer is putting into this! I'll leave my speculator unit running, hopefully I can figure out how to get TFs in place for arbitrary MAFs. That opens the possibility of building the sensing element into the inlet tract without it being very obvious, and for the extremely high power crowd to build 5" and 6" MAFs...
Joachim
1974 Jensen-Healey
1990 VW Caravelle Syncro - running MS3+X
2014 Ford Fiesta EcoBoost
bmwman91
MS/Extra Newbie
Posts: 30
Joined: Thu Apr 14, 2005 1:28 pm

Re: MAF implementation, ideas and discussion

Post by bmwman91 »

Agreed, shauer deserves a big thumbs-up for his work on this! It looks like a robust solution that will provide pretty accurate, and CONSISTENT air flow values over a wide operating range. I am sure that the weird effects at resonance conditions will get figured out eventually too.

Based on the Bosch data sheet for the HFM5 unit I am using (provides a 30-point TF table) I needed to use a 4th order poly fit to get an R^2 value of >0.99. I ended up paying $30 for some curve fitting software and the best non-poly fit that I could get was some sort of exotic 7-term thing that I can't recall the name of. Scalability for different sized inlet tubes will be interesting. Since the sensing element is a fixed distance from the top of the tube, it will be moving into different regions of the laminar flow profile so there will be a combination of the tube diameter and the element's position in the tube that affect the effective TF. Anyone have a flow bench? It would be really cool to build up a Megasquirt MAF database for the HFM5 element in different diameter tubes.
1991 BMW E30 318iS...soon to be Squirted.
Kzcleve
Helpful MS/Extra'er
Posts: 52
Joined: Mon Feb 13, 2012 9:57 pm

Re: MAF implementation, ideas and discussion

Post by Kzcleve »

I just though I would add my thanks to Shauer. I have been following the discussion here closely, as I have been somewhat frustrated with MAF tuning due to the issues discussed in this thread. I look forward to seeing something like this solution show up in the new firmware releases.
shauer
Experienced MS/Extra'er
Posts: 364
Joined: Wed Oct 05, 2005 10:39 am
Location: Rochester, NY USA
Contact:

Re: MAF implementation, ideas and discussion

Post by shauer »

Just a brief update on what I'm doing. With James' assistance I was able to implement the idea of initializing a 1024 value RAM table off of the 64 value table set by TS. James practically wrote the code for me and emailed it to me. I had to integrate it into my experimental code and fix a couple minor issues. I am now able to use the new TS 64 value table for tuning again, even with the g/s value look up. I also worked out a solution to automatically rebuild the bigger RAM table every time an edit is made to the TS table so you still have the real time tuning ability of editing the TS table while the engine is running and seeing the effect immediately. This needs to be reviewed to see if it is really compatible with the rest of the system. It works great for me but I may be doing something that messes a feature up that I don't use.

I have also experienced a couple instances of underflow error on the maf calculation. Now that I integrate negative flow it is possible to get enough negative flow data points in an ignition event to result in a net negative air flow. For me this happens in a WOT 3rd gear pull up to redline (7000 RPM). When I let off the gas to shift I experience a couple/three ignition events where the entire air flow is just slightly negative. I'm seeing about 0.9 - 0.95 volts (1V = zero flow). The resulting underflow error results in a huge maf value (3 or 4 times normal max value) and an injector pw and duty cycle that is well beyond normal maximum. It is all so fast that you don't feel it but it is definitely there. I have temporarily fixed this by adding a dead band to my maf curve so flow values between 0.9 and 1.0 volts are zero. I am working on adding underflow prevention into the sampling code but it is a challenge to do it with as few extra operations as possible. I think I have a solution and will try it out today or tomorrow.

I will post some screen shots later today, at work now without access to my tuning laptop.
Steve Hauer
http://www.77e21.info
1977 BMW 320i with MAF, COP, IAC, Sequential fuel and spark, MS3 knock sensing
MS3 / MS3X / V3 mainboard, MS3 V1.5 a4
shauer
Experienced MS/Extra'er
Posts: 364
Joined: Wed Oct 05, 2005 10:39 am
Location: Rochester, NY USA
Contact:

Re: MAF implementation, ideas and discussion

Post by shauer »

Here are some screen shots and log file shots from the current code I am running.

For reference, this is the 3d trim table that I started with as shown already on the previous page of this thread:

Image

Here is my latest trim table after a weekend of tuning using VEAL and then incorporating the VEAL corrections into the maf flow curve. As you can see I have it within almost +/- 5% now. There is still some fine tuning to do.

Image

Image

Here are some shots of the TS setups. The first one shows the new field I added to specify the maf zero flow adc value (default is 0)

Image

And the current flow curve now being read from the 64 value TS version. This is expanded to 1024 in the firmware on startup and each time a value is modified
maf_flow_curve.png
I had mentioned an underflow error. Here is a shot of a log trace showing it. Just to the left of the cursor the maf goes to an invalid value due to the period of slightly negative air flow. Notice also the bad PW and Duty cycle values.
maf_underrun.png
I think I have a solution for the underflow error. The accumulated raw maf reading is currently stored in a 32 bit unsigned variable. If my math is correct I can changed this to a 32 bit signed value and still have enough range to store up to a 4 second long ignition event. (65535 * 7812 samples/sec * 4 sec = 2,047,837,680) Max positive value for a 32 bit signed value is 2,147,483,647. I'm not aware of an engine that runs for 4 seconds between ignition events so I should be fine. :)

What I will do is change the accumulation math to use a signed, two's complement 32 bit value and then check for a maf less than zero after performing the average and set the maf to zero if it is negative.

I never thought an engine would show a net negative air flow for an entire ignition event. I think what happened is that I was at almost max air flow and then slammed the throttles closed and experienced a brief rebound of air through the maf sensor for a couple/three ignition events.
Steve Hauer
http://www.77e21.info
1977 BMW 320i with MAF, COP, IAC, Sequential fuel and spark, MS3 knock sensing
MS3 / MS3X / V3 mainboard, MS3 V1.5 a4
bmwman91
MS/Extra Newbie
Posts: 30
Joined: Thu Apr 14, 2005 1:28 pm

Re: MAF implementation, ideas and discussion

Post by bmwman91 »

Awesome work!

Forgive my newbie question, but what is VEAL? It makes me want an early dinner, but I assume that it isn't something you eat.

Which MAF (Bosch PN) are you using? Are you finding that the TF data from the data sheet is not correct for the MAF in your application? It sounded like you had the actual data sheet with the tabulated volts-to-g/s values, rather than graphically tracing the plot found in the more publicly available info sheet.

I'd believe that you can see transient net-negative air flow with an ITB setup. The runners and plenum are all enclosed with a single-TB, but with ITBs all of the momentum of the incoming air will use those volumes as a "spring" and shoot air back out the MAF when the throttles snap closed! A single-TB setup only has the volume of air between the TB and MAF to act as a spring with the incoming air's momentum. Surely well worth the improvement in throttle response when you do the opposite (snap the throttles open).

One thing I meant to mention a while back about using a MAF and dealing with resonance...
Using a stock air box exacerbates resonance since it is basically another relatively large resonant cavity in the intake track. Having a velocity stack in front of the MAF, and having it fed from open air would cut down on resonance since the open atmosphere is not going to act like any sort of resonant chamber. Spring-mass-damper stuff, which there is already enough of downstream of the MAF, and the air box is a giant spring. I saw a ~30% difference in resonance magnitude at "trouble spots" between my car's stock air box and a giant cone filter. Ultimately I stuck with the factory air box because paper filters offer the most particulate protection, and it also pulled cool air from behind the headlights. Software dealt with the rest.
1991 BMW E30 318iS...soon to be Squirted.
shauer
Experienced MS/Extra'er
Posts: 364
Joined: Wed Oct 05, 2005 10:39 am
Location: Rochester, NY USA
Contact:

Re: MAF implementation, ideas and discussion

Post by shauer »

bmwman91 wrote:Awesome work!

Forgive my newbie question, but what is VEAL? It makes me want an early dinner, but I assume that it isn't something you eat.
VEAL is a Tuner Studio feature "VE Analyze Live". It is an auto tuning feature where TS makes real time corrections to your VE table (trim table in this case) based on current and target AFR. My preferred method of tuning is to allow VEAL to change my trim table and then go through my logs and pick out the MAF voltages that correspond to various corrections in my trim table. I then apply those corrections to my maf curve, reset the trim table to 100% (no correction) and repeat as often as needed to converge on a stable solution. I tend to start with portions of my tune where the maf signal is more stable and get those regions dialed in. Then I start to work out to the regions of increased maf signal noise. This way the noisiest regions have (mostly) known good components to reference on the maf curve.
bmwman91 wrote: Which MAF (Bosch PN) are you using? Are you finding that the TF data from the data sheet is not correct for the MAF in your application? It sounded like you had the actual data sheet with the tabulated volts-to-g/s values, rather than graphically tracing the plot found in the more publicly available info sheet.
I'm using a Frankenstein maf. It is a maf body that I picked up on ebay that has a 71mm I.D. and a 80mm O.D. since that is the size of the HFM2 sensor housing I was using. Bosch pulled a fast one between the HFM2 and HFM5 and rotated the sensor element mounting holes 90 degrees so you cannot drop a HFM5 into a HFM2 housing. I inserted the HFM5 sensor element from a 2001 - 2006 VW (0280218063). The VW HFM5 sensor is readily available but the body size is too small for my application so I just found a body of the desired size and dropped the sensor in.

As far as the transfer curve, I started with the Bosch data sheet for a 0280218087 sensor which has the same I.D. as my other housing (71mm) and entered that curve from the data sheet as a starting point. My entire induction system is a 100% custom one-off so any transfer curve is simply a starting point to get the engine running. Bottom line is that I adjust the transfer curve until the engine is tuned. That is how I know it is right...
bmwman91 wrote:I'd believe that you can see transient net-negative air flow with an ITB setup. The runners and plenum are all enclosed with a single-TB, but with ITBs all of the momentum of the incoming air will use those volumes as a "spring" and shoot air back out the MAF when the throttles snap closed! A single-TB setup only has the volume of air between the TB and MAF to act as a spring with the incoming air's momentum. Surely well worth the improvement in throttle response when you do the opposite (snap the throttles open).
I agree completely. I have noticed that you tend to see some interesting things when you combine a custom intake, ITBs, and a long duration cam. It's like the perfect storm of worst case behaviors on a NA engine.
Steve Hauer
http://www.77e21.info
1977 BMW 320i with MAF, COP, IAC, Sequential fuel and spark, MS3 knock sensing
MS3 / MS3X / V3 mainboard, MS3 V1.5 a4
Post Reply