# Calculating MPG from VSS and MAF from OBD2

Show 40 post(s) from this thread on one page
• 09-22-2009, 08:08 AM
Rooster
Quote:

Originally Posted by VegasGuy
i just went out and looked, and Centrafuse is definitely reporting CFM. 340CFM at idle to be precise.

My idea about converting cubic feet to pounds and then grams doesn't produce the correct values either.

I'm stumped.

Yeah, come to think of it carburetors are rated in CFM so I guess it might make sense to show a value of CFM.

They are probably using the 'ideal gas law' pV = nRT to convert the mass into a volume, so you would have to do the same type of conversion but in the reverse direction. The value for 'R' is a constant but depends upon the gas. Maybe you could wiggle that value to get your calcs to come out?
• 11-23-2009, 09:02 AM
tylercee
Quote:

Originally Posted by lightner
For the record, the first "one-line" MPG formula above, taken from my Circuit Cellar article, is off by 100! The "4.54" should in fact be "454". The correct formula is:

MPG = (14.7 * 6.17 * 454 * VSS * 0.621371) / (3600 * MAF / 100)
MPG = 710.7 * VSS / MAF

Note that OBD-II VSS reading is in kilometers/hour and MAF reading is grams/sec times 100.

This formula works very well in a modern automobile because the engine computer spends almost 100% of its time managing the fuel-air-ratio to 14.7, which it can do very well because of the "closed loop" feedback from the O2 sensor(s).

In fact, the accuracy of this method has been proven in literally tens of thousands of gasoline-powered vehicles. Accuracy within a few percent is typical, often limited by the accuracy of the vehicle speed reading (i.e., VSS).

As for other ways of doing this, especially if you don't have a MAF sensor, by knowing the displacement of the engine, and after a simple "calibration" using fuel tank "fill-up" data to find the only unknown, namely the "volumetric efficiency" (VE) of the engine, MAF can be calculated from RPM, MAP and IAT. With VE, one can use the following formulas to calculate a synthetic "mass air-flow" (MAF) in grams per second, all without a MAF sensor, using the "Ideal Gas Law", as follows:

IMAP = RPM * MAP / IAT
MAF = (IMAP/120)*(VE/100)*(ED)*(MM)/(R)

where manifold absolute pressure (MAP) is in kPa, intake air temp (IAT) is in degrees Kelvin, R is 8.314 J/°K/mole and the average molecular mass of air (MM) is 28.97 g/mole. Note that, in the above formula, the volumetric efficiency of the (4-cycle!) engine is measured in percent and the engine displacement (ED) is in liters.

The VE of my 1999 7.4L Chevy Suburban is about 65%. Smaller, higher performance engines can have VE's of 85% or higher.

Best regards,

Bruce D. Lightner
[email protected]
http://www.lightner.net/lightner/bruce/

Thanks Bruce for providing this approximate MAF calculation. I'm in the process of making my own instantaneous MPG calculator for my 2004 Honda Civic and my ECU isnt giving me a MAF reading.

I was wondering if MAF could be obtained from an engine load equation. I read somewhere the ECU calculates the engine load from several parameters such as MAF, throttle pos, speed .. I can get engine load% from my ECU so Id liek to use it to solve for MAF.
Does anyone know equation for engine load?
• 11-23-2009, 02:55 PM
Aberk
Quote:

Originally Posted by tylercee
Thanks Bruce for providing this approximate MAF calculation. I'm in the process of making my own instantaneous MPG calculator for my 2004 Honda Civic and my ECU isnt giving me a MAF reading.

I was wondering if MAF could be obtained from an engine load equation. I read somewhere the ECU calculates the engine load from several parameters such as MAF, throttle pos, speed .. I can get engine load% from my ECU so Id liek to use it to solve for MAF.
Does anyone know equation for engine load?

Your Honda likely uses a MAP (manifold absolute pressure) sensor. This sensor data is located at mode 0x01 PID 0x0B. There have been equations posted to this site that will show you how to compute a pseudoMAF from MAP readings. That pseudoMAF takes the place of the MAF reading from the car in the previous equation. The hardest part of computing pseudoMAF is determining the volumetric efficiency.
• 11-23-2009, 03:05 PM
tylercee
Quote:

