High-Speed Counter
Hardware Precision
Capture signals that are too fast for the standard PLC cycle. Manage incremental encoders, frequency measurements, and high-speed positioning with nanosecond accuracy.
Why use High-Speed Counters?
Standard digital inputs are limited by the PLC scan time (typically 1-10ms), making them unable to detect pulses faster than 100Hz reliably. HSCs use dedicated hardware onboard the CPU to count pulses independently of the program cycle.
This offloading ensures that no pulses are missed even at frequencies up to 1MHz, which is essential for motion control, flow metering, and high-speed packaging lines where millisecond delays result in rejected products.
High-Speed Counting
Position tracking and event counting
CTRL_HSC — Counter Control
CTRL_HSCWhat it does
Instruction used to modify High-Speed Counter parameters during runtime, such as loading a new initial value or reference value.
When to use it
When you need to reset the counter position after a homing sensor trigger or update the target value for a hardware interrupt.
Pro Tips
Use the HW_HSC data type for the input parameter to ensure proper hardware mapping.
Only trigger the REQ input when a parameter change is actually needed to save CPU resources.
Always check the BUSY and DONE flags before attempting a subsequent control command.
A/B Quadrature — Encoder Logic
HSC_ConfigWhat it does
Hardware counting mode using two signals (Phase A and B) offset by 90 degrees to determine both position and direction of rotation.
When to use it
Tracking the exact position of a conveyor belt, a motor shaft, or any linear actuator equipped with an incremental encoder.
Pro Tips
Configure digital filter times in the Hardware configuration to eliminate electrical noise on encoder lines.
Use 4x evaluation mode in TIA Portal to quadruple the effective resolution of your encoder.
Verify signal levels (24V DC vs 5V Differential) to match your CPU's hardware capabilities.
Measurement
Speed, frequency and period calculation
Frequency Measurement — RPM
IDxx:PWhat it does
Hardware function that calculates the number of pulses received over a specific time window to determine frequency (Hz).
When to use it
Measuring motor speed without an analog tachometer or calculating liquid flow from a pulse-output flow meter.
Pro Tips
A longer measuring interval increases precision but slows down the update rate of the value.
The result is automatically mapped to an Input Double Word (ID) defined in the hardware configuration.
For very low speeds, use 'Period Measurement' mode instead of frequency for better stability.
Pulse Gating — Hardware Gating
GateWhat it does
Uses a physical hardware input (Gate) to start, stop, or capture the counter value instantly without software delay.
When to use it
Measuring the length of a product passing between two sensors where software latency would cause measurement errors.
Pro Tips
The 'Sync' input can be configured to reset the counter to a specific value on a rising edge.
Hardware interrupts can be triggered when the counter reaches a reference value (CV=RV).
Check the Status_HSC tag to detect if the counter has experienced an overflow or underflow.
Software vs Hardware Counter
When to upgrade to High-Speed hardware
| Requirement | Software Counter (CTU) | Hardware HSC |
|---|---|---|
| Max Frequency | Approx. 100 Hz | Up to 1 MHz (1,000,000 Hz) |
| Accuracy | Scan time dependent | Deterministic (Hardware-timed) |
| CPU Load | Significant at high speeds | Zero (Offloaded to ASIC) |
| Encoder Support | No (A/B logic difficult) | Native Quadrature (1x, 2x, 4x) |
| Signal Filtering | Software debouncing | Hardware filters (Nano-seconds) |
| Functionality | Simple counting | Frequency, Period, Velocity |
Frequently Asked Questions
Why is my HSC value not increasing in the program?
Ensure that the HSC is enabled in the Hardware Configuration and that the 'Counting' mode is correctly selected. You must also call CTRL_HSC once with CV=1 to start the counter if software enable is configured.
What is the maximum frequency supported by S7-1200?
Standard S7-1200 CPUs support up to 100kHz on onboard inputs. High-end models or Signal Boards (SB) can reach up to 200kHz or 1MHz with differential signals.
How do I reset the counter to zero from the program?
Use the CTRL_HSC instruction. Set the 'NEW_CV' input to 0 and toggle the 'CV' bit to 1. The new value will be loaded into the hardware on the next instruction execution.
Can I use any digital input for a High-Speed Counter?
No. Only specific inputs (usually I0.0 to I0.5 on small CPUs) are hard-wired to the HSC circuitry. Check the device manual for the exact mapping of your specific PLC model.