View Single Post
Old 01-05-2017, 06:25 PM   #1 (permalink)
t vago
MPGuino Supporter
t vago's Avatar
Join Date: Oct 2010
Location: Cedar Rapids, IA
Posts: 1,696

The Karen-Mobile - '05 Dodge Magnum SXT
Team Dodge
90 day: 25.49 mpg (US)

Fiat Dakota - '00 Dodge Dakota SLT RWD Quad Cab
90 day: 16.67 mpg (US)

The Red Sled - '01 Dodge Durango SLT 4WD
90 day: 16.96 mpg (US)
Thanks: 740
Thanked 630 Times in 403 Posts
t vago's MPGuino workspace thread, continued

In the course of modifying the original MPGuino 0.86 code to incorporate the fuel injection correction factor for Chrysler vehicles with returnless fuel systems, I've been fiddling with the code, doing this and that and the other thing.

Since that other thread is really only meant for addressing that issue with Chrysler returnless fuel systems, it became increasingly apparent that a separate thread was needed to describe the other things I have done with the code. So, here it is. (All CPU workload figures assume a 20 MHz processor)

Known Issues (as of 01 March 2017):
  • On the AtMega2560 platform, MPGuino does not always wake up from deep sleep when the engine is started. MPGuino reacts correctly otherwise. Investigation on-going.
  • With the Adafruit RGB LCD module, there is no way to wake up MPGuino from a deep sleep by pressing the 5 input buttons - not without modifying the RGB LCD module itself. The Reset button can still be pressed to wake up MPGuino, if desired. MPGuino still wakes up normally if the engine is started or if it senses the vehicle starting to move.
  • AtMega2560 sometimes freezes up when attempting to upload MPGuino code to it. Issue is with buggy AtMega2560 bootloader, and reflashing the bootloader with Arduino IDE 1.0.4 or later will fix the issue. No workarounds within the MPGuino code itself.
  • FE vs. speed graph shows a lone datum line at an impossibly high speed. Will investigate as time permits.

Hardware Support added (as of 08 February 2017):
  • Support for the Adafruit RGB LCD module with 5-button input. (h/t meelis11)
  • Support for just about any generic 2x16 LCD module that uses a Two Wire Interface (TWI) interface. Tested with a SainSmart IIC/I2C/TWI 1602 Serial LCD Module Display.
  • Support for the Arduino Mega as a hardware platform. (via josemapiro)
  • Support for 5 different buttons via a single wire, while freeing up the TWI (Two-Wire Interface) pins for use for other functionality. (via nickdigger)
  • Support for the Parallax 5-position switch.
  • Support for the Parallax serial UART LCD module. (Minor changes had to be made to the spiffy big number font to enable it to work with the Parallax LCD module - these changes do not appear if the legacy MPGuino LCD display is used).
  • Chrysler returnless fuel injector correction factor, based off of intake manifold pressure. Utilizes existing manifold pressure (MAP) sensor built into the existing engine control system, but requires an additional barometric sensor (in other words, a spare/extra MAP sensor).
  • Support for the TinkerKit! LCD hardware as a commercially-produced MPGuino module, with enhanced 5-button functionality (see above).

Implemented features undergoing testing (as of 25 January 2017):
  • Reduced-power sleep (via meelis11). Deep sleep mode implemented and appears to be working well on JBD board, AtMega2560, and TinkerKit! module. Still need to test on Meelis MPGuino (have to rig up a power circuit for it)

