Saturday, February 11, 2012

Encoders - How do they work?

 I will explain the term Quadrature a little later. This is a type of Incremental encoder, so I should first talk a little about how incremental encoders work.

Most encoders are based on a wheel of some sort. It might be made of some opaque material with a series of holes around the edge, or perhaps some transparent material with a series of opaque regions separated by transparent regions. Or it might be a printed circuit board with specially shaped traces to provide several different channels of electrical contact.

As the wheel turns, some sort of sensor, optical or electrical, marks the presence or absence of signal, and converts that information to some usable form. What is happening is that a mechanical device is generating digital data, which can be processed to give us the information we want.

                                   http://frontrangerobotics.org/Jan05/EncoderForRMS.jpg

In this picture, we see a code wheel and an optical sensor. It can detect the presence of the opaque sections of the encoder wheel, or the "see-through" areas. Sensors like this are used a lot in printers, to signal the presence/absence of a sheet of paper. I'll be showing you later how I used some to build my own encoder! This is an example of an Incremental encoder.

                                            http://en.wikipedia.org/wiki/Rotary_encoder

In this picture, we see a 13 track Absolute encoder. There are 13 concentric tracks of conductive areas on a non-conducive disk. 13 small metal spring contacts will ride on each of those 13 rings
and generate electrically a binary bit. All 13 of those bits will be used to generate a binary number,
that corresponds to one and only one position on the wheel.  And notice that the tracks don't go all the way around. We don't WANT an absolute encoder disk to turn more than one revolution.


We connect that wheel in some manner to something we want to monitor, like a rotating wheel, or the stem of a valve. Now, in the case of the tank level gauge, we are converting the linear motion of the float, riding on the surface of the liquid, into a measurement of distance.

Our little encoder wheel is revolving, being driven by a gearing system tied to the float by a flexible metal tape. Is it a rotary encoder? Or a linear encoder? Note there is a distinction made between how the encoder works and what sort of measurement is being made.

Also, consider that the encoder used in this tank level gauge is Absolute...it generates a unique digital pattern for each position on the wheel. That should tell you that we have to scale one revolution of this encoder wheel to the entire length that the float can travel, because if the wheel turns more than 360 degrees, we'd be generating these unique codes twice. This is done mechanically, with gearing.   

Investigating Rotary Incremental Quadrature Encoders

My interest in encoders started when I noticed that the volume control knob on my home stereo receiver/amplifier was acting strangely.

After some years of trouble free operation, I noticed that when I turned it on, and discovered that "the kids" had cranked the volume up to an intolerable level before turning it off, my frantic attempts to spin the volume knob in the CCW direction to lower the volume had the effect of increasing it even more!

Some experimentation revealed that by turning the knob very slowly CCW, the volume could be lowered. Turning the knob in the CW direction did not exhibit this behavior--that worked normally.

I mentioned this to my Electrical Engineer friend Gus. He asked me "Is the knob the kind that turns endlessly in either direction?" I told him it was, and he guessed it was probably a "rotary quadrature encoder".

Now, in my years as an Instrumentation & Controls technician, I had some exposure to shaft encoders on large machinery. Most of the ones I had seen simply output a switch contact to signal that a shaft or gear was either turning or not turning. Only a few of the ones I'd seen actually sent a signal range indicating the speed, direction or amount of rotation.

And I'd seen a float type level gauge for above-ground petroleum storage tanks. I'm referring to the trusty Varec 2900 Automatic Tank Gauge, with optional 2900 Float Tape Transmitter.  This device has a metal tape connected to a float inside the tank, going up and over two pulleys, and back down the outside of the tank (inside a metal tube) to a "head unit", where there is a spring to keep the tape under tension, without lifting the float out of the liquid, or preventing it from following the liquid level as it moves up or down.

Inside the head unit is a mechanical system which uses the motion of the metal tape to operate a large display, much like the old mechanical odometers found in automobiles. This provides a local display for reading the tank level visually.

The optional Float Tape Transmitter contained a circular wheel, much like a printed circuit board, with concentric rings of conductive traces linked together. Electrical spring contacts (we called them fingers) would ride on these rings and send either a "continuity" or "non-continuity" (as the encoder wheel was turned by the mechanical gauge) to an electronic circuit board that would convert that information into an analog signal range of 4 to 20 milliamps  of DC current--4 for "tank empty" and 20 for "tank full", and all the levels between those two points.

That signal could then be sent far away to a control room, to drive a remote display indicating the tank level, and perhaps optionally sound an alarm if the tank got "too full" or "too low", or turn pumps on and off, to maintain some desired level. 

OK, back from memory lane. Let me continue with a discussion of some terms I discovered.

This term "quadrature" sparked my curiosity, so I started searching the internets for more information. The first thing I learned is there are different words to describe encoders: Linear, Rotary, Absolute, Incremental, and Quadrature.

Linear and Rotary describe the type of motion the encoder detects. A linear encoder might report on the movement of some machine part that only moves in a straight line--forward and backwards, like the print head of a printer. A print head moves back and forth across the paper, depositing drops of ink, and its position and speed must be controlled precisely. Rotary, as the name suggests, means that the encoder is detecting motion in something that...(you guessed it) rotates.

Absolute and Incremental describe the manner in which the encoder detects and reports on the motion being observed. The example I gave, of a float type tank level gauge, would be an "absolute" encoder.

That means that for each position detected, there is a unique combination of bits (remember the multiple fingers reading "on" and "off"? That's a group of bits that can be read as numbers.)

Incremental, on the other hand, means the encoder can only detect changes--a change in distance (linear) or angle (rotary) from the previous to the current position, or the speed (and perhaps direction) of movement (linear) or rotation. You wouldn't be able to tell the exact position from that information.  You wouldn't know "where you are" unless you knew "where you were" and "how far you went".

So, I learned that my malfunctioning volume knob is an example of a Rotary Incremental Quadrature Encoder.

In my next post, I'll try to explain in more detail how encoders are made, and how they work.