Originally Posted by Aberk
Your Honda likely uses a MAP (manifold absolute pressure) sensor. This sensor data is located at mode 0x01 PID 0x0B. There have been equations posted to this site that will show you how to compute a pseudoMAF from MAP readings. That pseudoMAF takes the place of the MAF reading from the car in the previous equation. The hardest part of computing pseudoMAF is determining the volumetric efficiency.

Yes I get a MAP reading. Id like to avoid using the apprx MAF calculation which assumes VE is constant. Anyone know if its possible to get MAF from engine load % ?
• 12-02-2009, 04:22 PM
CapnBoost
MAF is going to give you air, you can only get fuel consumption/time with MAF if you're going to assume constant AFR.

Imho, the only way to get mileage is to know the instantaneous fuel consumption/speed.
• 12-29-2009, 11:15 PM
lightner
Using OBD-II LOAD to derive MAF
Quote:

Originally Posted by tylercee
Yes I get a MAP reading. Id like to avoid using the apprx MAF calculation which assumes VE is constant. Anyone know if its possible to get MAF from engine load % ?

There seems to be at least two different interpretations of the OBD-II parameter called "engine load" (i.e., LOAD, in the range of 0-100%), as reported over the OBD-II bus by modern engine computers. One version gives a LOAD value with is directly proportional to MAF (i.e., mass air flow). The other version seems to show that MAF is proportional to (LOAD x RPM).

So, if you want to solve for MAF using LOAD, first you need to determine which LOAD algorithm is being used by the vehicle in question, then you need to determine the appropriate constant scaling factor to derive MAF. Of course in one case you need to read RPM along with LOAD.

Given a calculated MAF, plus a periodic VSS (i.e., vehicle speed) reading, integrating these gets you incremental fuel consumed and distance traveled. Divide one by the other and you get MPG.

As I have noted before, using MAF to derive a fuel flow measured in gallons assumes a constant air-fuel (A/F) ratio and a fixed, known fuel density. Given that modern fuel injected engines are designed to run with a fixed, "stoichiometrically ideal" air fuel ratio of 14.7:1 almost all the time, using a constant A/F ratio for the MPG calculation makes good sense.
• 12-29-2009, 11:57 PM
VegasGuy
I've watched these discussions roll back and forth for several months and I've used Mr. Lightner's equations for a couple of CF plugins with some success.

When coasting, the plugin will show a value somewhere around 900MPG and when really gettin' it on it will display -450MPG. Since this is an 05 Tacoma, I suspect that those numbers might be off a smidge. Probably something to do with "new" math. :p

The point is: It doesn't matter. When I see a negative number, I alter my behavior to try and produce a positive number. Hopefully the largest positive number I can. What that number is is actually not relevant.

With regards to this conversation, what is the ACTUAL total variance from reality produced by using the 14.7:1 constant over time? .01% over a week? .2% a year? Unless it's significant enough to alter your driving behavior, or create a false representation of overall engine performance, then it really doesn't matter. And if you don't actually use the information, regardless of its source, to improve your mileage, then the numbers are TOTALLY meaningless.

I've always thought red, yellow and green leds were the answer. Keep it in the green as much as you can, and life is good. Maybe dispense a cookie when you get to your destination. You know, something nice like that.

Just an opinion...YMMV.

VegasGuy
• 12-30-2009, 01:24 PM
lightner
Calculating MPG / Using a "Constant" A/F Ratio
Quote:

Originally Posted by VegasGuy
I've watched these discussions roll back and forth for several months and I've used Mr. Lightner's equations for a couple of CF plugins with some success.

When coasting, the plugin will show a value somewhere around 900MPG and when really gettin' it on it will display -450MPG. Since this is an 05 Tacoma, I suspect that those numbers might be off a smidge. Probably something to do with "new" math. :p

