S7-1200 HSC for Hengstler Encoder: Fixing Zero Count and Wiring

David Krause14 min read
S7-1200SiemensTroubleshooting
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

1. Problem Statement

An Siemens S7-1214C is wired to a Hengstler RI58-O/5000EK.42KB incremental encoder (5000 pulses per revolution) on HSC1. The configuration in TIA Portal uses:

  • Type of counting: Count
  • Operating phase: A/B counter (also tried A/B counter fourfold)
  • Counting direction: Count Up
  • Wiring: channel A → I0.0, channel B → I0.1

The application reads the HSC value through input address %ID1000 and compares it to 500 in OB1 to set Q0.2. When the encoder shaft is rotated, the tag does not increment through the expected 5000/20000 count range. Instead, the value toggles between 0, -1, and -2, occasionally flickering.

Engineering interpretation: A count that drifts between 0, -1, and -2 at rest is the classic signature of (a) the default digital input filter stripping real encoder pulses while (b) electrical noise on the A/B lines causes the quadrature decoder to register phantom transitions. The HSC is alive, the firmware is counting, but the input stage is removing the real edges and feeding the decoder with crosstalk.

2. Hardware Identification

2.1 CPU 1214C High-Speed Counter Resources

The S7-1214C DC/DC/DC (firmware 4.x) provides six onboard HSCs with fixed input assignments. The first four HSCs use the onboard 24 V DC inputs and are usable without any signal board:

HSC Phase A Phase B Phase Z (Home) Max Frequency (1x/4x)
HSC1 I0.0 I0.1 I0.2 100 kHz / 80 kHz
HSC2 I0.3 I0.4 I0.5 100 kHz / 80 kHz
HSC3 I0.6 I0.7 I1.0 100 kHz / 80 kHz
HSC4 I1.0* I1.1* I1.2* 100 kHz / 80 kHz
HSC5 I1.3 I1.4 I1.5 100 kHz / 80 kHz

* HSC3 and HSC4 share I1.0 on the 1214C; do not enable both with overlapping edges.

For the present application, the encoder is correctly wired to I0.0 (A) and I0.1 (B), which is the canonical HSC1 pinout. The 1214C HSC supports up to 100 kHz single-phase and 80 kHz quadrature, well above the 1.4 kHz theoretical limit of a 5000 PPR, 4x encoder running at 240 RPM.

2.2 Hengstler RI58-O/5000EK.42KB Decoder

The Hengstler RI58 is a 58 mm industrial shaft encoder. The part number breaks down as follows:

Field Value Meaning
RI58 Series Industrial shaft, 58 mm housing
O Shaft style Solid shaft (Ø10 mm typical)
5000 PPR 5000 pulses per revolution (1x evaluation)
EK Output stage Push-pull (HTL) 24 V DC output, short-circuit proof
.42 Connection Cable gland axial (radial option: .41)
KB Cable length Standard cable output, length suffix depends on ordering code
Signal-level match: The "E" output stage on the RI58 is a 24 V DC push-pull driver, which is the correct interface for the S7-1200 HSC inputs (24 V sourcing, IEC 61131-2 Type 1). If the encoder had been supplied with the "S" or "F" output (RS422 / 5 V TTL), it would not interface directly with HSC inputs without an interposing signal conditioner. Always verify the data sheet ordering code matches the electrical environment of the PLC.

3. Wiring and Shielding Best Practices

The encoder must be wired with a twisted-pair shielded cable. The RI58EK cable assigns the following conductors (Hengstler standard colour code):

Wire Colour Signal 1214C Terminal
Brown +UB (24 V DC) 24 V sensor supply (or external PSU)
Blue 0 V (GND) M terminal on CPU
Black Channel A I0.0
White Channel B I0.1
Pink Channel Z (Home / Index) I0.2 (if used)
Yellow/Green Drain wire Ground bar (one end only)
  • Connect the cable shield at the cabinet entry only using a 360° EMC gland; do not ground the encoder end if the housing is not isolated.
  • Keep the encoder cable at least 200 mm from VFD motor cables and cross at 90° when unavoidable.
  • Verify that the encoder 24 V supply is referenced to the same 0 V as the CPU M terminal; floating supplies cause quadrature jitter.

4. TIA Portal HSC Configuration

4.1 Enable and Mode Selection

