AutomateDirectUSAMotion LibraryIndustrial monitors & PCs

Explainer

Incremental encoder vs counter input: speed and direction

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

Short answer

A counter input that only accumulates one encoder channel gives speed magnitude and loses direction, and a software-polled input misses edges as speed rises. Direction needs an input that decodes the quadrature channel phase in hardware, rated above the channel frequency at maximum speed. Signed rpm then comes from 60 times the signed count change, divided by decoded counts per revolution times the interval in seconds.

On this page
  1. What the encoder signal carries
  2. What a plain counter input gives you and what it hides
  3. Why a scanned input loses the signal
  4. The frequency rating that decides the choice
  5. Worked example: a hydraulic motor with a 1024 cycle encoder at 2000 rpm
  6. From decoded count to signed rpm
  7. Low speed and standstill
  8. The decision
  9. Questions asked

An incremental encoder feeding speed and direction to a controller needs an input that does more than count pulses. A counter that only accumulates one channel returns speed magnitude and loses direction: reverse motion pushes the reading further up instead of down. A software-polled input loses edges long before the motor reaches rated speed, and no filter or rescaling gets them back. The input that survives this measurement decodes the quadrature channel phase in hardware and is rated above the channel frequency at the motor's maximum speed. Signed rpm then falls out of the decoded count change over a timed interval: rpm = 60 × count change ÷ (decoded counts per revolution × seconds). This article explains why each cheaper input fails, sizes the input with real arithmetic, and ends with the decision for each case.

What the encoder signal carries #

An incremental encoder reports change in position, not absolute position. It puts out two channels, A and B, offset a quarter cycle from each other; which channel leads tells you which way the shaft is turning. That two-channel arrangement is called quadrature, and the direction information lives in the relative timing of the two channels, not in either edge count alone — there is no separate direction wire to fall back on.

A decoder that watches both channels can count one, two or four edges per channel cycle; the four-edge mode is the standard on dedicated encoder inputs and is the "×4" figure in module documentation. The phase-to-direction relationship, and why the sequence of channel states decides the sign, is worked through step by step in how an incremental encoder shows direction of rotation.

So the signal arriving at the terminals is not one pulse train but two, each at the same cycle frequency, and any input that hopes to report signed speed has to deal with both of them at edge timing.

What a plain counter input gives you and what it hides #

A counter input accumulates edges. Count channel A and you get a number proportional to distance travelled regardless of direction: forward and reverse both add to it. Some counter inputs include a quadrature mode that compares the channels and accumulates a signed count; if the module's operating-mode list has no such mode, the direction information is discarded at the input, and no calculation downstream can reconstruct it.

Choosing hardware because it "has a counter" therefore answers only the magnitude half of a speed-and-direction requirement. The first thing to verify is that the mode list includes incremental encoder or quadrature decoding — the same first check needed when matching an incremental encoder to a PLC high speed counter.

Why a scanned input loses the signal #

A digital input read by the program scan samples the line once per scan. Between two samples the shaft moves through several encoder states, and the states in between are gone: the application cannot rebuild a dependable signed count from what is left, and it certainly cannot tell from two samples which channel led. This is the same edge-loss problem described in counting encoder pulses on a PLC without losing position, and it gets worse exactly as the measurement gets useful — faster speed means more edges per scan window.

Two substitutions do not fix it. Slowing the displayed update rate or filtering the rpm value smooths the number but changes nothing about the electrical edges arriving at the terminal; a filter cannot recover edges that were never captured. A scaling factor corrects a proportional speed error in the magnitude, but a scale factor cannot recreate a phase comparison that never happened, so it does nothing for direction.

The frequency rating that decides the choice #

The input has to be specified for the signal at worst case. The channel cycle frequency at top speed follows a one-line rule:

channel frequency in hertz = cycles per revolution × absolute rpm ÷ 60

Read the module limit with its own definition before comparing. Channel cycle frequency, edge rate and decoded count rate are three different quantities: a decoder in four-edge mode produces four count transitions per channel cycle, so its decoded count rate is four times the channel frequency, and a datasheet that states its limit as a minimum pulse width is stating yet another view of the same wall. Compare your worst-case number against the like-for-like figure in the module's technical data, with margin.

