Program instructions
7.6 Counters
Example: Reading and saving the current count value
LAD
MAIN
Set current values and preset values with your program
Each high-speed counter has a 32-bit current value (CV) and a 32-bit preset value (PV)
stored internally. The current value is the actual count value of the counter, while the preset
value is a comparison value optionally used to trigger an interrupt when the current value
reaches the preset value. You can read the current value using the HC data type as
described in the previous section. You cannot read the preset value directly. To load a new
current or preset value into the high-speed counter, you must set up the control byte and the
special memory double-word(s) that hold the desired new current and/or new preset values,
and also execute the HSC instruction to cause the new values to be transferred to the high-
speed counter. The table below lists the special memory double-words used to hold the
desired new current and preset values.
Use the following steps to write a new current value and/or new preset value to the high-
speed counter (steps 1 and 2 can be done in either order):
1. Load the value to be written into the appropriate SM new current value and/or new preset
value (see the table below). Loading these new values does not affect the high-speed
counter yet.
2. Set or clear the appropriate bits in the appropriate control byte to indicate whether to
update the current and/or preset values (bit x.5 for preset and x.6 for current).
Manipulating these bits does not affect the high-speed counter yet.
3. Execute the HSC instruction referencing the appropriate high-speed counter number.
Executing this instruction causes the control byte to be examined. If the control byte
specifies an update for the current, the preset, or both, then the appropriate values are
copied from the SM new current value and/or new preset value locations into the high-
speed counter internal registers.
Value to be loaded
New current value (new
CV)
New preset value (new
PV)
Note
Changes to the control byte and the SM locations for new current value and new preset
value does not affect the high-speed counter until the corresponding HSC instruction is
executed.
274
Save the value of HSC0 into
VD200 when I3.0 transitions
from OFF to ON.
HSC0
HSC1
HSC2
SMD38
SMD48
SMD58
SMD42
SMD52
SMD62
STL
Network 1
LD I3.0
EU
MOVD HC0, VD200
HSC3
HSC4
SMD138
SMD148
SMD142
SMD152
System Manual, V2.3, 07/2017, A5E03822230-AF
HSC5
SMD158
SMD162
S7-200 SMART