How to calculate pulses per degree for an incremental encoder

When using an Incremental Encoder, you often have to know how many pulses there are per degree of rotation. This is a very straightforward math problem.

Pulses per Degree = Number of encoder pulses per rotation/Number of degrees in a circle

For a 5000 Line count incremental rotary encoder we divide 5000/360 to get 13.89 pulses per degree of rotation.

Calculating Degrees of rotation per pulse for an incremental encoder

If you want to find out how many mechanical degrees of rotation there are for one pulse, you would do the problem the other way:

  Pulses per Degree = Number of degrees in a circle/Number of encoder pulses per rotation

For a 5000 rotary incremental encoder we divide 360 by 5000 to get 0.072.

This means that there are  0.072 Mechanical Degrees of rotation for every incremental encoder pulse.

This calculation is often useful if you have a counter totalizing incremental encoder pulses over a given distance or rotation.

Help picking the resolution of an Incremental Encoder

I recently received an e-mail asking for some help picking the right resolution for an Optical Incremental Encoder.  I have removed the personal information and the drive/controller information, otherwise the e-mail is verbatim:

Hi,

I am using a  motor controller in dual loop velocity mode.

What resolution incremental encoder would I need if I wanted to achieve 1%
or better velocity regulation in the range of 0.1RPM to 230RPM on the output
shaft of the gearbox.

The velocity control loop on the controller runs at 1kHz.

I have used your online calculator and it says 600k lines is this correct?

Here was my response:

I think I see what you are after, but you are missing  some information.  The Encoder calculator on the web site is a bit too simple for what you are trying to do.  It is really meant to be a quick conversion tool to find out of your Incremental Encoder is going to violate controller input frequency limitations, and the like.

The ability of the system to regulate to a given speed will depend on more than just the line count of the encoder. The real question that needs to be answered before we can determine Incremental Encoder resolution is “How many pulses are needed per update?” this is a question that will need to be asked of the Drive manufacturer/supplier, but I am sure they will have further questions about the motor size  and loading as well. 

It is easy to see that a motor without a load is easier to regulate than one with a dynamic (changing) load.  Therefore the size of the motor (and it’s inertia)  and the size of the load (and it’s inertia) will need to be taken into account.

With all that being said, we can do some quick math to get a feel for what we do know about the application.

Before I get started, one major thing to note here is that it appears that you are asking for regulation to occur on the output of the gearbox.  I am guessing that the Incremental Encoder is on the motor side (input) of the gear box, so there will be a scaling factor of the input to output ratio that will need to be taken into account along with the following math:

We know that you want to regulate speed within a range of 0.1 RPM to 230 RPM.

Taking the maximum speed of 230 RPM:
230/60 = 3.83 RPS  (Revolutions per Second)

We also know that the drive does a loop update rate of 1000 times/sec  (1Khz)

1000/3.83 = 260.89   updates per Revolution

360 Mechanical Degrees in a revolution

260.89/360     .72469 loop Updates per Degree at full speed.   (Or  1.379 Degrees traveled for every update)

Taking the minimum speed of .1 RPM:
0.1/60 = 0.00167 RPS
1000/ 0.00167  =  600,000 updates per revolution
600000/360 = 1666.67 Loop Updates Per Degree at minimum speed.

After this we really need to ask is “What can the drive do?”  At the top speed we will travel over a degree before the drive can update the loop for any error component.  In the minimum speed example, the drive will not see a change in count over 1667 loop updates. How does the drive handle this? 

To see what this means in Incremental Encoder pulses vs Drive Loop Updates we can take the highest line count encoder we currently provide, a 20,000 LC QR12:

20,000 pulses/360 Mechanical Degrees = 55.5 pulses per mechanical degree

if we use the encoder “post quad”, we can look at the edges of channels A and B pulses to 4x our resolution to 80,000 edges
80000 edges/360 Mechanical Degrees = 222.22 Edges per mechanical degree

For 260 RPM:
55.5 Pulses per degree/.72469 updates per degree = 76.58 pulses per loop update
using edges:
222.22/ .72469 = 306.33 edges per update

For 0.1 RPM:
55.5 Pulses per degree/1666.7 updates per degree = .0333 pulses per loop update (or 30.03 loop updates per Edge)
using edges:
222.22/1666.7 = 0.1333 edges per update  =  0.1333 Edges per update (or 7.5 loop updates per Edge)

Just taking a very rough look at it, a 20,000 line count incremental Encoder appears to have more than enough data per update to give the drive a good idea of how fast the motor is turning at the high speed, while at the slow speed the drive has to wait for several loop updates to pass until it sees even one edge of the Incremental Encoder Signals.

