The engine on my boat didn't have any output from the lighting to drive a tachometer - the coil was open circuit. So the bog-standard ex-works gauge I installed didn't work either. Since I wanted to record rpm more than I wanted to see it displayed, this wasn't too much of a problem. The solution(s)?
Several turns of wire wrapped around an HT ignition lead and connected to the anode of an LED, the cathode connected to chassis ground (the exact number of turns required some experimentation). The LED was joined to a length of Toslink fibre optic with a receiver at the microcontroller end.
The Zener diode isn't strictly necessary but is included to try and protect the LED. When the zener diode is included, the direction of the turns around the HT lead does make a difference: one way it will work; the other way it won't. Only trial and error finds which way works.
The receiver circuit shown comes from the datasheet of the receiver (which is designed to receive Toslink connectors). The receiver is most sensitive to red light so a red LED was used. The fibre-optic is not affected by oil, petrol, etc., and acts as neither receiver nor transmitter of electrical noise; any generated by the windings round the HT lead has not been apparent as interference with radio, etc.,
The maximum rated rpm of the engine is 6,000. I used 7,200 rpm as a maximum, maximum, disaster top figure for a worked example, if only to see what sort of margin I had with the processor clock rate.
A two-stroke engine fires once per revolution per cylinder so for a single HT lead:
7,200 rpm = 7,200 / 60 pulses per second.
= 120 pulses per second.
Knowing the clock frequency of the Microcontroller and the number of pulses per second can be converted into the 'number of clock steps between pulses'. Rpm x number of clock-steps between pulses is a constant, working out at 1,200,000,000. Dividing 1,200,000,000 by the number of clock-steps between the rising edge of consecutive pulses gives the rpm.
Counting the pulses and converting them to a value was easy and could be reduced to fewer than the eleven lines I used...
Next, to generate a 'conventional' tachometer signal to drive the gauge....
A simple inverting amplifier built from components I had lying around was an easy way to allow a 12V pulse to be supplied to the tachometer gauge whenever a pulse was detected from the HT lead. I could have gone analogue all the way but liked having the option of playing with the characteristics of the pulse width should I need to.
Many, if not all, tachometers need 20 V+ to operate (the voltages that would typically be generated by the coils) but I was lucky and got away with it.