AutomateDirectUSAMotion LibraryIndustrial monitors & PCs

Explainer

How an incremental encoder shows direction of rotation

Sensors, encoders and machine vision on the machine Published 9 min read By AutomateDirectUSA engineering team

Short answer

An incremental encoder carries direction in the order of its A and B edges, not in their frequency: in quadrature, A leads B by 90 electrical degrees in one rotation direction and B leads A in the other. A quadrature-capable counter resolves that edge order into a signed count; a single channel or a slowly scanned input cannot.

On this page
  1. How does an incremental encoder show direction of rotation?
  2. What do the A and B channels actually output?
  3. Which channel leads when the shaft reverses?
  4. What state sequence does a quadrature decoder follow?
  5. How fast do the A and B edges arrive?
  6. Does the counting multiplier change direction or only resolution?
  7. Why can't a single channel or a slow scan recover direction?
  8. How do you verify lead and lag on the machine?
  9. Which fix fits which symptom?
  10. Questions asked

An incremental encoder shows direction through the order of its two channel edges, never through their frequency. Channels A and B emit square waves offset by a quarter of a cycle: in one rotation direction A leads B by 90 electrical degrees, and when the shaft reverses, B leads A. A counter built for quadrature signals watches which channel transitions first and turns that order into a plus or a minus on the position count, while frequency tells you only how fast the shaft turns. This page explains what the two channels output, which channel leads after a reversal, the state sequence a decoder follows, how fast edges arrive, and how to verify lead and lag on the machine with a two-channel oscilloscope.

How does an incremental encoder show direction of rotation? #

The direction signal is the order of the A and B transitions: with the shaft turning one way A rises before B, and after a reversal B rises before A, so a decoder that resolves which channel moved first returns a signed count. Frequency and direction are separate pieces of information. Cycles per second tell a drive how fast the shaft turns and say nothing about which way, which is why a single-channel encoder can feed a speed indication but never a positioning axis. Any counter module sold for incremental encoders decodes the edge order in hardware and hands the controller a signed count. The builder's job is to deliver clean A and B signals at a frequency the input accepts, and to set the sign convention once, deliberately.

What do the A and B channels actually output? #

Each channel is a square wave whose frequency follows shaft speed, and the two waves are offset by one quarter of a cycle, 90 electrical degrees, so four distinct edges occur in every channel cycle. Most encoders generate the pair with a slotted disk on the shaft and emitter-detector elements that read the slots as it turns, the two sensing elements placed a quarter slot pitch apart. The output stage then shapes the detector signals into square waves, single-ended or differential, and the receiver has to match that output type before anything else gets checked.

A third channel, Z or index, pulses once per revolution and gives homing a repeatable starting angle, which is what the page on homing an incremental encoder axis with a zero mark builds on. The index takes no part in per-edge direction.

Which channel leads when the shaft reverses? #

Reversing the shaft swaps the leader: A leads B through every cycle in one direction and B leads A in the other, and which of those means clockwise is set by the encoder datasheet, the wiring and the end of the shaft you view from. Lead and lag are names for the same quarter-cycle relationship seen from either side; nothing in the waveform declares clockwise. One datasheet may call A-leads-B positive viewed from the shaft end and another may use the opposite convention, and a cable that exchanges a differential pair can flip what the receiver sees.

Treat the sign as a configuration decision rather than a fact you read off the scope. The rule to commit to: jog the axis in the direction the machine calls positive, read the count, and if the sign is backwards, either exchange the channel assignment in the decoder configuration or enable its documented direction-reverse setting. Both fixes are legitimate; pick one, verify it through a full turn of known displacement, and record it on the machine file.

What state sequence does a quadrature decoder follow? #

A decoder walks a four-state cycle, reading the channel pair as two bits: one direction runs 00 → 10 → 11 → 01 → 00 and the reverse runs 00 → 01 → 11 → 10 → 00, with exactly one bit changing at each step. Write the two channels as a two-bit word AB and the decoder's job becomes visible: forward rotation and reverse rotation travel the same four states in opposite orders, in this illustrative assignment, and the one-bit rule holds throughout.

That one-bit rule is the diagnostic. A transition such as 00 → 11 is not a valid adjacent state; it means the decoder missed the intermediate step, which points to noise, a wiring fault or a shaft speed above what the input resolves. Which physical channel maps to which bit varies by product, so treat the printed sequences as logic, not as a wiring color code.

