Encoder Basics: How to use quadrature encoders?

Rotary Encoder

Hi, there are many rotary encoder tutorials and guides available in the internet and even I have borrowed some pictures from them. I don’t know how you ended up here. Still somehow you have made it HOORAYYY!!!

First, I will briefly walk you through the idea of rotary encoders and will cut to the chase of the blog and explain the strategy I used with a quadrature encoder. Towards the end I will include some useful websites that can help you get even more idea on the topic. For some reasons, I am not sharing the code but I will make sure the explanation is good enough and if you really need the code, that too from me, you can always reach out.

In many industrial applications that use motion from motors or circular motions of any sort, the position, speed and direction data are very crucial. In my case I needed feedback from a PMSM for FOC control. The rotary encoders are actually the best choice out there in the market to get these data. Obviously, we know that this encoder has to generate an electric signal else how can we expect a controller to receive the information. So the definition that it converts rotational motion to electric signal is good enough only for the books.

The rotary encoder actually has a rotating disc or shaft to which some slots will be made or some magnets will be attached. And the slots can be detected using light as light can pass through the slots. But what about magnets? The magnetic one uses Hall Effect sensors to get the job done. To get a big picture rotary encoders are classified as shown:

Encoder Claasification

Absolute encoders provide a unique digital output for every position of the rotating shaft, allowing for precise control and positioning in applications such as motor control and robotic arms. Incremental encoders, on the other hand, provide a pulse output for every increment of rotation, allowing for the measurement of speed and distance.

In quadrature encoders, which is an incremental optic encoder, there will be two concentric circular array of slots. These channels are generally mentioned as A channel and B channel. The slots in A and B channel differs by a small angle such that the pulses generated by them will differ by electrical 90 degrees.

Optical Encoder

The encoder will be connected to shaft of the motor and inside the encoder the slotted disc will rotate. On the either sides of the disc a light source and a photodiode will be placed. Depending on the encoder as the disc rotates the light will fall on the photodiode whenever a slot comes across its way and generates a signal which can be high or low. And the output of the quadrature encoder in two channels will be as shown.

Encoder Output

Depending on the number of slots present in the disc the number of pulses produced per rotation will vary and determine the resolution. The resolution of a rotary encoder refers to the smallest increment of rotation that can be detected. This is typically measured in pulses per revolution (PPR) for incremental encoder.

For example an encoder with 360 PPR will mean 360 pulse in every rotation or 360 pulse in every 360 degree that is, for every 1 degree of rotation one channel will produce a pulse and the resolution is 1 degree.

But we have two channels that can produce pulses with phase difference of 90 degrees. Why should we have two channels? One straight answer is to get information about direction. If the direction of rotation is in clockwise direction, and the pulse generated by channel a will lead by 90 degrees then during anti-clockwise direction, the B channel will lead by 90 degrees. This lead or lag can be determined easily by monitoring the state of one channel when the other channel changes its state. We can even make use of flip-flop logic.

Is the whole purpose of the two channel to detect direction? What if we want to increase the resolution? Yeah! Go on increase the number of slots. But do you think the electronics inside, the diode and everything will able to detect such small slots? Wont the light creep out through the two closely placed slots? So there is a limit to increase the resolution by increasing the number of slots and maintain the accuracy at the same time.

As you have guessed by now, another use of second channel is to increase the resolution of the encoder. When a slot enters the sensors way, channel change the state from high to low or low to high and when the slot exits the channel state again flips. So by detecting the signals from two channels we can make a new signal which changes its state when the state of any one channel change. So we will be end up with a signal that more pulse per rotation.

So going back to the example with 360 PPR, with two channel we can make 4 x 360 = 1440 PPR. And we can measure 360/1440 = 0.25 degree. You can verify the math from the graph I have added earlier.

Now we can get data about speed and direction, then what about the position? For this we will have one more slot with which only one pulse is generated for one complete rotation. This channel is generally called Z channel or index channel. When this channel creates a pulse, we can assume angle zero or any other angle and start adding the pulses from other channels to get information about the current position. However, to get better results for position we can use an absolute encoder.

I will add a sample flow chart that I have used to monitor the speed.

Encoder_Flow_Chart

Friends you can always discover the wide range of applications for rotary encoders, from robotics and automation to medical equipment and industrial control systems through various sources. Also, do explore the latest advancements in rotary encoder technology, including customization options and new interface protocols and find out how rotary encoders can improve the precision and efficiency of your industrial applications. Try to stay up-to-date with the latest trends and developments in rotary encoder technology.

Have fun learning!

Other good articles on rotary encoder:

https://howtomechatronics.com/tutorials/arduino/rotary-encoder-works-use-arduino/

https://how2electronics.com/construction-working-rotary-encoder/

https://www.youtube.com/watch?v=v4BbSzJ-hz4