Better Edge Determination for Rotary Encoders.

A standard edge sensing scheme for optical rotary encoders is to square up the raw analog sine wave by comparing it against a given voltage. If your analog signal has a 2Vpp amplitude, the value at which you switch off of, creating the edges of your square waves, could be around one Volt. This would put the determination point right in the middle of the analog signal and provide symmetrical high and low pulse times.
An example of this can be seen below. The Blue sin wave is the raw analog signal from the sensor, the red line is the DC voltage which it is compared against. You can see at that the crossing points of the red and blue lines are the points at which the edges of the square waves are determined. The Magenta waveform is the digital output of the optical encoder.

But what happens if the analog signal amplitude changes? Raw signal amplitude does vary over time, temperature, and rotational speed. Below is an example of the raw analog amplitude of a signal changing to twice the normal value.
Note that the frequency of the signal hasn’t changed. Frequency is determined by the optical encoders rotation speed.

We see that the Red line is at the same voltage level, which it would be, as a resistor divider, or Zener diode often sets this value, but the edge determination points have changed as the red line is now cutting though the sine wave at a position that is lower relative to the rest of the waveform. As you can see by the magenta digital output, this creates asymmetric high and low pulse times.
This is real positional error that will vary with time, temperature, and speed.
Quantum Devices Inc. patented sensing technology combats this by using two sets of analog signals for each channel and comparing them against each other.

Instead of using a fixed Voltage as the comparing signal, a complementary sine wave is used. The QDI interlaced sensor provides another sine wave that is a perfect match and exactly 180 degrees out of phase with the original. This complementary signal is shown in Red. The standard analog signal as shown in Blue.

When we look at a doubling in amplitude under this scenario, the advantage of making edge-determining decisions at the crossing points of the signal becomes clear. Not matter how much the amplitude changes, the complementary signal changes to match, maintaining perfect symmetry of the encoder signal.
E-mail on Creating a Post Quad Encoder signal
Below is an e-mail response I sent to someone who was asking about how to calculate the sampling rate they needed to 4X encoder signals. 4Xing or “Post Quad” is a way to use the fundamental A and B encoder pulses to get a higher line count.
I wasn’t sure if he was under the assumption that by sampling at a 4X rate he could essentially get 4X the signal, so I felt a long winded reply was needed.
The blue bulleted lines are his original questions.
Hi Stan,
I didn’t see it in this e-mail train, but I understand that your are looking to get 80,000 counts from the 20,000 line count encoder.
Here is my take on your questions which I have highlighted in Blue:
- One rotation per second would give me 20KHz from each phase (A&B)
This is correct.
- In a perfect world, I would need to sample the phases at 4 times this rate
- But there is a 10% tolerance on phase to phase, so I need to increase this rate by a factor of 1/.9 or a total 4.4 times the phase frequency
You must be going after the 2X rule as it applies to anti-aliasing, then since there are two channels multiplying that by two. Then I see that you are also adjusting for phase shift.
Your math appears to be right on track, but I am going to go into detail here with some pictures as it is easier for me to communicate my meaning this way. Besides, I was in AutoCad anyway…..
Below is a pictorial representation of sampling at 4X the fundamental frequency of A (or B) . The blue lines are sampling points and the red square waves are the A&B waveforms. The thickness of the blue line may not be appropriate as sampling will take a certain amount of time, so the lines could potentially be thicker, but the idea will be the same.
The points at which the blue lines cross the red square waves will define the high and low points, In the photo below they are circled.

Removing the Blue and Red lines indicates the data points as seen by the computer/sampling device.

Then connecting the dots….

We see that this sampling rate essentially correctly “maps” the waveform, introducing some phase shift error. Depending on where sampling occurs this error may be as high as just under 90 electrical degrees, but does not directly give you 4X the frequency.
You may already be aware of all of this and are just asking “How low of a sampling frequency can I get away with ?” My answer would be 4X will be more than enough, as 2X the Max freq. on each channel is all that is really necessary. Even the extra amount you added for phase shift may not be necessary, as any phase shift does not change the underlying frequency.
I just wanted to make sure that it was clear that sampling at 4X the rate is not the same as 4Xing the signal.
In practice 4Xing the fundamental signal is usually done by applying some sort of one shot or monostable circuits that are triggered off of the rising and falling edges on both channel A and Channel B, then using an AND logic gate to combine the two into one signal.
The duration of this pulse will be constant regardless of speed, as it is programmed into the one shot, but the “low time” between pulses will vary with rotational speed.
This is the hardware way to do it, it and sounds like you may be approaching it via software.
Let me know if you have any other questions,
Jim
How an absolute encoder works – Binary

