Siemens S7-200 High Speed Counter (HSC) Setup, Limits

David Krause11 min read
S7-200SiemensTechnical Reference
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. Overview of the S7-200 High Speed Counter

The S7-200 CPU family (CPU 221, 222, 224, 224XP, 226) integrates dedicated High-Speed Counters (HSCs) implemented in hardware so that pulse trains arriving on the CPU's digital inputs can be counted independently of the OB1 scan time. Six HSC channels are defined in the platform: HSC0 through HSC5, although the number of physical input terminals wired to each channel depends on the specific CPU and on the selected counting mode. Maximum input frequencies documented by Siemens range from 20 kHz on most CPUs up to 200 kHz on the CPU 224XP for the dedicated high-speed inputs I0.0/I0.1, with the remainder of the inputs limited to 30 kHz single-phase. The HSC mechanism is described in detail in the S7-200 SMART System Manual (the S7-200 SMART inherits the same HSC architecture with extended frequency limits) and in the legacy Siemens Industry Online Support knowledge base for the classic S7-200.

The HSC is started and parameterised by two instructions: HDEF (High-Speed Counter DEFinition) to assign the mode and initial I/O assignments, and HSC to load the new control byte and begin operation. In most engineering environments the HSC Wizard in STEP 7 Micro/WIN automatically generates a subroutine called HSC_CTRL that wraps the HDEF and HSC calls and exposes a defined interface (Mode, CV, PV, New_RV, New_CV, etc.).

2. Counter Value Data Type and Numeric Range

The current value of every S7-200 HSC is stored internally as a 32-bit signed double integer (DINT). The legal range is therefore:

  • Minimum: -2,147,483,648 (0x80000000)
  • Maximum: +2,147,483,647 (0x7FFFFFFF)

The original poster's question concerning values such as "-2312313 to 212313" is a typographical representation of this DINT limit. The displayed decimal values are simply user-defined subset limits chosen for a particular application (for example, "run between 0 and 100"); the hardware itself can count across the entire signed 32-bit range. Any logic that loads a new reference value (NEW_RV) or writes the current value (CV) must respect this DINT range, otherwise the HSC will saturate or the HSC instruction will reject the value.

Important: The HSC current value is not reset to zero on power loss unless the CPU is configured to do so in the system block, or the user program explicitly writes the CV through the HSC instruction. Always include a deterministic initial value (NEW_CV) in the first scan flag routine when the application cannot tolerate an unknown start count.

3. HSC Modes, Inputs, and I/O Assignment

The HDEF instruction selects one of 12 modes (0-11) for each HSC. The table below summarises the modes available on the S7-200 family. Inputs prefixed with a bullet (•) are dedicated to the HSC and cannot be used as ordinary I/O while the mode is active.

Mode Type Description Affected HSCs
0 Single-phase, internal direction Up/down controlled by user program HSC0, HSC3, HSC4, HSC5
1 Single-phase, external direction Direction read from dedicated input HSC0
2 Two-phase (quadrature) 1x Quadrature, 1x resolution HSC0, HSC3, HSC4, HSC5
3 Two-phase (quadrature) 1x Quadrature, 1x resolution (alt) HSC0, HSC3, HSC4, HSC5
4 Single-phase with reset External reset input HSC0, HSC3, HSC4, HSC5
5 Single-phase with start + reset External start and reset inputs HSC5
6 Single-phase with start (no reset) External start input only HSC5
7 Quadrature with reset 2x quadrature with external reset HSC0, HSC3, HSC4, HSC5
8 Quadrature with reset Alternate pin assignment with reset HSC0
9 Quadrature with start + reset 2x quadrature with start and reset HSC0, HSC3, HSC4, HSC5
10 Quadrature with start + reset Alternate pin assignment with start and reset HSC0
11 Quadrature with start + reset 4x quadrature with start and reset HSC0, HSC3, HSC4, HSC5

4. HSC_CTRL Subroutine Interface

The HSC Wizard generates a subroutine with a fixed local variable table. The pins exposed in the standard HSC_CTRL block are:

Parameter Direction Data Type Description
Mode IN BYTE Selected HSC mode (0-11)
HSC IN BYTE HSC channel number (0-5)
Direction IN BOOL Count direction (modes 0, 3, 6, 9, 10, 11)
Preset (PV) IN DINT Preset value (DINT, full range)
New_CV IN DINT New current value to be loaded
New_RV IN DINT New reference/reset value
CV OUT DINT Current count (read-only)
Done OUT BOOL One-shot completion flag for the HSC instruction

The NEW_RV input is the most commonly misunderstood parameter. It is the value that will be loaded into CV (or used as a reset target) at a defined event such as CV = PV, external reset, or HSC-direction change. It is stored in the special memory area of the HSC and is transferred to the counter only when the configured event occurs, not immediately upon writing the variable. This is what makes the field report's example (running between 0 and 100) feasible: PV=100 is configured, an interrupt is attached to CV=PV, and inside the interrupt the user program calls HSC_CTRL with New_CV = 0 to reload the counter at the next scan of the HSC instruction.

