Tachometer is a device that measures the rotational speed of any shaft or disc. The unit of the measurement is usually revolutions per minute or RPM. The traditional method of measuring RPM of a rotating shaft was based on velocity feedback concept where a dc generator is hooked to the rotating shaft so that the voltage induced across the generator’s terminals is proportional to the speed of the shaft. Today, we are going to make a digital tachometer based on a PIC microcontroller that requires no physical contact with the rotating shaft to measure its rotational speed. The physical contact is avoided by using an optical detection technique that requires an infrared light emitting diode in conjunction with a photo detecting diode. StartUSB for PIC from mikroElektronika is the main controller board used in this project. To read more about this board, visit my article Getting started with PIC18F Microcontrollers. This tachometer can measure speeds up to 99960 RPM with the resolution of 60 RPM. The result is shown on a 16×2 character LCD display.
The contact with the rotating shaft is avoided with an optical sensing mechanism that uses an infrared (IR) light emitting diode and a photo detecting diode. The IR LED transmits an infrared light towards the rotating disc and the photo detecting diode receives the reflected light beam. This special arrangement of sensors is placed at about an inch away and facing towards the rotating disc. If the surface of the disc is rough and dark, the reflected IR light will be negligible. A tiny piece of white paper glued to the rotating disc is just enough to reflect the incident IR light when it passes in front of the sensor, which happens once per rotation (shown below).
If the entire disc surface is bright and reflective, use a piece of black paper instead so that the IR light will be absorbed by this portion once per rotation. In either case, a pulse will be generated at the output of the signal conditioning circuit for each complete rotation of the disc. The circuit diagram for the sensor part is shown below.
When the IR Tx pin is pulled high, the BC547 transistor (NPN) conducts and infrared light is transmitted. This is controlled through RA3 pin of PIC18F255o, and is turned on for 1 sec during which the number of reflected pulses received by the photo detecting diode are counted. The pulses appears at the collector of the BC557 transistor (PNP) goes to RA4/T0CKI pin of PIC18F2550. It is the external input pin for Timer0 module which counts the external pulses arriving at this pin. Under normal condition, the resistance of photo detecting diode is very high and therefore, the BC557 transistor is almost cut-off. The output at its collector is pulled to ground. When the photo detecting diode receives the reflected IR light, it’s resistance drops and BC557 conducts, and the collector output goes high. Thus, this simple circuit converts the reflected IR light from the white mark on the rotating disc into a pulse.
Timer0 Module in PIC18F2550
The Timer0 module in PIC16F series is 8-bit but in case of PIC18F2550, it is software selectable for 8- or 16-bit mode. Its operation is controlled by T0CON register; the function of each bit in the T0CON register is shown below.
For our purpose, the Timer0 module will be configured as a 16-bit counter to count the number of pulses arriving at RA4/T0CKI input pin. The counter will be active for 1 sec and the number of pulses arrived during this interval will be recorded, and later multiplied by 60 to get the RPM of the disc. Without an overflow, the Timer0 in 16-bit mode can count up to 65535, that corresponds to 3932100 RPM. However, in this project, we will limit the range up to 99960 RPM. To serve our need, we will clear T08BIT (16-bit mode) and T0SE (increment on high-to-low transition on T0CKI pin) bits, and set T0CS (counter mode) and PSA (no prescaler) bits.
As I mentioned earlier, I am using StartUSB for PIC board for demonstration of this technique, and therefore, I am not providing the detail circuit diagram of this project. Rather, I will be showing the connections of LCD and the sensor unit (described above) to the board, as shown below. LCD data bits D4-D7 (11-14) are driven through RB4-RB7 pins, whereas the control pins, RS (4) and E (6) are connected to RC6 and RC7 pins of PIC18F2550. The transmission of infrared light is controlled by RA3 pin, whereas the reflected pulses are fed to the T0CKI pin. The microcontroller runs at 48.0 MHz using its internal PLL. The circuit diagram for the board itself can be found here.
As usual, I used my favorite mikroC compiler from mikroElektronika for programming the PIC. No external programmer is required with StartUSB board as the on-board PIC has pre-programmed with mikroElektronika’s fast USB bootloader. Those who are not familiar with StartUSB for PIC board, read my previous article Getting started with PIC18F Microcontrollers. The programming part is not very tough for this. It involves the initialization of I/O ports and Timer0 control register. The LCD interfacing part uses mikroC’s built-in LCD library functions, read my article ‘How to interface a character LCD with PIC‘ if you are new to this.
Once the program is loaded into the microcontroller, reset the StartUSB board and wait for 5 sec till it comes out of bootloader mode and starts running the application for your contact-less tachometer.
A digital tachometer based on an infrared light reflection technique has been demonstrated successfully. Its major advantage is that it doesn’t require any physical contact with the rotating shaft to measure its speed. This project can be extended further by adding data logging feature to it. This is required in certain applications where the RPM of a rotating shaft is needed to be monitored. The data logger will keep the records of varying RPM over time, and those records can be later transferred to a PC through the USB interface.