Quantum Devices offers an 8 bit absolute encoder. Unlike incremental encoders that output a train of serial pulses, an absolute encoder provides a parallel data output as wide as the number of bits.
A QD-787 8 bit absolute encoder has eight data lines. Each data line has a different binary “weight” allowing us to define 256 unique positions in rotation.
Below is a map of the binary pulse train coming out of each data line over one full rotation on a single turn absolute encoder.

The numbers on the left hand side of the signals indicate the value or weight that particular data line carries. Off to the right we see LSB and MSB, which stand for “Least Significant Bit,” and “Most Significant Bit”. If the data line is low that bit is counted as a zero. If the data line is high the bit is counted as a one.
Electrically this means that the wire or pin that corresponds to that bit will be at zero volts when low and at five volts when high.
Lets take a look at the first three bits to see how this works:
The Blue line represents the real world position of the encoder. We will move the line to the right over the next few illustrations to represents encoder rotation.
I am starting at the zero position for ease of explanation. In reality, the position at which any encoder would “wake up” is arbitrary. This is in fact the main benefit of an absolute encoder. If encoder power is lost, position information is retained, and known instantly on power up.
At the start all of the data lines are low giving us a value of zero for each bit.
You can see by the math that we multiply the value of the data line by it’s weight, or significance.
As we rotate the first 1/256th of the way around, our encoder see’s the LSB go high giving us a “one” for the first bit.
Rotating another 1/256th of the way causes the first bit to fall low and the second bit to go high. Notice that as we progress through the significance of bits each bit carries twice the weight of the one before it.
Turning yet another 1/256th of the way around we see the first bit again goes high, but the second bit stays high as well. We add the value of the two data lines together to get a number that is meaningful to us. “3″ is more universally understood than a binary “110″.
As we rotate, our encoder continues to count. This time the first two bits turn off and the third bit valued at “four” turns on.
We are a little over 7 degrees into our rotation and the encoder is at a count of five. Each count represents 1.40625 degrees (360 degrees/256 counts) .

Rotating 8.4375 degrees in is a binary 011, or a value of Six.
In the final position of our three bit example, all bits are high giving us a value of seven. In an eight bit encoder this 0 through 7 bit pattern repeats 45 times for these three bits over one rotation.
Absolute encoders are specified by the number of bits, the direction in which their count increments or decrements and the output bit pattern. Here we have covered Binary, but Absolute encoders can also output gray code.
Gray code is a binary like pattern that only allows one bit to change at a time. This makes it easier to check for errors in the count. It is a large enough topic that I will table it for discussion in a future post.
Reduce electrical noise in rotary incremental encoders with termination resistors

Since most electronics are set up to have high input impedance, in some situations the addition of a loading or “termination” resistor can help to reduce interference from electrical noise.
This can be of particular help when implementing an incremental encoder where there is a long cable run. If the input impedance of the receiving device (often a controller or drive) is high, the current through the cable is very small. The addition of a termination resistor where the encoder is connected to the controller/drive increases the current flowing through the cable. This increased signal current is less susceptible to interference of any electrical noise that may be coupled into the cable.
The termination resistor is placed in parallel with the output in a single ended set up; this connection is from the encoder channel to signal ground. In a differential setup this connection is between the channel and it’s complement (A and A-, B and B-, etc.).
Values of termination resistors depend on the current capability ability of the encoder. Our standard incremental encoders can deliver up to 20 mA per channel, which at 5VDC means a maximum total termination load of 100 ohms.
When troubleshooting a noise burdened application we tell our customers to start with a value of around 1K ohm and go from there. Many times 1K is more than enough resistance to solve a noise interference issue.
I would also like to point out that this type of termination loading should be done on each channel as each channel is a separate circuit.
It is also good to keep in mind that low value termination resistors may attenuate the amplitude of the incremental encoder output signals and that too low of a value could damage an incremental encoder.
The 100 Ohm value spoke of above works for Quantum Devices rotary incremental encoders. Other encoders may not have the ability to deliver current into such heavy loads.
Below is a pictorial example of how to add termination resistors to an incremental encoder that is set up Single ended (TTL).

