1. Overview and Application Context
Position-controlled ball screw linear axes commonly rely on an incremental encoder interpreted by a high-speed counter (HSC) inside the PLC. On a Siemens S7-1200 system, the CPU 1215C is widely used for compact machine skids, while the CPU 1217C is preferred when the application benefits from differential (RS-422) HSC inputs for stronger noise immunity. The reliability problem addressed in this reference is specific and recurring: the HSC is zeroed only on power-up and never during the repeated cycling of a ball screw linear system, so any count drift compounds over hours of operation and degrades axis repeatability.
This reference combines three layers of mitigation: configuration tuning in TIA Portal, electrical wiring best practices, and a passive homing strategy that re-aligns the counter in-motion using a reference sensor placed along the travel path. Together they convert an open-loop counting architecture into one that self-corrects without halting production.
2. HSC Architecture on S7-1200 CPUs
The S7-1200 HSC is a hardware counter implemented inside the CPU die. It runs independently of the scan cycle and accumulates edges on a digital input or pair of digital inputs. Several HSC channels are available, and each one can be configured in TIA Portal under Device configuration > Digital inputs > High speed counter (HSC). The exact number of HSC channels and the maximum counting rate depend on the CPU model.
| CPU model | HSC channels | Max HSC input frequency | Differential HSC inputs |
|---|---|---|---|
| CPU 1211C | 3 (configurable) | 100 kHz single-phase / 100 kHz quadrature | No |
| CPU 1212C | 4 (configurable) | 100 kHz single-phase / 100 kHz quadrature | No |
| CPU 1214C | 6 (configurable) | 100 kHz single-phase / 100 kHz quadrature | No |
| CPU 1215C | 6 (configurable) | 200 kHz single-phase / 100 kHz quadrature | No |
| CPU 1217C | 6 (configurable) | Up to 1 MHz on differential inputs | Yes (RS-422) |
Frequency limits reflect the per-input HSC ceiling declared in the S7-1200 System Manual. When signal levels exceed the rated value, the HSC silently saturates and edges are lost; verify headroom before commissioning. Refer to the S7-1200 System Manual for the latest values for your firmware version.
HSC channels support the following counting modes in TIA Portal:
- Single phase: counts edges on one input. Direction selected via a separate digital input.
- Two phase (CLK + DIR): counts edges on one input with a separate direction input.
- AB quadrature (x1): counts only one edge per cycle. Direction from A leading B or B leading A.
- AB quadrature (x2): counts both edges of channel A. Direction from B level.
- AB quadrature (x4): counts all four edges per cycle. Direction from A and B phase relationship.
For a ball screw axis the quadrature (x4) mode is the default choice because it quadruples the encoder resolution at the counter and gives maximum bandwidth headroom against mechanical slop and noise.
2.1 HSC instructions in the user program
The HSC is initialized by the CPU hardware configuration, but runtime control passes through two instruction blocks from the Siemens standard library:
-
CTRL_HSC— basic control: load new current value (CV), set reference value (RV), change direction, enable periodic interrupt. -
CTRL_HSC_EXT— extended control: same as CTRL_HSC plus support for DINT count range and additional status bits.
The HSC count value is read as a DINT from the process image or from the instance DB of the HSC. For axis positioning where the count may exceed INT range, always bind the count to a DINT tag. The HSC supports interrupt generation on events such as CV = RV, direction change, and external reset; these are bound to hardware-interrupt OBs in the device configuration.
3. Quadrature Counting Theory and Frequency Budget
Quadrature decoding requires two channels, A and B, that are 90 electrical degrees out of phase. The phase relationship defines direction; the number of edges counted per encoder cycle defines the multiplier.
For an encoder with N pulses per revolution, the HSC counts per revolution in each mode are:
| Mode | Counts per revolution |
|---|---|
| Quadrature x1 | N |
| Quadrature x2 | 2 × N |
| Quadrature x4 | 4 × N |
The frequency budget for an axis running at S RPM is therefore:
f_pulse_base = (S / 60) * N // Hz, raw A/B channel rate
f_count = f_pulse_base * 4 // Hz, quadrature (x4) count rate
Using the values from the field case (S = 2000 RPM, base pulse rate stated as 12 kHz at the input), the effective HSC count rate in quadrature (x4) mode becomes:
f_count = 12,000 Hz * 4 = 48 kHz
Against the CPU 1215C ceiling of 200 kHz, this leaves a 152 kHz margin. Saturation is impossible under normal conditions; the residual headroom can be traded for an aggressive input filter that improves noise immunity without losing edges. Always confirm this margin with the actual encoder PPR and maximum mechanical speed of the axis before commissioning. If the engineering data sheet is missing, capture the maximum pulse rate with a TIA Portal trace and verify it is below 70% of the rated ceiling to allow for filter-induced loss.
4. HSC Input Filter Configuration in TIA Portal
The S7-1200 digital inputs have a configurable input filter that suppresses noise below a chosen pulse width. Standard digital inputs default to 6.4 ms, which is far too slow for an HSC signal. For HSC use, the filter must be reduced to the smallest value compatible with the mechanical speed of the encoder.
| Filter value | Minimum pulse width | Maximum countable rate |
|---|---|---|
| 0.1 µs | 0.1 µs | Up to 1 MHz differential HSC |
| 0.2 µs | 0.2 µs | Up to ~1 MHz HSC |
| 0.4 µs | 0.4 µs | Up to 1 MHz HSC channels |
| 0.8 µs | 0.8 µs | Up to 500 kHz |
| 1.6 µs | 1.6 µs | Up to 300 kHz |
| 3.2 µs | 3.2 µs | Up to 150 kHz |
| 6.4 µs | 6.4 µs | Up to 78 kHz |
| 10.0 µs | 10.0 µs | Up to 50 kHz |
| 12.8 µs | 12.8 µs | Up to 39 kHz |
| 20.0 µs | 20.0 µs | Up to 25 kHz |
For the 48 kHz quadrature count rate in this application, a 3.2 µs or 6.4 µs filter provides substantial noise rejection while still passing every legitimate edge. Going below 0.8 µs invites false edges from EMI unless the wiring is exceptional.
How to set the filter in TIA Portal:
- Open the device configuration of the CPU.
- Select Digital inputs.
- Click on each input assigned to the HSC (channel A and channel B).
- Open the Input filter drop-down and select the desired value.
- Navigate to High speed counter (HSC) > select the channel > configure counting mode, initial count value, reset input, and any reference value / preset value triggers.
- Compile and download to the CPU.
5. Encoder Wiring, Shielding, and Differential Inputs
Count drift in one direction is, in the field, almost always a wiring problem rather than an HSC firmware bug. The S7-1200 HSC reads digital edges, but the encoder signal travels several meters through a noisy plant before arriving at the terminals. Shielding, earthing, and signal type (single-ended vs differential) determine the effective noise margin.
5.1 Cable selection
Use twisted-pair cable with an overall foil and braid shield rated for the encoder protocol:
- RS-422 / differential: two twisted pairs (A+/A-, B+/B-) plus power and ground. Required for CPU 1217C differential HSC inputs.
- 24 V single-ended (HTL): one signal pair plus power. Used on CPU 1215C / 1214C HSC inputs that are not differential.
- Avoid running the encoder cable parallel to VFD output cables, servo drives, or welding leads. Cross at 90 degrees if a crossing is unavoidable.
- Keep encoder cable length as short as practical. Above 30 m, RS-422 is preferred over 24 V HTL.
5.2 Shield termination
The cable shield should be bonded to earth at one end only, typically at the cabinet entry, to avoid ground loops. Use a 360-degree bond with a cable gland that contacts the full circumference of the shield, not a "pigtail" wire. Pigtail terminations can introduce tens of nanohenries of inductance and act as a noise antenna.
5.3 Differential inputs on CPU 1217C
The CPU 1217C supports true differential (RS-422) inputs on its HSC channels. A differential receiver rejects common-mode noise that is induced equally on both A and B lines, giving typically 10-20 dB more noise margin than a single-ended input. For ball screw axes in electrically noisy environments, this is the strongest single mitigation available short of moving the encoder cable.
When upgrading from a CPU 1215C to a 1217C for noise reasons:
- Replace the encoder with an RS-422 (line driver) output type.
- Wire A+/A- and B+/B- to the differential HSC inputs on the 1217C.
- Verify the input filter value is at or below 0.4 µs to fully exploit the differential bandwidth.
- Enable the higher HSC frequency ceiling on the 1217C if needed.
5.4 Power and grounding
Encoder power (typically +24 V) and signal common must be referenced to the same ground as the CPU module ground terminal. A floating encoder supply can shift the input threshold and cause asymmetric counting — which presents exactly as "drift in one direction." Measure the encoder supply at the encoder end and at the CPU end with a multimeter before trusting the wiring.
6. Diagnosing Counter Drift: Causes and Localization
Counter drift presents as the HSC value diverging from the true mechanical position over time. On a ball screw axis with no per-cycle zero, the symptom is that an axis that was at position 0 mm returns to a position several counts off after a long run. Use the following decision table to localize the cause.
| Symptom | Most likely cause | Diagnostic step |
|---|---|---|
| Drift in one direction only, slow accumulation | Ground loop, asymmetric noise pickup, single-ended wiring | Measure encoder supply at CPU end, swap A/B if direction reverses |
| Drift in both directions, occasionally large steps | Conducted EMI from a VFD or welding source | Use TIA Portal trace on HSC inputs and look for extra edges |
| Drift only when axis is moving in one direction | Backlash plus HSC direction decode glitch | Check direction change at the HSC, verify AB wiring phase |
| Drift only when adjacent equipment starts | Coupled noise from a switched load | Capture HSC edges with TIA Portal trace synchronized to equipment start |
| Drift after long idle periods | Encoder power supply drift, thermal effects | Log encoder supply voltage over 8 hours |
| Drift proportional to cable length | Insufficient shielding, capacitive coupling | Shorten or replace encoder cable with shielded twisted pair |
Using TIA Portal trace to localize noise edges:
- Open the CPU online and launch Traces.
- Add the HSC input bits (HSC input A, HSC input B) as digital signals.
- Add the HSC count value as an analog signal.
- Trigger on a rising edge of HSC input A.
- Run the axis through one full cycle and inspect the trace for unintended edges or skipped edges.
If the trace shows an extra edge on channel A or B that is not present at the encoder (verified with an oscilloscope at the encoder end), the noise is being picked up between the encoder and the CPU. The fix is wiring, not configuration.
Software-side corrections: Use the HSC instruction CTRL_HSC and CTRL_HSC_EXT from the Siemens standard library to:
- Set the HSC current count value at runtime (preset).
- Define a reference value that triggers an interrupt when reached.
- Define a preset value that is loaded on reset.
- Read the HSC status byte for direction and event flags.
Software correction alone is not a substitute for hardware noise rejection, but it is the foundation for the passive homing strategy described next. For applications that need closed-loop position control, TIA Portal also offers the Positioning axis technology object (TO_PositioningAxis), which consumes the HSC as its encoder input and adds a higher-level motion state machine. The HSC tuning described in this reference still applies unchanged; the technology object sits on top of the HSC and inherits its noise performance.
7. Passive Homing (In-Motion Referencing) Strategy
When a cycle-zero is not feasible, the next best mitigation is a passive homing reference: a sensor placed at a known physical position along the axis. Every time the axis passes the reference, the HSC count is captured and compared to the expected value. The difference is the drift; it is applied as an offset correction without stopping the axis.
7.1 Reference sensor selection
- Inductive proximity: rugged, reliable for metal targets, no contact wear.
- Magnetic (Hall or reed): ideal for non-magnetic ball screw nuts and stainless housings.
- Optical flag: highest precision, but requires a clean environment.
Mount the sensor trigger point at a position far from the deceleration zones of the axis (mid-stroke is best) so the axis is at constant velocity when the reference fires. Repeatability of the sensor itself becomes the floor for the achievable homing accuracy.
7.2 Capture and correction logic
The reference event triggers an OB (typically a hardware interrupt OB or a cyclic OB running at 1 ms). At the trigger:
- Read the HSC current value into a capture register (
capture_at_ref). - Compute the drift:
drift = expected_at_ref - capture_at_ref. - If
ABS(drift) > tolerance, issue a CTRL_HSC preset to adddriftto the HSC count value. - Log the drift value to a data block for trend analysis.
7.3 Implementation in TIA Portal
Use a hardware interrupt OB bound to the reference sensor input. Inside the OB:
// Read HSC current count value
capture_at_ref := "HSC_DB".CountValue;
expected_at_ref := "Axis_DB".ReferencePosition; // set during commissioning
drift := expected_at_ref - capture_at_ref;
IF ABS(drift) > "Axis_DB".DriftTolerance THEN
"Axis_DB".CorrectedCount := "HSC_DB".CountValue + drift;
// Apply via CTRL_HSC preset
"HSC_Ctrl"(HSC := 1,
DIR := FALSE,
CV := "Axis_DB".CorrectedCount,
RV := 0,
PERIOD := FALSE);
END_IF;
"Axis_DB".DriftHistory["Axis_DB".DriftIndex] := drift;
"Axis_DB".DriftIndex := ("Axis_DB".DriftIndex + 1) MOD 100;
The corrected count is applied only when drift exceeds a tolerance, avoiding constant HSC writes. If the drift trend over the last 100 cycles is growing, that is a strong signal that the noise or wiring problem is still present and must be addressed at the hardware level.
8. Commissioning Procedure
Use the following sequence to bring an HSC-driven ball screw axis online with reliable operation.
- Hardware pre-check. Verify encoder supply voltage at the encoder end under load. Verify cable shield termination. Verify A+/A- and B+/B- phase with an oscilloscope at the CPU terminal block.
- Configure the HSC in TIA Portal. Open the CPU device configuration, navigate to High speed counter (HSC), and create a new HSC. Select AB quadrature (x4) mode. Assign the channel A and channel B digital inputs. Set the initial count value to 0 and the reset input to "no reset" for this application (zero only on power-up).
- Set the input filter. For each HSC input, set the input filter to a value that comfortably passes the maximum encoder frequency. For 48 kHz count rate, 3.2 µs or 6.4 µs is appropriate.
- Wire and verify the encoder signal. With the CPU in STOP, observe the HSC input bits in a watch table while manually rotating the encoder. Confirm that the HSC count value increments correctly and that direction reverses when the encoder direction reverses.
- Run the axis at full speed. Switch the CPU to RUN. Command the axis through one full mechanical cycle. Monitor the HSC count in a watch table and verify the count returns to within ±1 encoder count of the starting value.
- Run a 24-hour drift test. Repeat cycles for 24 hours. Plot the HSC count at the end of each cycle. The trend should be flat; any monotonic drift is a noise problem that must be solved in wiring, not in software.
- Implement passive homing. Add the reference sensor, the capture OB, and the drift correction logic. Verify that the corrected count value matches the expected reference position to within one encoder count after the reference passes.
- Document the configuration. Record the HSC channel number, the counting mode, the input filter value, the wiring schematic, the reference sensor location, and the expected count value at the reference. This is the acceptance record for the axis.
9. Verification and Acceptance Test
The verification step is what separates a working axis from a reliable one. Run the following acceptance tests before signing off on the HSC configuration.
| Test | Method | Pass criterion |
|---|---|---|
| Static repeatability | Command axis to a fixed position 100 times, capture HSC count | Standard deviation ≤ 1 encoder count |
| Full-cycle repeatability | Run 1000 full mechanical cycles, capture HSC count at a fixed point | No monotonic drift; max-to-min spread ≤ 2 encoder counts |
| Long-duration drift | Run 24 hours, capture HSC count every hour | Hour-over-hour drift ≤ 1 encoder count |
| Passive homing accuracy | Compare HSC count at reference vs expected | Difference ≤ 1 encoder count after correction |
| Noise immunity | Start adjacent VFD or welding source during a cycle, verify HSC count | No spurious edges, no missed edges in TIA Portal trace |
| Power-cycle zero | Power down and up 10 times, capture HSC count at a fixed point | Count returns to 0 ±0 counts |
The power-cycle zero test is the unique acceptance criterion for an axis that uses power-up zeroing only. Any deviation here indicates that the HSC is being affected by residual capacitance, encoder power-up sequence, or input filter delay on the rising edge of supply. Inspect the encoder power supply ramp time, the input filter value, and the HSC initial-count-value configuration if this test fails.
10. Frequently Asked Questions
What is the maximum HSC frequency on a Siemens CPU 1215C?
The HSC inputs on the CPU 1215C are rated at 200 kHz for single-phase counting, with quadrature (x4) effectively dividing that ceiling by four in terms of mechanical encoder PPR. For an application with a 48 kHz quadrature count rate, the HSC is operating at roughly 25% of its rated ceiling. See the S7-1200 System Manual for the exact figures for your firmware version.
Does quadrature mode double or quadruple the count rate?
Quadrature (x4) mode counts all four edges of the A/B cycle per mechanical encoder cycle, so the HSC count is 4 times the encoder PPR. A 1000 PPR encoder yields 4000 counts per revolution at the HSC. Quadrature (x2) doubles it, and quadrature (x1) leaves it equal to the encoder PPR.
How do I fix HSC drift in one direction on a ball screw axis?
First, verify wiring: differential (RS-422) inputs on the CPU 1217C, properly shielded twisted-pair cable with the shield bonded to earth at the cabinet end only, and encoder power referenced to the same ground as the CPU. If the drift persists after wiring is corrected, add a passive homing reference sensor and correct the count value in software each time the reference is passed.
What input filter value should I set for an encoder running at 12 kHz raw / 48 kHz in quadrature?
Use 3.2 µs or 6.4 µs. The smallest standard filter on the S7-1200 HSC inputs is 0.1 µs, but that admits too much noise in typical industrial cabinets. 3.2 µs suppresses induced EMI while passing every legitimate edge at the 48 kHz count rate.
Should I use a CPU 1217C instead of a 1215C for ball screw reliability?
If the cabinet environment is electrically noisy (VFDs, servos, welding equipment) or the encoder cable is longer than 10 m, the CPU 1217C with differential (RS-422) HSC inputs is strongly recommended. The differential receiver provides 10-20 dB of additional common-mode noise rejection, which is typically the difference between a drifting counter and a stable one.