PLC Simulator
plc programming
encoder
motion
high speed counter
dialects
examples

PLC Encoder Programming Examples: Delta, Siemens, Allen-Bradley, Mitsubishi

By PLC Simulation Software12 min read

PLC Encoder Programming Examples: Delta, Siemens, Allen-Bradley, Mitsubishi

TL;DR: Every PLC platform provides a High-Speed Counter (HSC) function that counts encoder pulses independently of the scan cycle. The counter register (DINT or INT) holds the current position in counts. You convert counts to engineering units by multiplying by the resolution (mm/count or degrees/count). Homing: jog to a reference switch, reset the counter to zero. Position output: compare the counter value against setpoints in ladder or structured text.

PLC encoder programming examples — Delta, Siemens, Allen-Bradley, Mitsubishi quadrature HSC

Encoder programming comes up in every motion application — conveyor length tracking, rotary indexing tables, cut-to-length systems, bottling line position tracking. The physics is the same regardless of PLC brand: an incremental encoder generates A/B quadrature pulses, the HSC module counts them in hardware, and the program reads the count register to know position. The syntax differs significantly across dialects. This post covers the four most-requested brands in detail.

Prerequisites: Encoder Connection to the PLC

Before writing a line of code, the hardware must be correct:

  1. Wiring: encoder A+ to HSC A input, A− to HSC A complement, B+ to B input, B− to B complement. Z (index) to the Z input if homing is needed. Brown = +24V or +5V supply (match encoder supply voltage). Blue = 0V. Use shielded cable; ground the shield at the PLC end only.

  2. Input type: high-speed encoder inputs on PLCs are NOT the same as standard digital inputs. They have dedicated hardware counter circuits. Connecting an encoder to a standard input and counting in the ladder program will miss pulses at anything above ~200 Hz. Always use the designated HSC terminals.

  3. Signal level: confirm whether your encoder outputs TTL (5V), HTL (24V), or RS-422 differential signals. Most PLC HSC inputs accept 24V HTL directly. 5V TTL encoders need a signal converter or a 5V-powered input terminal. RS-422 differential requires a differential input module or a dedicated high-speed counter module.

The interactive encoder animation shows A/B quadrature pulse output and direction logic — useful to verify your understanding before configuring the HSC.

Delta PLC — DHSCS, C235 (D0/D1 Series)

Delta PLCs use dedicated high-speed counter input terminals. On the DVP-14SS, the high-speed counter inputs are X0–X5. Counters C235–C244 are reserved for high-speed operation.

C235 is a 2-phase quadrature counter using X0 (A) and X1 (B). The counter value is stored in the paired data registers D90/D91 (32-bit) or accessed directly via DMOV C235 D100.

HSC enable ladder (IEC Structured Text ladder — Delta ISPSoft):

// Enable high-speed counter C235 (A/B quadrature on X0/X1)
LD   M1000       // Always-on special relay
OUT  C235 K0     // Enable C235, preset = 0 (unused for quadrature mode)

Reading position:

// Every scan: move the 32-bit HSC value to D100/D101
LD   M1000
DMOV C235 D100   // D100 = low word, D101 = high word

Convert counts to mm (1000 PPR encoder, 5 mm/rev ballscrew):

// Multiply count by resolution factor
// Resolution = 5000 µm / (1000 PPR × 4 quadrature) = 1.25 µm/count
// In integer arithmetic: D100 × 5 / 4000 = position in mm (scaled)
LD   M1000
DMUL D100 K5 D102   // D102/D103 = count × 5
DDIV D102 K4000 D104  // D104/D105 = position in mm (integer)

Position output — turn on output Y0 at 50–150 mm:

LD>= D104 K50    // position ≥ 50 mm
AND<= D104 K150  // position ≤ 150 mm
OUT  Y0

Homing sequence (Delta):

// STEP 1: Jog negative until home limit switch X10 activates
LD   M10        // Homing command bit
ANI  X10        // Home switch NOT active
OUT  Y10        // Jog motor negative (via VFD run/reverse)

// STEP 2: On home switch rising edge, reset counter
LD   X10
LDF  X10        // Falling edge (reached switch)
DRST C235       // Reset 32-bit counter to zero
RST  M10        // Clear homing command
SET  M11        // Set "homed" flag

Siemens S7-1200 — CTRL_HSC + Technology DB

Siemens S7-1200 and S7-1500 use the CTRL_HSC function block (or the Motion Control axis objects for advanced motion). For standalone encoder position feedback, the CTRL_HSC approach is simpler.

