contactless tachometer circuit with code

Contactless tachometer using pic microcontrollerContactless digital tachometer project is designed to measure speed of dc motor using PIC18F46K22 microcontroller. As we already posted an articles on how to control speed of dc motor using pic microcontroller. But to measure speed of dc motor, we have to measure motors revolutions per minutes. There are many digital tachometers available in market. But all these tachometers are not contactless. By contactless means, they have physical contact with motor. But in this project, we have designed a tachometer which has no physical contact with motor.

So let’s start with definition of tachometer. Tachometer is an electrical device which is used to measure speed of rotating machines with the help of analog or digital electronics. But digital electronics is more popular. Digital displays are among the most widely used displays for displaying different parameters. So we will be using digital liquid crystal display to show speed measured by digital tachometer.




Contactless tachometer main components

Followings are the major components of contactless digital tachometer using pic microcontroller:

LCD: Liquid crystal display is used to display speed measured by tachometer. So if you want to make this project. You should know how to interface LCD with pic microcontroller.

PIC18F46K22 microcontroller: This microcontroller is a heart of this project which performs all calculations to measure speed and display measured on LCD. It is also used to drive dc motor by applying Pulse width modulation to transistor which is used to as a switch and it is used to drive dc motor.we have used external oscillator with pic microcontroller.

Optical infrared sensor: optical infrared sensor is used as a contactless sensor used in this digital tachometer. Infrared light emitter diode emits the infrared light and photo diode absorbs infrared light. So in this project Infrared light emitted by infrared light emitter diode and photo diode is used a optical sensor to measure speed. I will explain its working in later of this article.




Contactless tachometer block diagram

Block diagram of contactless digital tachometer is shown below. All the components used in this dc motor speed measurement are explained above.

contactless digital tachometer circuit diagram

Contactless tachometer working

As I discussed earlier there is no physical contact between in and optical sensor. Optical sensor consists of infrared light emitting diode and photo diode. As shown in figure below, both diodes are in front each other. When light emitted by infrared light emitting diode falls on photo diode, output of optical sensor remains zero. But when no light falls on photo diode, output of optical sensor becomes high. So we contact a piece of black small paper with motor shaft. When this paper comes between infrared light emitting diode and photo diode, output become high otherwise output remains zero. So we will get pulse on every revolution of motor.

dc-motor-with-encoder

As shown in above diagram whenever black piece of paper comes between photo diode and infrared diode, no light falls on photo diode and we get high pulse at the output of optical sensor otherwise output remains zero. so we get pulse once per revolution of motor.

so we need to measure these pulses to measure speed of dc motor or any rotating machine. To measure pulses we have used timer zero of pic18f46k22 microcontroller as a counter. when we use timer as a counter, counter increment on very positive or negative edge of pulse. we can configure it in any direction. For example we are using counter to increment on positive edge. So we will get one positive edge once per revolution of dc motor. So the number of times counter counts in one second is equal to speed of dc motor in revolution per second. We can convert it into minutes by multiplying it with 60. So this is a easy way to design contactless tachometer using pic microcontroller.

How to use timer as a counter to measure speed

we are using PIC18F46K22 microcontroller. It has four timers but we are using timer zero as a counter. To use timer as a counter, we have to adjust following bits of timer zero control register.

timer as a counter

All the bits of timer zero control register are clear. But to use it as counter T0CS set equal to one.

if T0cs = 0  // timer will be used as a timer

if  T0cs= 1 // timer will be used as a counter.

Rest of the things are explained very well in above picture. Circuit diagram of digital contactless tachometer is given below.

Video lecture contactless digital tachometer

Contactless tachometer circuit diagram

Speed measurement circuit is given below. output of optical sensor is connected with RA4/T0CLK pin which is input of timer zero when it is used as a counter. Pulse width modulation is used to change speed of dc motor. So we are using CCP1 module of PIC microcontroller. For simulation purpose we are using pulse generator in Proteus instead of actual circuit. Rest of the circuit is self explanatory.

contactless tachometer using pic microcontroller

Digital contactless tachometer code

 unsigned long speed;
 sbit LCD_RS at RD0_bit;
 sbit LCD_EN at RD1_bit;
 sbit LCD_D4 at RD2_bit;
 sbit LCD_D5 at RD3_bit;
 sbit LCD_D6 at RD4_bit;
 sbit LCD_D7 at RD5_bit;
 sbit LCD_RS_Direction at TRISD0_bit;
 sbit LCD_EN_Direction at TRISD1_bit;
 sbit LCD_D4_Direction at TRISD2_bit;
 sbit LCD_D5_Direction at TRISD3_bit;
 sbit LCD_D6_Direction at TRISD4_bit;
 sbit LCD_D7_Direction at TRISD5_bit;
 char text2[] = "digital tachometerTachometer";
 char text1[12];
 void main() {
 
 ANSELD=0x00;
 ANSELA=0X00;
 TRISD = 0x00;
 PORTA=0x00;
 TRISA = 0b00010000;
 T0CON = 0b00101000; // TMR0 as 16-bit counter
 Lcd_Init(); // Initialize LCD
 Lcd_Cmd(_LCD_CLEAR); // CLEAR display
 Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
 Lcd_Out(1,4,text2); // Write message1 in 1st row
 do {
 T0CON.TMR0ON = 1;
 TMR0L = 0;
 TMR0H = 0;
 Delay_ms(1000); // Wait for 1 sec
 T0CON.TMR0ON = 0; // Stop the timer
 speed = (256*TMR0H + TMR0L)*60;
 inttostr(speed,text1);
 lcd_out(2,1,text1);
 } while(1); // Infinite Loop
 }

if you have any issue after reading this article, let me know with your comments

One Response

  1. Komal November 13, 2016

Add Comment

Subscribe to our blog to get updates in your email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 901 other subscribers