A full state decoder also handles small reversals cleanly, stepping back down the same path it stepped up. Simpler schemes, such as counting B edges only while A is high, are not equivalent around a boundary and need explicit testing before you trust them on an axis that dithers. Machine position belongs on a hardware quadrature input, and embedded processors route the channels into a dedicated decoder peripheral for exactly this purpose, as described in configuring the i.MX RT1064 XBAR for quadrature decoder routing.

How fast do the A and B edges arrive? #

Adjacent edges arrive every 1/(4f) seconds, where f is one channel's cycle frequency in hertz, so a 1000-cycle encoder on a shaft at 1800 rpm produces edges every 8.33 microseconds and the receiver must resolve that interval. Take it as a calculated example, worked through step by step:

  • Shaft speed: 1800 rpm divided by 60 equals 30 revolutions per second.
  • Channel frequency: 1000 cycles per revolution times 30 revolutions per second equals 30,000 Hz, that is 30 kHz.
  • Edge rate: 4 edges per cycle times 30,000 cycles per second equals 120,000 edges per second.
  • Edge interval: 1 divided by 120,000 seconds equals 0.00000833 s, about 8.33 microseconds.

The calculation assumes ideal, evenly spaced edges. Real parts add phase error and duty-cycle skew, so the true shortest interval is somewhat shorter than the nominal one, and the numbers above are a calculated example for these inputs, not a measured result.

The decision follows directly: the counter input's quadrature frequency rating must exceed the channel frequency you computed, and the module manual tells you whether that rating is stated in channel cycles or in counted edges, because the same decoder is described either way and the two numbers differ by a factor of four.

Does the counting multiplier change direction or only resolution? #

The multiplier changes only resolution: X1 counts one edge per channel cycle, X2 counts two and X4 counts all four edges of both channels, quadrupling the counts, while the direction logic reads the same edge order in every mode. Under the usual datasheet convention where the stated resolution is cycles per revolution of one channel, decoded counts per revolution equal that resolution times the multiplier, so a 1000-cycle encoder returns 1000 counts per revolution in X1, 2000 in X2 and 4000 in X4.

Check the terminology before multiplying. If the datasheet already states decoded counts per revolution, the multiplier is already inside the number and multiplying again silently scales every position by four. Choose the mode for resolution against the edge-rate budget from the previous section: X4 gives the finest position resolution but also the highest edge rate, and if the computed edge rate approaches the input's rating, step down to X2 or X1 rather than losing counts.

Why can't a single channel or a slow scan recover direction? #

One channel gives frequency and an edge total but no direction, because rising edges look identical forward and backward, and a cyclic program that samples A and B as ordinary inputs sees states, not every edge between scans. Computing speed more often from that one channel does not manufacture the missing information; the direction bit was never in the signal. If several transitions pass between two program scans, the program undercounts or infers the wrong direction, which shows up on the machine as a count that no longer matches shaft turns, the same failure explored in why an incremental encoder counts wrong turns per revolution.

Input filtering cuts both ways: a longer filter rejects noise but also swallows valid pulses shorter than its time constant, so a filter set past the top-speed edge interval deletes real counts. Separate the two failure families before touching anything: a count whose magnitude is stable but whose sign is backwards is a convention problem, while a count that jumps, stalls or reverses while the shaft turns steadily is an acquisition problem.

How do you verify lead and lag on the machine? #

Put channels A and B on a two-channel oscilloscope, turn the shaft slowly by hand, and confirm the leading channel swaps when you reverse, because the capture at the receiver terminals shows the order the counter actually sees. Work through it in this order:

  1. Confirm the electrical interface from both datasheets, encoder output type against receiver input type, supply voltage and reference, and whether the signals need a differential or single-ended receiver; the page on wiring a TTL quadrature encoder to drive encoder terminals walks through a typical hookup.
  2. Capture A and B together while turning the shaft slowly by hand, probing at the receiver terminals so the measurement includes the cable.
  3. Reverse the rotation and confirm the leading channel swaps. If the order never changes, verify channel identity at both ends of the cable; motor and drive labels do not always agree, and matching encoder signal names between motor and servo drive is its own exercise.
  4. Set the counting multiplier, the input filter and the direction convention in the decoder configuration, reading the manual for whether its frequency limit means channel cycles or counted edges.
  5. Jog the machine in its defined positive direction and confirm the count sign; correct it with the channel assignment or the documented reverse setting.