5. Control Byte Definition

When the HSC instruction executes, it reads a control byte in the special memory (SMB) area to determine which options are active. The standard layout is:

Bit Function
0 Active level for direction input (0 = active high, 1 = active low)
1 Active level for start input
2 Active level for reset input
3 Counting rate selector (1x or 4x for quadrature)
4 Counting direction (0 = count down, 1 = count up)
5 Write CV / New_CV (1 = update, 0 = ignore)
6 Write reference value / New_RV (1 = update, 0 = ignore)
7 Enable HSC (1 = enable, 0 = disable)

Setting bit 5 forces the HSC to take the value at the New_CV input on the next clock pulse. Setting bit 6 forces the HSC to update the reference value from New_RV. The HSC Wizard exposes these flags as direct local variables so the user does not have to manipulate the SMB byte manually.

6. Hardware Interrupts Attached to HSCs

The S7-200 supports hardware interrupts triggered by HSC events. Each HSC channel can be configured to fire an interrupt on:

  1. CV = PV (current value equals preset value)
  2. Direction change (counting up vs. counting down)
  3. External reset event

The interrupt service routine is a standard subroutine attached to the relevant interrupt event in STEP 7 Micro/WIN. The recommended pattern is:

  1. Set PV to the desired trigger value (e.g., 100) in the HSC_CTRL block.
  2. Attach the CV=PV interrupt to a dedicated OB (e.g., INT_0).
  3. Inside INT_0, call HSC_CTRL again with New_CV := 0 and a one-shot write to bit 5 to force the counter back to 0.
  4. On the next scan, HSC resumes counting from 0 up to 100, creating a modulo-100 counter that never overflows the DINT range.

7. Example: Modulo-100 Counter with Reload on CV=PV

The following STL excerpt illustrates the pattern discussed in the source thread. Comments mark the wizard-generated variables.

// Main OB1 - count from 0 to 100 indefinitely
NETWORK 1
LD       SM0.1                // First scan flag
CALL     HSC_INIT, 0, 4, 0, 100, 0, 0, HSC_Done
//                       |  |  |   |    |  |
//                       |  |  |   |    |  +-- New_RV = 0 (initial)
//                       |  |  |   |    +----- New_CV = 0 (initial)
//                       |  |  +---+---------- PV = 100 (preset)
//                       |  +---------------- Mode 4 (single-phase, reset)
//                       +------------------- HSC0

NETWORK 2
LD       Always_On
ATCH     INT_HSC0, 12         // Attach CV=PV interrupt (event 12 for HSC0) to INT_HSC0
ENI                          // Enable global interrupt
// INT_HSC0 - reload counter to 0 on CV=PV interrupt
NETWORK 1
LD       SM0.0                // Always true inside interrupt
SI       HSC0_CV_W, 1         // Set bit 5 of control byte (write CV)
SI       HSC0_EN, 1           // Set bit 7 (HSC enable retained)
CALL     HSC_CTRL, 0, 4, 0, 100, 0, 0, HSC_Done
// New_CV = 0 forces CV back to 0 on next HSC tick

For a CPU 224XP running at 200 kHz, the above counter wraps every 100 counts, so the application logic that reads HSC0_CV always receives a value in the 0-99 window. The original DINT range is never approached.

8. Frequency Limits per CPU

CPU Max single-phase freq. Max quadrature freq. Notes
CPU 221 20 kHz (I0.0-I0.5) 20 kHz Single HSC0 only
CPU 222 20 kHz (I0.0-I0.5) 20 kHz HSC0-HSC3 (selectable)
CPU 224 20 kHz (I0.0-I0.5) 20 kHz HSC0-HSC5
CPU 224XP 200 kHz (I0.0-I0.1), 30 kHz (others) 100 kHz (1x), 80 kHz (4x) High-speed outputs also on Q0.0-Q0.3
CPU 226 20 kHz (I0.0-I0.7) 20 kHz All six HSCs available

9. Comparison with CLICK PLC and ControlLogix HSCs

While the source is focused on the S7-200, it is useful to compare the HSC architectures on the other platforms covered in the additional research.