Program Features built into the base MPGuino code (as of 08 February 2017):
  • Dedicated timeouts related to EOC, Idle, Park (engine off/vehicle stopped). Enables quick auto-saving of Current Trip and Tank Trip data. Allows auto-selection of EOC screen and Idle screen, as appropriate, after a programmable length of time has occurred.
  • Menu display system that provides access to added features or to system stored parameters.
  • Reduction of power consumption. MPGuino now consumes between 5 to 20 percent less power during normal operation.
  • On-The-Fly support for Metric vs SAE (or Imperial) readouts. Metric/US functionality has been more tightly integrated into the display coding. Selected stored parameters and parameter labels also reflect the metric parameter setting.
  • 2-second temporary Status Line, with real-time updating of lower LCD data display.
  • Display labels have been changed to be more descriptive, a la OBDuino.
  • Debounced buttons, with a "long-press" feature that effectively doubles the number of addressable button presses.
  • Button shortcuts are also possible. "Long-press" of the right button can now cause the main display to go directly to the next screen (like large Fuel Economy, FE vs. Time, FE vs. Speed, Large Distance to Empty, large Time To Empty, or System Clock)
  • Interface routines now take advantage of the above button enhancement to provide safeguards, such as requiring "long-press" button combinations to reset current and tank trip. Parameter editing has been enhanced with the addition of parameter reversion, and the ability to cancel settings changes instead of saving them to EEPROM.
  • The settings interface has been enhanced to allow stepping back and forth between different stored parameters, without having to go through editing all of them in sequence.
  • Leading spaces instead of zeros (of course).
  • Time values now show hhmmss, where they used to show
  • Inactivity timeout that shuts off LCD backlight when this timout is reached.
  • Ability to display the following calculations for Instant Trip, Current Trip, and Tank Trip.
    • Fuel Economy (MPG or L/K)
    • Speed (MPH or kph)
    • Distance (miles or km)
    • Fuel Consumption Rate (gal/hr or L/hr)
    • Fuel Consumed (gallons or liters)
    • Engine Speed (RPMs)
    • Engine Run Time (hhmmss)
    • Time spent moving (hhmmss)
    • Fuel Remaining (gallons or liters)
    • Distance To Empty (miles or km)
    • Time To Empty (hhmmss)

