Rotary Encoder Module interfacing with pic16f877a microcontroller




Rotary Encoder Module in  interfacing with pic16F877A microcontrollerIn this tutorial, I will show you how to interface rotary encoder with pic microcontroller. How to use rotator encoder for measurement of shaft rotation and position. What is rotary encoder and how rotary encoder works? How to interface it with PIC16F877A microcontroller? How to count each tick of rotary encoder with pic microcontroller and display it on 16X2 liquid Crystal display.  So let’s start with the introduction of rotary encoder.Rotary Encoder Module interfacing with pic16f877a microcontroller




I have already posted a article of rotatory encoder interfacing with Arduino and stepper motor control you may also like to read it:

What is Rotary Encoder Module?

Rotary encoder is a such type of encoder which is used for measuring the angular position of any rotating shaft and then it generates the electrical signal according to shaft the movement. This electrical signal could be in the form of pulses or analog, depends upon the type of encoder. These encoders are also known as shaft encoder and by using these encoders the user can easily defined the angular position, speed, linear displacement and direction of rotation of any shaft or any moving object. A Simple rotary encoder module is shown is figure 1Rotary Encoder Module

Figure 1 A Simple Rotary Encoder




Pin Configuration of Rotary Encoder Module

 Rotary encoder module consists of five pins such as CLK, DT, SW, + and GND shown in figure 2. According to the figure 2, for check the normal working of rotary encoder GND pin is connected to ground and positive voltages are applied at + pin. These voltages should be with in the rage of 3.3 volts to 5 volts for normal working of this encoder. Similarly, two light emitting diodes (LEDs) are connected at pins CLK and DT with the help of two 220 ohms resistor which are connected in series with these light emitting diodes. Clk and DT pins produce square waves which are 90 degree out of phase with each other and these two square waves are used to measure clock wise and anti clock wise rotation of shaftRotary Encoder pin configuration

Figure 2 Pins Configuration of Rotary Encoder Module

Types with Working of Rotary Encoder: Normally two types of encoders are currently used in market first one is magnetic encoder and second one is optical encoder. These are further divided into two types first one is absolute and second one incremental encoder. If we talk about magnet encoder, then it consists of a rotating disk and proximity sensor. The rotating disk consists of teethes when these teethes move then proximity sensor senses the movement of these teethes and then produces the pulses according to this movement. This encoder is quite simple as compared to incremental encoder. Similarly, if we talk about optical encoder then it consists of IR LED, photo transistor and rotating disk which consists of transparent segments. When IR LED emits the lights then this light pass through transparent segment of rotating disk then this light is received by photo transistor.

For further understanding we have divided the disk into two segments such as conductive and non conductive segment. Dark segment is the conductive segment and white segments is the nonconductive segment. A and B are two outputs of this rotary encoder shown in figure 3Rotary Encoder working

Figure 3 Rotary Encoder Disk Segments

Dark or conductive segment is directly connected with positive + 5 volts, similarly when the disk moves in clock wise direction then dark segment directly coupled with output point A then +5 volts are received at point A. After that, when this segment has passed then white segment directly coupled with point A then zero volts are received at point A.  Similarly, square wave pulses are received at output point A. So, the same waves are received at output point B. If the LEDs are connected at these output, then it would be turned on and off after some time. Signal output format of rotary encoder

How to Interface Rotary Encoder with PIC16F877A Microcontroller

As we have discussed in above paragraph the rotary encoder is connected according to its pin configuration. Because it consists of two outputs therefore these outputs are connected to any digital input of ports of pic16f877a microcontroller. Microcontroller is programmed in c language with help of mikro/c software and is also powered up with 5 volts dc. When the rotary encoder disk moves in any direction with the rotating shaft of any motor or any object then the voltages are generated in the form of pulses. These pulses are observed by the microcontroller so intelligently and then count these pulses with so efficiently. LCD display could be also interfaced with microcontroller.

If LCD display is interface with microcontroller then this controller easily displayed the direction of rotation and revolution per minute (RPM) of rotating shaft as well as with angle of rotations. Similarly, if this rotary encoder interface with pic microcontroller is used with any conveyor built at which objects are moved then this pic microcontroller interface with rotary encoder module can also tells displacement of the object form its original point.

In this tutorial, we have use PIC16F877A microcontroller, output pins of rotatory encoder module is connected with PORTB pin number 4 and 5. These pins 4 and 5 are configured as input pins.  Interrupt is used to detect whenever rotary encoder rotates in a specific direction.  LCD is connected with PORT D of pic16F877A microcontroller to display the counts. Video below shows the complete demonstration of this project.




Add Comment