I have a digital dashboard project I built for my car. I simply read in CAN signals and display them. The last step is to get an accurate Average Mpg value to display.
Currently I am using CAN signals for Fuel Usage L/Sec and Speed to calculate an instant Mpg. This works great.
Options for Avg Mpg.
-
My first thought was just to record the Instant Mpg every say 5 Seconds into an array of 20 values and take the average of the array. Using a moving Avg results in more accurate results without having to fill the entire array on startup. Additionally different time intervals in reading or array size can increase accuracy. My first attempts the array filled to fast and the avg was basically the same as the instant value. Additionally I have an if statement where the Instant Mpg value only gets sent to the array if the speed is greater than 5Mpg. Dont want 0s in the array if the car is stopped.
-
The odometer signal is broadcast on the CAN, so I know distance traveled. I thought about declaring a value that stores total miles driven and another that stores total gallons used.(I think I can get this from the L/sec value) Simple math would give an Avg Mpg value. However if one day I am pulling a trailer or large weight that decrease my instant Mpg, I think it would take a long time for the Avg to update since it would be looking at miles traveled and gallons used over the last 2-3 months. The window is so large a unique heavy load situation would not be reflected on the Avg value.
The vehicle also sends fuel level remaining in gallons on the CAN bus. I want to use my Avg Mpg value * my current fuel level to calculate a Range in miles until I need to refuel. The more accurate the Avg Mpg value the better.
The biggest issue is storing the Avg Mpg value when the Car/Arduino is powered off. All values are reset to 0 which is fine except I don't want to wait x mins of driving to repopulate the array to have an accurate Mpg reading.
Is storing the entire array in EEPROM the only way to retain an Avg Mpg value when powered of? Using method 2 I would only need to store the Total miles driven and total gallons used in EEPROM.
I am trying to stay away from using EEPROM and not have to leave the Arduino powered 24/7 in my vehicle. But leaving it on in a "sleep" mode could be an option.
I was using a moving avg for my fuel level remaining since signals can be erratic when driving but I switched to a recursive filter that initializes the fuel level on startup and then just changes it fractions based on signals from fuel level gauge. This kept me from having to use EEPROM and store an value long term. Looking for another clever way like this to do Avg MPG.