# Calculating MPG from VSS and MAF from OBD2

Show 40 post(s) from this thread on one page
• 10-31-2007, 04:26 PM
Curiosity
I use LtFt in the equation from something I saw here a few years ago, but running a few old OBD2 logs shows Lightner's code works quite well and faster with only 2 PIDs. It's a little sensitive when my MAF reads < 0.10 once in a while, so filtering that out helps. I wouldn't display it directly though. Average it out over several seconds using a circular buffer. I actually use a 3 second and 5 minute average to show more realistic numbers. I've also decided stoplights are bad for our economy. :)
• 11-06-2007, 03:22 PM
DrStoooopid
okay now how do you do it in a car without all those bells and whistles? (say a 63 Fairlane with a 221ci V-8 engine.)...some function of airflow to rpm?...
• 06-03-2008, 09:02 AM
W1BMW
There are a number of senders that you can place inline. I don't have links handy, but the last time I went shopping for this, I found several options between \$100-200 for kit built airplanes and marine applications. The aircraft ones are a little more expensive because they are designed not to be able to restrict fuel flow in the event of a failure. The one I spec'd sent a single pulse for every so many units of fuel that went through and cost about \$180

I'd be going this route with my project if I hadn't found out about the OBD port. That only cost me \$35 for the translator.

Good luck,
/z
• 08-07-2008, 01:02 AM
actual fuel consumption
as many have posted already, the formulas given here are for stoichiometric fuel ratios. Unfortunately, modern cars don't run at stoichiometric fuel ratios. They run as lean as possible, just on the cusp of lean missing when cruising. They run rich anywhere from half-throttle to WOT. They automatically compensate for sub-standard fuels and fuel additives that affect octane.

My suggestion is, use the formula for calculating stoichiometric fuel consumption, but use the LTFT (Long Term Fuel Trim) to find what the vehicle is actually using. LTFT is given in +/- % (percentage). An example of the formula to use is

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

This formula uses the car's fuel trim value to compensate for the difference in actual AFR and stoichiometric AFR, however I'm not 100% sure that the LTFT value is % difference from stoichiometric. If anybody has any ideas as to how correct my thoughts are, please respond.
• 08-07-2008, 09:06 AM
Grrrmachine
Quote:

Originally Posted by jiggersplat
I would suggest trying to use injector pulse width instead if it is available....

I like this idea, and even older vehicles (like E30 BMWs) used it to calculate the MPG for the on-board computer, whilst also taking a speed reading from the speedometer (which was pulsed from the diff rather than a mechanical cable)

How would you measure pulse width though, if not available via OBD? wouldn't you have to build your own circuit?
• 08-07-2008, 12:54 PM
mezz64
Quote:

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

I like this idea and the logic seems sound. I'm going to adjust my formula's and see how things work out. I'm using a calculated adjustment percentage at the moment because my calculations were coming out too optimistic. (eg. 50mpg when it's really 20mpg)

Since stoich is 0, and it varies +- from 0 I'm pretty sure it is % difference from stoich. I've got a inline-4 so just the bank 1 measurement should be needed.
• 08-07-2008, 03:07 PM
Curiosity
Yep, I'd agree. It's more accurate to use LTFT. Just one is fine unless your engine has problems. I use a little different math, but here are some ideas.

x = something like 30 in raw form. You'll notice when you let off on the gas, the MAF rate can drop fast and shows 500 MPG or more. I just skip showing it until it gets back to normal.

And LTFT must be positive for this math to work. So...

if(MAF < x ) return
if(LTFT < 0.0) LTFT = -LTFT

MPG = 710.7 * VSS / MAF * (1 + LTFT/100)
• 08-07-2008, 03:58 PM
marcw
Modern cars circa '96 do run at stiochiometric as soon as possible...
Quote:

as many have posted already, the formulas given here are for stoichiometric fuel ratios. Unfortunately, modern cars don't run at stoichiometric fuel ratios. They run as lean as possible, just on the cusp of lean missing when cruising. They run rich anywhere from half-throttle to WOT. They automatically compensate for sub-standard fuels and fuel additives that affect octane.