Feature Siemens S7-200 (HSC0-HSC5) AutomationDirect CLICK (HSC1-HSC4) Allen-Bradley 1756 HSC (1756-HSC)
Counter data type DINT (-2.1B to +2.1B) 32-bit signed (-2.1B to +2.1B) 32-bit signed; module returns scaled value
Max frequency 20-200 kHz 100 kHz on dedicated inputs 1 MHz (counter), 250 kHz (encoder)
Configuration HDEF + HSC instructions; HSC Wizard CLICK programming software (HSC setup dialog) RSLogix 5000 module properties; periodic / immediate data
Reference values PV (preset) and NEW_RV (new reference) Preset and Preload values Preset (P0, P1, P2, P3) and Rollover
Reset sources External input or CV=PV event External or internal Z input, software, or counted value
Documentation S7-200 SMART System Manual CLICK / CTRIO PDF 1756-HSC User Manual

For the CLICK family, the HSC function block is configured through the CLICK programming software's dedicated HSC setup screen; the CLICK HSC encoder tutorial walks through wiring and parameterisation. For the 1756-HSC module, refer to the 1756-HSC user manual for register definitions, scaling, and the CIP messaging interface.

10. Troubleshooting Matrix

Symptom Likely Cause Verification / Fix
Counter reads 0 even with pulses at the input Mode not defined (HDEF never called), or wrong I/O pin pair selected Cross-check Mode vs. input assignment in HSC Wizard; ensure HDEF is in first-scan routine
Counter value stuck at -2,147,483,648 Underflow (count went past DINT min) and the HDEF was not reloaded with New_CV Add modulo logic via CV=PV interrupt; preload New_CV at first scan
Counter does not reload on CV=PV Bit 5 of control byte not set, or interrupt not attached / not enabled (ENI) Set bit 5 explicitly before HSC instruction; verify ATCH and ENI in OB1
Counts are inconsistent / missed at high RPM Input frequency exceeds CPU rating, or encoder wiring introduces noise Confirm frequency vs. CPU table; use shielded twisted pair; add 4.7 kΩ pull-up/down
Quadrature direction is reversed A and B channels swapped, or active-level bit wrong Swap A/B inputs or toggle bit 0 of the control byte
New_RV value ignored Bit 6 of control byte not set Set bit 6 before HSC instruction; check that Mode supports reference reload
External reset does not clear CV Reset input not wired to assigned terminal, or active level wrong Verify wiring per Mode table; toggle bit 2 of control byte

11. Field Commissioning Checklist

  1. Confirm encoder supply voltage (typically 24 VDC, sometimes 5 VDC) matches CPU input threshold.
  2. Wire the encoder's A channel (and B, Z where used) to the dedicated HSC input pair defined in the mode table.
  3. Set the HSC filter group in the CPU system block to the lowest acceptable filter for the chosen frequency.
  4. Call HDEF once on first scan (SM0.1). Subsequent calls on the same HSC will return a non-fatal error.
  5. Program the first-scan preload of New_CV if the application must start from a known value.
  6. Attach the CV=PV interrupt and call HSC inside the interrupt to reload the counter if a modulo range is required.
  7. Monitor HSC0_CV (or the relevant channel) using a status chart and apply a slow pulse train to validate counting direction.
  8. Increase the pulse rate to confirm the HSC does not drop counts at the operating frequency.
Safety reminder: For applications where the HSC value drives safety-rated functions (e.g., emergency-stop distance monitoring, speed governors), use a separate safety-rated sensor and a certified safety relay or a fail-safe PLC module. The S7-200 is not certified to SIL/PL levels higher than general-purpose control unless paired with a TUV-certified safety extension.

12. Frequently Asked Questions

What is the maximum count value of an S7-200 HSC?

The HSC stores its current value as a 32-bit signed DINT, so the range is -2,147,483,648 to +2,147,483,647. The application logic typically uses a smaller subset (e.g., 0-100) by reloading the counter in a CV=PV interrupt.

Why does the HSC not reload when I write New_CV in OB1?

New_CV is only transferred to the hardware counter when bit 5 of the HSC control byte is set before the HSC instruction executes. The HSC Wizard exposes this as a local variable; you must pulse it from 0 to 1 each time you want the load to occur.

Can I use HSC0 and HSC3 at the same time on a CPU 224?

Yes. HSC0 and HSC3 use different input pin groups (HSC0 uses I0.0/I0.1, HSC3 uses I0.4/I0.5 on the CPU 224), so they can run independently. Mode selection must, however, use a pin set that is not already assigned to another active HSC.

What is the difference between PV and New_RV in the HSC_CTRL block?

PV (preset) is the value the HSC compares CV against to generate a CV=PV interrupt. New_RV is the new reference or reset value that the HSC will load into CV at a defined event. Both are DINTs; they are independent parameters but are often set to the same value when the goal is a "reset to 0 on reaching preset" workflow.

How fast can the S7-200 HSC count on a CPU 224XP?

The CPU 224XP supports up to 200 kHz on inputs I0.0 and I0.1 (single-phase) and 100 kHz in 1x quadrature, 80 kHz in 4x quadrature. Other inputs are limited to 30 kHz. Always refer to the specific CPU manual for the exact pin group limits.

Back to blog