102BTechnology instructions
9.1 High-speed counter
S7-1200 Programmable controller
System Manual, 11/2011, A5E02486680-05
317
9.1.1
Operation of the high-speed counter
The high-speed counter (HSC) counts events that occur faster than the OB execution rate. If
the events to be counted occur within the execution rate of the OB, you can use CTU, CTD,
or CTUD counter instructions. If the events occur faster than the OB execution rate, then use
the HSC. The CTRL_HSC instruction allows your user program to programmatically change
some of the HSC parameters.
For example: You can use the HSC as an input for an incremental shaft encoder. The shaft
encoder provides a specified number of counts per revolution and a reset pulse that occurs
once per revolution. The clock(s) and the reset pulse from the shaft encoder provide the
inputs to the HSC.
The HSC is loaded with the first of several presets, and the outputs are activated for the time
period where the current count is less than the current preset. The HSC provides an interrupt
when the current count is equal to preset, when reset occurs, and also when there is a
direction change.
As each current-count-value-equals-preset-value interrupt event occurs, a new preset is
loaded and the next state for the outputs is set. When the reset interrupt event occurs, the
first preset and the first output states are set, and the cycle is repeated.
Since the interrupts occur at a much lower rate than the counting rate of the HSC, precise
control of high-speed operations can be implemented with relatively minor impact to the scan
cycle of the CPU. The method of interrupt attachment allows each load of a new preset to be
performed in a separate interrupt routine for easy state control. (Alternatively, all interrupt
events can be processed in a single interrupt routine.)
Table 9- 4
Maximum frequency (KHz)
HSC
Single phase
Two phase and AB quadrature
CPU
100 KHz
80 KHz
High-speed SB
200 KHz
160 KHz
HSC1
SB
30 KHz
20 KHz
CPU
100 KHz
80 KHz
High-speed SB
200 KHz
160 KHz
HSC2
SB
30 KHz
20 KHz
HSC3
CPU
100 KHz
80 KHz
HSC4
CPU
30 KHz
20 KHz
CPU
30 KHz
20 KHz
High-speed SB
200 KHz
160 KHz
HSC5
SB
30 KHz
20 KHz
CPU
30 KHz
20 KHz
High-speed SB
200 KHz
160 KHz
HSC6
SB
30 KHz
20 KHz