Professional Documents
Culture Documents
Chapter 6
Counter Instructions
SIMATIC Counter Instructions
Count Up Counter
The Count Up instruction (CTU) counts up from the current value
each time the count up (CU) input makes the transition from off to
on. When the current value Cxx is greater than or equal to the
preset value PV, the counter bit Cxx turns on. The counter is reset
when the Reset (R) input turns on, or when the Reset instruction is
executed. The counter stops counting when it reaches the
maximum value (32,767).
STL operation :
H Reset input: Top of stack
H Count Up input: Value loaded in the second stack location
Inputs/Outputs
Data Types
Operands
Cxx
WORD
BOOL
PV
INT
IW, QW, VW, MW, SMW, SW, LW, T, C, AC, AIW, *VD, *LD, *AC, Constant
107
Tip
Since there is one current value for each counter, do not assign the same number to more than one
counter. (Up Counters, Up/Down Counters, and Down counters with the same number access the
same current value.)
When you reset a counter using the Reset instruction, the counter bit is reset and the counter current
value is set to zero. Use the counter number to reference both the current value and the counter bit of
that counter.
Table 6-22
Type
Operation
Counter Bit
CTU
Current value = 0
CTUD
You can select that the current value for the counter be retentive. See Chapter 4 for information about memory retention
for the S7-200 CPU.
LD
LD
CTD
Network 2
LD
=
Timing Diagram
I0.0 Down
I0.1 Load
3
2
1
C1 (current)
C1 (bit) Q0.0
108
Chapter 6
LD
LD
LD
CTUD
//I0.0 counts up
//I0.1 counts down
//I0.2 resets current value to 0
I0.0
I0.1
I0.2
C48, +4
Network 2
LD
=
Timing Diagram
I0.0 (up)
I0.1 (down)
I0.2 (reset)
C48 (current) 0
5
4
3
109
Down Counter
The Count Down instruction (CTD) counts down from the preset
value (PV) on the rising edges of the Count Down (CD) input.
When the current value (CV) is equal to zero, the counter output
bit (Q) turns on. The counter resets and loads the current value
with the preset value when the load input (LD) is enabled. The
Down Counter stops counting when it reaches zero.
Up/Down Counter
The Count Up/Down instruction (CTUD) counts up or down from
the current value (CV) on the rising edges of the Count Up (CU) or
Count Down (CD) input. When the current value is equal to preset,
the up output (QU) turns on. When the current value is equal to
zero, the down output (QD) turns on. The counter loads the current
value with the preset value (PV) when the load (LD) input is
enabled. Similarly, the counter resets and loads the current value
with 0 when the reset (R) is enabled. The counter stops counting
when it reaches preset or 0.
Table 6-23
Inputs/Outputs
Data Types
Operands
Cxx
BOOL
PV
INT
IW, QW, VW, MW, SMW, SW, LW, AC, AIW, *VD, *LD, *AC, Constant
Q, QU, QD
BOOL
I, Q, V, M, SM, S, L
CV
INT
IW, QW, VW, MW, SW, LW, AC, *VD, *LD, *AC
Tip
Since there is one current value for each counter, do not assign the same number to more than one
counter. (Up Counters, Down Counters, and Up/Down Counters access the same current value.)
110
Chapter 6
VW0
CV -Current Value
3
2
4
3
3
2
1
0
Q0.0
QU -- Up
Q0.1
QD -- Down
111