Below is an example of termination resistors wired into an Incremental Encoder that is set up differentially (RS-422)

Interlaced Sensor Technology in Rotary Incremental Encoders.

.
If you search the web for a rotary encoder tutorial on incremental encoder construction, the simplest two channel A & B style encoders talk about a light source and a single photo receptive element for each channel. The light beam of this optical pair is then interrupted by the rotating optical encoder disk. The light shuttering from the disk occurs over rotation, alternately illuminating and darkening the single element sensor.
The photo sensor turns the intermittent light beam into low level electrical signals which are strengthened and squared up with some type of comparator circuit. This creates the rotary encoder output pulses.
There are a few weaknesses in this basic design for example, what if the light source strength changes? This can happen over time and with increased or decreased temperature. A varying light source means that the signal out of the sensor will vary and possibly effect the decision point at which the rotary encoder channel is driven high or low. This variation in decision point results in real positional error and needs to be avoided. In order to combat this a differential sensor circuit is used.
In a differential circuit two sensors are placed so they are 180 electrical degrees out of phase. What this means in simple terms is that when one is “on” or illuminated by the light source, the other sensor is in the shadow or “off”. By maintaining the relationship between these two sensing elements, the ambiguity of a varying light source can be common mode errored out. The light level is no longer important, but instead the relative relationship between these two equal and opposite sensors is now what matters.
There is, however, still a weakness with this set up. As we increase the line count of the encoder, the geometry of the disk and sensor elements becomes very small. This opens up concerns for anything that may occlude the disk, such as debris or other contamination.
A way to handle this is by breaking up the individual differential sensor elements into several interlaced sensor elements over an array. Instead of a single element and it’s complement, there are many elements and again as many complementary elements that are alternately positioned on the sensor. As the optical encoder disk rotates, multiple window openings align with the elements illuminating them and darkening multiple complementary elements at the same time. The signals from all of these elements are summed together. The complements are compared against the fundamental elements to determine a switching point.
The advantage to this set up is that the sensor becomes spread out over a wider area along the disk and needs multiple disk segments to activate it. This makes the reliance on any one individual disk or sensor segment less crucial to the overall signal integrity. If there is any debris that makes its way onto the disk, or even creates total blockage of one or two sensor segments the output signal will not be effected.
The shadow technology sensing scheme patented by Quantum Devices Incorporated also corrects for disk centering problems such as disk eccentricity and disk wobble, where the movement and alignment of the disk varies in three dimensions, and normally creates variations in signal amplitude and ultimately output signal.
For more information on interlaced sensing technology and how it is used to improve optical rotary encoder performance, check out the document titled Optical error components and their effect on signal quality.
.
.
Quantum Devices Inc. is a leading manufacturer of Rotary Incremental Encoders. They can assist in encoder selection and can be reached at (608) 924-3000 or via E-mail
The robust QD-H20 IP-66 Industrial Rotary Encoder

