##
(new) Engine Speed Measurement *2010/06/06*

*Posted by Michael in 2JZduino.*

trackback

trackback

I recently removed the cam signal processing from the design of 2JZduino on the grounds that it isn’t required to effect moderate ignition timing retard, and also because there remained an unsolved problem.

As a result I needed an alternate method to measure engine speed (originally I was using every third cam sensor signal to count 1 revolution).

I’ve taken a slightly different approach. The crank sensor provides a higher resolution measurement of total rotation. Rather than count the time for one revolution the new method calculates the total rotation for a fixed time interval. See relevant code below…

void setup() { TCCR4B = B11000010; // Input Capture Noise Canceler = ON, Input Capture Edge Select = RISING, Prescaler = clk/8 TIMSK4 |= B00001000; // enable Timer4 Output Compare Match C } ISR(TIMER4_COMPC_vect) { // Event every ~30ms for RPM calculation { OCR4C += 59000; // next Interrupt in +29.5ms static byte iteration = 1; if (iteration >= 4) { // calculate engine speed every 29.5*4 = 118ms EngineHz = CrankSignalCounter >> 2; // Hz ~= RisingCrankSignals/4 (for a 118ms period) EngineHzIndex = constrain(EngineHz >> 2, 0, RPMIntervals_LookupTable-1); // index: 0->30 = Hz: 0-120 iteration = 1; CrankSignalCounter = 0; } else iteration++; }

In the above, the Timer4 Output Capture C register fires every 59000 counts or 29.5ms (prescaler = 8), and the engine Hz is calculated on every 4th iteration of the interrupt. Thus EngineHz is calculated every 118ms. A sufficiently long duration is used so that at idle at least one full revolution occurs between calculations to minimize the potential error attributed to the 2 absent signals in the crank wheel (34 teeth spaced 10 degrees apart + 2 missing teeth).

The number of rotations that occurred since the beginning of the 118ms interval is CrankSignalCounter/34. The frequency is then calculated as rotations/period. 34 * 0.118 simplifies to 4.0 and the result is the efficient calculation…

EngineHz = CrankSignalCounter / 4

## Comments»

No comments yet — be the first.