Report 7
Report 7
Experiment # 7
Rimsha Jawad
385345
What is an Encoder?
An incremental optical encoder, shown in Figure 2-1, is a relative angular displacement sensor which
measures angular displacement relative to a previously known position. Unlike an absolute encoder, an
incremental encoder does not retain its position information upon power loss. An incremental encoder
outputs a series of pulses which correlate to the relative change in angular position. Encoders are
commonly used to measure angular displacement of rotating load shafts. Information extracted from
an incremental encoder can also be used to derive instantaneous rotational velocities.
An incremental optical encoder typically consists of a coded disk, an Infrared (IR) LED, and two
photosensors. The disk is coded with an alternating light and dark radial pattern causing it to act as a
shutter. As shown schematically in Figure 2-2, the light emitted by the IR LED is interrupted by the
coding as the disk rotates around its axis.
Figure 2-2: Output of an incremental encoder showing signals A and B when rotating in a clockwise
manner
The two photosensors (A and B) positioned behind the coded disk sense the infrared light emitted by
the IR LED, which results in A and B signals/pulses, in four distinct states as outlined in Table 2-1:
1 OFF ON
2 OFF OFF
3 ON OFF
4 ON ON
Encoders which output A and B signals are often referred to as quadrature encoders since the signals
are separated in phase by 90° and result in four distinct states. Non-quadrature encoders have only
one output signal and thus are unable to detect direction. The resolution of an encoder is determined
using the number of light or dark patterns on the disk, a measure that is given in terms of pulses per
revolution, or PPR.
Some encoders utilize an index pulse (Z channel), which is triggered once for every full rotation of the
disk (see Figure 2-3). The index pulse can be used for calibration or so-called homing of a system, as
well as a revolution counter. Depending on the encoder, the width of the index plus may be aligned
with any of the four quadrature states. For example, the index pulse may have a width that spans a full
cycle (4 states), a half cycle (2 states), or a quarter cycle (1 state). In the example shown in Figure 2-3,
the width of the index pulse is aligned with a full cycle of the B signal.
There are two methods that an encoder registers the index pulse: (a) using pre-defined states of
signals A and B, or (b) using user-defined states of signals A and B, in which case the user must select a
combination of A and B states that occurs only once during the width of the index pulse.
Figure 2-3: Output of a quadrature encoder with an index pulse
Encoder Decoding
In order to make encoder measurements, you need to connect the encoder outputs to a counter. A
decoding algorithm is then used to determine the number of counts and possibly the direction of
rotation.
Four common decoding algorithms are used: non-quadrature, X1, X2, and X4.
Non-quadrature
When a non-quadrature decoder is used, only the rising edge of signal A is counted as the shaft
rotates. The counter is incremented on the rising edge of signal A. Because signal B is not used, the
encoder cannot detect the direction of rotation. For example, using a non-quadrature decoder, a 9 PPR
encoder will result in a total of 9 counts for every rotation of the encoder shaft. The count will increase
regardless of which direction the shaft is rotated.
X1 Decoder
When an X1 decoder is used, only the rising edge of signal A is counted as the shaft rotates. When a
rising edge of signal A occurs, the algorithm looks at the current state of signal B. If signal B is low, the
counter is incremented. Otherwise, when signal B is high, the counter is decremented. Using an X1
decoder, a 9 PPR encoder will result in a total of 9 counts for every rotation of the encoder shaft.
X2 Decoder
When an X2 decoder is used, both the rising and falling edges of signal A are counted as the shaft
rotates. When a rising edge of signal A occurs, the algorithm looks at the current state of signal B. If
signal B is low, the counter is incremented. Otherwise, when signal B is high, the counter is
decremented. When a falling edge of signal A occurs, if signal B is high the counter is incremented,
otherwise when signal B is low the counter is decremented. Using an X2 decoder, a 9 PPR encoder will
generate a total of 18 counts for every rotation of the encoder shaft.
X4 Decoder
When an X4 algorithm is used, both the rising and falling edges of both signals A and B are counted.
Using a state machine diagram, Figure 2-4 illustrates how the counter is incremented or decremented
depending on the state of signals A and B. An X4 decoder generates four times the number of counts
generated by an X1 decoder resulting in the highest resolution among the three types of decoders.
Using an X4 decoder, a 9 PPR encoder will generate a total of 36 counts for every rotation of the
encoder shaft.
Equation 2-1
𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶𝐶
𝜃𝜃 = ∙ 360°
𝑁𝑁 ∙ 𝑃𝑃𝑃𝑃𝑃𝑃
Equation 2-2
360°
∆𝜃𝜃 =
𝑁𝑁 ∙ 𝑃𝑃𝑃𝑃𝑃𝑃
Figure 2-5 compares the number of counts generated by each of the non-quadrature, X1, X2, and X4
decoders.
Figure 2-5: Comparison of the number of counts generated by different decoding algorithms
Procedure
The Virtual Instrument (VI) used to collect data from and calibrate the encoder is
shown in Figure 5.
Figure 5: VI used to collect data from and calibrate the encoder.
Analysis of Non-quadrature Decoding
1. Open QNET Mechatronic Sensors.lvproj .
2. From the Project Explorer window, open QNET Sensors Encoder.vi .
3. From the Device drop-down menu, select the device name.
4. From the Decoding Algorithm drop-down menu, select non-quadrature (no index) .
5. Run the VI.
6. In non-quadrature decoding only A signal is used. Rotate the encoder knob in the
clockwise direction. How does the Edge (counts) numeric display change?
Note : The index pulse is not used in non-quadrature decoding.
7. Rotate the knob in the counterclockwise direction. How does the Edge (counts)
numeric display change?
Note: At any time, you can press the Reset button to reset the counter. This will rest the
Edge (counts) and Angle (deg) numeric displays to zero.
8. Using the Edge (counts) numeric display, measure the number of pulses the
encoder generates per each full revolution (PPR).
Screenshot:
3. Calculate the expected angular resolution using Equation 2 in the Concept Review .
Rotate the encoder knob and verify if you measure the same resolution?
𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄 𝟐𝟐
𝜽𝜽 = × 𝟑𝟑𝟑𝟑𝟑𝟑 = × 𝟑𝟑𝟑𝟑𝟑𝟑 = 𝟖𝟖𝟖𝟖°
𝑵𝑵 ⋅ 𝑷𝑷𝑷𝑷𝑷𝑷 𝟏𝟏 ⋅ 𝟗𝟗
𝟑𝟑𝟑𝟑𝟑𝟑 𝟏𝟏
𝚫𝚫𝜽𝜽 = = × 𝟑𝟑𝟑𝟑𝟑𝟑 = 𝟒𝟒𝟒𝟒°
𝑵𝑵 ⋅ 𝑷𝑷𝑷𝑷𝑷𝑷 𝟏𝟏 ⋅ 𝟗𝟗
VERIFIED
4. Continue to the next section.
Analysis of X2 Decoding
1. From the Decoding Algorithm drop-down menu, select X2 .
2. Press the Reset button.
3. In X2 decoding both A and B signals are used. Rotate the encoder knob in the
clockwise direction. How do the Edge (counts) and Angle (deg) numeric displays
change?
Ans: The edge counts decrease and the angle measured is negative
Note : The PPR value remains constant regardless of the decoding algorithm used.
4. Rotate the knob in the counterclockwise direction. How do the Edge (counts) and
Angle (deg) numeric displays change?
Screenshot:
5. Examine the response of the A and B signals.
360 1
Δ𝜃𝜃 = = × 360 = 20°
𝑁𝑁 ⋅ 𝑃𝑃𝑃𝑃𝑃𝑃 2 ⋅ 9
7. Continue to the next section.
2. Analysis of X4 Decoding
1. From the Decoding Algorithm drop-down menu, select X4 .
2. Press the Reset button.
3. Rotate the knob in the clockwise and counterclockwise directions. How do the
Edge (counts) and Angle (deg) numeric displays change?
Screenshot:
𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄 𝟏𝟏
𝜽𝜽 = × 𝟑𝟑𝟑𝟑𝟑𝟑 = × 𝟑𝟑𝟑𝟑𝟑𝟑 = 𝟏𝟏𝟏𝟏°
𝑵𝑵 ⋅ 𝑷𝑷𝑷𝑷𝑷𝑷 𝟒𝟒 ⋅ 𝟗𝟗
5. Continue to the next section.
Analysis of the Index Pulse
1. Before using the index pulse, you must first determine the unique combination of
signal A and signal B that occurs only once during the width of the index pulse. It is
preferred to select a unique state that occurs closer to middle of the index pulse.
2. Slowly turn the encoder until you see a full index pulse. Immediately stop the VI
using the Stop button.
Screenshot:
Conclusion:
In this lab, we dealt with encoder which measure the angular displacement. We
studied about non-quadrature and quadrature decoders.