.
The QD-H20 is an idea replacement encoder for size 20 and size 25 industrial applications. It is an IP-66 sealed rotary incremental encoder. This high IP rating provides outstanding environmental protection with all of the line count and output options of the QD-145 incremental encoder.
The QDH20 style Industrial Rotary Encoder is typically used in applications such as Machine Control, Process Control, Elevator Controls, Agricultural Machinery, Textile Equipment, Robotics, Food processing, Conveyors, Material Handling, as well as, any application where water/contaminant ingress or durability is a concern.
The QD-H20 Incremental Encoder has three styles of MS connectors, 6,7, and 10 pin, along with a flying lead option, and the ability to come with custom cable lengths. Each connector option is possible in radial and axial configurations.
The QD-H20 Rotary Encoder boasts a wide –20 to 100 Deg. C temperature range and a 500kHz frequency response. Multiple shaft sizes ranging from .250” to .650” in both hollow and solid shaft are available.
The rugged dual bearing set allows the QD-H20 industrial rotary encoder to handle overhung loads, such as direct mount pulleys, with side load forces as high as 40 pounds nominally and 80 pounds maximum.
More information can be found at the Quantum Devices main site at http://www.quantumdev.com/products/optical_encoders/qdh20.html
A PDF of the QD-H20 encoder specifications can be downloaded directly at http://www.quantumdev.com/pdf/qdh20.pdf
Quantum Devices Inc. is a leading manufacturer of Rotary incremental encoders. They can assist in encoder selection and can be reached at (608) 924-3000 or via E-mail
.
.
Choosing the resolution of a rotary incrementnal encoder
.
“What resolution of rotary encoder do I need?” is a question designers often ask themselves. A common mistake is that a higher resolution is always better. This may or may not be the case. Ultimately it is the nature of the application that decides.
Here are some things to take into consideration.
Cost
Higher line count encoders typically cost more. Higher line counts require tighter disk to sensor alignment and air gapping, as well as, improvements in the light source and the associated electronics. All of these factor in to an increase in cost as resolution increases.
Frequency Limit & RPM
It is important to note that interface electronics have a maximum input frequency that will cap the speed of the encoder. You would like to use a 5000 line count encoder in a 6000 RPM application, but if the encoder or the interface electronics is limited to 200 kHz, you can’t as this combination of RPM and resolution is putting out 500kHz.
Quantum Devices has a standard frequency response of 500kHz over most of their rotary encoder line.
How does the math work out?
Sometimes it is more important for a programmer to be able to make their math work cleanly than possibly introducing rounding errors that could compound over time. A 360 line count works nicely as one pulse equals one degree. A 3600 line count rotary encoder is popular for this same reason.
Does the performance of my application actually benefit from a higher line count?
Higher line count rotary encoders allow a drive or controller to make faster and more accurate decisions with regard to speed regulation, but much of that is application dependent. For applications that are running with a large inertial load, the added information from a higher line count may not improve the systems performance as there is only so much any motor can do to overcome the mass of the load. Higher resolution may add information that can aid in the electronic decision making, but the system may not be able to respond any better than with a lower line count device.
A crude analogy and the reason for the photo at the top:
A race car driver can certainly out-drive my elderly grandmother when it comes to auto racing, but I bet they are both on even ground with a lawn tractor. The race car driver has a much faster reaction time than my grandmother, but the lawn tractor cannot benefit from this, so the race car driver would be overkill for this application.
You can also see how my grandmother behind the wheel of a race car would limit the performance of the vehicle, much in the way that too low of resolution on a rotary encoder can limit speed regulation, acceleration/deceleration profiles and the precision to which a system can position.
Choosing the resolution that best suits your application is a careful balance between Cost, Frequency limitations, Math, and application limitations.
Quantum Devices Inc. is a leading manufacturer of Rotary incremental encoders. They can assist in encoder slection and can be reached at (608) 924-3000 or via E-mail
The HR-12 HEDS replacement optical encoder
.

.
HEDS style encoders have long been a popular choice for an enclosed low line count positional feedback device. The packaging allows for added enclosure protection in a lighter duty encoder. This type of product is often seen in applications such as vending machines, printers, plotters, positioning tables, etc.
The Quantum Devices Inc. HR-12 optical encoder picks up where traditional HEDS replacements leave off, offering line counts of up to 20,000 PPR, (80,000 Post Quad), high temperature range, and commutation (Hall) options. Besides providing all of these extended options, the HR-12 optical encoder also boasts a 500kHz frequency response.
This device can be mounted on multiple bolt circles, and accepts varying shaft sizes up to 10mm.
The HR-12 includes an internal bearing set that eliminates the need for the mounting shaft to hold tight TIR and Axial tolerances.
Installation of the HR-12 encoder can be seen below.

For more information on the advantages of the HR-12 encoder check the Quantum Devices Inc. main web site at http://www.quantumdev.com/products/optical_encoders/hr12.html
.
.
What is Hysteresis and how is it used in optical encoders?