Will the drive be able to regulate at this lower speed without falling out of the 1% tolerance? My guess is probably not, but only the drive manufacturer can answer that for sure.  I am also wondering if 1% regulation is really needed at these slow speeds.

Keep in mind that these numbers would also need to be scaled by the input to output shaft ratio if the encoder is on the input side to the gearbox and the RPM’s above are actually referring to the output shaft speed.

Can the application tolerate being out of the 1% specification momentarily while the drive recovers?  If so, your focus should likely be on loop response time.

At the very least I am guessing tuning the loop to accommodate for both full speed and slow speed may be difficult.

I hope this helps,

Jim

The lost Optical Encoder Demo Box

Optical ENcoder Demo Box Main Menu

We recently teamed up with one of our distributors to create a Demo box that showcased our QD145 optical encoder with a Delta Tau PLC and touchscreen panel.  It was sent off to a trade show where potential customers would get to spin the encoder and watch on the screen as counts were incremented and decremented and needles on dials spun.

I thought the Optical Encoder Demo box would make for a fantastic topic to write a post on, so that was my plan as soon as the demo box returned from the show.

Well… it never did come back.  I would love to tell you that I did such a great job on it that our distributor insisted on keeping it but the truth of the matter is that it was lost in shipping.

What I do have is the code and screenshot of the Optical Encoder Demo box, which should be more than enough to explain the functionality. What I don’t have are pictures, or video of the Optical Encoder Demo box in action, so you will have to use a little imagination on your part.
I  mounted the PLC, HMI and encoder to an enclosure that can set on a table.  The default screen (shown above) tells a little about the encoder. From this screen you can select a few different screens that allow you to interact with the encoder.

Count Screen:
This screen shows Pulse Count, Angle, RPM and direction.

Optical Encoder Data Screen

Degree Screen:

This screen shows mechanical degrees. The needle rotates in conjunction with encoder rotation:

Optical Encoder Mechanical Degree Screen

Pulse Count:
This screen shows the direct read count of the encoder, the needle rotates in conjunction with  encoder rotation:

Optical Encoder Pulse Count Screen

Tank Screen:
This is sort of a fun screen where rotation the encoder fills tanks in sequence, tank one fills, when tank one is full it “empties” into tank 2, when tank 2 is full it “empties” into tank 3.  Tank 3 continues to accumulate until 2 billion counts or so. The Drain button clears the levels on all of the tanks.

Optical Encoder Tank Filling Screen

ABZ screen:
This screen indicates status of inputs coming from the encoder.  Since I used a 5000 LC encoder, the screen was not be able to keep up real time when the encoder was rotated really fast, and it was nearly impossible to land on Z(Index) and have it light.

Optical Encoder Incremental Signals Screen

Programming

The Delta Tau was pretty easy to program, with only a couple hiccups.  The manual was a little vague in its explanation of the way two registers were used for some of the counter functions, but a little troubleshooting showed me which bits were activated when the counter set point was hit.

The Ladder Logic

This first rung of code is needed to do some basic housekeeping to ensure that D1022 is properly configured with a “1″ on the first program scan. It is set by  M1002 and forever latched by M110.  The value of 1 tells the high speed input that we want a double frequency selection A/B phase counter.

The second rung sets up our high speed counter and checks the count to see if we have gone negative in value. If so, bit M120 is set high.

Rung three turns on a physical output Y11 if the counter set point has been hit.

Rung four moves the set point of 5000 back into the counter if we have gone negative in value. This allows the needles on our display screens to rotate continuously and not peg out to a high or low value.

Rung five updates Register D300 with our counter value every 10mS via the handy M1011 10 mS clock pulse.

Rung six divides the counter value by 16 and moves the answer into Register D302. This is where we start our math for the degree conversion. The rest is scaled by the configuring the screen register in the screen editor software.

Run seven uses the trailing edge of our 10 mS clock pulse to move the counter value into register D310.  This value is held for comparison in time to get RPM.

Rung eight uses the leading edge  of our 10mS clock pulse to find the difference in our stored value and put it out to register D312.  D312 is then doubled and sent out to register D350.

For any of you interested in repeating the project, I have included the BOM below.

Of course, I also used some miscellaneous wire and hardware to construct the Optical Encoder Demo box, but the list below includes all the big ticket items.

From Cymatix:

QD145-5/26-5000-0-02-T1-01-02 Optical Encoder

DOP-AS35THTD 3.5” Color touch screen

DVP12C11T Micro programmable Logic controller 8 inputs 4 High Speed outputs

DRP024V060W1AZ CliQ 24 Vdc, 60 Watt power supply