Before putting a hand on the shaft, apply lockout to the drive and secure any vertical axis that could back-drive, following the machine's risk assessment.

Which fix fits which symptom? #

A steady count with the wrong sign is a convention problem: swap the channel assignment or set the documented direction-reverse setting, while a count that jumps, loses steps or reverses during steady turning is an acquisition problem: verify levels, mode, wiring and the frequency rating before changing any filter. Match the symptom to the family before ordering parts or rewriting logic.

Wrong sign with steady magnitude means the fix takes one configuration change and nothing else. A drifting or jumping count during steady turning means you check the output type against the receiver, confirm the counter is in quadrature mode rather than pulse-and-direction, which expects a separate direction signal and is not interchangeable, verify the computed channel frequency sits inside the input rating, then tighten grounding and shielding, raising the filter only as far as the top-speed edge interval allows. No count at all is electrical: supply, reference and termination. Work through them cheapest check first, and the direction signal will be the least of the problem.

Questions asked

Is there a standard that defines which channel leads for clockwise rotation?

No single rule covers every product. Each encoder datasheet defines its channel naming and the shaft end it is viewed from, and the drive or counter input adds its own convention on top. Jog the machine in the direction it calls positive, read the count, and set the sign with the channel assignment or the documented direction-reverse setting. Record the result on the machine file so the next person does not repeat the test.

Does the Z index channel carry any direction information?

No. The index channel produces one pulse per revolution, so it marks a fixed angular position for homing and position checks and cannot say which way a single edge moved. Direction comes only from the order of the A and B transitions. Some drives gate the index pulse with a direction latched from A and B, but the direction decision itself still belongs to the quadrature pair.

Why does the position count step back and forth while the shaft sits still?

The shaft is resting near a transition point, and vibration or electrical noise pushes the signal across that boundary repeatedly, so the decoder counts one step up and one step down. Around a single boundary a correct four-state decoder nets to zero and only jitters. A count that walks steadily away means real extra edges from noise, a grounding problem or a damaged cable, not harmless dither.

Can swapping the A and B wires reverse a count that runs backwards?

Yes, exchanging the two channels flips the decoded sign, and it is a legitimate fix when the magnitude of the count is stable and only the sign is wrong. It cannot repair missed edges, wrong voltage levels or a receiver set to the wrong counting mode, so confirm the count tracks the shaft through a known displacement before treating the swap as the fix.

How do I check that a counter input can handle my encoder's speed?

Compute one channel's cycle frequency as its cycles per revolution multiplied by revolutions per second, then require the module's quadrature input rating to exceed that figure. For the worked example above, the channel frequency came to 30 kHz and the rating has to clear it. Read the module manual to learn whether the rating is stated in channel cycles or in counted edges, because an edges rating is four times a cycles rating for the same decoder.

Keep reading

  • Selection guide

    Choosing Encoder Resolution to Match a Stepper Step Response

    A 50 ppr encoder read in x4 gives 200 counts/rev — one count per 1.8° full step, so the loop sees only before and after each step and ±1 count is ±1.8°. Size the encoder by counts per full step: 10 counts per step, which is 500 ppr in x4 at 2000 counts/rev and 0.18° per count, is the working minimum to reproduce a stepper's damped step response.

    Sensors, encoders and machine vision on the machine

  • Troubleshooting

    Why an incremental encoder counts wrong turns per revolution

    One measured revolution settles an incremental encoder turn-count fault: with 2,000-cycle channels decoded in x4 mode the raw counter must advance exactly 8,000 counts per shaft revolution, and at 300 rpm that stream arrives as 40,000 counts per second — fast enough to overflow a signed 16-bit register between resets. Measure the raw counter first; retuning the divisor to 6,810 only rescales the error.

    Sensors, encoders and machine vision on the machine

  • Troubleshooting

    Servo Drive Encoder Phase Alarm: Isolate Wiring, Encoder or Drive

    An encoder phase error alarm means the drive is not receiving A and B as clean square waves 90° apart, and the cable is the most common cause. Check in order of cost — connections, waveforms on a scope, encoder mounting, drive parameters — then decide encoder versus drive by substitution: the fault that follows the encoder condemns the encoder; the fault that stays with the drive condemns the drive's feedback input circuit.

    Sensors, encoders and machine vision on the machine