Configuring S7-1200 HSC for Kübler Limes LI20 Linear Encoder

David Krause13 min read
S7-1200SiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Field reference: integrating a Kübler Limes LI20 magnetic linear encoder (model 8.LI20.1121.2020) with a Siemens SIMATIC S7-1200 high-speed counter in TIA Portal. This guide documents the wiring, the technology-object configuration, the A/B vs A/B fourfold selection logic, the impulse-to-length conversion math, and a homing procedure that survives power-cycle.

Overview

The Kübler Limes LI20 is a non-contact magnetic linear encoder used for direct linear position feedback. The 8.LI20.1121.2020 variant emits a 25 µm pulse period on a quadrature A/B output, with an additional zero/reference pulse for absolute referencing. When the encoder is mounted to read the linear travel of a load carried on a rotating circular plate, the S7-1200 HSC samples the A/B edges, multiplies by the fold factor, and the user program converts the resulting integer count into a floating-point distance in mm or m.

The Siemens application entry "How do you realize Length and Speed Measurement using High Speed Counters of SIMATIC S7-1200?" (entry ID 109754525) confirms the fourfold quadrature approach as standard practice for incremental encoders, and the S7-1200 System Manual documents the technology object and CTRL_HSC instruction used here.

Kübler Limes LI20 Encoder Specifications

Relevant specifications for the 8.LI20.1121.2020 variant, cross-referenced against the Kübler Limes LI20 leaflet:

Parameter Value Notes
Measurement principle Magnetic, single-track Pole pitch 2 mm
Pulse period 25 µm (typical) 1000 cycles per 25 mm physical travel
Output signals A, /A, B, /B, 0, /0 Differential push-pull (HTL)
Output level HTL 10–30 V Segment "11" in part number = 10–30 V HTL
Maximum frequency 25 kHz (HTL) Scales with mechanical speed
Resolution selectable 25 µm / 50 µm / 100 µm Suffix "2020" = 25 µm
Zero/reference pulse 1 per travel length Width depends on magnet spacing
Operating temperature –40 °C to +85 °C Magnetic read head
Protection class IP67 Sealed housing
Supply voltage 10–30 VDC Encoder power

The differential outputs require twisted-pair cabling to maintain noise immunity on industrial panels. Use shielded cable with the drain terminated at the encoder end and at the PLC end to a grounded shield bar.

Critical: Never power the encoder from the same 24 V rail that feeds VFD brake coils or DC contactors. Use a dedicated regulated 24 VDC supply, or an isolated DC-DC converter, to prevent counter drift from inductive kickback.

S7-1200 HSC Hardware Requirements

The S7-1200 provides up to six HSC channels on the CPU. HSC1 is the most commonly used for linear measurement because it is mapped to the fastest digital inputs on most CPU variants. Input assignment is fixed by channel:

HSC Channel Default Digital Input Pins Max Count Frequency (FW 4.4)
HSC1 I0.0 (A), I0.1 (B), I0.2 (Z/zero), I0.3 (gate) 200 kHz
HSC2 I0.4, I0.5, I0.6, I0.7 200 kHz
HSC3 I1.0, I1.1, I1.2, I1.3 200 kHz
HSC4 I2.0, I2.1, I2.2, I2.3 200 kHz
HSC5 I3.0, I3.1, I3.2, I3.3 200 kHz
HSC6 I4.0, I4.1, I4.2, I4.3 200 kHz

CPU hardware input filters must be disabled or set to the minimum value on HSC pins; the default 6.4 ms filter will corrupt encoder signals above ~75 Hz. Navigate to Device configuration → Digital inputs → Filter and set the HSC pins to 0.1 µs or the minimum the firmware exposes.

For applications that exceed CPU HSC count rates, attach a TM PTO/HSC signal board or use an SM 1278 high-speed counter module.

Wiring and Signal Termination

Wire the LI20 outputs to the S7-1200 HSC inputs as follows:

LI20 Wire Color (typical) Signal S7-1200 Terminal
Brown +24 V supply 24 V terminal block
Blue 0 V (GND) M terminal block
Green Signal A I0.0 (HSC1 A)
Yellow Signal /A Optional (line receiver)
White Signal B I0.1 (HSC1 B)
Gray Signal /B Optional (line receiver)
Pink Reference 0 I0.2 (HSC1 Z) — optional
Red Reference /0 Not connected
Black Shield/drain Ground bar, PE

