Embedded: Tach Success!

It worked! The filtering hardware that I built (zener diode + MOSFET) gave a clear enough signal to simply trigger off the falling edge of the input spikes; this was the trigger condition for my hardware interrupt.

I recorded the time intervals between pulses for four individual events in a buffer and then used the average to calculate RPM. The results speak for themselves:

Embedded: EDIS Tachometer Signal

I’ve been scratching my head as to why I can’t get a decent tach signal for my pneumatic gearshift system. The 12v square wave signal comes into the micro controller via a zener diode and a switching MOSFET. The pin is held high through a pull-up resistor and grounded by the MOSFET. The zener diode cuts the bottom 5 volts off the tach signal to remove any noise around the 0v value.

My mistake, and I think its a fair one, was believing the square wave tach signal would have an equal time high as it does low; at a constant engine speed. Therefore, assuming a maximum rpm measurement of say 15000rpm, I could sample the signal at a fixed period and gain all the data I needed; I was using a 2 microsecond sample period.

2 microseconds
1/0.002s = 500hz
500hz = 30000 samples per minute
or 15000 rpm with one high and one low

I wrote the code to do this but it just gave me gibberish so I decided to pack it in at the end of a long day and just log some very high rate data to look over with a glass of wine. Once I sat down in the warm to try and fix the issue it quickly became clear to me what the problem was. The figure below is a snippet of the log; the xaxis is time in microseconds.

 

Note: I’ve inverted the pin signal because the input pin is active ground.

So the tachometer high period is only half a millisecond long! This does not help things in the slightest. I have two options:

  • Poll the pin at a far higher rate.
  • se a hardware interrupt on the pin.

Because the time period between the pulses is long I’ve decided to go with an interrupt as this should be less resource intensive for the microcontroller. I don’t want to be reading the tach pin every half a millisecond!

I’ll let you know how I get on.