View Single Post
Old 08-28-2005, 05:07 PM   #15
Erorus
Low Bitrate
 
Erorus's Avatar
 
Join Date: Feb 2005
Location: NEPA
Posts: 100
Quote: Originally Posted by knubile
Any progress on this? I'm wondering if MPG calculations are possible using OBD-II.

PHP Code:
Function GetMPG(tMAF As VarianttSpeed As VarianttLTFuelTrim As Variant) As Variant

''MAF is maf_air_flow sensorTo convert from what the OBD returnsvalue=OBDData 0.01
''tSpeed is vehicle speed in MPHTo convert from what the OBD returnsvalue=OBDData 0.621371192
''tLTFuelTrim is long-term fuel trimTo convert from what the OBD returnsvalue=0.7812 * (OBDData 128)
    
    If 
IsNull(tMAF) Or IsNull(tSpeed) Or IsNull(tLTFuelTrimThen
        GetMPG 
Null
        
Exit Function
    
End If

    
Dim tMPG As String

    
'' Do MAF over an hour
    tMAF 
tMAF 60
    tMAF 
tMAF 60

    
'' Turn into KG/litre equivalent
    tMAF 
tMAF 1000

    
'' Get petrol flow based on 14.7:1
    tMAF 
tMAF 14.7

    
'' convert litres to gallons
    tMAF 
tMAF 0.219969157

    
'' convert long term fuel trim to percentage
        tLTFuelTrim 
= (tLTFuelTrim 100) + 1

    
'' Calculate MPG
    tMPG 
= (tSpeed tMAF) * tLTFuelTrim

    GetMPG 
FormatNumber(tMPG1TrueFalseFalse)
End Function 

The problem I have with this is the air flow sensor is very optimistic, and you probably run richer than this formula indicates. It says I average around 60-90MPG when cruising on the hwy and up to 200+ MPG when coasting. However, it does change when you have the pedal down, etc. I forget where I stole this code from.
Erorus is offline   Reply With Quote