For single-ended HTL operation (cost-optimised), connect only A, B, and the supply. Differential wiring is preferred on long cable runs (>5 m) or in VFD environments. Place a 1 kΩ pull-down at the PLC input if the encoder driver cannot sink the full 24 V.

TIA Portal Project Setup and HSC Configuration

  1. Create a new TIA Portal project and add the S7-1200 CPU that matches your hardware (e.g., CPU 1214C DC/DC/DC with firmware 4.4 or later).
  2. Open the device configuration and disable the input filter on the HSC pins.
  3. In the project tree, expand Technology objects → Add new object → High_Speed_Counter → HSC_1.
  4. Select the HSC channel that matches the input wiring (HSC1 by default).
  5. Set the operating mode to A/B counter fourfold (see selection logic in the next section).
  6. Configure the initial count value, gate control, and interrupt behaviour as required.
  7. Compile and download the hardware configuration.

If using a signal board or SM 1278, the HSC instance number is reassigned automatically. The IDB associated with HSC1 is the technology object DB (default name HSC_1_DB), and the count value is accessible as %ID1000 in the default instance-DB layout.

A/B vs A/B Fourfold Mode Selection

TIA Portal exposes four operating modes for HSC:

Mode Description Counts per pulse cycle Recommended for LI20
Single phase Counts A only, direction from internal flag 1 No
Two phase Counts both phases, direction from phase order 2 No
A/B counter Quadrature, counts A and B on rising edges 2 Possible
A/B counter fourfold Quadrature, counts A and B on all edges 4 Preferred

The Kübler LI20 emits true quadrature A/B signals with nominal 50/50 duty cycle. Both "A/B counter" and "A/B counter fourfold" are electrically valid. The fourfold mode quadruples the count density and therefore improves the effective resolution:

Resolution_eff = Pulse_period / Fold_factor

With a 25 µm pulse period the effective resolution is 6.25 µm = 0.00625 mm.

Caveat: Fourfold mode is only safe if the encoder guarantees a 50/50 mark-space ratio on both channels. Magnetic encoders with coarse pole pitch may have slight asymmetry. Verify on a stationary encoder that the count does not drift when the scale is at rest. If drift is observed, fall back to "A/B counter" (2× mode), which uses only the rising edges and tolerates wider mark-space tolerance.

Conversion Mathematics

Define:

  • N = integer count read from HSC IDB (DInt, %ID1000 for HSC1)
  • P = pulse period (m/pulse cycle) = 25 × 10⁻⁶ m = 0.000025 m
  • F = fold factor = 4 for fourfold, 2 for A/B

The physical distance traveled is:

D [m] = N × (P / F)

Numerical form for the fourfold, 25 µm case:

D [m] = N × (0.000025 / 4) = N × 0.00000625
D [mm] = N × 0.00625

N (counts) Distance (mm) Distance (m)
0 0.0 0.0
1 600 10.0 0.010
16 000 100.0 0.100
160 000 1 000.0 1.000
1 600 000 10 000.0 10.000

DInt range is –2 147 483 648 to +2 147 483 647. At 0.00625 mm/count this corresponds to ±13 421 km of signed travel before overflow — practical lifetime is constrained by encoder length, not counter width.

Always perform the conversion in floating-point to avoid cumulative integer truncation. Multiply by 0.00625 (REAL literal) in SCL or load the constant in a global DB.

SCL Sample Code and Homing Routine

Place the following SCL function block in the S7-1200 program. It reads HSC1, converts to mm and m, and exposes a homing flag with edge detection.

FUNCTION_BLOCK "FB_LinearPosition"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1

VAR_INPUT
    bExecute       : BOOL;    // TRUE = run, FALSE = freeze
    bHomeRequest   : BOOL;    // rising edge → reset count to 0
END_VAR

VAR_OUTPUT
    rPosition_mm   : REAL;    // distance in millimeters
    rPosition_m    : REAL;    // distance in meters
    diRawCount     : DINT;    // raw integer count
    bHomeDone      : BOOL;    // homing complete flag
END_VAR

