View Single Post
Old 07-24-2013, 04:04 AM   #1 (permalink)
t vago
MPGuino Supporter
t vago's Avatar
Join Date: Oct 2010
Location: Cedar Rapids, IA
Posts: 1,766

The Karen-Mobile - '05 Dodge Magnum SXT
Team Dodge
90 day: 26.72 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: 799
Thanked 681 Times in 437 Posts
t vago's MPGuino workspace thread

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)

Hardware Support added (as of 10 December 2013):
  • 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).

Program Features added (as of 20 May 2015):
  • 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 mL/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.
  • Addition of fuel cost, fuel remaining cost, fuel cost per unit distance, distance per unit fuel cost, and fuel cost rate calculations for instant, current, and tank trips.
  • Addition of Instant Trip Distance-To-Empty, Current Trip Distance-To-Empty, and Tank Trip Distance-To-Empty large number displays.
  • Addition of Instant Trip Time-To-Empty, Current Trip Time-To-Empty, and Tank Trip Time-To-Empty large number displays.
  • 2-second temporary Status Line now shows real-time updating of lower LCD data display
  • Tank and Current trip save/load/reset menu now adds shortcuts to their respective pages for easy pen-and-paper logging.
  • 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.
  • 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.
  • Button shortcuts are also possible. "Long-press" of the right button can now cause the value display to go directly to the instant fuel economy screen. "Long-press" of the center button now briefly shows the CPU loading for that page.
  • The settings interface has been enhanced to allow stepping back and forth between different parameters, without having to go through editing them.
  • Metric/US functionality has been more tightly integrated into the display coding. Parameters and parameter labels also reflect the metric parameter setting.
  • Leading spaces instead of zeros (of course).
  • 8 user-programmable display screens. Any combination of 4 instant, trip, or tank readings may be displayed on any of 8 screens. These combinations may be stored in EEPROM.
  • Bar graphs for differential fuel economy vs. time (a la ScanGauge E), fuel economy vs. time, 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).
  • Spiffy large numbers have been added from the MPGuino Code Hacks wiki page.
  • System clock, which is used as a "screen saver" once inactivity timeout has been reached.
  • Saving of complete current trip or tank trip data, into one of 10 EEPROM slots. Ability to view raw trip data stored in EEPROM.
  • Time values now show hhmmss, where they used to show
  • 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.

Technical Features added (as of 25 October 2013):
  • 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.
  • 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 3.4% and 26.2%.
  • 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.
  • A 2 second window filter, which can be enabled via a dedicated parameter, has been added to the instant fuel economy readout. This has greatly reduced jitter associated with this readout.
  • Time-to-empty, distance-to-empty, and idle-time-to-empty values have been added. Engine speed (RPM) value has also been added.
  • 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.
  • Fuel injector pulse measurement has been made more robust. Two separate rationality checks have been added.
  • Display routines re-written to separate low-level LCD hardware support from higher-level character output. This should make it easier to modify the code to support alternate display devices.

Features in progress (as of 18 Jan 2016):
  • Add user-definable support for two separate output pins, that can either drive LEDs or be used as a variable voltage source for external gauges. Currently adding hardware support for this feature.
  • Add alert displays for up to 4 different programmable monitored variables. Currently modifying display code to support this feature.
  • Two-Wire Interface support. The Arduino Wire module takes up too much space, and does not support interrupt-driven coding. A small buffer class has been formally defined, with support for interrupt-driven servicing routines. The buffered LCD and Serial output now use this class.
  • 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.
  • Coastdown variable determination. Currently working on adding matrix math support into SWEET64.

Features to be added (as of 12 May 2014):
  • Addition of RTC support
  • Addition of vehicle battery voltage display
  • System date setting, in conjunction with system time
  • ?

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 a JellyBeanDriver board - a 20 MHz AtMega328 with the traditional MPGuino 3 direct-wired pushbuttons and 2x16 character LCD screen. Make changes to the "#define" section, beginning at line 226, as needed.

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 20150520 - (44.7 KB, 528 views)
The Fiat Dakota

The Karen-mobile

The Red Sled

Last edited by t vago; 01-18-2016 at 04:55 PM.. Reason: Add features in progress
  Reply With Quote
The Following 4 Users Say Thank You to t vago For This Useful Post:
AndrzejM (07-24-2013), Ettore_M (01-23-2016), NachtRitter (08-25-2013), sendler (09-05-2013)