View Single Post
Old 07-18-2013, 12:33 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 682 Times in 437 Posts
Would anybody be interested in an optimized version of the base MPGuino 0.86 code?

As I was going through the MPGuino 0.86 code in order to add my Chrysler fuel adjustment algorithm, I got to thinking that I could tweak the base code to reduce the code size, make the code more robust, and get rid of some nasty and subtle bugs in the code.

I went through the base code again, separate from the code I've been working on, and managed to shrink it by a smidge over 20%. It still retains the same functionality as the base 0.86 code. I added no new features to it.

I am going to test the optimized base code tomorrow to make sure it still works.

SizeRemoved BytesComment
17178.original 0.86 code
16898280Re-wrote microseconds() to more accurately calculate the 'microseconds' (actually clock cycles), and to remove a nasty bug that could cause unwanted nested interrupts. Removed (unsigned long) lastMicroseconds.
1687424Re-wrote elapsedMicroseconds to remove reference to floating point number, and to correct negation error.
16774100Re-wrote setup(). Completed moving displayFuncNames strings into flash memory.
156981076added setupGuino() to handle MPGuino-specific system variable setup and fuel injector interrupt setup. Removed floating point calculations (3.785, 1.609) and replaced with (3785 ul / 1000 ul, 1609ul / 1000ul).
1567424Removed indirect function references to ISR(INT0_vect) and ISR(INT1_vect). Re-wrote fuel injector close event to remove fuel consumption runaway bug. Re-wrote instantmpg() to remove integer division before integer multiplication bug.
15530144Re-wrote bignum(). Added LCD:: printBigNum() function. Moved bignumchar1[] and bignumchar2[] into flash.
15332198Re-wrote 64-bit math section to optimize code and to remove separate conditional functions.
15212120Re-wrote LCD:: print and LCD:: pushNibble, added LCD:: printFlash(), removed getstr(), removed tickleEnable().
137341478Removed instantlkm(). Removed Trip::lkm(). Turned injhius and injhisec into injtime[2]. Turned injIdleHius and injIdleHiSec into injIdleTime[2]. Added private Trip::doMiles() and private Trip::doGallons() functions. Eliminated redundant code in Trip::Miles(), Trip::EOCMiles(), Trip::Gallons, and Trip::IdleGallons().

The Fiat Dakota

The Karen-mobile

The Red Sled
  Reply With Quote
The Following User Says Thank You to t vago For This Useful Post:
Piwoslaw (07-19-2013)