You should be able to make this work---I know because I have. As I've told people that have contacted me via email, the "hard part" of implementing a real-time MPG meter with embedded firmware is doing what needs to be done within the constraints of fixed-point integer math---typically limited to 32-bit of precision.

The formulas that I have provided yield perfectly fine results---using floating-point math. (You also have to make sure that you use the correct "units" for each of the parameters in the calculation.) Converting these formulas to work on an 8-bit microcontroller requires careful attention to detail. Just one integer overflow somewhere in your calculation chain will destroy the intended result---which is likely what you are seeing.

One way to work this out is to collect a bunch of "raw" OBD-II data and put that into a MS Excel Spreadsheet (e.g., as a .CSV file). Then use Excel "formulas" to calculate MPG using the formulas that I have suggested. Once you have that working, convert the Excel formulas to use "integer math" in place of the floating point math that Excel uses by default. Keep working until you get it right. Trust me! Debugging something like this with a spreadsheet is a heck of a lot easier than doing it in an 8-bit microcontroller! :-)

Quote:

Originally Posted by VegasGuy
With regards to this conversation, what is the ACTUAL total variance from reality produced by using the 14.7:1 constant over time? .01% over a week? .2% a year? Unless it's significant enough to alter your driving behavior, or create a false representation of overall engine performance, then it really doesn't matter. And if you don't actually use the information, regardless of its source, to improve your mileage, then the numbers are TOTALLY meaningless.

A modern engine computer maintains a 14.7:1 A/F ratio most of the time. When calculating a real-time MPG value, given the precision of the measured OBD-II parameters, and the accuracy of "constants" such as fuel density, one can expect errors in the range of 5-10%. If anything, the assumed A/F ratio of 14.7:1 likely has the lowest error of all.

BTW: The only time the A/F ratio varies from the "ideal" is during "open loop" fuel control mode, which can be monitored with one of the OBD-II parameters (i.e., Mode 01 PID 03). For example, an engine will run "open loop" for a short period of time after it is started, or when you stomp on the accelerator to get full power---again for short periods of time.

The only time I've seen extended periods in "open loop" mode was whenever I put the engine in my 1999 Suburban under extreme heavy load, for example when towing a large trailer up a long, steep hill. It is my understanding that the engine computer was running the A/F ratio "rich" in order to cool the exhaust gases, in order to protect my truck's very expensive catalytic converter---which, by Federal law, must be warranted for close to 100K miles!
• 12-30-2009, 02:19 PM
VegasGuy
Quote:

Originally Posted by lightner
You should be able to make this work---I know because I have. As I've told people that have contacted me via email, the "hard part"......

As is so often the case (just ask my wife), my sense of humor isn't as highly tuned as I think it is.

The plugins I have built using your formula all work perfectly, producing values which are comparable to those of several different commercial software packages and the ScanGuage hardware device. My exaggerated numbers were a (very weak) effort to point out to those people who think the formula is not precise enough that the actual numbers produced by ANY software or hardware is irrelevant. Only the variance indicated by those numbers is significant.

If you drive your car back and forth to work for a year and see your average MPG decrease by 2%, is it significant if the numbers involved were 75mpg to 73.5MPG or 25mpg to 24.5MPG? Either way, it was about a 2% decrease.

On the other hand, if the averages from one plugin indicate a 2% decrease, and another a 5% decrease, then that difference might be significant. That was my real (poorly made) point.

in the end, the only important question is what is the real deviation produced between using the 14.7:1 constant and directly measuring fuel flow and distance etc over a given period of time?

Like you've said, except in extreme situations (towing, racing), the deviation is probably not going to be statistically significant.

I apologize for interupting this thread, since this is more about application and not theory.

Cheers!

VegasGuy
• 12-30-2009, 10:19 PM
Curiosity
What would cause the negatives? Is it possible you're getting invalid values?

As far as changing your driving habits, you can do more than just going lighter on the peddle with the exception of highway driving. City driving often has different routes to get to the same distination but with differing amounts of stop lights/signs, speed limits, congestion, bridges, etc. Knowing the fuel consumed over different routes can help as well. Although nav software usually finds the best path.
Show 40 post(s) from this thread on one page