100BBasic instructions
7.3 Counters
S7-1200 Programmable controller
178
System Manual, 11/2011, A5E02486680-05
7.3
Counters
Table 7- 22 Counter instructions
LAD / FBD
SCL
Description
"IEC_Counter_0_DB".CTU(
CU:=_bool_in,
R:=_bool_in,
PV:=_int_in,
Q=>_bool_out,
CV=>_int_out);
"IEC_Counter_0_DB".CTD(
CD:=_bool_in,
LD:=_bool_in,
PV:=_int_in,
Q=>_bool_out,
CV=>_int_out);
"IEC_Counter_0_DB".CTUD(
CU:=_bool_in,
CD:=_bool_in,
R:=_bool_in,
LD:=_bool_in,
PV:=_int_in,
QU=>_bool_out,
QD=>_bool_out,
CV=>_int_out);
Use the counter instructions to count internal program events and
external process events. Each counter uses a structure stored in a
data block to maintain counter data. You assign the data block when
the counter instruction is placed in the editor.
CTU is a count-up counter
CTD is a count-down counter
CTUD is a count-up-and-down counter
1
For LAD and FBD: Select the count value data type from the drop-down list below the instruction name.
2
STEP 7 automatically creates the DB when you insert the instruction.
3
In the SCL examples, "IEC_Counter_0_DB" is the name of the instance DB.
Table 7- 23 Data types for the parameters
Parameter
Data type
1
Description
CU, CD
Bool
Count up or count down, by one count
R (CTU, CTUD)
Bool
Reset count value to zero
LD (CTD, CTUD)
Bool
Load control for preset value
PV
SInt, Int, DInt, USInt, UInt, UDInt
Preset count value
Q, QU
Bool
True if CV >= PV
QD
Bool
True if CV <= 0
CV
SInt, Int, DInt, USInt, UInt, UDInt
Current count value
1
The numerical range of count values depends on the data type you select. If the count value is an unsigned integer
type, you can count down to zero or count up to the range limit. If the count value is a signed integer, you can count
down to the negative integer limit and count up to the positive integer limit.
The number of counters that you can use in your user program is limited only by the amount
of memory in the CPU. Counters use the following amount of memory: