English German C no.
Z no.
Z_VORW
ZW
Q
DUAL
R
DEZ
ZV
S
Parameter English Parameter German Data Type Memory Area Description C no.
Z no.
COUNTER
C
Counter identification number;
range depends of CPU
CU
ZV
BOOL
I, Q, M, L, D
Count up input
S
S
BOOL
I, Q, M, L, D
Set input for presetting counter
PV
ZW
WORD
I, Q, M, L, D
or constant
Enter counter value as
C# in the range from 0 to
999
PV
ZW
WORD
I, Q, M, L, D
Value for presetting counter
R
R
BOOL
I, Q, M, L, D
Reset input
CV
DUAL
WORD
I, Q, M, L, D
Current counter value,
hexadecimal number
CV_BCD
DEZ
WORD
I, Q, M, L, D
Current counter value, BCD
coded
Q
Q
BOOL
I, Q, M, L, D
Status of the counter
Description S_CU (Up Counter) is preset with the value at input PV if there is a positive edge at input S.
The counter is reset if there is a "1" at input R and the count value is then set to zero.
The counter is incremented by one if the signal state at input CU changes from "0" to "1" and the
value of the counter is less than "999".
If the counter is set and if RLO = 1 at the inputs CU, the counter will count once in the
next scan
cycle, even if there was no change from a positive to a negative edge or viceversa.
The signal state at output Q is "1" if the count is greater than zero and "0" if the count is equal to
zero.
Counter Instructions
4.3 S_CU Up Counter
Ladder Logic (LAD) for S7-300 and S7-400 Programming
60
Reference Manual, 04/2017, A5E41524738-AA
Status word
BR CC 1 CC 0 OV OS OR STA RLO /FC writes:
-
-
-
-
-
x
x
x
1
Note Avoid to use a counter at several program points (risk of counting errors).
Example S_CU
S
CV
PV
R
CV_BCD
CU
I 0.0
I 0.2
I 0.3
MW10
C10
Q
Q 4.0
If I0.2 changes from "0" to "1", the counter is preset with the value of MW10. If the signal state of
I0.0 changes from "0" to "1", the value of counter C10 will be incremented by one - unless the value
of C10 is equal to "999". Q4.0 is "1" if C10 is not equal to zero.
Counter Instructions
4.4 S_CD Down Counter
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
61
4.4 S_CD Down Counter Symbol S_CD
PV
Q
CV
R
CV_BCD
CD
S
English German C no.
Z no.
Z_RUECK
ZW
Q
DUAL
R
DEZ
ZR
S
Parameter English Parameter German Data Type Memory Area Description C no.
Z no.
COUNTER
C
Counter identification number;
range depends of CPU
CD
ZR
BOOL
I, Q, M, L, D
Count down input
S
S
BOOL
I, Q, M, L, D
Set input for presetting counter
PV
ZW
WORD
I, Q, M, L, D
or constant
Enter counter value as
C# in the range from 0 to
999
PV
ZW
WORD
I, Q, M, L, D
Value for presetting counter
R
R
BOOL
I, Q, M, L, D
Reset input
CV
DUAL
WORD
I, Q, M, L, D
Current counter value,
hexadecimal number
CV_BCD
DEZ
WORD
I, Q, M, L, D
Current counter value, BCD
coded
Q
Q
BOOL
I, Q, M, L, D
Status counter
Description S_CD (Down Counter) is set with the value at input PV if there is a positive edge at input S.
The counter is reset if there is a 1 at input R and the count value is then set to zero.
The counter is decremented by one if the signal state at input CD changes from "0" to "1" and the
value of the counter is greater than zero.
If the counter is set and if RLO = 1 at the inputs CD, the counter will count once in the
next scan
cycle, even if there was no change from a positive to a negative edge or viceversa.
The signal state at output Q is "1" if the count is greater than zero and "0" if the count is equal to
zero.
Counter Instructions
4.4 S_CD Down Counter
Ladder Logic (LAD) for S7-300 and S7-400 Programming
62
Reference Manual, 04/2017, A5E41524738-AA
Status word
BR CC 1 CC 0 OV OS OR STA RLO /FC writes:
-
-
-
-
-
x
x
x
1
Note Avoid to use a counter at several program points (risk of counting errors).
Example C_CD
S
CV
PV
R
CV_BCD
CD
I 0.0
I 0.2
I 0.3
MW10
C10
Q
Q 4.0
If I0.2 changes from "0" to "1", the counter is preset with the value of MW10. If the signal state of
I0.0 changes from "0" to "1", the value of counter C10 will be decremented by one - unless the
value of C10 is equal to "0". Q4.0 is "1" if C10 is not equal to zero.
Counter Instructions
4.5 ---( SC ) Set Counter Value
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
63
4.5 ---( SC ) Set Counter Value Symbol English German ---( SC ) ---( SZ ) value>
Parameter English Parameter German Data Type Memory Area Description COUNTER
C
Counter number to be preset
WORD
I, Q, M, L, D
or constant
Value for presetting BCD
(0 to 999)
Description ---( SC ) (Set Counter Value) executes only if there is a positive edge in RLO. At that time, the
preset value transferred into the specified counter.
Status word
BR CC 1 CC 0 OV OS OR STA RLO /FC writes:
x
-
-
-
-
0
x
-
0
Example I 0.0
SC
C5
C#100
The counter C5 is preset with the value of 100 if there is a positive edge at input I0.0 (change from
"0" to "1"). If there is no positive edge, the value of counter C5 remains unchanged.
Counter Instructions
4.6 ---( CU ) Up Counter Coil
Ladder Logic (LAD) for S7-300 and S7-400 Programming
64
Reference Manual, 04/2017, A5E41524738-AA
4.6 ---( CU ) Up Counter Coil Symbol
English German ---( CU ) ---( ZV )
Parameter English Parameter German Data Type Memory Area Description COUNTER
C
Counter identification number;
range depends on CPU
Description ---( CU ) (Up Counter Coil) increments the value of the specified counter by one if there is a
positive edge in the RLO and the value of the counter is less than "999". If there is no positive edge
in the RLO or the counter already has the value "999", the value of the counter will be unchanged.
Status word
BR CC 1 CC 0 OV OS OR STA RLO /FC writes:
-
-
-
-
-
0
-
-
0
Example I 0.1
C10
CU
Network 1
Network 2
Network 3
I 0.0
C10
SC
C#100
I 0.2
C10
R
If the signal state of input I0.0 changes from "0" to "1" (positive edge in RLO), the preset value of
100 is loaded to counter C10.
If the signal state of input I0.1 changes from "0" to "1" (positive edge in RLO), counter C10 count
value will be incremented by one unless the value of C10 is equal to "999". If there is no positive
edge in RLO, the value of C10 will be unchanged.
If the signal state of I0.2 is "1", the counter C10 is reset to "0".
Counter Instructions
4.7 ---( CD ) Down Counter Coil
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
65
4.7 ---( CD ) Down Counter Coil Symbol
English German ---( CD ) ---( ZD )
Parameter English Parameter German Data Type Memory Area Description COUNTER
C
Counter identification number;
range depends on CPU
Description ---( CD ) (Down Counter Coil) decrements the value of the specified counter by one, if there is a
positive edge in the RLO state and the value of the counter is more than "0". If there is no positive
edge in the RLO or the counter has already the value "0", the value of the counter will be
unchanged.
Status word
BR CC 1 CC 0 OV OS OR STA RLO /FC writes:
-
-
-
-
-
0
-
-
0
Example I 0.1
Network 4
Network 3
Network 1
Network 2
C10
CD
C10
Q 4.0
I 0.0
Z10
SC
C#100
I 0.2
C10
R
"0" count value
detector
Counter Instructions
4.7 ---( CD ) Down Counter Coil
Ladder Logic (LAD) for S7-300 and S7-400 Programming
66
Reference Manual, 04/2017, A5E41524738-AA
If the signal state of input I0.0 changes from "0" to "1" (positive edge in RLO), the preset value of
100 is loaded to counter C10.
If the signal state of input I0.1 changes from "0" to "1" (positive edge in RLO), counter C10 count
value will be decremented by one unless the value of C10 is equal to "0". If there is no positive
edge in RLO, the value of C10 will be unchanged.
If the count value = 0, then Q4.0 is turned on.
If the signal state of input I0.2 is "1", the counter C10 is reset to "0".
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
67
5 Data Block Instructions 5.1 ---(OPN) Open Data Block: DB or DI Symbol or ---(OPN)
Parameter Data Type Memory Area Description BLOCK_DB
DB, DI
Number of DB/DI; range depends on
CPU
Description ---(OPN) (Open a Data Block) opens a shared data block (DB) or an instance data block (DI). The
- --(OPN) function is an unconditional call of a data block. The number of the data block is
transferred into the DB or DI register. The subsequent DB and DI commands access the
corresponding blocks, depending on the register contents.
Status word
BR CC 1 CC 0 OV OS OR STA RLO /FC writes:
-
-
-
-
-
-
-
-
-
Example Network 2
Network 1
OPN
DB10
Q 4.0
DBX0.0
Data block 10 (DB10) is opened. The contact address (DBX0.0) refers to bit zero of data byte zero
of the current data record contained in DB10. The signal state of this bit is assigned to the output
Q4.0.
Data Block Instructions
5.1 ---(OPN) Open Data Block: DB or DI
Ladder Logic (LAD) for S7-300 and S7-400 Programming
68
Reference Manual, 04/2017, A5E41524738-AA
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
69
6 Logic Control Instructions 6.1 Overview of Logic Control Instructions Description You can use logic control instructions in all logic blocks: organization blocks (OBs), function blocks
(FBs), and functions (FCs).
There are logic control instructions to perform the following functions:
•
---( JMP )--- Unconditional Jump
•
---( JMP )--- Conditional Jump
•
---( JMPN )--- Jump-If-Not
Label as Address The address of a Jump instruction is a label. A label consists of a maximum of four characters. The
first character must be a letter of the alphabet; the other characters can be letters or numbers (for
example, SEG3). The jump label indicates the destination to which you want the program to jump.
Label as Destination The destination label must be at the beginning of a network. You enter the destination label at the
beginning of the network by selecting LABEL from the ladder logic browser. An empty box appears.
In the box, you type the name of the label.
SEG3
JMP
I 0.1
=
Q 4.0
I 0.4
Network 1
Network 2
Network X
SEG3
. . R
Q 4.1
Logic Control Instructions
6.2 ---(JMP)--- Unconditional Jump
Ladder Logic (LAD) for S7-300 and S7-400 Programming
70
Reference Manual, 04/2017, A5E41524738-AA
6.2 ---(JMP)--- Unconditional Jump Symbol
Logic Control Instructions
6.3 ---(JMP)--- Conditional Jump
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
71
6.3 ---(JMP)--- Conditional Jump Symbol
Logic Control Instructions
6.4 ---( JMPN ) Jump-If-Not
Ladder Logic (LAD) for S7-300 and S7-400 Programming
72
Reference Manual, 04/2017, A5E41524738-AA
6.4 ---( JMPN ) Jump-If-Not Symbol
Logic Control Instructions
6.5 LABEL Label
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
73
6.5 LABEL Label Symbol LABEL
Description LABEL is the identifier for the destination of a jump instruction.
The first character must be a letter of the alphabet; the other characters can be letters or numbers
(for example, CAS1).
A jump label (
LABEL) must exist for every ---( JMP ) or ---( JMPN ).
Example I 0.0
Q 4.0
R
I 0.3
Network 2
Network 1
Network 3
I 0.4
Q 4.1
R
JMP
CAS1
CAS1
If I0.0 = "1", the jump to label CAS1 is executed. Because of the jump, the instruction to reset
output Q4.0 is not executed even if there is a logic "1" at I0.3.
Logic Control Instructions
6.5 LABEL Label
Ladder Logic (LAD) for S7-300 and S7-400 Programming
74
Reference Manual, 04/2017, A5E41524738-AA
Ladder Logic (LAD) for S7-300 and S7-400 Programming
Reference Manual, 04/2017, A5E41524738-AA
75
7 Integer Math Instructions 7.1 Overview of Integer Math Instructions Description Using integer math, you can carry out the following operations with
two integer numbers (16 and
32 bits):
•
ADD_I Add Integer
•
SUB_I Subtract Integer
•
MUL_I Multiply Integer
•
DIV_I Divide Integer
7.2 Evaluating the Bits of the Status Word with Integer Math Instructions
Ladder Logic (LAD) for S7-300 and S7-400 Programming
76
Reference Manual, 04/2017, A5E41524738-AA
7.2 Evaluating the Bits of the Status Word with Integer Math Instructions Description The integer math instructions affect the following bits in the Status word: CC1 and CC0, OV and
OS.
The following tables show the signal state of the bits in the status word for the results of
instructions with Integers (16 and 32 bits):
Valid Range for the Result CC 1 CC 0 OV OS 0 (zero)
0
0
0
*
16 bits: -32 768 <= result < 0 (negative number)
32 bits: -2 147 483 648 <=result < 0 (negative number)
0
1
0
*
16 bits: 32 767 >= result > 0 (positive number)
32 bits: 2 147 483 647 >= result > 0 (positive number)
1
0
0
*
* The OS bit is not affected by the result of the instruction.