VAR
    bHomeTrig      : BOOL;    // edge memory for home request
END_VAR

BEGIN
    // 1. Read raw count from HSC technology object IDB
    diRawCount := "HSC_1_DB".CountValue;

    // 2. Convert to mm and m
    // Pulse period 25 µm / 4 fold = 6.25 µm = 0.00625 mm per count
    rPosition_mm := DINT_TO_REAL(diRawCount) * 0.00625;
    rPosition_m  := rPosition_mm / 1000.0;

    // 3. Homing on rising edge of bHomeRequest
    IF bHomeRequest AND NOT bHomeTrig THEN
        "HSC_1_DB".CountValue := 0;
        bHomeDone := TRUE;
    ELSE
        bHomeDone := FALSE;
    END_IF;
    bHomeTrig := bHomeRequest;

    // 4. Freeze output when not executing
    IF NOT bExecute THEN
        rPosition_mm := 0.0;
        rPosition_m  := 0.0;
    END_IF;
END_FUNCTION_BLOCK

If the legacy CTRL_HSC instruction is preferred (CPU firmware < 4.2), the count value is still read from the assigned IDB address (typically %ID1000 for HSC1). Configuration is done via the CTRL_HSC input pins rather than the TO configurator. The conversion math is identical.

Homing Procedure

The HSC counter does not retain its count across power-cycle, and the linear encoder itself is incremental only (absolute when the zero pulse is used). Two homing strategies are commonly applied:

Strategy A — Software homing (recommended for LI20)

  1. Drive the actuator at low speed toward the mechanical home position.
  2. A limit switch or proximity sensor wired to a digital input (e.g., I0.4) signals the home reference.
  3. On the rising edge of the home switch signal, write 0 to the HSC count value via the TO IDB or a CV bit on CTRL_HSC.
  4. Drive the actuator at low speed off the home switch (rising edge → falling edge) to begin measurement from a known offset.

Strategy B — Zero-pulse homing

  1. Use the LI20 reference pulse (output 0) wired to the HSC Z input.
  2. Enable "Count only with zero signal" in the TO so the count is held outside the reference window.
  3. On the falling edge of the reference pulse, latch the position. The reference pulse appears once per encoder length; repeatability is therefore limited to the encoder length.

For a rotating circular plate that has only partial encoder coverage (e.g., 1 m of LI20 strip wrapped around the circumference), software homing with an external switch is the only viable choice.

Verification and Commissioning Checklist

  1. With the encoder at rest and the HSC running, monitor %ID1000 in the TIA Portal watch table. The value must be stable; any drift > 1 count/second indicates noise pickup or filter mismatch.
  2. Move the carriage by a known distance (caliper-measured). Compare the HSC count × 0.00625 with the measured distance. Acceptable tolerance: ±2 counts (±12.5 µm at 25 µm/4).
  3. Verify direction: rotate the disc in the "positive" mechanical direction and check that the count increases when "A/B counter fourfold" mode is active. If the count decreases, swap A+ and B+ wiring at the PLC terminals.
  4. Power-cycle the CPU. Verify that bHomeRequest is required after restart and that the FB correctly resets the count.
  5. Run at maximum mechanical speed and confirm that the count value changes smoothly without skipped counts. Skipped counts usually indicate filter activation on the HSC pins — return to Device configuration and disable the input filter.
  6. Verify against the Siemens online diagnostics: in the TIA Portal HSC technology object, the Status tab shows the current count, error flags, and overflow status. Use this as the authoritative commissioning readout.

Troubleshooting Matrix