DVPACAB2A30 3 Meter connection cable

 

From Automation Direct:

DN-R35S1 Din Rail 35mm X7.5mm

WC12C12  N12 Desktop enclosure 12”X12”X9”

DN-T12A Terminal Blocks

DN-EB35MN End Brackets

DN-LAB terminal block labels

Finding the RPM of an Optical Encoder using an Oscilloscope

 

We only need to measure one of the incremental channels in order to calculate the RPM of an optical encoder.  Using an oscilloscope to measure the period of one incremental channel A cycle.

We will need to find the frequency of the incremental signal. Keep in mind that converting from time to frequency is just a simple press of the “one over X” button on a scientific calculator.

Frequency =(1/X time)

Time = (1/X Frequency)

To find RPM Once you have the frequency, Multiply by sixty and divide by the line count.

RPM = (Frequency X 60)/Line count of encoder

 

 

The encoder in the video is a 5000 Line Count encoder.  Channel A is outputting pulses at a frequency of 224.2 Khz

RPM = (224.2Khz X 60)/5000

RPM = (13452000)/5000

RPM = 2690.4 RPM

I often use this method to either verify the speed of a motor controller I have built, or if I know the RPM of the motor, I will sometimes use this as a quick way to verify the line count of an encoder.

You can also use the handy Web-based QDI optical encoder calculator  as well.

 

Jim

Optical Encoder Calculator

Quantum Devices optical encoder Resolution/RPM/Frequency Calculator.

We just added a new page to the main Quantum Devices Inc. web site that provides a way to calculate RPM, Frequency, or line count (optical encoder resolution) by entering in the other two variables.

Encoder RPM-Frequency-Resolution Calculator

When would you want to use such a tool?  You might find it useful under the following circumstances:

Read more of this post

Gray Code for Rotary Incremental Encoders

Gray code was named for Frank Gray, a Bell labs researcher, who patented the procession in 1953,  even though a form of it was used by Emile Baudot for telegraphy as early as 1878.

The most important thing to understand about Gray code is that only one bit changes from transition to transition.   In binary it is possible for a number to go from all ones to all zeros, as is the case with 11111111 (255 decimal)  going back around to 00000000 (zero).

Dec           Bin                    Gray
0              0000                0000
1              0001                0001
2              0010                0011
3              0011                0010
4              0100                0110
5              0101                0111
6              0110                0101
7              0111                0100
8              1000                1100
9              1001                1101
10            1010                1111
11            1011                1110
12            1100                1010
13            1101                1011
14            1110                1001
15            1111                1000

Notice how only one of the 0’s or 1’s of the Gray code change as the number increments?  In binary there are times when all of the bits change, (0111  to 1000 (Seven to Eight ) and 1111 back to 0000 (Fifteen to Zero) ).

Error Checking

The advantage to only one bit changing in Gray code is that it gives you error-checking ability.  If you sum the number of bits the bit total will always change by only one.

You could also do some error checking knowing that the bit sum will always alternate between even and odd.

Gray      Bit Sum
0000         0
0001           1
0011           2
0010           1
0110           2
0111            3
0101            2
0100           1

Gray Code in Incremental Encoders

The A & B channels of Incremental Encoders are in quadrature, which makes a two-bit gray code progression.  Depending on direction, the Incremental Encoder bit progression with be a cyclical pattern of either 00 – 01 -11 – 10  or  00 – 10 – 11 – 01 – 00.

Only one bit changes from transition to transition.

The QD787 absolute encoder shown at the top of this post has an option for an eight bit Gray code output.

Links to more information on Gray code:

http://encyclopedia2.thefreedictionary.com/Grey+code

http://www.itl.nist.gov/div897/sqg/dads/HTML/graycode.html

http://mathworld.wolfram.com/GrayCode.html

Sample C code:

http://www.nrbook.com/a/bookcpdf/c20-2.pdf

WIKI:

http://en.wikipedia.org/wiki/Gray_code#Constructing_an_n-bit_gray_code

For more information on encoders, go to http://www.quantumdev.com

Jim can be reached at:  jmiller@quantumdev.com

Using an optical encoder to measure angles

I have interfaced a 200 LC QD145 to a DL06 PLC to show how to convert from a line count to mechanical degrees. This type of conversion may be useful for any application needing to know an angular measurement.

To calculate a degree measurement we divide 360 by the line count to get the number of degrees per pulse.

(360 Degrees /200 Pulses per revolution) = 1.8 Degrees per pulse.

The High Speed counter we have set up will automatically add one to it’s running total any time the encoder is rotated counter-clockwise, and subtract one from the running total any time the optical encoder is rotated clockwise.


