100BBasic instructions
7.3 Counters
S7-1200 Programmable controller
System Manual, 11/2011, A5E02486680-05
179
●
For SInt or USInt data types, the counter instruction uses 3 bytes.
●
For Int or UInt data types, the counter instruction uses 6 bytes.
●
For DInt or UDInt data types, the counter instruction uses 12 bytes.
These instructions use software counters whose maximum counting rate is limited by the
execution rate of the OB in which they are placed. The OB that the instructions are placed in
must be executed often enough to detect all transitions of the CU or CD inputs. For faster
counting operations, see the CTRL_HSC instruction (Page 315).
Note
When you place counter instructions in an FB, you can select the multi-instance DB option,
the counter structure names can be different with separate data structures, but the counter
data is contained in a single DB and does not require a separate DB for each counter. This
reduces the processing time and data storage necessary for the counters. There is no
interaction between the counter data structures in the shared multi-instance DB.
Operation of the counters
Table 7- 24 Operation of the CTU counter
Counter
Operation
The CTU counter counts up by 1 when the value of parameter CU
changes from 0 to 1. The CTU timing diagram shows the operation for
an unsigned integer count value (where PV = 3).
If the value of parameter CV (current count value) is greater than or
equal to the value of parameter PV (preset count value), then the
counter output parameter Q = 1.
If the value of the reset parameter R changes from 0 to 1, then the
current count value is reset to 0.
&8
5
&9
4
Table 7- 25 Operation of the CTD counter
Counter
Operation
The CTD counter counts down by 1 when the value of
parameter CD changes from 0 to 1. The CTD timing diagram
shows the operation for an unsigned integer count value
(where PV = 3).
If the value of parameter CV (current count value) is equal
to or less than 0, the counter output parameter Q = 1.
If the value of parameter LOAD changes from 0 to 1, the
value at parameter PV (preset value) is loaded to the
counter as the new CV (current count value).
&'
&9
4
/2$'