Hardware configuration: In TIA Portal, under the PLC device configuration, expand "High Speed Counters" and enable HSC1. Set counting mode to "A/B counter" for quadrature. Assign the I/O addresses (e.g. A phase = I0.0, B phase = I0.1). The configuration wizard creates a hardware interrupt OB (OB40) for the Z pulse if used.

Technology Data Block: TIA Portal generates a technology DB (e.g. HSC_1) with tags:

  • HSC_1.Status.CValue — current counter value (DINT)
  • HSC_1.Status.Dir — current direction (TRUE = forward)

CTRL_HSC in OB1 (Structured Text):

// Call CTRL_HSC every scan to update the position register
#tempStatus := "HSC_1_CTRL_HSC"(HSC := "HSC_1",
                                 CTRL_DIR := FALSE,
                                 CTRL_CV := FALSE,
                                 CTRL_PERIOD := FALSE,
                                 NEW_DIR := TRUE,
                                 NEW_CV := 0,
                                 NEW_PERIOD := 1000,
                                 BUSY => #hscBusy,
                                 STATUS => #hscStatus);

// Read position
#positionCounts := "HSC_1".Status.CValue;

// Convert to mm: 2500 PPR encoder, 10 mm/rev (10,000 µm / 10,000 counts)
// Resolution = 1 µm/count → position_mm = counts / 1000.0
#positionMm := INT_TO_REAL(#positionCounts) / 1000.0;

Position output — enable output Q0.0 between 100 mm and 200 mm:

IF #positionMm >= 100.0 AND #positionMm <= 200.0 THEN
    Q0.0 := TRUE;
ELSE
    Q0.0 := FALSE;
END_IF;

Homing (reset counter value via CTRL_HSC):

// On rising edge of home limit switch input
IF "HomeSwitch" AND NOT #prevHomeSwitch THEN
    #resetCV := TRUE;  // Request CV reset on next CTRL_HSC call
END_IF;
#prevHomeSwitch := "HomeSwitch";

// Inside CTRL_HSC call block, set CTRL_CV := TRUE and NEW_CV := 0
// when #resetCV is TRUE — this atomically resets the counter to zero.

Allen-Bradley CompactLogix — HSC Module / Motion Axis

Allen-Bradley CompactLogix systems handle encoder input in two ways:

1769-HSC module (standalone encoder counter, simpler):

Configure the 1769-HSC in RSLogix 5000 / Studio 5000 via the Module Properties:

  • Mode: X4 Quadrature (4× counting, recommended for best resolution)
  • Input A: channel 0 A terminal, Input B: channel 0 B terminal

Reading the counter:

// The HSC module provides a position tag automatically
// Tag name matches module address, e.g.: HSC:0:I.CH0Value (DINT)
positionCounts := HSC:0:I.CH0Value;

// Convert to mm: 1000 PPR × 4 = 4000 counts/rev, 5 mm/rev
// Resolution = 5.0 / 4000 = 0.00125 mm/count
positionMm := INT_TO_DINT(positionCounts) * 0.00125;

Position output in Ladder Diagram:

[GEQ]           [LEQ]               (OTE)
positionMm      positionMm          Output_Zone1
100.0           200.0

2. Motion Control (Kinetix drives with integrated encoder):

For servo axis applications, the encoder is wired to the Kinetix drive, not directly to the PLC. The drive connects over EtherNet/IP. In the Logix program, a MAPC (Move Axis with Position Control) instruction or MAP with MAAT/MASD handles position automatically. The current position is read from Axis.ActualPosition — already in engineering units (mm, degrees) per the axis scaling configuration.

Homing in Logix:

// Use MAHD (Move Axis Home Direct) or define a homing sequence
// using MAJ (jog) until home switch input, then MASD (stop) + MAFR (reset)
IF homeCommand THEN
    MAHD(Axis, Velocity:=10.0, Direction:=CW);  // Home to limit switch
END_IF;

Mitsubishi FX3U / iQ-R — C235/C251, DHSCS instruction

Mitsubishi FX3U high-speed counters are similar in concept to Delta. C235–C255 are the 32-bit high-speed counters. For quadrature (2-phase, 2-input), use C251 (X0/X1) or C252 (X2/X3).

Enable C251 in ladder:

LD   M8000      // Special relay — always ON
DDMOV K0 C251   // Enable C251, set to 0 (quadrature mode enabled automatically)

Use DHSCS to trigger an output at a setpoint (interrupt-driven, not scan-dependent):

