Every S7-1500 CPU has high-speed counters (HSC) built in: hardware counter units that tally encoder or pulse signals directly, without loading the scan cycle, so they keep up with pulses far faster than the program loop. Using them comes down to three decisions: the counting mode, the signal input type, and the gating and reset conditions.
An add counter in OB1 runs once per scan, so the count drifts as soon as the cycle time changes, and short pulses that rise and fall between two scans are lost entirely. An HSC counts in hardware, and the program only reads the current value and the status bits, so it can follow signals in the kHz range and above. The first selection question is therefore whether the pulse frequency exceeds what the scan can capture; if it does, an HSC or a dedicated counter module is required.
Configuration normally offers counting, frequency measurement, period measurement and position tracking. Counting mode adds or subtracts pulses and reports a current value; frequency measurement works out the pulse rate over a fixed time window and is used for speed; period measurement suits very slow signals and derives speed from the interval between pulses; position tracking follows an incremental encoder to record displacement. The mode also decides how direction is determined. Single-phase uses one pulse input and takes direction from the program; two-phase uses the A/B quadrature pair and derives direction from the phase order automatically; up/down counting uses two separate inputs, one for forward pulses and one for reverse pulses.
Each HSC channel needs an assigned pulse input, a direction input, and digital inputs that act as gate or reset. The gate decides when counting is active; the reset clears the count to zero. These inputs are fixed high-speed channels on the CPU or technology module and cannot be re-assigned as ordinary I/O. Sourcing or sinking wiring must match the polarity of the module common terminal, otherwise the signal level cannot be resolved.
Enable the HSC in the hardware configuration, pick the operating mode, then set the counting range, the comparison values and the output response. Most applications read the count into the process image or via an instruction and set an output with a comparison instruction when the setpoint is reached; where an immediate reaction is needed, the hardware comparator does it with no scan delay. An interrupt can be triggered on reaching a comparison value or on zero crossing to catch a momentary event, but keep the interrupt routine short.
Common uses include spindle speed, web or coil length measurement, flow-pulse totalising and work-piece positioning. Speed conversion needs care with units: frequency divided by pulses per revolution gives revolutions per second, and only after multiplying by 60 do you get r/min. For length, divide the accumulated count by the pulses per metre. Flow totalising converts each pulse into the volume it represents. The higher the frequency, the more the signal quality and cable screening matter.
| Counting mode | Signal inputs | Direction | Typical use |
|---|---|---|---|
| Single-phase counting | One pulse input | Up or down, set by the program | Simple pulse totalising |
| Up/down counting | One forward, one reverse input | From which input the pulse arrives on | Bi-directional length |
| Two-phase counting (1x) | A/B quadrature | From the phase order of the pair | Slow positioning |
| Two-phase counting (2x) | A/B quadrature | Rising and falling edges counted | Higher resolution |
| Two-phase counting (4x) | A/B quadrature | All edges of both phases counted | High-precision tracking |
| Frequency measurement | One pulse input | Not applicable | Mid to high speed measurement |
| Period measurement | One pulse input | Not applicable | Low speed measurement |
| Gated counting | Pulse + gate | Set by the program | Counting within a window |
| Reset counting | Pulse + reset | Set by the program | Repeating piece counting |
How many HSC channels, what maximum frequency and which modes a CPU or technology module supports differ from one model to another; the manufacturer's manual is the authority. The higher the frequency and the longer the cable, the more signal quality matters, and for long runs or electrically noisy areas a differential encoder on twisted screened cable is preferred. The counter only counts; direction and position logic still have to be handled in the program.
The high-speed counter function blocks and programming language conventions follow GB/T 15969.3 (identical to IEC 61131-3) and the equipment requirements standard IEC 61131-2. The electrical connection, protection and earthing of the counter wiring follow GB 5226.1 and the equivalent international standard IEC 60204-1. The frequency and mode figures quoted here are general; the exact limits are as stated in the manufacturer's manual.
Stop the machine before changing the HSC configuration, and make wiring changes only after isolating, proving dead and applying lock-out/tag-out. Routing signal cables away from power cables markedly reduces false counts caused by common-mode noise.