My suggestion is, use the formula for calculating stoichiometric fuel consumption, but use the LTFT (Long Term Fuel Trim) to find what the vehicle is actually using. LTFT is given in +/- % (percentage). An example of the formula to use is

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

This formula uses the car's fuel trim value to compensate for the difference in actual AFR and stoichiometric AFR, however I'm not 100% sure that the LTFT value is % difference from stoichiometric. If anybody has any ideas as to how correct my thoughts are, please respond.

and as much as possible because this represents the ideal mixture of air/fuel that produces the exhaust gases best processed by the 3-way converters.

Under non-open loop operation (cold start, hard acceleration, closed throttle coast down) the controller can go open loop and then can feed teh engine nearly any air/fuel mixture it wants.

All fuel consumption calculations are going to be imprecise unless one knows the weight the gas being consumed to a precise value. Gas weight varies due to differences in blends that arise from octane differences, or gas targeted for a season or a region that has some botique blend requirement and temperature to name a few factors that I can think of. There could be more.

But fuel consumption based on air consumption is probably good enough for all but labs needs.

Sincerely,

MarcW.
• 08-07-2008, 04:50 PM
malcom2073
So if you happened to have your A/F ratio from say.. a wideband O2 sensor, you could plug that in and get an even more accurate guesstimate right?
• 08-08-2008, 01:29 AM
Quote:

Originally Posted by Curiosity
Yep, I'd agree. It's more accurate to use LTFT. Just one is fine unless your engine has problems. I use a little different math, but here are some ideas.

x = something like 30 in raw form. You'll notice when you let off on the gas, the MAF rate can drop fast and shows 500 MPG or more. I just skip showing it until it gets back to normal.

And LTFT must be positive for this math to work. So...

if(MAF < x ) return
if(LTFT < 0.0) LTFT = -LTFT

MPG = 710.7 * VSS / MAF * (1 + LTFT/100)

LTFT does not have to be positive to work correctly. I convert the % LTFT value to a decimal value to multiply the result by. This means if the computer is using 5% more fuel than what hard-coded fuel tables tells it to use, then the formula compensates by adding 5% to the result. Similarly, if the computer is using 5% less than what the fuel tables say to use, the formula subtract 5%. Notice that when LTFT if +5%, the formula multiplies by 1.05, and when the LTFT is -5%, it multiplies by 0.95.

There's only two issues I'm having with the formula I came up with. The first is that LTFT is really only the difference in pulse width of the injectors. This means it also compensates for different tolerance levels in the injectors output themselves. For example, a partially clogged injector will be given a positive LTFT to compensate for the smaller amount of fuel it outputs as compared to the other injectors.

Which brings me to the second problem: Modern vehicles are starting to have LTFT's for each individual cylinder, which throws this formula out the window because it only pays attention to one over-all LTFT. I suppose you could take each available LTFT (whether it's 2 banks or 8 banks), and find the average, which should theoretically find the overall LTFT, but then again, LTFT could also be compensating for defective injectors or any other number of factors.

Another method to directly figure the amount of fuel used is to use a home-made injector-tester kit. You could create a microcontroller that outputs 25% PW, 50% PW, 75% PW, and 100% PW to each individual injector for an arbitrary amount of time, say 10 seconds for each level. Use a calibrated test tube to measure the volume of fuel dispensed by each fuel injector, then graph the results. Find a formula that closely fits the curve of the graph, and use that to interpolate fuel amounts of each injector with the PCM's give PW.

One problem I see with this method, however, is that the fuel rail is under different amounts of pressure at various times, and the vacuum in the intake is different at various times. However, the fuel pressure is changed proportionately to the amount of vacuum. This is because as vacuum increases, it has a tendency to "pull" the fuel out of the injectors, and when vacuum is minimal, it takes more pressure to "push" the same amount of fuel out. The idea is to even it out so the computer doesn't have to do so much work and computations to get the right fuel mixture. Hopefully, this idea means that the varying pressures and vacuums shouldn't matter.

Anywho, if anybody has any ideas to further these lines of thoughts, please post a reply
Show 40 post(s) from this thread on one page