1. Overview
This reference covers configuring a Siemens SIMATIC S7-1200 CPU 1214C high-speed counter (HSC) for an Omron E6C2-CWZ5B incremental encoder (quadrature phases A and B, with index Z) using TIA Portal V11/STEP 7 Basic and the equivalent path in TIA Portal V21. The application produces a direction bit (count up / count down) and a linear speed reading in metres per second from a pulse-train source.
The HSC on the S7-1200 supports four operating modes:
- Single-phase count with internal direction control
- Single-phase count with external direction control
- Two-phase count (quadrature x1, x2, x4)
- Frequency measurement (the mode used for velocity)
For encoder-based speed measurement the HSC is configured for two-phase counting in frequency-measurement mode, where the firmware counts the number of HSC edges detected during a configurable integration window and writes that count to the HSC's process image address (ID1000 for HSC1 on the CPU 1214C).
2. Prerequisites
Before configuring, verify the following:
-
CPU: SIMATIC S7-1200 CPU 1214C DC/DC/DC (article number
6ES7214-1AG40-0XB0) or later DC/DC/DC variant. AC/DC/RLY variants have lower HSC limits and are not recommended for encoder inputs above 30 kHz. - Encoder: Omron E6C2-CWZ5B, NPN open-collector, 12–24 VDC, quadrature A/B + index Z. Confirm the PPR stamp on the encoder body (typical resolutions stocked: 100, 360, 500, 1000, 2000).
- Software: TIA Portal V11 with STEP 7 Basic V11 (for legacy controllers) or TIA Portal V17/V18/V19/V20/V21 for current firmware. The HSC configuration interface is functionally identical across versions.
- Wiring: Shielded twisted-pair cable, encoder case grounded at one end only, 24 VDC supplied to the encoder from the PLC's sensor power terminal.
- Load: Know the linear distance represented by one encoder revolution (wheel circumference, conveyor pitch, lead of a screw, etc.) so the counts-to-engineering-units conversion can be derived.
3. S7-1200 CPU 1214C HSC Hardware Limits
Selecting an HSC channel and an evaluation mode is constrained by the maximum input frequency of the CPU. For the CPU 1214C DC/DC/DC, the limits in the S7-1200 System Manual are:
| HSC channel | Single-phase max | Quadrature 1x / 2x | Quadrature 4x |
|---|---|---|---|
| HSC1 – HSC4 | 100 kHz | 100 kHz | 80 kHz |
| HSC5 – HSC6 | 30 kHz | 30 kHz | 20 kHz |
For an Omron E6C2-CWZ5B with 500 PPR at its rated 6,000 RPM mechanical limit, the maximum pulse frequency is 500 × 6000 / 60 = 50 kHz. With x4 evaluation, the effective count frequency is 200 kHz, which exceeds the 80 kHz HSC limit. Either de-rate the mechanical speed, select x1 evaluation, or move to an encoder with a lower PPR rating.
4. Omron E6C2-CWZ5B Encoder Specifications
| Parameter | Value |
|---|---|
| Supply voltage | 12 – 24 VDC ± 10 % |
| Current draw | ≤ 80 mA |
| Output type | NPN open collector (CWZ5B suffix) |
| Output phases | A, B, Z (index) |
| Response frequency | 50 kHz (resolutions ≤ 1000 PPR); 25 kHz (higher resolutions) |
| Shaft speed max | 6,000 RPM |
| Protection | IP65 (shaft seal) |
| Connection | Pre-wired cable, 2 m standard |
The NPN open-collector output sinks current to 0 V when active. To interface with the S7-1200 bi-directional inputs the encoder outputs are pulled up to 24 VDC through 4.7 kΩ resistors on each phase, then wired into the HSC input terminals on the CPU.
5. Wiring Diagram
The NPN open-collector outputs are pulled up to +24 V through 4.7 kΩ resistors at the PLC cabinet terminal block. The PLC inputs are bi-directional (IEC 61131-2 type 3) and register a logic 1 whenever the encoder transistor is OFF (line idles high). When the transistor switches ON, the input is pulled low.
6. TIA Portal HSC Configuration
The configuration procedure differs slightly between TIA Portal V11 (STEP 7 Basic) and TIA Portal V17/V21.
6.1 TIA Portal V11 / STEP 7 Basic
- Open the project and select the PLC device view.
- In the device properties, select Digital inputs.
- Click on the Input filter group and assign the inputs that will be used for HSC1 (default: I0.0 / I0.1).
- Switch to High-speed counter (HSC) in the same properties panel.
- Enable HSC1.
- Set Type of counting to Frequency measurement.
- Set Operating phase to Two-phase.
- Set Evaluation to x1, x2, or x4. For maximum resolution at low speed use x4, but check the frequency limit against the encoder's expected maximum pulse rate.
- Set the Measuring period (integration window). Typical values: 0.1 s for fast response, 1.0 s for smooth output.
- Assign the input terminals for channels A and B. The Z input can be left disabled if unused.
- Compile the hardware configuration and download to the CPU.
6.2 TIA Portal V17 / V21
The HSC can still be configured standalone via the CPU properties, but the recommended path for encoder-based motion is to use a positioning axis technology object that consumes the HSC. The relevant option is documented at Encoder on HSC (S7-1200) – TIA Portal V21 documentation:
- Add a new technology object → TO_PositioningAxis.
- In Basic parameters → Encoder, select Encoder via High Speed Counter (HSC).
- Choose the HSC channel (HSC1 – HSC6). The HSC must already be configured for quadrature counting.
- Set the filter times for both HSC input channels per the encoder signal quality.
- Define the mechanical configuration: distance per encoder revolution (e.g., π × wheel diameter for a wheel application).
7. CTRL_HSC Instruction
The CTRL_HSC instruction runs the HSC from user logic — typically OB1 (cyclic) or OB35 (cyclic interrupt). It is located in the instructions panel under Technology → Counting.
| Parameter | Type | Description |
|---|---|---|
HSC |
HW_HSC | HSC hardware identifier (e.g., HSC_1) |
DIR |
BOOL | 1 = count up, 0 = count down (for single-phase only; ignored in quadrature) |
CV |
BOOL | Rising edge sets the count to NEW_CV
|
RV |
BOOL | Rising edge sets the reference value to NEW_RV
|
PERIOD |
BOOL | Rising edge sets measurement period to NEW_PERIOD
|
NEW_CV |
DINT | New current value (initial count) |
NEW_RV |
DINT | New reference value (compare trigger) |
NEW_PERIOD |
INT | New measurement period in ms (only writable in frequency measurement mode) |
BUSY |
BOOL | Function busy |
STATUS |
WORD | Error code (0 = no error) |
For a static configuration (period and reference fixed in hardware setup), CV, RV, and PERIOD can be left unwired and only HSC is required.
8. Frequency Measurement Principle
The HSC firmware accumulates HSC edges within a sliding integration window of length Tperiod. At the end of each window, the count is written to ID1000 (for HSC1) as a DINT, then the accumulator is cleared for the next window.
The instantaneous frequency is therefore:
f (Hz) = ID1000 / T_period (s)
For example: Tperiod = 1.0 s, ID1000 reads 450 → f = 450 Hz.
9. Converting Counts to Engineering Units (m/s)
The conversion chain from raw count to linear speed follows:
-
Pulse frequency:
f = ID1000 / T_period -
Effective pulses per revolution depends on evaluation:
- x1:
PPR_eff = PPR - x2:
PPR_eff = 2 × PPR - x4:
PPR_eff = 4 × PPR
- x1:
-
Mechanical revolutions per second:
n = f / PPR_eff -
Linear speed:
v = n × d_per_rev
Where d_per_rev is the linear distance travelled per encoder revolution. For a wheel of diameter D this equals π × D.
9.1 Worked Example
| Encoder PPR | 500 |
| Evaluation | x4 → PPR_eff = 2000 |
| Measurement period | 0.1 s |
| ID1000 reading | 300 |
| f | 300 / 0.1 = 3000 Hz |
| Revolutions per second | 3000 / 2000 = 1.5 rps |
| Wheel diameter | 200 mm → circumference 628.32 mm |
| Linear speed | 1.5 × 628.32 = 942.48 mm/s = 0.942 m/s |
10. SCL Implementation
The following Structured Text (SCL) snippet reads HSC1 and converts to m/s. Place it in a function block that is called from OB1.
// FB_SpeedFromHSC1
FUNCTION_BLOCK "FB_SpeedFromHSC1"
VAR
HSC1_Count : DINT; // Raw count from ID1000
PPR : INT := 500; // Encoder PPR from nameplate
EvalFactor : INT := 4; // 1, 2, or 4
Period_ms : INT := 100; // Matches TIA hardware setup
WheelDiameter_m: REAL := 0.2; // 200 mm wheel
Frequency_Hz : REAL;
Speed_mps : REAL;
END_VAR
BEGIN
HSC1_Count := "ID1000"; // Read process image
Frequency_Hz := DINT_TO_REAL(HSC1_Count)
/ (DINT_TO_REAL(Period_ms) / 1000.0);
Speed_mps := Frequency_Hz
/ (DINT_TO_REAL(PPR) * DINT_TO_REAL(EvalFactor))
* (3.14159265 * WheelDiameter_m);
END_FUNCTION_BLOCK
STATUS word bit 30 (STATUS.30) or the value of the DIR output of CTRL_HSC indicates count direction. Alternatively, expose the raw count value and let the application logic evaluate its sign (count up from zero = positive direction, count down = negative direction).
11. Edge Cases and Pitfalls
| Pitfall | Effect | Mitigation |
|---|---|---|
| Forgetting x4 multiplier in conversion | Speed reads 4× too high | Always use PPR_eff = PPR × eval in the formula |
| Period too short for low speed | ID1000 = 0 between updates, jittery output | Increase T_period to ≥ 0.5 s for slow applications |
| Encoder PPR × RPM exceeds HSC frequency limit | Counts lost; speed reads low | De-rate speed, reduce PPR, or use x1 mode |
| NPN wired without pull-up | Inputs float; HSC counts noise | Install 4.7 kΩ pull-ups to +24 V on each phase |
| Long unshielded cable runs | Capacitive coupling injects edges | Use shielded twisted pair, ground shield at one end |
| Reading ID1002 / ID1003 directly | Reads high half of DINT, not the actual count | Declare ID1000 as DINT symbol, never byte-wise |
| Input filter set too long | HSC misses fast edges | Leave filter at default or ≤ 0.8 µs for HSC inputs |
12. Verification Procedure
-
Watch table test: Add ID1000 and the calculated
Speed_mpsto a watch table in TIA Portal. Spin the encoder by hand and confirm ID1000 increments with each quadrature edge. - Direction test: Reverse rotation. Confirm ID1000 decrements (or speed sign flips).
-
Static reference test: Drive the encoder at a known RPM (use a calibrator or stopwatch). Compute the expected
Speed_mpsfrom the formula and compare with the PLC value. Tolerance should be ±2 % at > 10 % of full scale. - Frequency limit test: Run the encoder at maximum process RPM. Verify ID1000 increases linearly with speed and does not saturate. If saturation occurs, switch evaluation from x4 to x1 or x2.
- Edge timing test: Use the HSC's online diagnostic in TIA Portal (Right-click HSC → Online & Diagnostics) to confirm edge counts and capture any reported overflows.
13. Troubleshooting Matrix
| Symptom | Likely Cause | Corrective Action |
|---|---|---|
| ID1000 always 0 | HSC not enabled; wrong input wired; encoder not powered | Verify HSC enable in hardware config; check 24 V at encoder Vcc |
| ID1000 increments in one direction only | Phase B not wired or shorted | Check continuity from encoder pin B to I0.1 |
| Speed reading is 4× expected | Formula uses raw PPR but HSC is in x4 mode | Multiply PPR by 4 in conversion (PPR_eff) |
| Speed reading jumps erratically | Noise; ground loop; long unshielded cable | Use shielded cable, ground shield at PLC end only |
| Speed reads correct at high RPM, wrong at low RPM | Measurement period too short | Increase T_period to 0.5 – 1.0 s |
| Direction indicator always positive | DIR output not wired to status logic | Use the sign of accumulated ID1000 over the period, or read STATUS bit |
| Counts lost above certain RPM | HSC frequency exceeded | Switch to x1 or x2 evaluation; check HSC limits |
14. FAQ
Why does my HSC reading jump by a factor of four when I switch from x1 to x4 evaluation?
The HSC counts each quadrature edge in x4 mode, so a 500 PPR encoder produces 2,000 counts per revolution instead of 500. Adjust the conversion formula to use PPR_eff = PPR × eval (4 for x4) so the engineering-units calculation compensates.
How do I obtain the direction of rotation from the HSC?
In two-phase (quadrature) mode the phase relationship between A and B determines the count direction. Use the sign of the accumulator (count up from zero = forward, count down = backward) or read the STATUS bit / DIR output of CTRL_HSC, and translate that into a forward/reverse Boolean for downstream logic.
What is the maximum pulse frequency the CPU 1214C can handle?
For the CPU 1214C DC/DC/DC: HSC1–HSC4 support 100 kHz single-phase and 80 kHz quadrature 4x. HSC5–HSC6 support 30 kHz single-phase and 20 kHz quadrature 4x. AC/DC/RLY variants support only 30 kHz. Verify the encoder's expected maximum pulse rate against these limits before selecting evaluation mode.
How do I convert the HSC count to metres per second for a wheel-driven application?
First compute the pulse frequency f = ID1000 / T_period. Then revolutions per second n = f / (PPR × eval). The linear speed is v = n × π × D, where D is the wheel diameter in metres. Apply the formula in user logic (FB) and output the result in REAL engineering units.
Why is the frequency reading unstable at low speeds?
The HSC integrates pulses over a fixed window, so at low speeds the count per window is small (often 0 or 1) and the output steps in coarse increments. Increase the measurement period (e.g., from 0.1 s to 1.0 s) to stabilise the readout, or apply exponential moving-average filtering on the calculated speed.