View Single Post
Old 02-19-2009, 02:04 PM   #849 (permalink)
rmccomiskie
EcoModding Lurker
 
Join Date: Aug 2008
Location: Massachusetts USA
Posts: 84

Ziggy - '95 Audi S6 Sedan

Manfred - '97 Audi A6 Quattro Sedan
90 day: 20.61 mpg (US)

Clarabell - '03 Audi A4 Quattro Avant

Sherman - '98 Audi A6 Quattro Avant

Cab - '96 Audi Cabriolet
Thanks: 0
Thanked 2 Times in 2 Posts
I found an error in my code mod. The value of x should be determined by a call to elapsedMicroseconds() as shown here:

Code:
void processInjClosed(void){      
  long t =  microSeconds();
  unsigned long s = parms[injectorSettleTimeIdx];	
  unsigned long x = elapsedMicroseconds(injHiStart, t); //using elapsedMicroseconds afterall
  if (x < s) {  //if pulse width < settling time
    x = 0;      //pulse width must be zero
  }else{
    x -= s;     //otherwise subtract settling time from the pulse width
  }
//  if(x >0)    //not needed because x is always zero or greater
    tmpTrip.injHius += x;       
  tmpTrip.injPulses++;      

  if (tmpInstInjStart != nil) {
    if(x >0)
      tmpInstInjTot += x;     
    tmpInstInjCount++;
  } else {
    tmpInstInjStart = t;
  }
  
  tmpInstInjEnd = t;
}
By eliminating elapsedMicroseconds(), I disregarded the case where the injHiStart (start of pulse) could be larger than t (end of pulse). That can occur when the unsigned integer returned by Microseconds() rolls off the end of the number range and starts again from zero.

For example, suppose injHiStart is set to 4294967285, i.e. near the end of the number range for an unsigned long. Then the pulse takes 260uS. When processInjClosed() executes on the trailing edge of the pulse, the number returned by microSeconds() will be 250.

To determine the elapsed time a call is made to elapsedMicroseconds() with startMicroSeconds=4294967285 and currentMicroseconds=250 as parameters. From the v0.75 code:

Code:
unsigned long elapsedMicroseconds(unsigned long startMicroSeconds, unsigned long currentMicroseconds ){  
  if(currentMicroseconds >= startMicroSeconds) return currentMicroseconds-startMicroSeconds;      
  return 4294967295 - (startMicroSeconds-currentMicroseconds);      
}
Since currentMicroSeconds is not >= startMicroSeconds, this calculation is used:

4294967295 - (4294967285 - 250) = 260

So, every so often, the clock will roll off the end of the number range and the values being compared will be reversed. The elapsedMicroseconds() routine handles the situation correctly and returns the true elapsed time (260uS in this case).
  Reply With Quote