Optional Compile-Tile Program Features added (as of 25 January 2017):
  • Idle/EOC Tracking - Tracks idle/EOC using separate Instant Idle/EOC Trip, Current Idle/EOC Trip, and Tank Idle/EOC Trip. Current and Tank Idle/EOC Trips are treated identically to Current and Tank Trip (auto-saved/auto-restored/auto-reset) with regard to the base MPGuino code and the other optional features here.
  • Deep Sleep Mode - Reduced-power sleep (via meelis11), which is entered once inactivity timeout has been reached. Not compatible with system clock function.
  • Software Clock - System clock, which is used as a "screen saver" once inactivity timeout has been reached. Not compatible with reduced-power sleep mode.
  • Programmable Current Trip Auto-Reset - Ability to select current trip reset upon wakeup due to running engine only, current trip reset upon wakeup due to button press only, current trip reset upon wakeup due to both running engine or button press, or disable current trip reset upon wakeup.
  • Trip Save - Saving of complete current trip or tank trip data. Current Trip and Tank Trip are auto-saved into EEPROM once inactivity timeout has been reached. Current Trip and Tank Trip are auto-restored from EEPROM, if MPGuino is then switched off and switched back on at some later time.
  • Stored Trip View - Ability to view raw trip data stored in EEPROM.
  • Imperial Gallons - Support for Imperial gallons vs US gallons.
  • Spiffy large numbers have been added from the MPGuino Code Hacks wiki page.
  • Large Fuel Economy - Instant Trip Fuel Economy, Current Trip Fuel Economy, and Tank Trip Fuel Economy large number displays.
  • Large Distance-To-Empty - Instant Trip Distance-To-Empty, Current Trip Distance-To-Empty, and Tank Trip Distance-To-Empty large number displays.
  • Large Time-To-Empty - Instant Trip Time-To-Empty, Current Trip Time-To-Empty, and Tank Trip Time-To-Empty large number displays.
  • Drag Race Mode - (via meelis11), Enables recording 0-30 MPH, 0-60 MPH, and 1/4 mile time. Also records fuel consumption and distance travelled.
  • Partial Refuel - For Partial Refuel, Tank Trip Reset has been replaced with a smaller sub-menu that allows temporary increases in Tank Size by a Partial Refuel amount. Each Partial Refuel amount is additive; the total Partial Refuel amount increases with each partial refuel value entered. It is also possible to reset just the Partial Refuel value by itself, or to reset the Tank Trip and Partial Refuel value together.
  • Easy Fuel Calibration - Eliminated requirement to know or look up microseconds/(gallons or liters) from somewhere on the web. Ability to calculate microseconds/(gallons or liters). # of injectors, reference injector flow rate in cc/min, reference fuel pressure for reference flow rate, and system fuel pressure are used to determine microseconds per unit volume figure. This figure can then be tweaked as necessary, as before.
  • Fuel Cost - Addition of below calculations for Instant Trip, Current Trip, Tank Trip (and Instant Idle/EOC Trip, Current EOC/Trip, Tank Idle/EOC Trip). Fuel Cost per (gallon or liter) is a stored parameter accessible through the Settings screen.
    • Fuel Consumed Cost
    • Remaining Fuel Cost
    • Fuel Cost per distance (money/mile or money/km) - example 0.12 dollars per mile
    • Distance per Fuel Cost (mile/money or km/money) - example 8.33 miles per dollar
    • Fuel Cost per hour (money/hr)
  • Tank and Current trip save/load menu now adds shortcuts to their respective pages for easy pen-and-paper logging.
  • CPU Monitoring - "Long-press" of the center button briefly shows the CPU loading for that page. System display mode added which shows CPU loading, time since power-up, and
  • Editable Display Screens - 8 user-programmable display screens. Any combination of 4 instant, trip, or tank readings may be displayed on any of 8 screens. These combinations are stored in EEPROM.
  • Fuel Economy vs. Time - Bar graph for fuel economy vs. time. Bar graph for differential fuel economy vs. time (a la ScanGauge E)
  • Fuel Economy vs. Speed - Bar graphs for fuel economy vs. speed, total (tank) time travelled vs. speed, total (tank) distance travelled vs. speed, and total (tank) fuel used vs. speed. Bar graphs are plotted graphically on-the-fly, vs. using a clunky custom font. 15 elements are supported. FE vs. time and dFE vs. time periods are selectable via a single EEPROM parameter. FE vs. speed, fuel rate vs. speed, distance traveled vs. speed, and time spent travelling vs. speed have two EEPROM parameters (lower speed cutoff which is set at a default of 25 MPH, and speed bar length which is set at a default of 5 MPH).
  • JSON Output Logging - JSON output capability to show a more capable output screen via Raspberry PI or similar (via skybolt). Sample output looks like this:

    Not compatible with serial data logging on Legacy MPGuino hardware.
  • Serial Data Logging - MPGuino spits out 5 parameters to the serial output port while active, 2 times a second. A user-programmable stored parameter allows enabling or disabling of serial data logging. Not compatible with JSON output logging on Legacy MPGuino hardware.

Technical Features added (as of 08 February 2017):
  • MPGuino now consumes less power to operate, taking advantage of the built-in ability to turn on/off various hardware modules within the AVR chip that MPGuino runs on.
  • Interrupts for injector capture and VSS capture have been optimized for speed. This code can now easily handle VSS pulse-trains that come from an ABS wheel speed sensor.
  • The acceleration test (drag race) function operates completely independently of the display routines.
  • Interrupt driven, buffered LCD character output. The LCD buffer is processed through the freewheeling ADC interrupt handler, which now causes LCD character processing to be transparent to the display update loop.
  • Interrupt driven, buffered serial character output. Serial output is now transparent to the display update loop. Serial output can be enabled or disabled via a dedicated parameter, if desired.
  • Interface coding has been re-written so that any display mode (primary display, clock set, settings edit, parameter edit, trip save/retrieval, or trip raw data view) will reliably allow fuel readings to be collected and updated, and serial logging data to be output (if selected), regardless of mode. The inactivity timeout function also works, regardless of mode.
  • Parameters can now be variable length, whereas before they were all 32-bit numbers. Parameters may be sized from 1 bit to 32 bits in length. The parameter entry/editing routine enforces this specified length. The EEPROM routines have been modified to read and write these variable length parameters along byte boundaries.
  • Arrays, consisting of strings and characters and program pointers, have all been moved into Flash memory, as opposed to RAM. This has freed up some 200 bytes of RAM.
  • Fuel injector pulse measurement has been made more robust. Two separate rationality checks have been added.
  • Display routines were re-written to separate low-level LCD hardware support from higher-level character output. A common text streaming module handles string and character output, and can output to multiple output devices. This should make it easier to modify the code to support alternate display devices.
  • A fully functional TWI interface library was added, based off the twi.c library for Arduino. MPGuino itself could be configured as a slave TWI device, with a little extra coding. The TWI interface plays nicely with the rest of the MPGuino interrupt infrastructure, and allows for TWI input button pressing and output interfacing in a manner transparent to the main loop.

