tvago1972 / MPGuino

MPGuino is a great Arduino/AVR based fuel trip computer that calculates mileage by directly reading fuel injector pulses and vehicle speed pulses. Great for pre-OBDII cars, and more accurate than OBDII-based trip computers.
http://www.ecomodder.com
GNU General Public License v3.0
8 stars 4 forks source link

Instant MPG sometimes reverts to fuel flow. #30

Open FlashStopFall opened 1 week ago

FlashStopFall commented 1 week ago

Instant MPG seemingly randomly reports fuel flow (g/h for my settings) instead of MPG. Affects every screen as well as serial output. It seems to be working correctly about 20% of the time, and showing fuel flow the other 80%. It usually starts working, and then stops working after coming to a stop. Sometimes though it doesn't start in a working condition, and sometimes it will come back after driving (usually after coming to a halt).

From what I can tell, fuel economy is calculated in prgmFuelEcon() in functions.h.

static const uint8_t prgmFuelEcon[] PROGMEM = {
    instrLdRegTripVarIndexed, 0x02, rvVSSpulseIdx,      // fetch the accumulated number of VSS pulses counted
    instrMul2byMain, mpCyclesPerVolumeIdx,              // multiply by cycles per unit volume to get the denominator for fuel economy
    instrLdReg, 0x21,                                   // save denominator for later
    instrLdRegTripVarIndexed, 0x02, rvInjCycleIdx,      // fetch the accumulated fuel injector open cycle measurement
    instrMul2byEEPROM, pPulsesPerDistanceIdx,           // multiply by the pulses per unit distance factor to get the numerator for fuel economy
    instrBranchIfFuelOverDist, 6,                       // if MPGuino is in metric mode, skip ahead
    instrSwapReg, 0x21,                                 // swap the numerator and denominator terms around
    instrMul2byConst, idxDecimalPoint,                  // put in the decimal point constant used for output formatting (for mi/gal or km/L)
    instrSkip, 2,                                       // go skip ahead

//fecont1:
    instrMul2byConst, idxMetricFE,                      // put in the output formatting decimal point constant, multiplied by 100 (for L/100km or gal/100mi)

//fecont2:
    instrDiv2by1,                                       // divide the numerator by the denominator
    instrAdjustQuotient,                                // bump up quotient by adjustment term (0 if remainder/divisor < 0.5, 1 if remainder/divisor >= 0.5)
    instrDone                                           // exit to caller
};

So it seems like it calculates (amount of fuel/amount of distance) and then swaps the numerator and denominator to get (distance/fuel). (I'm using U.S. settings). So if I'm only getting (amount of fuel) reported instead of (distance/fuel), it seems like the code must be first calculating (fuel/distance), somehow loosing (distance) (or setting it = 1?) and then not swapping the numerator and denominator before returning the value.

I'll start looking here.

FlashStopFall commented 1 week ago

Interesting. I found that I can put the car in park/neutral and wait 5-10 seconds, and it will correctly show instant mpg after that every time. Then when I come to stop again, and the screen goes to the "park" screen (no vehicle movement) if I don't shift to park/neutral, it will continue to read the g/h rate which replaces mpg on the "park" screen. I wonder if there is a fuel rate threshold for stopping/restarting the instant mpg reading? Because that's the only thing really noticeably different from idling in gear (idle in gear at 0.78-0.88g/h, idle in neutral 0.47-0.68g/h).