Here are a few definitions of the word “hysteresis” I found online:
From Sensorland.com
Hysteresis – Non-uniqueness in the relationship between two variables as a parameter increases or decreases. Also called deadband, or that portion of a system’s response where a change in input does not produce a change in output.
.
From Wikipedia
A system with hysteresis can be summarized as a system that may be in any number of states, independent of the inputs to the system. To be exact, a system with hysteresis exhibits path-dependence, or “rate-independent memory”[citation needed]. By contrast, consider a deterministic system with classical dynamics but no Hysteresis. In that case, one can predict the output of the system at some instant in time, given only the input to the system at that instant. If the system has hysteresis, then this is not the case; one cannot predict the output without looking at the history of the input, i.e., the state of the system for a given input. In order to predict the output, one must look at the path that the output followed before it reached its current value.
Here is my spin on hysteresis:
The place where we can most relate to hysteresis is in our home. Furnaces and air conditioning systems use hysteresis to help buffer the set point at which they turn on and off. If you can imagine having a temperature set point of exactly 70 degrees, the moment the temperature dropped to 69.9 degrees the furnace would come on. If it rose to 70.1 degrees, the AC would come on. You can see how this could result in frequent cycling of the equipment in our home.
In order to reduce this, hysteresis is used to buffer the area around our set point. In HVAC equipment it is often called “temperature swing”. For example at my house I have a 3 degree swing set up in my programmable thermostat. This means that at a setpoint of 70 degrees, my furnace doesn’t come back on until it reaches 67 degrees. I could tighten this up to say a one degree swing, but it costs a bit more to heat that way.
For me, it is a careful balance between saving money and keeping my girlfriend from complaining about how cold it is.
.
How it relates to Optical Encoders:
In optical encoders hysteresis is used to buffer the analog signal coming from the sensor before a switching decision is made. This is particularly needed when rotary encoders are turning very slowly. As the decision point slowly approaches any variation in signal amplitude due to noise could cause the digital output to quickly switch on and off this would be seen as several quick pulses at the leading and trailing edges of the digital square waves often referred to as “chattering”.
Below is a picture of how too little hysteresis may affect encoder signals. Particularly in a system with electrical noise.

Below is a representation of the analog signal (shown in red) of an encoder as it crosses the decision point (blue line). The output is the black digital signal.

This is what we would expect, and get, in a perfect electrical world. In the real world we have to deal with issues such as electrical noise.
The image below shows how electrical noise introduced in a system can cause extra pulse or “chattering. The noise is shown as a voltage anomaly on the red analog line causing multiple crossing points along the blue decision line, resulting in extraneous pulses at the edge of our digital signal.

In the next image we see how the addition of hysteresis affects the digital output signal. The cyan line represents the delay is decision point or “deadband” that is created by the addition of hysterysis. The digital signal switches high with the original red analog signal, but doesn’t switch off again until the cyan hysteresis line crosses the blue decision point.
The new hysteresis filtered digital output is shown in magenta with the original unfiltered digital output shown in black.

One would tend to think that the more Hysteresis you add, the better as it adds more noise immunity to the system. This is true, but the other side of adding Hysteresis is that it results in positional error.
Since we are essentially delaying the point at which the digital decision is made, we are delaying the point in rotation before the signal is switched on.
In the image above when comparing the black digital signal to the magenta one we notice how the switch off point has been delayed in time. This is real system error that is the cost of hysteresis.
We can compare this to a HVAC system in that additional hysteresis around the temperature set point makes it easier for the system to withstand thermal “noise”, such as a quick temperature variation from opening a door, but ultimately keeps the system from tightly regulating to a temperature set point.
Encoder manufacturers always have to carefully balance the amount of hysteresis they add against the error introduced in the system from it.
The way that Quantum Devices fights this is through the use of their interlaced sensor, and use of differential signals to determine switching points. The interlaced sensor provides a large amplitude signal when compared to typical noise introduced into a system, so that minimum hysteresis is needed when making the switching decisions.
.
Hysteresis in Magnetism
Here are some links to some information on the origin of the word hysteresis and how it relates to magnetism.
Magnetic hysterysis in the iron core or “stack” of electric motors is what is responsible for a significant portion of heat build up.
The last link is particularly interesting as it talks about how hysterysis curves in magnetic materials may not be smooth.
http://www.lassp.cornell.edu/sethna/hysteresis/WhatIsHysteresis.html
http://hyperphysics.phy-astr.gsu.edu/Hbase/solids/hyst.html
http://www.lassp.cornell.edu/sethna/hysteresis/hysteresis.html
.
.
Quantum Devices Inc. is a leading manufacturer of optical rotary encoders their main website is at www.quantumdev.com They can be contacted via e-mail at info@quantumdev.com.
.
.

The
The amplitude has been reduced by about 40% using our light source graph from above, we see that this indicates a temperature change equivalent to going from about room temperature to 100 Deg C.