Technical 64-bit math specific features added (as of 25 January 2017):
  • 64-bit math routines are all written in bytecode that is interpreted by a 64-bit pseudoprocessor that I've named SWEET64. All of the 64-bit math routines have been shrunk by about 70%, compared to the original code.
  • CPU workload per display update loop is now between 1.15% and 11.3%.
  • Portions of the SWEET64 64-bit pseudoprocessor have been re-written in assembly language, to speed up 64-bit shifts, adds, and condition tests. Minor portions of the rest of the code have also been re-written in assembly language.
  • 64-bit division has been re-written to gain speed.
  • Time-to-empty, distance-to-empty, and idle-time-to-empty values have been added. Engine speed (RPM) value has also been added. Time-to-Empty is accurate to the second, and Distance-to-Empty is accurate to 1/10th of a mile/kilometer.
  • The decimal number output function now uses SWEET64 to perform conversions from 64-bit numbers into strings. The function can output 0 through 3 decimal places (dependent on the value to be output). Distance and speed values now have one decimal place, and engine speed and remaining available RAM have no decimal places.

Features in progress (as of 08 February 2017):
  • Coastdown variable determination. Underlying data capture mechanism in place. Currently working on adding matrix math support into SWEET64.
  • Add user-definable support for two separate output pins, that can either drive LEDs (as described in the MPGuino Code Hacks), or be used as a variable voltage source for external gauges. Currently coding SWEET64 bytecode routines to support variable voltage output.
  • Add alert displays for up to 4 different programmable monitored variables. Currently modifying display code to support this feature.

Features to be added (as of 13 March 2017):
  • Easy method for performing VSS and fuel calibration
  • Addition of RTC support. Two-Wire Interface code has been written, needs testing for master receiver. Once done, should be a simple matter to read in clock data from the RTC module I own.
  • System date setting, in conjunction with system time. Possibly limited just to adding day of week.
  • Addition of vehicle battery voltage display (via meelis11)
  • Addition of SPI communications.
  • A-B comparison mode for saved trip/tank data, based off of fuel rate vs. speed graphs. Debugging of bar graph code is in progress.
  • ?

The attached source code was developed to be copied and pasted into an Arduino 1.6.4 IDE window.

Also, the code is configured to work on base legacy MPGuino board - a 16 MHz AtMega328 with the traditional MPGuino 3 direct-wired pushbuttons and 2x16 character LCD screen. Make changes to the "#define" section, beginning at line 246, as needed, to fit your configuration.

If you use the AVR command-line tools, use these settings for setting the programmable fuses to ensure that your MPGuino will work:
Originally Posted by Ettore_M View Post
lfuse:0xf7 hfuse:0xd9 efuse:0x07

Attached Files
File Type: zip 20170210 - (83.8 KB, 33 views)
The Fiat Dakota

The Karen-mobile

The Red Sled

Last edited by t vago; 03-13-2017 at 05:18 PM.. Reason: ooopsie, missed one line in the code
  Reply With Quote
The Following 4 Users Say Thank You to t vago For This Useful Post:
Felar (02-17-2017), josemapiro (01-06-2017), MetroMPG (02-23-2017), skyking (01-08-2017)