Symptom Probable cause Corrective action
Count always 0 Encoder not powered, or signal on wrong input pin Check 24 V supply, verify wiring to I0.0/I0.1
Count increments only on one direction Mode set to single phase or quadrature but only A connected Switch to "A/B counter" mode and verify both A and B wired
Count drifts when encoder stationary Input filter too long, or electrical noise Set HSC pins filter to 0.1 µs, add 1 kΩ pull-down, check shield termination
Count direction reversed A/B order wrong Swap A and B wires at PLC terminal
Resolution appears half of expected Set to "A/B counter" instead of fourfold Change operating mode in TO configuration
Counter overflows Travel exceeds DInt range, or encoder pulses per mm mis-set Verify 0.00625 mm/count, check for physical overtravel
Homing does not reset bHomeTrig edge not detected Latch bHomeRequest in a separate bit, debug with watch table
Position jumps by 1 mm randomly Loose encoder mounting, mechanical backlash Tighten encoder mount, add mechanical preload
"HSC" technology object missing in TIA Portal TIA Portal version below V14, or missing HSP Upgrade to V16+ with HSP for CPU firmware 4.x
Count lags actual position OB1 cycle time too long for fast-moving actuator Move HSC read to a fast OB (e.g., OB30) or use hardware interrupt
Direction toggles at zero pulse Zero pulse incorrectly interpreted as count pulse Disable Z-input gating in TO, or filter zero pulse hardware input

Measuring Velocity from the HSC Count

To compute instantaneous velocity from the HSC count, sample the count in a fixed time base (e.g., every 100 ms in a cyclic interrupt OB30) and apply:

v [mm/s] = (N_now – N_prev) × 0.00625 / dt

Use a 32-bit LREAL for the result to avoid truncation at low speeds. Average over 4–8 samples to suppress jitter when the count delta is small. This produces a usable velocity signal for PID control of the disc rotation; pair with a Siemens PID_Compact instance if closed-loop control is required.

Firmware and Compatibility Notes

The TIA Portal HSC interface has been revised between firmware 4.0 and 4.4. Earlier firmware (4.0, 4.1) exposes a smaller subset of the technology object and the fourfold mode is present but the zero-pulse handling differs. CPU firmware 4.4 or later is recommended for new installations because it increases HSC count rates to 200 kHz on all HSC channels and adds the enhanced zero-pulse evaluation described in the Siemens S7-1200 System Manual.

If the CPU firmware is below 4.2, the legacy CTRL_HSC instruction must be used. Conversion math and wiring are identical.

FAQ

What is the difference between "A/B counter" and "A/B counter fourfold" in TIA Portal?

"A/B counter" evaluates only the rising edges of channels A and B, generating 2 counts per pulse cycle. "A/B counter fourfold" evaluates both rising and falling edges of both channels, generating 4 counts per cycle. Fourfold mode gives better resolution (6.25 µm vs 12.5 µm with a 25 µm LI20) but requires that the encoder maintain a 50/50 mark-space ratio.

Why does the LI20 datasheet show 25 µm resolution but the count value increments in 6.25 µm steps?

The 25 µm value is the pulse period of the scale (one A cycle plus one B cycle together). The fourfold HSC multiplies the apparent resolution by 4, so each count now represents 25 µm / 4 = 6.25 µm. The physical encoder is unchanged; the PLC simply extracts more edges per unit travel.

Do I need to wire the /A and /B differential outputs of the LI20?

Not strictly. S7-1200 HSC inputs are single-ended 24 V. For cable runs under 5 m in low-noise panels, single-ended A/B wiring works reliably. For long cable runs or VFD environments, use a Siemens differential receiver or wire the /A, /B signals to a third-party line receiver.

Where can I find the official Siemens documentation for HSC on S7-1200?

The S7-1200 System Manual (latest revision) and the Siemens KB article "How do you realize Length and Speed Measurement using High Speed Counters of SIMATIC S7-1200?" (entry ID 109754525) cover the HSC operating modes, configuration, and conversion formulas in detail.

What is the maximum linear travel I can measure with a DInt count and the fourfold mode?

DInt counts from –2 147 483 648 to +2 147 483 647. At 0.00625 mm per count the signed travel range is ±13 421 km. Practical travel is limited by the encoder strip length and the mechanical system, not by the counter width.

How do I reverse the count direction without rewiring the encoder?

Swap the A and B signal wires at the PLC terminal block only. The encoder itself does not need to be touched. Alternatively, configure the HSC technology object to invert the direction through the "Count direction" parameter if the firmware exposes that option (4.4+).

My HSC count drifts by a few counts per minute when the encoder is stationary. What should I check?

Most likely cause: the default digital input filter is enabled. Open Device configuration → Digital inputs → Filter and set the HSC pin filter to the minimum value (typically 0.1 µs or "none"). Other causes: noise on the 24 V supply, missing shield termination, or improper ground reference between encoder and PLC.

Back to blog