View Single Post
Old 07-16-2013, 08:28 PM   #25 (permalink)
t vago
MPGuino Supporter
 
t vago's Avatar
 
Join Date: Oct 2010
Location: Hungary
Posts: 1,807

iNXS - '10 Opel Zafira 111 Anniversary

Suzi - '02 Suzuki Swift GL
Thanks: 828
Thanked 708 Times in 456 Posts
Testing my updated code revealed that rather interesting fuel consumption runaway bug that was first documented in this post by DCB. It is always interesting to see my tank fuel economy just drop from 23.6 MPG to 1.0 MPG.

Re-examined the code and did some more searching around this sub-forum, and theorized that when my car goes into DFCO, it shuts off the fuel injectors, but it still sends little pulses, like in this post by rmccomiskie. I can reliably see the above fuel consumption runaway happen on every commute so far. Hopefully, tonight, when I load in this code, it will squash this bug.

Code:
ISR(INT0_vect) { // fuel injector open event handler

	injOpenStart = timer2_overflow_count | TCNT2; // calculate current cycle count
	// if timer overflow condition occurred, recalculate current cycle count and fold in overflow
	if (TIFR2 & 0b00000001) injOpenStart = (timer2_overflow_count + 256) | TCNT2;

	dirty |= dirtyInjTick; // tell close event handler that fuel injector has in fact opened

}

ISR(INT1_vect) { // fuel injector close event handler

	injOpenStop = timer2_overflow_count | TCNT2; // calculate current cycle count
	// if timer overflow condition occurred, recalculate current cycle count and fold in overflow
	if (TIFR2 & 0b00000001) injOpenStop = (timer2_overflow_count + 256) | TCNT2;

	if (dirty & dirtyInjTick) { // must have read in a injector start event first

		// calculate fuel injector pulse length
		if (injOpenStop < injOpenStart) cycleLength = 4294967295ul - injOpenStop + injOpenStart + 1;
		else cycleLength = injOpenStop - injOpenStart;

		if (cycleLength > injSettleCycles) { // if the pulse length is greater than the settle time, it's valid

			cycleTemp = injOpenCycles[1] + cycleLength - injSettleCycles; // add to injector cycle accumulator
			if (injOpenCycles[1] > cycleTemp) injOpenCycles[0]++; // handle any possible overflow
			injOpenCycles[1] = cycleTemp;
			injPulseCount++; // update pulse count
			timerStatus |= timerWakeUp; // tell timer to wake up main program
			dirty |= dirtyInj; // signal that a valid fuel injector pulse has just been read

		}

		dirty &= ~dirtyInjTick; // ignore any more close events until another open event is received

	}

}
Astute readers will be able to make out the remnants of functions microSeconds() and elapsedMicroseconds().
  Reply With Quote
The Following User Says Thank You to t vago For This Useful Post:
nickdigger (07-20-2013)