The digital RPM meter calculates Revolution of piston or flywheel. The technique behind this is CCP (Capture and Compare) and Pulse width.
This is give away of "MMD ramper" secrets ;-)
INPUT:
- All motorbike or Car engine is provided with fry-wheel with pulsar coil to activate spark plugs. these pulses can be taken for RPM reading.
- The spark plug sensor can also be applied, but the problem is unwanted high level spike and distortions, and also not that accurate as previous method
CCP:
This includes 3 modules in microcontrollers they are, Capture and compare/ PWM/PPM, we need only Capture and compare here.
Capture and compare the name itself says capturing pulse and comparing them, This module takes pulses as input. If one pulse occurs, the timer will starts for either rising edge of pulse or falling edge (whatever programmer specified) and waits for another pulse to occur, after second pulses specified edge it gives the timer outputs in form of bits ( say timer of 16 bits it gives output like 65535-lapsed bits). That means you got period (1/frequency) of pulse.
Conversion:
Got pulse frequency in bits form for calculations
Actual formula
f = clock(
32MHZ)/(8(
prescaler)*(65536-timer value))
My formula by trial and error:
countrevalue = (60000.0 / (0.008 * rpm_timer (
16bit timer value) ) ; // For 32 MHZ
- for RPM (For 4 stroke bike or 2 cylinder car) = countervalue*1.085;
- for RPM (For 4 cylinder car) = countervalue*0.5425;
RPM output will be in form of 1K RPM =
100 (10RPM), you can divide the value by 100 to get in form of 1s(1=1k)
Pulse:
I have differentiated pulse pattrns for motorbike and car,
- For motorbike
- 4 stroke: you will get 1 pulse per 2 rotation of fly-wheel
- 2 stroke: 1 pulse per 1 rotation
- But car having 2 to 4 pistons (cylinders),
- Car with 2 cylinders (cylinders) gives pulses same as 4 stroke motorbike.
- Car with 4 cylinders will give 2 pulses per 1 rotation.
Sensor circuit
The diode gets pulses from pulsar coil, and then that is fed to protection circuit. Because the input voltage may be in 10 to 18V dc, we need pulses in 5VDC for microcontroller TTL level. After transistor the pluse is inverted, so we have added schmitt trigger IC,
output graph
Red -Input say 24V
Orange - voltage at transistor base
Yellow - at transistor collector
Green - Output 5Vdc
Output
You can get output in forms of 7 segment, Alphanumeric LCD or even led graph.
My suggestion:
PIC18F26k22 (40 pin)
2 - 7 segment display (not multiplexed) with 13 LED bargraph.
RPM meter working video
Happy Programming,
Correct me if i'm wrong,
sources:
- http://www.microcontrollerboard.com/pic-timer1-tutorial.html
- http://www.mikroe.com/chapters/view/53/chapter-5-input-capture/
- http://www.mikroe.com/chapters/view/6/chapter-5-ccp-modules/