// Set up: when C251 reaches 20000, activate Y0 (interrupt-driven response)
LD   M8000
DHSCS K20000 C251 Y0    // When count = 20000, Y0 turns ON immediately

Read position to data register:

LD   M8000
DMOV C251 D200   // D200/D201 = current 32-bit position

Position window (between 5000 and 15000 counts):

LD>= D200 K5000
AND<= D200 K15000
OUT  Y1

Homing on Mitsubishi FX:

// Jog until home switch X10
LD   M5         // Homing active
ANI  X10        // Home switch inactive
OUT  Y10        // Jog motor forward

// On home switch active: reset counter
LD   X10
DRST C251       // Reset to zero
RST  M5         // Clear homing flag
SET  M6         // Set homed flag

Resolution and Units Conversion

The formula to convert encoder counts to engineering units is:

distance (mm) = counts × (travel per revolution mm) / (PPR × 4)

Where PPR × 4 is the quadrature count per revolution (4× counting). Examples:

| Encoder PPR | Travel/rev | Counts/rev (4×) | Resolution (µm/count) | |---|---|---|---| | 500 | 5 mm (5 mm pitch ballscrew) | 2000 | 2.5 µm | | 1000 | 10 mm | 4000 | 2.5 µm | | 2500 | 25.4 mm (1 inch) | 10000 | 2.54 µm | | 5000 | 360° (rotary table) | 20000 | 0.018°/count |

For integer arithmetic PLCs: scale the resolution to avoid floating point. Example: if 1 count = 0.00125 mm, multiply by 1000 to work in micrometres (1 count = 1.25 µm). Store in a long integer, display to the HMI as mm/1000.

Frequently Asked Questions

Q: What is the maximum encoder speed my PLC can handle?

A: The maximum input frequency of the HSC input, divided by the encoder's counts per revolution (PPR × 4), gives the maximum RPM. Example: S7-1200 CPU HSC maximum = 200 kHz. With a 1000 PPR encoder (4000 counts/rev): max speed = 200,000 / 4000 × 60 = 3000 RPM. For higher speeds, use a dedicated HSC module (e.g. 1769-HSC for AB: up to 1 MHz).

Q: My encoder count jumps randomly. What causes this?

A: The three most common causes are: (1) electrical noise — add a 120 Ω resistor between A+ and A−, B+ and B− at the PLC end to ensure proper termination of the RS-422 differential line; ensure the cable shield is grounded at the PLC end only; (2) connecting to a standard digital input instead of the designated HSC input — the scan-based debounce filter in standard inputs causes missed or doubled counts; (3) mechanical coupling slop — a loose coupling between encoder and shaft introduces backlash that appears as count instability near reversal.

Q: Can I use one encoder signal for both a VFD and a PLC?

A: With an RS-422 differential output encoder, you can connect up to 8 receivers to the same differential pair (the RS-422 driver standard). Use a line driver with sufficient fan-out, or use a signal splitter/buffer. Do not try to share a single open-collector (HTL, NPN) encoder output between two destinations — the pull-up resistors will fight each other and corrupt the signal.


The interactive encoder sensor animation shows quadrature A/B pulse output and the direction detection logic — run it before configuring your HSC to build the mental model.

To go deeper on encoder selection, see incremental vs absolute encoder — it covers when each type is the right choice and the SSI/EnDat interfaces used with absolute encoders.

Share:X / TwitterLinkedIn

Practice this yourself in the simulator

3 scenarios free — no install, no credit card. Write real ladder logic against a live machine model.

Try the simulator free →

Related articles

sensors
encoder

Incremental vs Absolute Encoder: Position Feedback for PLC Applications

Incremental encoders output a pulse train — you count pulses to track relative position, but lose it on power loss. Absolute encoders output a unique digital word for every shaft position — position is retained across power cycles. Learn when to use each, how to wire them, and how PLCs read both types.

June 12, 2026 · 9 min read
analog
examples

Analog Input PLC Programming Examples (4 Worked, With the Maths)

Four fully worked analog input PLC programming examples: 4-20mA to PSI scaling (including the 4mA offset trap), tank level %, temperature with deadband, and valve % output. The maths shown, wiring noted, Allen-Bradley and Siemens dialect explained.

June 11, 2026 · 15 min read
ladder logic
examples

PLC Programming Examples and Solutions (with Ladder Logic)

Eight classic PLC programming examples with full ladder logic solutions and explanations — motor seal-in, timers, counters, traffic lights, tank control and star-delta.

June 7, 2026 · 10 min read