Technology instructions
10.1 Counting (High-speed counters)
S7-1200 Programmable controller
System Manual, V4.2, 09/2016, A5E02486680-AK
571
A typical application uses the HSC to monitor feedback from an incremental shaft encoder.
The shaft encoder provides a specified number of counts per revolution that you can use as
the clock generator input to the HSC. There is also a reset pulse that occurs once per
revolution that you can use as the sync input to the HSC.
To start, the program loads the first reference value into the HSC and sets the outputs to
their initial states. The outputs remain in this state for the time period that the current count is
less than the reference value. The HSC provides an interrupt when the current count is equal
to the reference value, when the sync event (reset) occurs, and also when there is a
direction change.
As each counter value equals the reference value, an interrupt event occurs, and the
program loads a new reference value into the HSC and sets the outputs to their next state.
When the sync interrupt event occurs, the program sets the first reference value and the first
output states and repeats the cycle.
Since the interrupts occur at a much slower rate than the counting rate of the HSC, you can
implement precise control of high-speed operations 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, you can
process all interrupt events in a single interrupt routine.
The Gate function, triggered either by the user program or an external input signal, can
disable counting of the encoder pulses. You can ignore any movement of the shaft by
deactivating the gate. This means that while the encoder continues to send pulses to the
HSC, the count value is held at the last value before the gate goes inactive. When the gate
goes active, counting resumes from the last value before the gate went inactive.
When enabled, the Capture function causes the current count to be captured on the
occurrence of an external input. A process (for example, a calibration routine) can use this
function to determine how many pulses occur between events.
When enabled, the Compare output function generates a single, configurable pulse that
occurs every time the current count reaches one of the reference values or overflows
(exceeds the counting limits). You can use this pulse as a signal to start another process
whenever a certain HSC event occurs.
The counting direction is controlled by either the user program or an external input signal.
To obtain the speed of the rotating shaft, you can configure the HSC for Frequency mode.
This function provides a signed integer value in units of Hz. Because the reset signal occurs
once per revolution, measuring the frequency of the reset signal provides a quick indication
of the shaft’s speed, in revolutions per second.
If you desire a floating point value of the frequency, configure the HSC for Period mode. You
can use the ElapsedTime and EdgeCount values returned in Period mode to calculate the
frequency.