Open the device view in TIA Portal, select the CPU 1214C, and navigate to Properties → High-speed counters (HSC). Expand HSC1 and enable the function:

  1. Set Function enable = Enable.
  2. Set Type of counting = Count (or Frequency if you prefer the firmware to derive speed directly).
  3. Set Operating phase = A/B counter fourfold (preferred for 5000 PPR — 4x evaluation quadruples resolution to 20,000 counts/rev).
  4. Set Counting direction = Count up if shaft rotation is mechanically fixed; Count up / down (hardware gate via B-direction input) if direction can reverse.
  5. Set Initial count value = 0.
  6. Set Initial reference value = 0.

4.2 Input Address Assignment

Under Hardware input, confirm the input address. The default for HSC1 is %ID1000 (DINT, 32-bit signed). If you have additional HSCs configured, Siemens increments this address automatically. Use this tag as the source for the count.

Do not read the count from the process image at %I0.0 / %I0.1. The HSC maintains its own hardware register; the inputs I0.0/I0.1 are consumed by the HSC firmware and no longer appear as ordinary digital inputs once the HSC is enabled.

5. Root Cause: The Default Input Filter

The single most common reason an S7-1200 HSC fails to count encoder pulses is the digital input filter. By default, every standard digital input on the 1214C is set to a filter time of 6.4 ms (firmware 4.0 and later). At 6.4 ms the filter rejects any pulse shorter than ~78 µs, which means:

Filter Time Max Counted Frequency Max RPM @ 5000 PPR (4x)
6.4 ms (default) ~78 Hz <1 RPM
3.2 ms ~156 Hz ~2 RPM
0.8 ms ~625 Hz ~7 RPM
0.4 ms (HSC preset "high-speed") ~1.25 kHz ~15 RPM
0.1 µs (HSC preset, hardware-dependent) 100 kHz ~300 RPM (limit: 80 kHz @ 4x)

With the 6.4 ms filter active, the HSC sees only noise from the input stage and counts random quadrature transitions, producing exactly the 0 / -1 / -2 behaviour reported in the field case.

5.1 Correcting the Filter

  1. In TIA Portal, navigate to Device view → CPU → Properties → Digital inputs.
  2. Select channels I0.0, I0.1, and I0.2 (the channels assigned to HSC1).
  3. In the inspector pane, change Input filter from the default to HSC preset (sometimes labelled high-speed counter or 10 µs depending on firmware).
  4. Compile and download the hardware configuration. Re-test by manually rotating the encoder shaft at low speed; the count should advance smoothly.
For firmware 4.4 and later, the input filter for HSC-assigned channels must be set explicitly. The dropdown shows only the values the CPU firmware can support; choosing anything other than the high-speed preset will cause HSC under-counting or total failure at low RPM.

6. Quadrature Mode and Effective Resolution

Selecting A/B counter fourfold makes the firmware count on every edge of channels A and B (four events per physical pulse period). The effective resolution becomes:

Effective_counts_per_rev = PPR × 4

For 5000 PPR:

  • 1x mode: 5,000 counts/rev
  • 2x mode: 10,000 counts/rev
  • 4x mode: 20,000 counts/rev (recommended)

The relationship between shaft RPM and the HSC pulse rate at 4x evaluation is:

f_pulse = (RPM × PPR × 4) / 60

At a typical conveyor speed of 60 RPM, fpulse = 60 × 5000 × 4 / 60 = 20,000 Hz, comfortably below the 80 kHz 4x limit.

Quadrature A/B signals (4x evaluation) A B 1 2 3 4 1 2 3 4 1 2 3 Edges 1,2,3,4 are counted in 4x mode → 20,000 counts / rev In 1x mode only edges 1 are counted → 5,000 counts / rev

7. Reading the HSC Value in OB1

Once HSC1 is enabled and the input filter is set to the high-speed preset, the count is exposed at the configured input address. Read it directly in OB1 (or any cyclic OB) and store it in a DINT tag:

// SCL - read HSC1 count
"HSC1_Count_Value" := "HSC_1";   // direct read of configured input address %ID1000

For debugging, drop the value on a watch table or directly into a comparator:

// SCL - debug comparator
IF "HSC1_Count_Value" = 500 THEN
    "Debug_Q0_2" := TRUE;
END_IF;

With the input filter corrected, manually turning the shaft one full revolution should advance HSC1_Count_Value by 20,000 in 4x mode (or 5,000 in 1x mode). If it does not, re-check the wiring and the filter.

8. Calculating RPM from the HSC Count

8.1 Counting-Mode Speed Calculation

