Using the pulse generators of the S7-1200
7.1 High-speed counters
Easy Book
Manual, 05/2009, A5E02486774-01
85
Using the CTRL_HSC instruction
The CTRL_HSC instruction controls the high-speed counters that are used to count events
that occur faster than the CPU scan rate. While the counting rate of the CTU, CTD, and
CTUD counter instructions is limited by the CPU scan rate, the high-speed counters operate
asynchronously to the CPU scan and allow counting events up to a 100 kHz count rate (for
HSC 1, 2, or 3 and onboard CPU count input configuration).
Each CTRL_HSC instruction uses a structure stored in a data
block to maintain data. You assign the data block when the
CTRL_HSC instruction is placed in the editor.
Inserting the CTRL_HSC instruction into your user program also
creates an instance DB.
Parameter Data type Description
HSC HW_HSC HSC identifier
DIR BOOL 1 = Request new direction
CV BOOL 1 = Request to set new counter value
RV BOOL 1= Request to set new reference value
PERIOD BOOL 1 = Request to set new period value
(only for frequency measurement mode)
NEW_DIR INT New direction: 1= forward, -1= backward
NEW_CV DINT New counter value
NEW_RV DINT New reference value
NEW_PERIOD INT New period value in seconds: .01, .1, or 1
(only for frequency measurement mode)
BUSY BOOL Function busy
STATUS WORD Execution condition code
You must configure the high-speed counters in the project settings for the CPU device
configuration before you can use high-speed counters in your program. The HSC device
configuration settings select counting modes, I/O connections, interrupt assignment, and
operation as a high-speed counter or as a device to measure pulse frequency. You can
operate the high-speed counter with no program control or with program control.
Many high-speed counter configuration parameters are set only in the project device
configuration. Some high-speed counter parameters are initialized in the project device
configuration, but can be modified later under program control. The CTRL_HSC instruction
parameters provide program control of the counting process:
● Set the counting direction to a NEW_DIR value
● Set the current count value to a NEW_CV value