View Single Post
Old 08-28-2005, 05:16 PM   #16
stevieg
See me in my wet t-shirt.
 
stevieg's Avatar
 
Join Date: Aug 2003
Location: Warwickshire, UK
Posts: 1,909
Quote: Originally Posted by Erorus
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.


It looks like my botched attempt at MPG conversion I think.

I didn't think it was accurate as it could be either, and haven't actually used it in real-life.

Any idea what could be done using the OBD to get a more accurate measure?
__________________
Ford Focus MP3 : www.stevieg.org/carpc
Car PC Status: COMPLETE
stevieg is offline   Reply With Quote