This is why dedicated encoder interfaces exist: motor controllers and motion drives ship hardware decoder blocks whose only job is comparing the channel phases at edge speed, because no scan-time software loop can. The hardware does the phase evaluation; the rating check above tells you whether it also survives your top speed.

Worked example: a hydraulic motor with a 1024 cycle encoder at 2000 rpm #

The case is the one this article answers: an incremental speed encoder on a hydraulic motor where the controller needs both rpm and direction. The numeric inputs below are example values — take your own from the encoder datasheet and the drive's maximum intended speed.

Inputs:

  • Encoder resolution: 1024 cycles per revolution, two quadrature channels (encoder datasheet).
  • Maximum motor speed: 2000 rpm (the hydraulic drive's maximum intended speed).
  • Decoding mode: four-edge, so decoded counts per revolution = 4 × 1024 = 4096.
  • Measurement: signed count change of +8192 counts over a 0.1 s interval (controller read).

The rules, in words: the channel frequency equals cycles per revolution times absolute rpm divided by 60; the decoded edge rate equals channel frequency times the number of edges counted per cycle; signed rpm equals 60 times the signed count change, divided by decoded counts per revolution times the interval in seconds.

Arithmetic:

  • Channel frequency = 1024 × 2000 ÷ 60 = 34,133 Hz, about 34.1 kHz per channel.
  • Decoded edge rate = 4 × 34,133 = 136,533 edges per second, about 136.5 kHz.
  • Signed rpm = 60 × 8192 ÷ (4096 × 0.1) = 491,520 ÷ 409.6 = 1200 rpm, and the positive sign reads as forward under the module's documented convention.

Result: at top speed the input sees 34.1 kHz channel cycles and roughly 136,500 edges per second, and the interval calculation returns 1200 rpm forward.

Decision: a scan that reads the input every 1 ms observes it at most 1000 times per second against those 136,500 edges per second, so it misses all but under one percent of the transitions and the count it builds is meaningless — the scanned input is out. The input that survives decodes quadrature in hardware with a documented limit above the 34.1 kHz channel frequency, or above the 136.5 kHz edge rate if its datasheet defines the limit that way. A single-channel counter, however fast, still answers only magnitude. When you confirm the sign convention with a manual test turn, lock the hydraulic power unit out and release accumulated pressure first, following your site's energy-control procedure.

From decoded count to signed rpm #

Set the scaling to the decoded counts per revolution of the selected mode, not to the pulse number on the encoder label — in four-edge decoding the decoded count per revolution is four times the label. Confirm it once with a full known revolution and the count change you actually see, gear ratio included if the encoder shaft and the reported speed refer to different shafts.

The sign is only usable if the module delivers a signed position count: forward accumulates up, reverse down, with the convention documented for the selected mode. Handle rollover by subtracting across the documented counter range rather than reading raw wrapped values. And if that count travels to your application through a gateway that carries it as a raw 16-bit register, reverse motion arrives looking like a huge positive jump until the receiver decodes the register as signed — the same wrap problem explained in how Node-RED decodes signed Modbus register values.

The count-difference arithmetic itself is the same calculation worked through for a conveyor roller in calculating roller RPM from encoder HSC counts.

Low speed and standstill #

Below the frequency problem sits a resolution one. A short interval at low speed holds few counts, and the calculated rpm moves in visible steps; lengthening the interval improves the resolution and delays the answer.

At standstill the count-difference method returns zero after any interval with no movement, which is correct — but the same zero appears when the module has faulted or the encoder is disconnected. Separate a valid zero from no-data using the module's diagnostic status. A period-based measurement, timing between edges, resolves low speeds better and instead needs a defined no-pulse timeout to declare standstill.

If reversals and standstill matter more than raw resolution, an absolute encoder sidesteps the accumulated-count problem entirely: rpm comes from consecutive position differences, as worked in calculating RPM from an absolute encoder position difference.

The decision #

Input at the terminals Speed magnitude Direction Condition to verify
Plain counter, channel A only Yes, below its count-rate limit No Worst-case count rate below the documented limit
Counter with quadrature decoder mode Yes Yes Channel frequency or edge rate at top speed below the limit for the selected mode
Program-scanned digital input Only at very low speed No in practice Scan time against the edge rate — almost never closes above slow speeds
  • You need rpm and direction from an incremental encoder: use an input that decodes quadrature in hardware, rated above the channel frequency at the motor's maximum speed, and compute signed rpm from the signed count change over a timed interval.
  • You need magnitude only, at low speed: a plain counter on one channel is acceptable within its documented count rate, and you give up direction by that choice, not by accident.
  • All you have are scanned inputs: they cannot carry this signal above slow speeds, so add an encoder interface on the I/O side or move the measurement to a drive or motion controller with encoder inputs.
  • The platform has no incremental encoder input at all: a dedicated encoder interface in front of the controller, or absolute feedback the controller already supports, are the two paths that keep both numbers honest.

Questions asked

Can two plain counters, one per encoder channel, recover direction?

Not by themselves. Each counter accumulates edges in both directions, so comparing the two totals after the fact still does not tell you which channel led during the motion. Direction comes from the order of the channel states at the moment they occur, which only a decoder evaluating both channels in hardware captures. Two counters give you two magnitudes, not a sign.

The module datasheet states its input limit as an edge rate. How do I compare?

Convert your encoder number into the same quantity before comparing. In four-edge decoding the edge rate is four times the channel cycle frequency, in two-edge decoding twice, and in single-edge decoding equal. Check the documented minimum pulse width at top speed too, because some inputs state both. Keep a margin between your worst-case figure and the limit rather than sizing at exactly the maximum.

Can I read channel A with a counter and channel B as a level input for direction?

Only for a shaft you can guarantee barely moves between samples. A level reading gives channel B's state at the sampling instant, not which channel led, so above a crawl the direction it reports flips without relation to the real motion. The phase comparison must happen at edge timing in hardware; sampled levels cannot reproduce it.

Does this input choice matter at low speed?

The frequency limit stops mattering and resolution takes over. For example, a 60 cycle encoder decoded four-edge at 60 rpm delivers 240 counts per second, so a 0.1 s window steps in about 2.5 rpm increments. Direction decoding still requires quadrature hardware, and a scanned input still drops states whenever the shaft reverses, so the input choice does not go away.

What if the I/O family has no incremental encoder module at all?

Three paths keep the measurement. Put a dedicated encoder interface or motion controller with encoder inputs in front of the existing I/O and pass it a signed value. Use a converter that turns the quadrature signal into an output your I/O already accepts. Or switch to an absolute encoder whose interface the controller supports, taking speed from consecutive position differences.

Keep reading

  • How-to

    Sizing a Spindle Encoder Input for Servo Feed Control

    A 2000 PPR quadrature encoder on a 250 RPM spindle produces 33,333 counts/s, which fits a 50 kHz counter but overruns a 10 kHz variant; the most resolution that counter family allows is 3000 PPR. Scale feed per revolution to motor RPM through screw lead and gear ratio, then keep command pulses per revolution low enough that rapid speed stays under the 100 kHz pulse-output ceiling.

    Sensors, encoders and machine vision on the machine

  • How-to

    Counting Encoder Pulses on a PLC Without Losing Position

    Count encoder pulses with a hardware high-speed counter input wired for quadrature, never with a count instruction in the scan. At 214 rpm and 75 pulses per revolution the encoder delivers 267.5 pulses per second, one every 3.7 ms, while a 10 ms scan cannot guarantee seeing even one in three. Zero the counter at a reference switch and treat every target as counts from that switch.

    Sensors, encoders and machine vision on the machine

  • Explainer

    Matching an incremental encoder to a PLC high speed counter

    Choose the counter mode before you touch a wire: single-channel counting turns a 1000 P/R encoder into 1000 counts per revolution, while quadrature x4 turns the same encoder into 4000. Then verify the encoder's output circuit — driver type, polarity and common — against the counter input's voltage class and wiring terminals from the PLC manual.

    Sensors, encoders and machine vision on the machine