To calculate shaft speed in RPM, sample the HSC count periodically and divide the delta by the sampling interval:

RPM = (ΔCounts / ΔT_seconds) × (60 / (PPR × 4))

Where ΔCounts is the difference between the current sample and the previous sample, ΔT is the sampling interval in seconds, and the divisor is the effective counts per revolution (PPR × 4 in 4x mode).

// SCL - periodic RPM calculation in OB1
// Sample every 1 second using a cyclic interrupt OB (OB30..OB38)
IF "Sample_1Hz".Q THEN
    "Sample_1Hz"(IN := FALSE);

    // Capture current HSC value
    "CurrentCount" := "HSC_1";
    "DeltaCount"  := "CurrentCount" - "LastCount";
    "LastCount"   := "CurrentCount";

    // RPM with 5000 PPR, 4x evaluation, 1 s sample
    "Encoder_RPM" := (INT_TO_REAL("DeltaCount") / 20000.0) * 60.0;

    // Linear conveyor speed in m/min
    // Wheel diameter 160 mm -> circumference = π × 0.160 m
    "Conveyor_m_per_min" := "Encoder_RPM" * 3.14159265 * 0.160;
END_IF;

"Sample_1Hz"(IN := TRUE, PT := T#1s);
Selection of sampling interval: A 1 s sample at 60 RPM gives ΔCounts ≈ 20,000, which yields acceptable resolution (1 RPM per 333 counts). At very low RPM (e.g., 5 RPM) the same 1 s interval produces only ΔCounts ≈ 1,667 — still fine. Below ~0.5 RPM, extend the sample interval to 5 s or 10 s to keep the calculation numerically stable.

8.2 Frequency-Mode Speed Calculation

Alternatively, configure HSC1 in Frequency mode and let the firmware return pulses per second directly:

  1. Set Type of counting = Frequency.
  2. Set Time base = 1.0 s (longer = better resolution at low speed, shorter = faster update).
  3. Set Operating phase = A/B counter fourfold.

The HSC returns a DINT in Hz at the configured input address:

// SCL - RPM from frequency mode
"HSC1_Frequency_Hz" := "HSC_1";   // value in pulses per second

// At 4x evaluation: counts per rev = 20000
"Encoder_RPM" := "HSC1_Frequency_Hz" / 20000.0 * 60.0;

Frequency mode removes the need for a cyclic timer and an internal "last count" variable, but the time base dictates the trade-off between resolution and response.

8.3 Conveyor Mechanics

If the encoder is mounted on a 160 mm conveyor pulley driving an axis of 25 mm (e.g., a roller), the mechanical ratio is:

i = Ø_conveyor / Ø_axis = 160 / 25 = 6.4

If the encoder is on the conveyor wheel, axis RPM = encoder RPM × i. If it is on the axis, conveyor RPM = encoder RPM / i. Linear belt speed is then:

v [m/min] = RPM × π × D [m]

Encoder Mounted On Conveyor RPM Belt Speed (m/min)
160 mm pulley (direct) = encoder RPM = RPM × 0.5027
25 mm axis (indirect) = encoder RPM / 6.4 = (RPM / 6.4) × 0.5027

9. Alternative: Motion Control Technology Object

For applications where the conveyor speed ultimately feeds into a position-controlled drive or where HMI/web-server integration is desired, the S7-1200 Motion Control technology object (TO_PositioningAxis) can consume the HSC directly. The motion control library exposes the current position and velocity without manual counting logic:

  • Add a new Technology object → Positioning axis → TO_PositioningAxis.
  • Under Configuration → Encoder → Encoder on high-speed counter (HSC), select the configured HSC and verify the filter times are still set correctly.
  • Configure Mechanics with the wheel diameter or leadscrew pitch.
  • Read <TO>.ActualVelocity and <TO>.ActualPosition from your user program.

Refer to the TIA Portal V21 documentation on encoder on HSC for the S7-1200 positioning axis for the exact property mapping, and the Siemens support article 109747174 for the configuration procedure.

Trade-off: The motion control TO adds a useful velocity output but also adds cyclic CPU load, a heartbeat requirement, and interdependencies that complicate small "just calculate RPM" applications. For a pure indicator or PID speed setpoint, count or frequency mode is lighter weight.

10. Commissioning Verification

Use this checklist to validate the HSC encoder on the 1214C before commissioning the conveyor logic:

  1. Power check: Verify +UB at the encoder terminals is between 10 V DC and 30 V DC and 0 V is bonded to the CPU M terminal.
  2. Wiring check: A on I0.0, B on I0.1, Z (if used) on I0.2. No cross-over.
  3. Filter check: Inspect CPU properties → Digital inputs → I0.0/I0.1/I0.2 → Input filter; confirm the HSC preset is selected.
  4. Online watch: Add HSC_1 (%ID1000) to a watch table. Manually rotate the encoder shaft by exactly one revolution. The value should advance by 20,000 (4x mode) or 5,000 (1x mode).
  5. Direction check: Note the sign convention. If rotation in the "production forward" direction decrements the count, swap channels A and B or change the count direction in the HSC configuration.
  6. High-speed verification: Drive the conveyor at rated speed and confirm the count rate in the PLC trace. At 80 RPM, 4x, you should see 80 × 5000 × 4 / 60 = 26,667 counts/s.
  7. Compare with hand-held tachometer: The calculated RPM should match the tachometer reading within ±2% at steady state.

11. Troubleshooting Matrix

Symptom Likely Root Cause Corrective Action
Count reads 0, -1, -2 at rest and does not advance Default 6.4 ms input filter stripping real pulses; only noise passes Set I0.0/I0.1 input filter to HSC preset; recompile; download
Count advances but value is exactly wrong by 4x or 1x factor Operating phase set to 1x but calculations assume 4x Either change operating phase to A/B counter fourfold or divide calculated RPM by 4
Count decrements during forward rotation Encoder channel A and B swapped, or direction bit inverted Swap A/B wiring or set count direction = Count down
Count drifts while shaft is stationary Electrical noise, floating encoder supply, broken shield Bond 0 V at both ends (or use single-point ground); re-route cable away from VFD
Count is correct at low RPM but reads zero above ~15 RPM Input filter still too slow; or signal board conflicts with HSC Re-check filter preset; confirm no HSC conflict with signal-board DI channels
HSC1 configured but input address %ID1000 reads 0 and force table has no effect HSC not actually enabled, or firmware version does not support function Verify Function enable = Enable; verify CPU firmware ≥ V4.0 (some features need V4.2+)
Count occasionally wraps from positive to negative Count exceeded 31-bit positive range; no CV/OV handling Reset count at known reference (home/Index channel Z on I0.2) or use DINT math with explicit modulo
Encoder is on a Signal Board DI but HSC does not start Signal-board DIs on 1214C cannot be used as HSC inputs Use onboard I0.0–I1.5 for HSC; reserve signal-board DIs for slow signals

Why does my S7-1200 HSC read 0, -1, or -2 instead of incrementing when the encoder turns?

The S7-1200 standard digital inputs default to a 6.4 ms filter, which strips out the fast encoder pulses and only passes noise. In TIA Portal, open the CPU properties, navigate to Digital inputs, select I0.0 / I0.1 (and I0.2 if used), and change the input filter to the HSC preset. Recompile and download. The count should immediately begin tracking the encoder shaft.

Which TIA Portal HSC mode should I choose for RPM measurement: Count or Frequency?

Count mode gives you a position you can sample at a known time interval; Frequency mode returns a value in Hz directly, computed by the HSC firmware using the time base you specify (e.g., 1.0 s). Frequency mode is simpler because you no longer need a "last count" variable and timer in OB1, but Count mode gives full flexibility for position-based logic and lets you increase the sampling interval for low-RPM accuracy.

What is the maximum RPM my 5000 PPR encoder can reach on HSC1?

The 1214C HSC1 supports up to 80 kHz in 4x quadrature. At 5000 PPR and 4x evaluation (20,000 counts/rev), the theoretical limit is 80,000 / 20,000 × 60 = 240 RPM. In 1x mode (5,000 counts/rev), the limit rises to 1,200 RPM. Always stay below 80 % of the rated maximum for production margin.

Can I use the signal-board digital inputs (SB) as HSC inputs on the 1214C?

No. On the 1214C, only the onboard digital inputs I0.0 through I1.5 can be assigned to the high-speed counters. Signal-board and SM digital inputs are too slow for HSC and must be reserved for normal-purpose signals.

How do I read the HSC value in my user program?

Use the input address configured in TIA Portal (default: %ID1000 for HSC1). In SCL, assign it to a DINT tag with "TagName" := "HSC_1";. Do not read the underlying I0.0/I0.1 process image — once the HSC is enabled, those inputs are owned by the HSC firmware and no longer reflect raw state in the process image.

Back to blog