View Single Post
Old 09-14-2009, 05:05 PM   #893 (permalink)
EcoModding Apprentice
Join Date: Aug 2009
Location: terra firma
Posts: 138
Thanks: 4
Thanked 24 Times in 22 Posts

I think there is an error in processInjOpen/Closed. I understand the change made from 0.74 to 0.75 resulted in more steady GPH calculations, but I believe the results are incorrect.

In 0.74, InstInjStart/End were always set to the beginning of the "On" signal. GPH was calc'd as (Total On Time) / (Total On+Off Time).

In 0.75, InstInjEnd was changed to the beginning of "Off". This causes the last "Off" period to drop from the GPH calc. Suppose 10 equal-length pulses occur during one loop period. GPH = (10 * On) / (10 * On + 9 * Off). Since injector pulses are "Off" much longer than "On", this will skew the result several percent higher.

My suggested fix is to return to the 0.74 Start/End method (always at leading edge of "On"), but instead of updating Inj totals on the Off signal (processInjClosed), wait until the pulse cycle is complete, and then update the totals in processInjOpen.

void processInjOpen (void)
  injHiStart = microSeconds();

  if (tmpInstInjStart == nil)  tmpInstInjStart = injHiStart;
// else { // edit 9/26/09 - see note below
    tmpInstInjTot += tmpInstInjOn;
    tmpTrip.injHius += tmpInstInjOn;
//  } // edit 9/26/09

  tmpInstInjEnd = injHiStart;

void processInjClosed (void)
    tmpInstInjOn = elapsedMicroseconds(injHiStart)- parms[injectorSettleTimeIdx];

in loop():

change     tmpInstInjStart=nil;
to:     tmpInstInjStart=tmpInstInjEnd; //preserve InjStart of unfinished pulse from previous loop

near line 200:

change:  unsigned volatile long tmpInstInjEnd=nil;
and add: unsigned volatile long tmpInstInjOn=0;
edit 9/26/2009 processInjOpen -- remove the else condition. If one or more loops were entirely EOC, tmpInstStart will alwayss == nil, and the last good tmpInstInjOn will not get added to tmpTrip, and thus, will never be added to tank or current via update(). Removing the else will allow the old injOn to get updated to all the Trip structures, regardless of injStart's status.

The side-effect of this unconditional update: instantgph & rpm will be a little off for the re-entry loop, but you're coming off an EOC where gph=0.00 and mpg=999.999, so no real harm.

Last edited by nickdigger; 09-27-2009 at 03:31 AM..
  Reply With Quote