Quote: Originally Posted by Erorus
PHP Code:
Function GetMPG(tMAF As Variant, tSpeed As Variant, tLTFuelTrim As Variant) As Variant
''MAF is maf_air_flow sensor. To convert from what the OBD returns, value=OBDData * 0.01
''tSpeed is vehicle speed in MPH. To convert from what the OBD returns, value=OBDData * 0.621371192
''tLTFuelTrim is long-term fuel trim. To convert from what the OBD returns, value=0.7812 * (OBDData - 128)
If IsNull(tMAF) Or IsNull(tSpeed) Or IsNull(tLTFuelTrim) Then
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(tMPG, 1, True, False, False)
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?