This value is loaded into the PLC’s accumulator and multiplied by 1.8  (K18) to convert to degrees. The number is then outputted to an address(V2500)that we can display on the screen.

When the index (Z) pulse occurs, we reset the counter to let it know we are back at zero.

Below is the PLC code for the pulses to degree conversion.

It is good to note that the PLC is set up to retain the count value when powered off, but if the optical encoder is rotated during this time, the count will not change and the value at power up will be different than the encoders real world position.

It is good practice to rotate an incremental encoder/optical encoder on power up until an index pulse is seen and start counting from there. This is technique is known as “homing”.

By default the quadrature counting mode within the PLC keeps track of negative numbers, so we are able to accumulate a negative degree value depending on the direction of rotation after zero. While this may seem a bit confusing, it is really just a matter of your point of reference. –90 Degrees is the same exact point as a positive 270 Degrees.  If we wanted to convert to where we stayed within a positive degree range, you could change the PLC code to add 360 to the measured value any time it went negative.

For more information on encoders go to  http://www.quantumdev.com

For technical questions Jim can be reached at:  jmiller@quantumdev.com

Optical Encoder Incremental Signal Measurement

While most of us are familiar with how to measure something in mechanical degrees, incremental optical encoder signals are measured in electrical degrees.

360 electrical degrees is the period in which a signal completes one high to low transition.  This can be in any sort of waveform, but for encoders electrical degrees are usually used when referring to digital signals

Why Measure in Electrical Degrees?

We measure Incremental Optical Encoder signals in electrical degrees because this gives us a number that is not depended on other information.  If you were to talk about the high time of your encoder signal being 10 milliseconds, It doesn’t say anything about the quality of the signal unless you also talk about total cycle time.

An electrical degree specification gives us information about the signal with just one number.

Incremental Optical Encoder Symmetry

The ideal output for an incremental channel is a waveform with a 50/50 duty cycle.  This specification is termed “symmetry” and called out in electrical degrees.  Ideal symmetry is one where the high and low times of a channel are each 180 electrical degrees.

Some oscilloscopes will have a way to measure electrical degrees directly by setting a  full cycle to 360 degrees. In this post I am going to assume that your scope doesn’t have that feature and calculate electrical Degree symmetry measurements using the high, low and cycle durations as measured in time.

In the photo above the duration of a full cycle is 50.00 uS.

In this next photo we adjust the cursors to check the High time of the A channel we see that it is 24.80 uS

To find what this time would be in electrical degrees, we calculate as:

(high time/ cycle time) *360

Or

(24.80 uS/50.00 uS)* 360  = 178.56 Electrical Degrees

To find the low time you could measure it and again repeat the calculation (substituting in Low time for high time, but as long as the high time measurement was done carefully it is just as easy to subtract the high time from 360 Electrical Degrees to get the low time in Electrical Degrees.

360 – High pulse in electrical degrees = Low pulse in electrical Degrees

Or

360 – 178.56 = 181.44 Electrical Degrees

Note that to get the most accurate measurement you will want to widen out the cycle as far as possible.

Channel B is measured in the same way.

Incremental Optical Encoder Minimum Edge Separation.

Minimum A to B edge separation is an important measurement as the more time you have between the edges, the easier it is for a drive or controller to “see” the data coming in. This is particularly true with older equipment and when running at high speed.

Ideal A to B edge separation is 90 electrical degrees.  To find edge separation in an incremental optical encoder look for the smallest separation between adjacent edges of all six edges within an overlapping set of  A & B cycles.

To change from time to electrical degrees, we use a calculation similar to the one used for symmetry.

(Smallest Measurement/cycle time) *360 = Minimum Edge Separation in Electrical Degrees.

or

(12.00 uS/ 50.00 uS) * 360 = 86.4 Electrical Degrees Minimum A to B edge Separation


Video of an incremental optical encoder being tested for Symmetry and Minimum Edge Separation.

If you have any questions, I can be reached at jmiller@quantumdev.com.

For Optical Encoders with excellent  symmetry and edge separation go to Quantum Devices Encoder page

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.

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.Sampling

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.

Crossing

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

Data-points

Then connecting the dots….

remap

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

productThmb_QD787A

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.

8-bit-binary

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:

Bin-0The 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.

Bin-1As 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.

Bin-2Rotating 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.

Bin-3Turning 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″.

Bin-4As we rotate, our encoder continues to count.  This time the first two bits turn off and the third bit valued at “four” turns on.

Bin-5We 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) .

Bin-6

Rotating 8.4375 degrees in is a binary 011, or a value of Six.

Bin-7In 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.

Follow

Get every new post delivered to your Inbox.