S7 Ladder Instruction
S7 Ladder Instruction
LAD
                                                   -1-
                                    Bit logic operations (S7-1200, S7-1500)
                                                     -2-
                               ---| |---: Normally open contact (S7-1200, S7-1500)
Description
The activation of the normally open contact depends on the signal state of the associated operand.
When the operand has signal state "1", the normally open contact closes and the signal state at the
output is set to the signal state of the input.
When the operand has signal state "0", the normally open contact is not activated and the signal state
at the output of the instruction is reset to "0".
Two or more normally open contacts are linked bit-by-bit by AND when connected in series. With a
series connection, power flows when all contacts are closed.
The normally open contacts are linked by OR when connected in parallel. With a parallel connection,
power flows when one of the contacts is closed.
Parameter
The following table shows the parameters of the instruction:
Example
The following example shows how the instruction works:
The "TagOut" operand is set when one of the following conditions is fulfilled:
•   The operands "TagIn_1" and "TagIn_2" have signal state "1".
•   The operand "TagIn_3" has the signal state "1".
                                                      -3-
                               ---| / |---: Normally closed contact (S7-1200, S7-1500)
Description
The activation of the normally closed contact depends on the signal state of the associated operand.
When the operand has signal state "1", the normally closed contact opens and the signal state at the
output of the instruction is reset to "0".
When the operand has signal state "0", the normally closed contact is not enabled and the signal state
of the input is transferred to the output.
Two or more normally closed contacts are linked bit-by-bit by AND when connected in series. With a
series connection, power flows when all contacts are closed.
The normally closed contacts are linked by OR when connected in parallel. With a parallel connection,
power flows when one of the contacts is closed.
Parameter
The following table shows the parameters of the instruction:
Example
The following example shows how the instruction works:
The "TagOut" operand is set when one of the following conditions is fulfilled:
•   The operands "TagIn_1" and "TagIn_2" have signal state "1".
•   The operand "TagIn_3" has the signal state "0".
                                                        -4-
                                    --|NOT|--: Invert RLO (S7-1200, S7-1500)
Description
You use the "Invert RLO" instruction to invert the signal state of the result of logic operation (RLO). If
the signal state is "1" at the input of the instruction, the output of the instruction has signal state "0". If
the signal state is "0" at the input of the instruction, the output has the signal state "1".
Example
The following example shows how the instruction works:
                                                      -5-
                                     ---( )---: Assignment (S7-1200, S7-1500)
Description
You can use the "Assignment" instruction to set the bit of a specified operand. If the result of logic
operation (RLO) at the input of the coil has signal state "1", the specified operand is set to signal state
"1". If the signal state is "0" at the input of the coil, the bit of the specified operand is reset to "0".
The instruction does not influence the RLO. The RLO at the input of the coil is sent directly to the out‐
put.
Parameter
The following table shows the parameters of the "Assignment" instruction:
Example
The following example shows how the instruction works:
The "TagOut_1" operand is set when one of the following conditions is fulfilled:
•   The operands "TagIn_1" and "TagIn_2" have signal state "1".
•   The signal state of the operand "TagIn_3" is "0".
The "TagOut_2" operand is set when one of the following conditions is fulfilled:
•   Operands "TagIn_1", "TagIn_2", and "TagIn_4" have signal state "1".
•   The signal state of the "TagIn_3" operand is "0" and the signal state of the "TagIn_4" operand is
    "1".
                                                       -6-
                                 --( / )--: Negate assignment (S7-1200, S7-1500)
Description
The "Negate assignment" instruction inverts the result of logic operation (RLO) and assigns it to the
specified operand. When the RLO at the input of the coil is "1", the operand is reset. When the RLO at
the input of the coil is "0", the operand is set to signal state "1".
Parameter
The following table shows the parameters of the "Negate assignment" instruction:
Example
The following example shows how the instruction works:
                                                      -7-
                                   ---( R )---: Reset output (S7-1200, S7-1500)
Description
You can use the "Reset output" instruction to reset the signal state of a specified operand to "0".
The instruction is only executed if the result of logic operation (RLO) at the input of the coil is "1". If
power flows to the coil (RLO = "1"), the specified operand is reset to "0". If the RLO at the input of the
coil is "0" (no signal flow to the coil), the signal state of the specified operand remains unchanged.
Parameter
The following table shows the parameters of the "Reset output" instruction:
Example
The following example shows how the instruction works:
                                                      -8-
                                     ---( S )---: Set output (S7-1200, S7-1500)
Description
You can use the "Set output" instruction to set the signal state of a specified operand to "1".
The instruction is only executed if the result of logic operation (RLO) at the input of the coil is "1". If
power flows to the coil (RLO = "1"), the specified operand is set to "1". If the RLO at the input of the
coil is "0" (no signal flow to the coil), the signal state of the specified operand remains unchanged.
Parameter
The following table shows the parameters of the "Set output" instruction:
Example
The following example shows how the instruction works:
The "TagOut" operand is set when one of the following conditions is fulfilled:
•   The operands "TagIn_1" and "TagIn_2" have signal state "1".
•   The signal state of the operand "TagIn_3" is "0".
                                                       -9-
                                    Timer operations (S7-1200, S7-1500)
Timer operations
                                                   - 10 -
                                        IEC Timers (S7-1200, S7-1500)
IEC Timers
                                                    - 11 -
                                     TP: Generate pulse (S7-1200, S7-1500)
Description
You can use the "Generate pulse" instruction to set the output Q for a programmed duration. The in‐
struction is started when the result of logic operation (RLO) at input IN changes from "0" to "1" (posi‐
tive signal edge). The programmed time PT begins when the instruction starts. Output Q is set for the
duration PT, regardless of the subsequent course of the input signal. Even if a new positive signal
edge is detected, the signal state at the output Q is not affected as long as the PT time duration is
running.
You can scan the current time value at the ET output. The time value starts at T#0s and ends when
the value of duration PT is reached. When the duration PT is reached and the signal state at input IN
is "0", the ET output is reset.
Each call of the "Generate pulse" instruction must be assigned to an IEC timer in which the instruction
data is stored.
    Note
    If the timer is not called in the program because it is skipped, for example, the ET output returns a
    constant value as soon as the timer has expired.
Parameters
The following table shows the parameters of the "Generate pulse" instruction:
                                                     - 12 -
                                   TP: Generate pulse (S7-1200, S7-1500)
                                                   - 13 -
                                   TON: Generate on-delay (S7-1200, S7-1500)
Description
You can use the "Generate on-delay" instruction to delay setting of the Q output by the programmed
duration PT. The instruction is started when the result of logic operation (RLO) at input IN changes
from "0" to "1" (positive signal edge). The programmed time PT begins when the instruction starts.
When the duration PT expires, the output Q has the signal state "1". Output Q remains set as long as
the start input is still "1". When the signal state at the start input changes from "1" to "0", the Q output
is reset. The timer function is started again when a new positive signal edge is detected at the start
input.
The current time value can be queried at the ET output. The time value starts at T#0s and ends when
the value of duration PT is reached. The ET output is reset as soon as the signal state at the IN input
changes to "0".
Each call of the "Generate on-delay" instruction must be assigned to an IEC timer in which the instruc‐
tion data is stored.
    Note
    If the timer is not called in the program because it is skipped, for example, the ET output returns a
    constant value as soon as the timer has expired.
•   Declaration as a local tag of the type TON_TIME or IEC_TIMER in the "Static" section of a block
    (for example, #MyIEC_TIMER)
Parameters
The following table shows the parameters of the "Generate on-delay" instruction:
                                                     - 14 -
                                 TON: Generate on-delay (S7-1200, S7-1500)
                                                   - 15 -
                                   TOF: Generate off-delay (S7-1200, S7-1500)
Description
You can use the "Generate off-delay" instruction to delay resetting of the Q output by the programmed
duration PT. The Q output is set when the result of logic operation (RLO) at input IN changes from "0"
to "1" (positive signal edge). When the signal state at input IN changes back to "0", the programmed
time PT starts. Output Q remains set as long as the duration PT is running. When duration PT ex‐
pires, the Q output is reset. If the signal state at input IN changes to "1" before the PT time duration
expires, the timer is reset. The signal state at the output Q continues to be "1".
The current time value can be queried at the ET output. The time value starts at T#0s and ends when
the value of duration PT is reached. When the time duration PT expires, the ET output remains set to
the current value until the IN input changes back to "1". If input IN switches to "1" before the duration
PT has expired, the ET output is reset to the value T#0s.
Each call of the "Generate off-delay" instruction must be assigned to an IEC timer in which the instruc‐
tion data is stored.
    Note
    If the timer is not called in the program because it is skipped, for example, the ET output returns a
    constant value as soon as the timer has expired.
•   Declaration as a local tag of the type TOF_TIME or IEC_TIMER in the "Static" section of a block
    (for example, #MyIEC_TIMER)
Parameters
The following table shows the parameters of the "Generate off-delay" instruction:
                                                     - 16 -
                                 TOF: Generate off-delay (S7-1200, S7-1500)
                                                   - 17 -
                                 TONR: Time accumulator (S7-1200, S7-1500)
Description
The "Time accumulator" instruction is used to accumulate time values within a period set by the PT
parameter. When the signal state at input IN changes from "0" to "1" (positive signal edge), the in‐
struction executes and the duration PT starts. While the duration PT is running, the time values are
accumulated that are recorded when the IN input has signal state "1". The accumulated time is written
to output ET and can be queried there. When the duration PT expires, the output Q has the signal
state "1". The Q parameter remains set to "1", even when the signal state at the IN parameter
changes from "1" to "0" (negative signal edge).
The R input resets the outputs ET and Q regardless of the signal state at the start input.
Each call of the "Time accumulator" instruction must be assigned to an IEC timer in which the instruc‐
tion data is stored.
Parameters
The following table shows the parameters of the "Time accumulator" instruction:
                                                   - 18 -
                                 TONR: Time accumulator (S7-1200, S7-1500)
                                                   - 19 -
                                  ---( TP )---: Start pulse timer (S7-1200, S7-1500)
Description
Use the "Start pulse timer" instruction to start an IEC timer with a specified duration as pulse. The IEC
timer is started when the result of logic operation (RLO) changes from "0" to "1" (positive signal edge).
The IEC timer runs for the specified duration regardless of any subsequent changes in the RLO. The
run of the IEC timer is also not affected by the detection of a new positive signal edge. As long as the
IEC timer is running, the querying of the timer status for "1" returns the signal state "1". When the IEC
timer has expired, the timer status returns the signal state "0".
    Note
    You can start and query the IEC timer at various execution levels, as each querying of the outputs
    Q or ET updates the IEC_TIMER structure.
Parameter
The following table shows the parameters of the "Start pulse timer" instruction:
                                                        - 20 -
                                ---( TP )---: Start pulse timer (S7-1200, S7-1500)
                                                           IEC_TIMER,
                                     IEC_TIMER,            IEC_LTIMER,                 IEC timer that
 <IEC timer>       InOut                                                        D, L
                                     TP_TIME               TP_TIME,                    is started.
                                                           TP_LTIME
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The "Start pulse timer" instruction is executed when the signal state of the operand "Tag_Input"
changes from "0" to "1". The timer "DB1".MyIEC_TIMER is started for the time stored in the operand
"TagTime".
As long as the timer "DB1". MyIEC_TIMER is running, the timer status ("DB1".MyIEC_TIMER.Q) has
signal state "1" and the operand "Tag_Output" is set. When the IEC timer has expired, the signal state
of the time status changes back to "0" and the "Tag_Output" operand is reset.
                                                      - 21 -
                              ---( TON )---: Start on-delay timer (S7-1200, S7-1500)
Description
Use the "Start on-delay timer" instruction to start an IEC timer with a specified duration as on-delay.
The IEC timer is started when the result of logic operation (RLO) changes from "0" to "1" (positive sig‐
nal edge). The IEC timer runs for the specified time. The output returns the signal state "1" if the RLO
at the input of the instruction has the signal state "1". If the RLO changes to "0" before the time ex‐
pires, the IEC timer is reset. In this case, querying the timer status for "1" returns signal state "0". The
IEC timer restarts when the next positive signal edge is detected at the input of the instruction.
    Note
    You can start and query the IEC timer at various execution levels, as each querying of the outputs
    Q or ET updates the IEC_TIMER structure.
Parameter
The following table shows the parameters of the "Start on-delay timer" instruction:
                                                      - 22 -
                              ---( TON )---: Start on-delay timer (S7-1200, S7-1500)
                                                           IEC_TIMER,
                                      IEC_TIMER,           IEC_LTIMER,                 IEC timer that
 <IEC timer>       InOut                                                       D, L
                                      TON_TIME             TON_TIME,                   is started.
                                                           TON_LTIME
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The "Start on-delay timer" instruction is executed when the signal state of the operand "Tag_Input"
changes from "0" to "1". The "MyIEC_TIMER timer is started for the time stored in the "TagTime" op‐
erand.
If the timer "MyIEC_TIMER" has expired and the operand "Tag_Input" has the signal state "1", query‐
ing the timer status ("MyIEC_TIMER).Q) returns signal state "1" and the "Tag_Output" operand is set.
When the signal state of the operand "Tag_Input" changes to "0", the querying of the timer status re‐
turns the signal state "0" and the operand "Tag_Output" is reset.
                                                      - 23 -
                               ---( TOF )---: Start off-delay timer (S7-1200, S7-1500)
Description
Use the "Start off-delay timer" instruction to start an IEC timer with a specified duration as on-delay.
The query of the timer status for "1" returns the signal state "0" if the result of logic operation (RLO) at
the input of the instruction has the signal state "1". When the RLO changes from "1" to "0" (negative
signal edge), the IEC timer starts with the specified time. The timer status remains at signal state "1"
as long as the IEC timer is running. When the timer has run out and the RLO at the input of the in‐
struction has the signal state "0", the timer status is set to the signal state "0". If the RLO changes to
"1" before the time expires, the IEC timer is reset and the timer status remains at signal state "1".
    Note
    You can start and query the IEC timer at various execution levels, as each querying of the outputs
    Q or ET updates the IEC_TIMER structure.
Parameters
The following table shows the parameters of the "Start off-delay timer" instruction:
                                                       - 24 -
                              ---( TOF )---: Start off-delay timer (S7-1200, S7-1500)
Example
The following example shows how the instruction works:
The "Start off-delay timer" instruction is executed when the signal state of the operand "Tag_Input"
changes from "1" to "0". The timer #MyIEC_TIMER is started for the time stored in the operand "Tag‐
Time".
As long as timer #MyIEC_TIMER is running, the query of the time status (#MyIEC_TIMER.Q) returns
the signal state "1" and operand "Tag_Output" is set. If the timer has expired and the operand
"Tag_Input" has the signal state "0", the query of the timer status returns the signal state "0". If the
signal state of the operand "Tag_Input" changes to "1" before timer #MyIEC_TIMER expires, the timer
is reset. When the signal state of the operand "Tag_Input" is "1", the query of the timer status returns
the signal state "1".
                                                      - 25 -
                              ---( TONR )---: Time accumulator (S7-1200, S7-1500)
Description
You can use the "Time accumulator" instruction to record how long the signal is at the input of instruc‐
tion "1". The instruction is started when the result of logic operation (RLO) changes from "0" to "1"
(positive signal edge). The time is recorded as long at the RLO is "1". If the RLO changes to "0", the
instruction is halted. If the RLO changes back to "1", the time recording is continued. The query of the
timer status for "1" returns the signal state "1" if the recorded time exceeds the value of the specified
duration and the RLO at the input of coil is "1".
The timer status and the currently expired timer can be reset to "0" using the "Reset timer" instruction.
    Note
    You can start and query the IEC timer at various execution levels, as each querying of the outputs
    Q or ET updates the IEC_TIMER structure.
Parameter
The following table shows the parameters of the "Time accumulator" instruction:
                                                    - 26 -
                              ---( TONR )---: Time accumulator (S7-1200, S7-1500)
Example
The following example shows how the instruction works:
The "Time accumulator" instruction executes on a positive signal edge in the RLO. The time is recor‐
ded as long as the operand "Tag_Input" has the signal state "1".
If the recorded time exceeds the value of the operand "TagTime", then the query of the timer status
("MyIEC_TIMER".Q) will return the signal state "1" and the operand "Tag_Output" will be set.
                                                    - 27 -
                                   ---( RT )---: Reset timer (S7-1200, S7-1500)
Description
You can use the "Reset timer" instruction to reset an IEC timer to "0". The instruction is only executed
if the result of logic operation (RLO) at the input of the coil is "1". If current is flowing to the coil (RLO
is "1"), the structure components of the timer in the specified data block are reset to "0". If the RLO at
the input of the instruction is "0", the timer remains unchanged.
The instruction does not influence the RLO. The RLO at the input of the coil is sent directly to the out‐
put of the coil.
You assign the "Reset timer" instruction an IEC timer that has been declared in the program.
The instruction data is updated only when the instruction is called and not each time the assigned IEC
timer is accessed. Querying the data is only identical from the call of the instruction to the next call of
the instruction.
Parameters
The following table shows the parameters of the "Reset timer" instruction":
Example
The following example shows how the instruction works:
The "Generate on-delay" instruction executes when the signal state of the "Tag_Input_1" operand
changes from "0" to "1". The timer stored in the "TON_DB" instance data block starts running for the
time duration specified by operand "Tag_PT".
                                                      - 28 -
                                 ---( RT )---: Reset timer (S7-1200, S7-1500)
If operands "Tag_Input_2" and "Tag_Input_3" have the signal state "1", the "Reset timer" instruction is
executed and the timer stored in the "TON_DB" data block.
                                                    - 29 -
                               ---( PT )---: Load time duration (S7-1200, S7-1500)
Description
You can use the "Load time duration" instruction to set the time for an IEC timer. The instruction is
executed in every cycle when the result of logic operation (RLO) at the input of the instruction has the
signal state "1". The instruction writes the specified time to the structure of the specified IEC timer.
 Note
 If the specified IEC timer is running while the instruction executes, the instruction overwrites the
 current time of the specified IEC timer. This can change the timer status of the IEC timer.
You assign an IEC timer declared in the program to the "Load time duration" instruction.
The instruction data is updated only when the instruction is called and each time the assigned IEC
timer is accessed. The query on Q or ET (for example, "MyTimer".Q or "MyTimer".ET) updates the
IEC_TIMER structure.
Parameter
The following table shows the parameters of the "Load time duration" instruction:
Example
The following example shows how the instruction works:
                                                     - 30 -
                             ---( PT )---: Load time duration (S7-1200, S7-1500)
The "Generate on-delay" instruction executes when the signal state of the "Tag_Input_1" operand
changes from "0" to "1". The IEC timer stored in the instance data block "TON_DB" is started with the
time duration that is specified by the operand "Tag_PT".
The "Load time duration" instruction is executed when the operand "Tag_Input_2" has the signal state
"1". The instruction writes the time duration "Tag_PT_2" in the instance data block "TON_DB" and at
the same time overwrites the value of the operand "Tag_PT" within the data block. The signal state of
the timer status may therefore change at the next query or when "MyTimer".Q or "MyTimer".ET are
accessed.
                                                   - 31 -
                                             SIMATIC Timers (S7-1500)
SIMATIC Timers
                                                      - 32 -
                          S_PULSE: Assign pulse timer parameters and start (S7-1500)
Description
The "Assign pulse timer parameters and start" instruction starts a programmed timer when a change
from "0" to "1" (positive signal edge) is detected in the result of logic operation (RLO) at input S. The
timer expires with the programmed duration (TV) as soon as the signal state at input S is "1". If the
signal state at input S changes to "0" before the programmed duration expires, the timer is stopped. In
this case, the signal state at output Q is "0".
The duration is made up internally of a time value and a time base and is programmed at parameter
TV. When the instruction is started, the programmed time value is counted down towards zero. The
time base indicates the time period with which the time value is changed. The current time value is
output BI-coded at output BI and BCD-coded at output BCD.
If the timer is running and the signal state at input R changes to "1" then the current time value and
the time base are also set to zero. If the timer is not running, the signal state "1" at the R input has no
effect.
The "Assign pulse timer parameters and start" instruction requires a preceding logic operation for
edge evaluation and can be placed within or at the end of the network.
The instruction data is updated at every access. It can therefore happen that the query of the data at
the start of the cycle returns different values than at the end of the cycle.
 Note
 In the time cell, the operating system reduces the time value in an interval specified by the time
 base by one unit until the value equals "0". The decrementation is performed asynchronously to the
 user program. The resulting timer is therefore at maximum up to one time interval shorter than the
 desired time base.
You can find an example of how a time cell can be formed under: See also "L: Load timer value".
Parameters
The following table shows the parameters of the instruction "Assign pulse timer parameters and start":
                                                    - 33 -
                          S_PULSE: Assign pulse timer parameters and start (S7-1500)
Example
The following example shows how the instruction works:
                                                    - 34 -
                         S_PULSE: Assign pulse timer parameters and start (S7-1500)
The timer "Timer_1" is started when the signal state of the operand "TagIn_1" changes from "0" to "1".
The timer expires with the time value of the operand "TagIn_Number" as long as the operand "Ta‐
gIn_1" has the signal state "1". If the signal state of the operand "TagIn_1" changes from "1" to "0"
before the timer expires, the timer "Timer_1" is stopped. The operand "TagOut" is reset to "0" in this
case.
The operand "TagOut" has the signal state "1" as long as the timer is running and the operand "Ta‐
gIn_1" has the signal state "1". When the timer expires or is reset, the operand "TagOut" is reset to
"0".
                                                   - 35 -
                      S_PEXT: Assign extended pulse timer parameters and start (S7-1500)
Description
The "Assign extended pulse timer parameters and start" instruction starts a programmed timer when a
change from "0" to "1" (positive signal edge) is detected in the result of logic operation (RLO) at input
S. The timer expires with the programmed duration (TV), even if the signal state at input S changes to
"0". As long as the timer is running, the output Q has the signal state "1". When the timer expires, the
output Q is reset to "0". If the signal state at input S changes from "0" to "1" while the timer is running,
the timer is restarted with the duration programmed at input TV.
The duration is made up internally of a time value and a time base and is programmed at parameter
TV. When the instruction is started, the programmed time value is counted down towards zero. The
time base indicates the time period with which the time value is changed. The current time value is
output BI-coded at output BI and BCD-coded at output BCD.
If the timer is running and the signal state at input R changes to "1" then the current time value and
the time base are also set to zero. If the timer is not running, the signal state "1" at the R input has no
effect.
The "Assign extended pulse timer parameters and start" instruction requires a preceding logic opera‐
tion for edge evaluation and can be placed within or at the end of the network.
The instruction data is updated at every access. It can therefore happen that the query of the data at
the start of the cycle returns different values than at the end of the cycle.
 Note
 In the time cell, the operating system reduces the time value in an interval specified by the time
 base by one unit until the value equals "0". The decrementation is performed asynchronously to the
 user program. The resulting timer is therefore at maximum up to one time interval shorter than the
 desired time base.
You can find an example of how a time cell can be formed under: See also "L: Load timer value".
Parameter
The following table shows the parameters of the instruction "Assign extended pulse timer parameters
and start":
                                                    - 36 -
                      S_PEXT: Assign extended pulse timer parameters and start (S7-1500)
Example
The following example shows how the instruction works:
The timer "Timer_1" is started when the signal state of the operand "TagIn_1" changes from "0" to "1".
The timer expires with the time value of the operand "TagIn_Number" without being affected by a neg‐
                                                    - 37 -
                     S_PEXT: Assign extended pulse timer parameters and start (S7-1500)
ative edge at input S. If the signal state of the operand "TagIn_1" changes from "0" to "1" before the
timer expires, the timer is restarted.
The operand "TagOut" has the signal state "1" as long as the timer is running. When the timer expires
or is reset, the operand "TagOut" is reset to "0".
                                                   - 38 -
                          S_ODT: Assign on-delay timer parameters and start (S7-1500)
Description
The "Assign on-delay timer parameters and start" instruction starts a programmed timer when a
change from "0" to "1" (positive signal edge) is detected in the result of logic operation (RLO) at input
S. The timer expires with the programmed duration (TV) as soon as the signal state at input S is "1". If
the timer expires correctly and input S still has signal state "1" then output Q returns signal state "1". If
the signal state at input S changes from "1" to "0" while the timer is running, the timer is stopped. In
this case, output Q is reset to signal state "0".
The duration is made up internally of a time value and a time base and is programmed at parameter
TV. When the instruction is started, the programmed time value is counted down towards zero. The
time base indicates the time period with which the time value is changed. The current time value is
output BI-coded at output BI and BCD-coded at output BCD.
If the time is running and the signal state at input R changes from "0" to "1" then the current time val‐
ue and the time base are also set to zero. In this case, the signal state at output Q is "0". The timer is
reset if the signal state is "1" at the R input even if the timer is not running and the RLO at input S is
"1".
Specify the timer of the instruction in the placeholder above the box. The timer must be declared with
the data type TIMER.
The "Assign on-delay timer parameters and start" instruction requires a preceding logic operation for
edge evaluation and can be placed within or at the end of the network.
The instruction data is updated at every access. It can therefore happen that the query of the data at
the start of the cycle returns different values than at the end of the cycle.
  Note
  In the time cell, the operating system reduces the time value in an interval specified by the time
  base by one unit until the value equals "0". The decrementation is performed asynchronously to the
  user program. The resulting timer is therefore at maximum up to one time interval shorter than the
  desired time base.
You can find an example of how a time cell can be formed under: See also "L: Load timer value".
Parameter
The following table shows the parameters of the "Assign on-delay timer parameters and start" instruc‐
tion:
                                                     - 39 -
                          S_ODT: Assign on-delay timer parameters and start (S7-1500)
                                                                    I, Q, M, T, C, D, L,
 R                     Input                 BOOL                                        Reset input
                                                                    P or constant
                                                                                        Current time value
 BI                    Output                WORD                   I, Q, M, D, L, P
                                                                                        (BI-coded)
                                                                                        Current time value
 BCD                   Output                WORD                   I, Q, M, D, L, P
                                                                                        (BCD format)
 Q                     Output                BOOL                   I, Q, M, D, L       Status of the timer
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
                                                     - 40 -
                        S_ODT: Assign on-delay timer parameters and start (S7-1500)
The timer "Timer_1" is started when the signal state of the operand "TagIn_1" changes from "0" to "1".
The timer expires with the time value of the operand "TagIn_Number". If the timer expires and the op‐
erand has the signal state "1", the operand "TagOut" is set to "1". If the signal state of the operand
"TagIn_1" changes from "1" to "0" before the timer expires, the timer is stopped. The operand "Tag‐
Out" has the signal state "0" in this case.
                                                   - 41 -
                     S_ODTS: Assign retentive on-delay timer parameters and start (S7-1500)
Description
The "Assign retentive on-delay timer parameters and start" instruction starts a programmed timer
when a change from "0" to "1" (positive signal edge) is detected in the result of logic operation (RLO)
at input S. The timer expires with the programmed duration (TV), even if the signal state at input S
changes to "0". If the timer expires, the "Q" output returns signal state "1" regardless of the signal
state at input "S". If the signal state at input S changes from "0" to "1" while the timer is running, the
timer is restarted with the duration programmed at input (TV).
The duration is made up internally of a time value and a time base and is programmed at parameter
TV. When the instruction is started, the programmed time value is counted down towards zero. The
time base indicates the time period with which the time value is changed. The current time value is
output BI-coded at output BI and BCD-coded at output BCD.
Signal state "1" at input R resets the current time value and time base to "0" regardless of the signal
state at start input S. In this case, the signal state at output Q is "0".
The "Assign retentive on-delay timer parameters and start" instruction requires a preceding logic oper‐
ation for edge evaluation and can be placed within or at the end of the network.
The instruction data is updated at every access. It can therefore happen that the query of the data at
the start of the cycle returns different values than at the end of the cycle.
 Note
 In the time cell, the operating system reduces the time value in an interval specified by the time
 base by one unit until the value equals "0". The decrementation is performed asynchronously to the
 user program. The resulting timer is therefore at maximum up to one time interval shorter than the
 desired time base.
You can find an example of how a time cell can be formed under: See also "L: Load timer value".
Parameter
The following table shows the parameters of the "Assign retentive on-delay timer parameters and
start" instruction:
                                                     - 42 -
                     S_ODTS: Assign retentive on-delay timer parameters and start (S7-1500)
Example
The following example shows how the instruction works:
The timer "Timer_1" is started when the signal state of the operand "TagIn_1" changes from "0" to "1".
The timer expires with the time value of the operand "TagIn_Number", even if the signal state of the
operand "TagIn_1" changes to "0". When the timer expires, the operand "TagOut" is set to "1". If the
signal state of the operand "TagIn_1" changes from "0" to "1" while the timer is running, the timer is
restarted.
                                                     - 43 -
                         S_OFFDT: Assign off-delay timer parameters and start (S7-1500)
Description
The "Assign off-delay timer parameters and start" instruction starts a programmed timer when a
change from "1" to "0" (negative signal edge) is detected in the result of logic operation (RLO) at input
S. The timer expires with the programmed duration (TV). As long as the timer is running or input S
returns signal state "1", then output Q has signal state "1". When the timer expires and the signal
state at input S is "0", output Q is reset to the signal state "0". If the signal state at input S changes
from "0" to "1" while the timer is running, the timer is stopped. The timer is only restarted after a falling
signal edge is detected at input S.
The duration is made up internally of a time value and a time base and is programmed at parameter
TV. When the instruction is started, the programmed time value is counted down towards zero. The
time base indicates the time period with which the time value is changed. The current time value is
output BI-coded at output BI and BCD-coded at output BCD.
Signal state "1" at input R resets the current time value and time base to "0". In this case, the signal
state at output Q is "0".
The "Assign off-delay timer parameters and start" instruction requires a preceding logic operation for
edge evaluation and can be placed within or at the end of the network.
The instruction data is updated at every access. It can therefore happen that the query of the data at
the start of the cycle returns different values than at the end of the cycle.
 Note
 In the time cell, the operating system reduces the time value in an interval specified by the time
 base by one unit until the value equals "0". The decrementation is performed asynchronously to the
 user program. The resulting timer is therefore at maximum up to one time interval shorter than the
 desired time base.
You can find an example of how a time cell can be formed under: See also "L: Load timer value".
Parameter
The following table shows the parameters of the "Assign off-delay timer parameters and start" instruc‐
tion:
                                                     - 44 -
                        S_OFFDT: Assign off-delay timer parameters and start (S7-1500)
Example
The following example shows how the instruction works:
The timer "Timer_1" is started when the signal state of the operand "TagIn_1" changes from "1" to "0".
The timer expires with the time value of the operand "TagIn_Number". The operand "TagOut" is set to
"1" when the timer is running and when the operand "TagIn_1" has the signal state "0". If the signal
state of the operand "TagIn_1" changes from "0" to "1" while the timer is running, the timer is reset.
                                                    - 45 -
                                     ---( SP ): Start pulse timer (S7-1500)
Description
The "Start pulse timer" instruction starts a programmed timer when a change from "0" to "1" (positive
signal edge) is detected in the result of logic operation (RLO). The time runs with the specified dura‐
tion as long as the RLO has the signal state "1". As long as the timer is running, the querying of the
timer status for "1" returns the signal state "1". If there is a change from "1" to "0" in the RLO before
the time value has elapsed, the timer stops. In this case, the querying of the timer status for "1" re‐
turns the signal state "0".
The duration is made up internally of a time value and a time base. When the instruction is started,
the programmed time value is counted down towards zero. The time base indicates the time period
with which the time value is changed.
The "Start pulse timer" instruction requires a preceding logic operation for edge evaluation and can
only be placed at the right side of the network.
 Note
 In the time cell, the operating system reduces the time value in an interval specified by the time
 base by one unit until the value equals "0". The decrementation is performed asynchronously to the
 user program. The resulting timer is therefore at maximum up to one time interval shorter than the
 desired time base.
You can find an example of how a time cell can be formed under: See also "L: Load timer value".
Parameters
The following table shows the parameters of the "Start pulse timer" instruction:
Example
The following example shows how the instruction works:
                                                     - 46 -
                                    ---( SP ): Start pulse timer (S7-1500)
The timer "Timer_1" is started when the signal state of the operand "TagIn_1" changes from "0" to "1".
The timer expires with the time value of the operand "TagIn_Number" as long as the signal state of
the operand "TagIn_1" is "1". If the signal state of the operand "TagIn_1" changes from "1" to "0" be‐
fore the timer expires, the timer is stopped. As long as the timer is running, the operand "TagOut" has
the signal state "1". A signal state change of the operand "TagIn_1" from "0" to "1" resets the timer,
which stops the timer and sets the current time value to "0".
                                                    - 47 -
                                 ---( SE ): Start extended pulse timer (S7-1500)
Description
The "Start extended pulse timer" instruction starts a programmed timer when a change from "0" to "1"
(positive signal edge) is detected in the result of logic operation (RLO). The timer expires with the
specified duration, even if the RLO changes to the signal state "0". As long as the timer is running, the
querying of the timer status for "1" returns the signal state "1". If the RLO changes from "0" to "1"
while the timer is running, the timer is restarted with the programmed duration. The querying of the
timer status for "1" returns the signal state "0" when the timer expires.
The duration is made up internally of a time value and a time base. When the instruction is started,
the programmed time value is counted down towards zero. The time base indicates the time period
with which the time value is changed.
The "Start extended pulse timer" instruction requires a preceding logic operation for edge evaluation
and can only be placed at the right side of the network.
 Note
 In the time cell, the operating system reduces the time value in an interval specified by the time
 base by one unit until the value equals "0". The decrementation is performed asynchronously to the
 user program. The resulting timer is therefore at maximum up to one time interval shorter than the
 desired time base.
You can find an example of how a time cell can be formed under: See also "L: Load timer value".
Parameter
The following table shows the parameters of the "Start extended pulse timer" instruction:
Example
The following example shows how the instruction works:
                                                     - 48 -
                                ---( SE ): Start extended pulse timer (S7-1500)
The timer "Timer_1" is started when the signal state of the operand "TagIn_1" changes from "0" to "1".
The timer expires with the time value of the operand "TagIn_Number" without being affected by a neg‐
ative edge in the RLO. As long as the timer is running, the operand "TagOut" has the signal state "1".
If the signal state of the operand "TagIn_1" changes from "0" to "1" before the timer expires, the timer
is restarted.
                                                    - 49 -
                                     ---( SD ): Start on-delay timer (S7-1500)
Description
The "Start on-delay timer" instruction starts a programmed timer when a change from "0" to "1" (posi‐
tive signal edge) is detected in the result of logic operation (RLO). The timer runs for the specified
duration as long as the RLO is "1". If the timer expires and the RLO still has the signal state "1", the
query of the timer status for "1" returns the signal state "1". If the RLO changes from "1" to "0" while
the timer is running, the timer is stopped. In this case, the querying of the timer status for "1" returns
the signal state "0".
The duration is made up internally of a time value and a time base. When the instruction is started,
the programmed time value is counted down towards zero. The time base indicates the time period
with which the time value is changed.
The "Start on-delay timer" instruction requires a preceding logic operation for edge evaluation and can
only be placed at the right side of the network.
 Note
 In the time cell, the operating system reduces the time value in an interval specified by the time
 base by one unit until the value equals "0". The decrementation is performed asynchronously to the
 user program. The resulting timer is therefore at maximum up to one time interval shorter than the
 desired time base.
You can find an example of how a time cell can be formed under: See also "L: Load timer value".
Parameter
The following table shows the parameters of the "Start on-delay timer" instruction:
Example
The following example shows how the instruction works:
                                                      - 50 -
                                   ---( SD ): Start on-delay timer (S7-1500)
The timer "Timer_1" is started when the signal state of the operand "TagIn_1" changes from "0" to "1".
The timer expires with the time value of the operand "TagIn_Number". If the timer expires and the
RLO has the signal state "1", the operand "TagOut" is set to "1". If the signal state of the operand
"TagIn_1" changes from "1" to "0" before the timer expires, the timer is stopped. If the signal state of
the operand "TagIn_2" is "1", the timer "Timer_1" is reset, which stops the timer and sets the current
time value to "0".
                                                    - 51 -
                                ---( SS ): Start retentive on-delay timer (S7-1500)
Description
The "Start retentive on-delay timer" instruction starts a programmed timer when a change from "0" to
"1" (positive signal edge) is detected in the result of logic operation (RLO). The timer expires with the
specified duration, even if the RLO changes to the signal state "0". When the timer expires, the query‐
ing of the timer status for "1" returns the signal state "1". After expiry of the timer, the timer can only
be restarted if it is explicitly reset.
The duration is made up internally of a time value and a time base. When the instruction is started,
the programmed time value is counted down towards zero. The time base indicates the time period
with which the time value is changed.
The "Start retentive on-delay timer" instruction requires a preceding logic operation for edge evalua‐
tion and can only be placed at the right side of the network.
 Note
 In the time cell, the operating system reduces the time value in an interval specified by the time
 base by one unit until the value equals "0". The decrementation is performed asynchronously to the
 user program. The resulting timer is therefore at maximum up to one time interval shorter than the
 desired time base.
You can find an example of how a time cell can be formed under: See also "L: Load timer value".
Parameters
The following table shows the parameters of the "Start retentive on-delay timer" instruction:
Example
The following example shows how the instruction works:
                                                      - 52 -
                                ---( SS ): Start retentive on-delay timer (S7-1500)
The timer "Timer_1" is started when the signal state of the operand "TagIn_1" changes from "0" to "1".
The timer expires with the time value of the operand "TagIn_Number". When the timer expires, the
operand "TagOut" is set to "1". If the signal state of the operand "TagIn_1" changes from "0" to "1"
while the timer is running, the timer is restarted. If the signal state of the operand "TagIn_2" is "1", the
timer "Timer_1" is reset, which stops the timer and sets the current time value to "0".
                                                      - 53 -
                                     ---( SF ): Start off-delay timer (S7-1500)
Description
The "Start off-delay timer" instruction starts a programmed timer when a change from "1" to "0" (nega‐
tive signal edge) is detected in the result of logic operation (RLO). The timer expires with the specified
duration. As long as the timer is running, the querying of the timer status for "1" returns the signal
state "1". If the RLO changes from "0" to "1" while the timer is running, the timer is reset. The timer is
always restarted when the RLO changes from "1" to "0".
The duration is made up internally of a time value and a time base. When the instruction is started,
the programmed time value is counted down towards zero. The time base indicates the time period
with which the time value is changed.
The "Start off-delay timer" instruction requires a preceding logic operation for edge evaluation and can
only be placed at the right side of the network.
 Note
 In the time cell, the operating system reduces the time value in an interval specified by the time
 base by one unit until the value equals "0". The decrementation is performed asynchronously to the
 user program. The resulting timer is therefore at maximum up to one time interval shorter than the
 desired time base.
You can find an example of how a time cell can be formed under: See also "L: Load timer value".
Parameter
The following table shows the parameters of the "Start off-delay timer" instruction:
Example
The following example shows how the instruction works:
                                                       - 54 -
                                    ---( SF ): Start off-delay timer (S7-1500)
The timer "Timer_1" is started when the signal state of the operand "TagIn_1" changes from "1" to "0".
The timer expires with the time value of the operand "TagIn_Number". As long as the timer is running,
the operand "TagOut" is set to "1". If the signal state of the operand "TagIn_1" changes from "1" to "0"
while the timer is running, the timer is restarted. If the signal state of the operand "TagIn_2" is "1", the
timer "Timer_1" is reset, which stops the timer and sets the current time value to "0".
                                                      - 55 -
                                   Counter operations (S7-1200, S7-1500)
Counter operations
                                                   - 56 -
                                     IEC Counters (S7-1200, S7-1500)
IEC Counters
                                                   - 57 -
                                    CTU: Count up (S7-1200, S7-1500)
CTU: Count up
Description
You can use the "Count up" instruction to increment the value at output CV. When the signal state at
the CU input changes from "0" to "1" (positive signal edge), the instruction is executed and the current
counter value at the CV output is incremented by one. When the instruction executes for the first time,
the current counter value at the CV output is set to zero. The counter is incremented each time a posi‐
tive signal edge is detected, until it reaches the high limit for the specified data type at output CV.
When the high limit is reached, the signal state at the CU input no longer has an effect on the instruc‐
tion.
You can scan the counter status at the Q output. The signal state at the Q output is determined by the
PV parameter. If the current counter value is greater than or equal to the value of the PV parameter,
the Q output is set to signal state "1". In all other cases, the Q output has signal state "0".
The value at the CV output is reset to zero when the signal state at input R changes to "1". As long as
the R input has the signal state "1", the signal state at the CU input has no effect on the instruction.
 Note
 Only use a counter at a single point in the program to avoid the risk of counting errors.
Each call of the "Count up" instruction must be assigned to an IEC counter in which the instruction
data is stored. An IEC counter is a structure with one of the following data types:
                                                 - 58 -
                                       CTU: Count up (S7-1200, S7-1500)
• IEC_LCOUNTER / IEC_ULCOUNTER
Parameters
The following table lists the parameters of the "Count up" instruction:
Example
The following example shows how the instruction works:
                                                    - 59 -
                                    CTU: Count up (S7-1200, S7-1500)
When the signal state of the "TagIn_1" operand changes from "0" to "1", the "Count up" instruction
executes and the current counter value of the "Tag_CV" operand is incremented by one. With each
additional positive signal edge, the counter value is incremented until the high limit of the data type
(INT = 32767) is reached.
The value of the PV parameter is adopted as the limit for determining the "TagOut" output. The "Tag‐
Out" output has signal state "1" as long as the current counter value is greater than or equal to the
value of the "Tag_PV" operand. In all other cases, the "TagOut" output has signal state "0".
                                                 - 60 -
                                   CTD: Count down (S7-1200, S7-1500)
Description
You can use the "Count down" instruction to decrement the value at output CV. When the signal state
at the CD input changes from "0" to "1" (positive signal edge), the instruction is executed and the cur‐
rent counter value at the CV output is decremented by one. When the instruction executes the first
time, the counter value of the CV parameter is set to the value of the PV parameter. Each time a posi‐
tive signal edge is detected, the counter value is decremented until it reaches the low limit of the
specified data type. When the low limit is reached, the signal state at the CD input no longer has an
effect on the instruction.
You can scan the counter status at the Q output. If the current counter value is less than or equal to
zero, the Q output is set to signal state "1". In all other cases, the Q output has signal state "0".
The value at the CV output is set to the value of the PV parameter when the signal state at the LD
input changes to "1". As long as the LD input has the signal state "1", the signal state at the CD input
has no effect on the instruction.
 Note
 Only use a counter at a single point in the program to avoid the risk of counting errors.
Each call of the "Count down" instruction must be assigned an IEC counter in which the instruction
data is stored. An IEC counter is a structure with one of the following data types:
                                                 - 61 -
                                     CTD: Count down (S7-1200, S7-1500)
• IEC_LCOUNTER / IEC_ULCOUNTER
Parameters
The following table lists the parameters of the "Count down" instruction:
Example
The following example shows how the instruction works:
                                                    - 62 -
                                  CTD: Count down (S7-1200, S7-1500)
When the signal state of the "TagIn_1" operand changes from "0" to "1", the "Count down" instruction
executes and the value at the "Tag_CV" output is decremented by one. With each additional positive
signal edge, the counter value is decremented until the low limit of the specified data type (INT =
-32768) is reached.
The "TagOut" output has signal state "1" as long as the current counter value is less than or equal to
zero. In all other cases, the "TagOut" output has signal state "0".
                                                - 63 -
                               CTUD: Count up and down (S7-1200, S7-1500)
Description
You can use the "Count up and down" instruction to increment and decrement the counter value at
the CV output. If the signal state at the CU input changes from "0" to "1" (positive signal edge), the
current counter value is incremented by one and stored at the CV output. If the signal state at the CD
input changes from "0" to "1" (positive signal edge), the counter value at the CV output is decremen‐
ted by one. If there is a positive signal edge at the CU and CD inputs in one program cycle, the cur‐
rent counter value at the CV output remains unchanged.
The counter value can be incremented until it reaches the high limit of the data type specified at the
CV output. When the high limit is reached, the counter value is no longer incremented on a positive
signal edge. When the low limit of the specified data type is reached, the counter value is not decre‐
mented any further.
When the signal state at the LD input changes to "1", the counter value at the CV output is set to the
value of the PV parameter. As long as the LD input has the signal state "1", the signal state at the CU
and CD inputs has no effect on the instruction.
The counter value is set to zero when the signal state at the R input changes to "1". As long as the R
input has the signal state "1", a change in the signal state of the CU, CD and LD inputs has no effect
on the "Count up and down" instruction.
You can scan the current status of the up counter at the QU output. If the current counter value is
greater than or equal to the value of the PV parameter, the QU output is set to signal state "1". In all
other cases, the QU output has signal state "0".
You can scan the current status of the down counter at the QD output. If the current counter value is
less than or equal to zero, the QD output is set to signal state "1". In all other cases, the QD output
has signal state "0".
 Note
 Only use a counter at a single point in the program to avoid the risk of counting errors.
Each call of the "Count up and down" instruction must be assigned an IEC counter in which the in‐
struction data is stored. An IEC counter is a structure with one of the following data types:
                                                 - 64 -
                                  CTUD: Count up and down (S7-1200, S7-1500)
Parameters
The following table lists the parameters of the "Count up and down" instruction:
                                                    - 65 -
                                CTUD: Count up and down (S7-1200, S7-1500)
                                                                                              Status of the
 QU                Output             BOOL                  I, Q, M, D, L   I, Q, M, D, L
                                                                                              up counter
                                                                                              Status of the
 QD                Output             BOOL                  I, Q, M, D, L   I, Q, M, D, L
                                                                                              down counter
                                      Integers,             I, Q, M, D, L,                    Current counter
 CV                Output                                                  I, Q, M, D, L, P
                                      CHAR, DATE            P                                 value
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
If the signal state at the "TagIn_1" or "TagIn_2" input changes from "0" to "1" (positive signal edge),
the "Count up and down" instruction is executed. When there is a positive signal edge at the "Ta‐
gIn_1" input, the current counter value is incremented by one and stored at the "Tag_CV" output.
When there is a positive signal edge at the "TagIn_2" input, the counter value is decremented by one
and stored at the "Tag_CV" output. When there is a positive signal edge at the CU input, the counter
value is incremented until it reaches the high limit of 32767. If input CD has a positive signal edge, the
counter value is decremented until it reaches the low limit of INT = -32768.
The "TagOut" output has signal state "1" as long as the current counter value is greater than or equal
to the value at the "Tag_PV" input. In all other cases, the "TagOut" output has signal state "0".
The "TagOut_QD" output has signal state "1" as long as the current counter value is less than or
equal to zero. In all other cases, the "TagOut_QD" output has signal state "0".
                                                   - 66 -
                                        SIMATIC Counters (S7-1500)
SIMATIC Counters
                                                   - 67 -
                          S_CUD: Assign parameters and count up / down (S7-1500)
Description
You can use the "Assign parameters and count up / down" instruction to increment or decrement the
value of a counter. If the signal state at the CU input changes from "0" to "1" (positive signal edge),
the current counter value is incremented by one. If the signal state at the CD input changes from "0"
to "1" (positive signal edge), the counter value is decremented by one. The current counter value is
output as a hexadecimal value at output CV and BCD-coded at output CV_BCD. If there is a positive
signal edge at the CU and CD inputs in one program cycle, the counter value remains unchanged.
The counter value can be incremented until the high limit of "999" is reached. When the high limit val‐
ue is reached, the counter value is no longer incremented on a positive signal edge. When the low
limit "0" is reached, the counter value is not decremented any further.
When the signal state at input S changes from "0" to "1", the counter value is set to the value of the
PV parameter. If the counter is set and if RLO is "1" at the inputs CU and CD, the counter counts
accordingly in the next scan cycle, even if no change in the signal edge was detected.
The counter value is set to zero when the signal state at the R input changes to "1". As long as the R
input has the signal state "1", processing of the signal state of the CU, CD and S inputs has no effect
on the counter value.
The signal state at output Q is "1" if the counter value is greater than zero. If the counter value is
equal to zero, output Q has the signal state "0".
 Note
 Only use a counter at a single point in the program to avoid the risk of counting errors.
The "Assign parameters and count up / down" instruction requires a preceding logic operation for
edge evaluation and can be placed within or at the end of the network.
Parameters
The following table shows the parameters of the "Assign parameters and count up / down" instruction:
                                                  - 68 -
                           S_CUD: Assign parameters and count up / down (S7-1500)
                                                                  I, Q, M, D, L, T, C
 R                     Input                BOOL                                        Reset input
                                                                  or constant
                                                                                        Current counter
                                            WORD, S5TIME,
 BI                    Output                                     I, Q, M, D, L         value (hexadeci‐
                                            DATE
                                                                                        mal)
                                                                                        Current counter
                                            WORD, S5TIME,
 CV_BCD                Output                                     I, Q, M, D, L         value (BCD for‐
                                            DATE
                                                                                        mat)
                                                                                        Status of the
 Q                     Output               BOOL                  I, Q, M, D, L
                                                                                        counter
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
If the signal state at the "TagIn_1"" or "TagIn_2" input changes from "0" to "1" (positive signal edge),
the "Assign parameters and count up / down" instruction is executed. When there is a positive signal
edge at the "TagIn_1" input and the current counter value is less than "999", the counter value is in‐
cremented by one. When there is a positive signal edge at the "TagIn_2" input and the current counter
value is greater than "0", the counter value is decremented by one.
When the signal state at input "TagIn_3" changes from "0" to "1", the counter value is set to the value
of the operand "TagPresetValue". The counter value is reset to "0" when the "TagIn_4" operand has
signal state "1".
The current counter value is saved as a hexadecimal value in the operand "TagValue_1" and BCD-
coded in the operand "TagValue_2".
The "TagOut" output has the signal state "1" as long as the current counter value is not equal to "0".
                                                   - 69 -
                               S_CU: Assign parameters and count up (S7-1500)
Description
You can use the "Assign parameters and count up" instruction to increment the value of a counter. If
the signal state at the CU input changes from "0" to "1" (positive signal edge), the current counter val‐
ue is incremented by one. The current counter value is output as a hexadecimal value at output CV
and BCD-coded at output CV_BCD. The counter value can be incremented until the limit of "999" is
reached. When the limit is reached, the counter value is no longer incremented on a positive signal
edge.
When the signal state at input S changes from "0" to "1", the counter value is set to the value of the
PV parameter. If the counter is set and if RLO at input CU is "1", the counter will count accordingly in
the next scan cycle, even when no change has been detected in the signal edge.
The counter value is set to zero when the signal state at the R input changes to "1". As long as the R
input has the signal state "1", processing of the signal state of the CU and S inputs has no effect on
the counter value.
The signal state at output Q is "1" if the counter value is greater than zero. If the counter value is
equal to zero, output Q has the signal state "0".
 Note
 Only use a counter at a single point in the program to avoid the risk of counting errors.
The "Assign parameters and count up" instruction requires a preceding logic operation for edge evalu‐
ation and can be placed within or at the end of the network.
Parameter
The following table shows the parameters of the "Assign parameters and count up" instruction:
                                                   - 70 -
                                S_CU: Assign parameters and count up (S7-1500)
                                                                                     Current counter
                                             WORD, S5TIME,
 CV_BCD                Output                                      I, Q, M, D, L     value (BCD for‐
                                             DATE
                                                                                     mat)
                                                                                     Status of the
 Q                     Output                BOOL                  I, Q, M, D, L
                                                                                     counter
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
When the signal state at the "TagIn_1" input changes from "0" to "1" (positive signal edge) and the
current counter value is less than "999", the counter value is incremented by one. When the signal
state at input "TagIn_2" changes from "0" to "1", the counter value is set to the value of the operand
"TagPresetValue". The counter value is reset to "0" when the "TagIn_3" operand has signal state "1".
The current counter value is saved as a hexadecimal value in the operand "TagValue_1" and BCD-
coded in the operand "TagValue_2".
The "TagOut" output has the signal state "1" as long as the current counter value is not equal to "0".
                                                    - 71 -
                               S_CD: Assign parameters and count down (S7-1500)
Description
You can use the "Assign parameters and count down" instruction to decrement the value of a counter.
If the signal state at the CD input changes from "0" to "1" (positive signal edge), the counter value is
decremented by one. The current counter value is output as a hexadecimal value at output CV and
BCD-coded at output CV_BCD. The counter value is decremented until the low limit of "0" is reached.
When the low limit is reached, the counter value is no longer decremented on a positive signal edge.
When the signal state at input S changes from "0" to "1", the counter value is set to the value of the
PV parameter. If the counter is set and if RLO at input CD is "1", the counter will count accordingly in
the next scan cycle, even when no change has been detected in the signal edge.
The counter value is set to zero when the signal state at the R input changes to "1". As long as the R
input has the signal state "1", processing of the signal state of the CD and S inputs has no effect on
the counter value.
The signal state at output Q is "1" if the counter value is greater than zero. If the counter value is
equal to zero, output Q has the signal state "0".
 Note
 Only use a counter at a single point in the program to avoid the risk of counting errors.
The "Assign parameters and count down" instruction requires a preceding logic operation for edge
evaluation and can be placed within or at the end of the network.
Parameter
The following table shows the parameters of the "Assign parameters and count down" instruction:
                                                    - 72 -
                                S_CD: Assign parameters and count down (S7-1500)
                                                                                     Current counter
                                              WORD, S5TIME,
 CV_BCD                Output                                       I, Q, M, D, L    value (BCD for‐
                                              DATE
                                                                                     mat)
                                                                                     Status of the
 Q                     Output                 BOOL                  I, Q, M, D, L
                                                                                     counter
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
When the signal state at the "TagIn_1" input changes from "0" to "1" (positive signal edge) and the
current counter value is greater than "0", the counter value is decremented by one. When the signal
state at input "TagIn_2" changes from "0" to "1", the counter value is set to the value of the operand
"TagPresetValue". The counter value is reset to "0" when the "TagIn_3" operand has signal state "1".
The current counter value is saved as a hexadecimal value in the operand "TagValue_1" and BCD-
coded in the operand "TagValue_2".
The "TagOut" output has the signal state "1" as long as the current counter value is not equal to "0".
                                                     - 73 -
                                     ---( SC ): Set counter value (S7-1500)
Description
You can use the "Set counter value" instruction to set the value of a counter. The instruction is execu‐
ted when the result of logic operation (RLO) at the input changes from "0" to "1". When the instruction
is executed, the counter is set to the specified counter value.
The "Set counter value" instruction needs a preceding logic operation for the edge evaluation and can
only be placed on the right edge of the network.
Parameter
The following table lists the parameters of the "Set counter value" instruction:
Example
The following example shows how the instruction works:
the counter "Counter_1" starts with the value "100" when the signal state of the "TagIn" operand
changes from "0" to "1".
                                                     - 74 -
                                        ---( CU ): Count up (S7-1500)
---( CU ): Count up
Description
With the "Count up" instruction you can increment the value of the specified counter by one if there is
a positive signal edge in the result of logic operation (RLO). The counter value can be incremented
until the limit of "999" is reached. When the limit is reached, the counter value is no longer incremen‐
ted on a positive signal edge.
The "Count up" instruction requires a preceding logic operation for edge evaluation and can only be
placed at the right side of the network.
Parameter
The following table shows the parameters of the "Count up" instruction:
Example
The following example shows how the instruction works:
When the signal state of the "TagIn_1" operand changes from "0" to "1" (positive signal edge), the
counter "Counter_1" is preset with the value "100".
The value of the counter "Counter_1" is incremented by one when the signal state of the operand "Ta‐
gIn_2" changes from "0" to "1".
When the operand "TagIn_3" has the signal state "1", the value of the counter "Counter_1" is reset to
"0".
                                                   - 75 -
                                       ---( CD ): Count down (S7-1500)
Description
With the "Count down" instruction you can increment the value of the specified counter by one if there
is a positive signal edge in the result of logic operation (RLO). The counter value can be decremented
until the limit of "0" is reached. When the limit is reached, the counter value is no longer changed on a
positive signal edge.
The "Count down" instruction requires a preceding logic operation for edge evaluation and can only
be placed at the right side of the network.
Parameter
The following table shows the parameters of the "Count down" instruction:
Example
The following example shows how the instruction works:
When the signal state of the "TagIn_1" operand changes from "0" to "1" (positive signal edge), the
counter "Counter_1" is preset with the value "100".
The value of the counter "Counter_1" is decremented by one when the signal state of the operand
"TagIn_2" changes from "0" to "1".
When the operand "TagIn_3" has the signal state "1", the value of the counter "Counter_1" is reset to
"0".
                                                   - 76 -
                                   Comparator operations (S7-1200, S7-1500)
Comparator operations
                                                    - 77 -
                                      CMP ==: Equal (S7-1200, S7-1500)
Description
You can use the "Equal" instruction to determine if a first comparison value (<Operand1>) is equal to
a second comparison value (<Operand2>).
If the condition of the comparison is fulfilled, the instruction returns the result of logic operation (RLO)
"1". If the comparison condition is not fulfilled, the instruction returns RLO "0". The RLO of the instruc‐
tion is logically combined with the RLO of the entire rung as follows:
•    By AND, when the comparison instruction is connected in series.
•    By OR, when the comparison instruction is connected in parallel.
Specify the first comparison value (<Operand1>) at the operand placeholder above the instruction.
Specify the second comparison value (<Operand2>) at the operand placeholder below the instruction.
The individual characters are compared by means of their code (for example, 'a' is greater than 'A')
during the comparison of the strings. The comparison is performed from left to right. The first charac‐
ter to be different decides the result of the comparison.
The following table lists examples of string comparisons:
    Note
    Comparison of floating-point numbers
    If you want to compare the data types REAL or LREAL, instead of the instruction "CMP ==: Equal",
    use the instruction "IN_RANGE: Value within range".
    Note
    Comparison of the data type PORT
    To be able to compare the operands of the PORT data type with the "Equal" instruction, you need
    to select the WORD data type from the drop-down list of the instructions box.
Parameters
The following table lists the parameters of the "Equal" instruction:
                                                   - 78 -
                                      CMP ==: Equal (S7-1200, S7-1500)
Example
The following example shows how the instruction works:
The "TagOut" output is set when the following conditions are fulfilled:
•   The operands "TagIn_1" and "TagIn_2" have signal state "1".
•   The condition of the comparison instruction is fulfilled if "Tag_Value1" = "Tag_Value2".
                                                   - 79 -
                                     CMP <>: Not equal (S7-1200, S7-1500)
Description
You can use the "Not equal" instruction to determine if a first comparison value (<Operand1>) is not
equal to a second comparison value (<Operand2>).
If the condition of the comparison is fulfilled, the instruction returns the result of logic operation (RLO)
"1". If the comparison condition is not fulfilled, the instruction returns RLO "0". The RLO of the instruc‐
tion is logically combined with the RLO of the entire rung as follows:
•    By AND, when the comparison instruction is connected in series.
•    By OR, when the comparison instruction is connected in parallel.
Specify the first comparison value (<Operand1>) at the operand placeholder above the instruction.
Specify the second comparison value (<Operand2>) at the operand placeholder below the instruction.
The individual characters are compared by means of their code (for example, 'a' is greater than 'A')
during the comparison of the strings. The comparison is performed from left to right. The first charac‐
ter to be different decides the result of the comparison.
The following table lists examples of string comparisons:
    Note
    Comparison of the data type PORT
    To be able to compare the operands of the PORT data type with the "Not equal" instruction, you
    need to select the WORD data type from the drop-down list of the instructions box.
Parameters
The following table lists the parameters of the "Not equal" instruction:
                                                     - 80 -
                                    CMP <>: Not equal (S7-1200, S7-1500)
                                                        ing-point num‐
                                     ing-point num‐
                                                        bers, character
                                     bers, character
                                                        strings, TIME,
                                     strings, TIME,
                                                        LTIME, DATE,
                                     DATE, TOD,
                                                        TOD, LTOD,
                                     DTL
                                                        DTL, DT, LDT
                                                        Bit strings, in‐
                                     Bit strings, in‐
                                                        tegers, float‐
                                     tegers, float‐
                                                        ing-point num‐
                                     ing-point num‐
                                                        bers, character I, Q, M, D, L, P Second value
    <Operand2>      Input            bers, character
                                                        strings, TIME, or constant       to compare
                                     strings, TIME,
                                                        LTIME, DATE,
                                     DATE, TOD,
                                                        TOD, LTOD,
                                     DTL
                                                        DTL, DT, LDT
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The "TagOut" output is set when the following conditions are fulfilled:
•   The operands "TagIn_1" and "TagIn_2" have signal state "1".
•   The condition of the comparison instruction is fulfilled if "Tag_Value1" <> "Tag_Value2".
                                                   - 81 -
                                     CMP >=: Greater or equal (S7-1200, S7-1500)
Description
You can use the "Greater or equal" instruction to determine if a first comparison value (<Operand1>)
is greater than or equal to a second comparison value (<Operand2>). Both values to be compared
must be of the same data type.
If the condition of the comparison is fulfilled, the instruction returns the result of logic operation (RLO)
"1". If the comparison condition is not fulfilled, the instruction returns RLO "0". The RLO of the instruc‐
tion is logically combined with the RLO of the entire rung as follows:
•    By AND, when the comparison instruction is connected in series.
•    By OR, when the comparison instruction is connected in parallel.
Specify the first comparison value (<Operand1>) at the operand placeholder above the instruction.
Specify the second comparison value (<Operand2>) at the operand placeholder below the instruction.
The individual characters are compared by means of their code (for example, 'a' is greater than 'A')
during the comparison of the strings. The comparison is performed from left to right. The first charac‐
ter to be different decides the result of the comparison. If the left part of the longer string is identical to
the shorter string, the longer string is considered greater.
The following table lists examples of string comparisons:
Parameters
The following table lists the parameters of the "Greater or equal" instruction:
                                                        - 82 -
                                 CMP >=: Greater or equal (S7-1200, S7-1500)
                                                         LTIME, DATE,
                                     DATE, TOD,
                                                         TOD, LTOD,
                                     DTL
                                                         DTL, DT, LDT
                                                         Integers, float‐
                                     Integers, float‐
                                                         ing-point num‐
                                     ing-point num‐
                                                         bers, character
                                     bers, character                      I, Q, M, D, L, P Second value
    <Operand2>      Input                                strings, TIME,
                                     strings, TIME,                       or constant      to compare
                                                         LTIME, DATE,
                                     DATE, TOD,
                                                         TOD, LTOD,
                                     DTL
                                                         DTL, DT, LDT
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The "TagOut" output is set when the following conditions are fulfilled:
•   The operands "TagIn_1" and "TagIn_2" have signal state "1".
•   The condition of the comparison instruction is fulfilled if "Tag_Value1" >= "Tag_Value2".
                                                    - 83 -
                                     CMP <=: Less or equal (S7-1200, S7-1500)
Description
You can use the "Less or equal" instruction to determine if a first comparison value (<Operand1>) is
less than or equal to a second comparison value (<Operand2>). Both values to be compared must be
of the same data type.
If the condition of the comparison is fulfilled, the instruction returns the result of logic operation (RLO)
"1". If the comparison condition is not fulfilled, the instruction returns RLO "0". The RLO of the instruc‐
tion is logically combined with the RLO of the entire rung as follows:
•    By AND, when the comparison instruction is connected in series.
•    By OR, when the comparison instruction is connected in parallel.
Specify the first comparison value (<Operand1>) at the operand placeholder above the instruction.
Specify the second comparison value (<Operand2>) at the operand placeholder below the instruction.
The individual characters are compared by means of their code (for example, 'a' is greater than 'A')
during the comparison of the strings. The comparison is performed from left to right. The first charac‐
ter to be different decides the result of the comparison. If the left part of the longer string is identical to
the shorter string, the shorter string is considered smaller.
The following table lists examples of string comparisons:
Parameters
The following table lists the parameters of the "Less or equal" instruction:
                                                      - 84 -
                                  CMP <=: Less or equal (S7-1200, S7-1500)
                                                        LTIME, DATE,
                                     DATE, TOD,
                                                        TOD, LTOD,
                                     DTL
                                                        DTL, DT, LDT
                                                        Integers, float‐
                                     Integers, float‐
                                                        ing-point num‐
                                     ing-point num‐
                                                        bers, character
                                     bers, character                     I, Q, M, D, L, P Second value
    <Operand2>      Input                               strings, TIME,
                                     strings, TIME,                      or constant      to compare
                                                        LTIME, DATE,
                                     DATE, TOD,
                                                        TOD, LTOD,
                                     DTL
                                                        DTL, DT, LDT
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The "TagOut" output is set when the following conditions are fulfilled:
•   The operands "TagIn_1" and "TagIn_2" have signal state "1".
•   The condition of the comparison instruction is fulfilled if "Tag_Value1" <= "Tag_Value2".
                                                   - 85 -
                                     CMP >: Greater than (S7-1200, S7-1500)
Description
You can use the "Greater than" instruction to determine if a first comparison value (<Operand1>) is
greater than a second comparison value (<Operand2>). Both values to be compared must be of the
same data type.
If the condition of the comparison is fulfilled, the instruction returns the result of logic operation (RLO)
"1". If the comparison condition is not fulfilled, the instruction returns RLO "0". The RLO of the instruc‐
tion is logically combined with the RLO of the entire rung as follows:
•    By AND, when the comparison instruction is connected in series.
Specify the first comparison value (<Operand1>) at the operand placeholder above the instruction.
Specify the second comparison value (<Operand2>) at the operand placeholder below the instruction.
The individual characters are compared by means of their code (for example, 'a' is greater than 'A')
during the comparison of the strings. The comparison is performed from left to right. The first charac‐
ter to be different decides the result of the comparison. If the left part of the longer string is identical to
the shorter string, the longer string is considered greater.
The following table lists examples of string comparisons:
Parameters
The following table lists the parameters of the "Greater than" instruction:
                                                     - 86 -
                                   CMP >: Greater than (S7-1200, S7-1500)
                                                        Integers, float‐
                                     Integers, float‐
                                                        ing-point num‐
                                     ing-point num‐
                                                        bers, character
                                     bers, character                     I, Q, M, D, L, P Second value
    <Operand2>      Input                               strings, TIME,
                                     strings, TIME,                      or constant      to compare
                                                        LTIME, DATE,
                                     DATE, TOD,
                                                        TOD, LTOD,
                                     DTL
                                                        DTL, DT, LDT
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The "TagOut" output is set when the following conditions are fulfilled:
•   The operands "TagIn_1" and "TagIn_2" have signal state "1".
•   The condition of the comparison instruction is fulfilled if "Tag_Value1" > "Tag_Value2".
                                                   - 87 -
                                      CMP <: Less than (S7-1200, S7-1500)
Description
You can use the "Less than" instruction to determine if a first comparison value (<Operand1>) is less
than a second comparison value (<Operand2>). Both values to be compared must be of the same
data type.
If the condition of the comparison is fulfilled, the instruction returns the result of logic operation (RLO)
"1". If the comparison condition is not fulfilled, the instruction returns RLO "0". The RLO of the instruc‐
tion is logically combined with the RLO of the entire rung as follows:
•    By AND, when the comparison instruction is connected in series.
Specify the first comparison value (<Operand1>) at the operand placeholder above the instruction.
Specify the second comparison value (<Operand2>) at the operand placeholder below the instruction.
The individual characters are compared by means of their code (for example, 'a' is greater than 'A')
during the comparison of the strings. The comparison is performed from left to right. The first charac‐
ter to be different decides the result of the comparison. If the left part of the longer string is identical to
the shorter string, the shorter string is considered smaller.
The following table lists examples of string comparisons:
Parameters
The following table lists the parameters of the "Less than" instruction:
                                                     - 88 -
                                     CMP <: Less than (S7-1200, S7-1500)
                                                         Integers, float‐
                                     Integers, float‐
                                                         ing-point num‐
                                     ing-point num‐
                                                         bers, character
                                     bers, character                      I, Q, M, D, L, P Second value
    <Operand2>      Input                                strings, TIME,
                                     strings, TIME,                       or constant      to compare
                                                         LTIME, DATE,
                                     DATE, TOD,
                                                         TOD, LTOD,
                                     DTL
                                                         DTL, DT, LDT
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The "TagOut" output is set when the following conditions are fulfilled:
•   The operands "TagIn_1" and "TagIn_2" have signal state "1".
•   The condition of the comparison instruction is fulfilled if "Tag_Value1" < "Tag_Value2".
                                                    - 89 -
                                     Math functions (S7-1200, S7-1500)
Math functions
                                                   - 90 -
                                    CALCULATE: Calculate (S7-1200, S7-1500)
CALCULATE: Calculate
Description
The "Calculate" instruction is used to define and execute an expression for the calculation of mathe‐
matical operations or complex logic operations depending on the selected data type.
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
Depending on the data type selected, you can combine the functions of certain instructions to perform
a complex calculation. The expression to be calculated is specified via a dialog you can open via the
"Calculator" icon at the top of the instruction box. The expression can contain names of input parame‐
ters and the syntax of the instructions. Operand names and operand addresses cannot be specified.
In its initial state, the instruction box contains at least 2 inputs (IN1 and IN2). The number of inputs
can be extended. The inserted inputs are numbered in ascending order in the box.
The values of the inputs are used to execute the specified expression. Not all of the defined inputs
have to be used in the expression. The result of the instruction is transferred to the output OUT.
    Note
    If one of the mathematical operations fails in the expression, no result is transferred to the output
    OUT and the enable output ENO returns the signal state "1".
If you use inputs in the expression that are not available in the box, they are inserted automatically.
This requires that there are no gaps in the numbering of the inputs to be newly defined in the expres‐
sion. For example, you cannot use the IN4 input in the expression unless the IN3 input has been de‐
fined.
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•    The EN enable input has the signal state "0".
•    The result of the "Calculate" instruction is outside the range permitted for the data type specified at
     the OUT output.
•    A floating-point number has an invalid value.
•    An error occurred during execution of one of the instructions in the expression.
The following table shows the instructions that can be executed together in the expression of the in‐
struction "Calculate", depending on the selected data type:
                                                     - 91 -
                                  CALCULATE: Calculate (S7-1200, S7-1500)
Parameters
The following table shows the parameters of the "Calculate" instruction:
                                                   - 92 -
                                 CALCULATE: Calculate (S7-1200, S7-1500)
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                   - 93 -
                                        ADD: Add (S7-1200, S7-1500)
ADD: Add
Description
You can use the "Add" instruction to add the value at input IN1 and the value at input IN2 and query
the sum at output OUT (OUT := IN1+IN2).
In its initial state, the instruction box contains at least 2 inputs (IN1 and IN2). The number of inputs
can be extended. The inserted inputs are numbered in ascending order in the box. When the instruc‐
tion is executed, the values of all available input parameters are added. The sum is stored at the OUT
output.
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   The enable input EN has the signal state "0".
•   The result of the instruction is outside the range permitted for the data type specified at the OUT
    output.
•   A floating-point number has an invalid value.
Parameters
The following table shows the parameters of the "Add" instruction:
Example
The following example shows how the instruction works:
                                                    - 94 -
                                     ADD: Add (S7-1200, S7-1500)
If operand "TagIn" has the signal state "1", the "Add" instruction is executed. The value of operand
"Tag_Value1" is added to the value of operand "Tag_Value2". The result of the addition is stored in
operand "Tag_Result". If the instruction is executed without errors, the ENO enable output has the
signal state "1" and the "TagOut" output is set.
                                                - 95 -
                                      SUB: Subtract (S7-1200, S7-1500)
SUB: Subtract
Description
You can use the "Subtract" instruction to subtract the value at input IN2 from the value at input IN1
and query the difference at output OUT (OUT := IN1-IN2).
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   The EN enable input has the signal state "0".
•   The result of the instruction is outside the range permitted for the data type specified at the OUT
    output.
•   A floating-point number has an invalid value.
Parameters
The following table shows the parameters of the "Subtract" instruction:
Example
The following example shows how the instruction works:
If operand "TagIn" has the signal state "1", the "Subtract" instruction is executed. The value of oper‐
and "Tag_Value2" is subtracted from the value of operand "Tag_Value1". The result of the subtraction
is stored in operand "Tag_Result". If the instruction is executed without errors, the ENO enable output
has the signal state "1" and the "TagOut" output is set.
                                                    - 96 -
                                      MUL: Multiply (S7-1200, S7-1500)
MUL: Multiply
Description
You can use the "Multiply" instruction to multiply the value at input IN1 with the value at input IN2 and
query the product at output OUT (OUT := IN1*IN2).
The number of inputs can be expanded in the instruction box. The added inputs are numbered in as‐
cending order in the box. When the instruction is executed, the values of all available input parame‐
ters are multiplied. The product is stored at the OUT output.
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   The EN input has the signal state "0".
• The result is outside the range permitted for the data type specified at output OUT.
Parameters
The following table shows the parameters of the "Multiply" instruction:
Example
The following example shows how the instruction works:
                                                    - 97 -
                                     MUL: Multiply (S7-1200, S7-1500)
If operand "TagIn" has the signal state "1", the "Multiply" instruction is executed. The value of operand
"Tag_Value1" is multiplied by the value of operand "Tag_Value2". The result of the multiplication is
stored in operand "Tag_Result". If the instruction is executed without errors, the ENO enable output
has the signal state "1" and the "TagOut" output is set.
                                                  - 98 -
                                       DIV: Divide (S7-1200, S7-1500)
DIV: Divide
Description
You can use the "Divide" instruction to divide the value at input IN1 by the value at input IN2 and
query the quotient at output OUT (OUT := IN1/IN2).
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   The EN enable input has the signal state "0".
•   The result of the instruction is outside the range permitted for the data type specified at the OUT
    output.
•   A floating-point number has an invalid value.
Parameters
The following table shows the parameters of the "Divide" instruction:
Example
The following example shows how the instruction works:
If operand "TagIn" has the signal state "1", the "Divide" instruction is executed. The value of operand
"Tag_Value1" is divided by the value of operand "Tag_Value2". The division result is stored in oper‐
and "Tag_Result". If the instruction is executed without errors, the ENO enable output has the signal
state "1" and the "TagOut" output is set.
                                                    - 99 -
                               NEG: Create twos complement (S7-1200, S7-1500)
Description
You can use the "Create twos complement" instruction to change the sign of the value at the IN input
and query the result at the OUT output. If there is a positive value at input IN, for example, the nega‐
tive equivalent of this value is sent to output OUT.
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   The EN enable input has the signal state "0".
•   The result of the instruction is outside the range permitted for the data type specified at the OUT
    output.
•   A floating-point number has an invalid value.
Parameters
The following table shows the parameters of the "Create twos complement" instruction:
Example
The following example shows how the instruction works:
If operand "TagIn" has the signal state "1", the "Create twos complement" instruction is executed. The
sign of the value at input "TagIn_Value" is changed and the result is provided at "TagOut_Value" out‐
                                                    - 100 -
                             NEG: Create twos complement (S7-1200, S7-1500)
put. If the instruction is executed without errors, the ENO enable output has the signal state "1" and
the "TagOut" output is set.
                                                 - 101 -
                                     INC: Increment (S7-1200, S7-1500)
INC: Increment
Description
You can use the "Increment" instruction to change the value of the operand at the IN/OUT parameter
to the next higher value and query the result. The "Increment" instruction is only started when the sig‐
nal state at the EN enable input is "1". If no overflow error occurs during the execution, the ENO ena‐
ble output also has the signal state "1".
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   The EN enable input has the signal state "0".
•   A floating-point number has an invalid value.
Parameters
The following table shows the parameters of the "Increment" instruction:
Example
The following example shows how the instruction works:
If operands "TagIn_1" and "TagIn_2" have the signal state "1", the value of operand "Tag_InOut" is
incremented by one and the "TagOut" output is set.
                                                    - 102 -
                                     DEC: Decrement (S7-1200, S7-1500)
DEC: Decrement
Description
You can use the "Decrement" instruction to change the value of the operand at the IN/OUT parameter
to the next lower value and query the result. The "Decrement" instruction is only started when the sig‐
nal state at the EN enable input is "1". If the range of values of the selected data type is not exceeded
during processing, the ENO output also has the signal state "1".
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   The EN enable input has the signal state "0".
•   A floating-point number has an invalid value.
Parameter
The following table shows the parameters of the "Decrement" instruction:
Example
The following example shows how the instruction works:
If operands "TagIn_1" and "TagIn_2" have the signal state "1", the value of operand "Tag_InOut" is
decremented by one and the "TagOut" output is set.
                                                    - 103 -
                                     MIN: Get minimum (S7-1200, S7-1500)
Description
The "Get minimum" instruction compares the values at the available inputs and writes the lowest val‐
ue to the OUT output. The number of inputs can be expanded at the instruction box by additional in‐
puts. The inputs are numbered in ascending order in the box.
A minimum of two and a maximum of 100 inputs must be specified for the execution of the instruction.
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   Enable input EN has the signal state "0".
• The implicit conversion of the data types fails during execution of the instruction.
Parameters
The following table shows the parameters of the "Get minimum" instruction:
                                                    - 104 -
                                    MIN: Get minimum (S7-1200, S7-1500)
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                  - 105 -
                                     MAX: Get maximum (S7-1200, S7-1500)
Description
The "Get maximum" instruction compares the values at the available inputs and writes the highest val‐
ue to the OUT output. The number of inputs can be expanded at the instruction box by additional in‐
puts. The inputs are numbered in ascending order in the box.
A minimum of two and a maximum of 100 inputs must be specified for the execution of the instruction.
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   Enable input EN has the signal state "0".
• The implicit conversion of the data types fails during execution of the instruction.
Parameters
The following table shows the parameters of the "Get maximum" instruction:
                                                    - 106 -
                                   MAX: Get maximum (S7-1200, S7-1500)
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                  - 107 -
                                   LIMIT: Set limit value (S7-1200, S7-1500)
Description
You can use the "Set limit value" instruction to limit the value at input IN to the values at the inputs MN
and MX. If the value at the IN input meets the condition MN <= IN <= MX, it is copied to the OUT
output. If the condition is not fulfilled and the input value IN is below the low limit MN, the output OUT
is set to the value of the MN input. If the MX high limit is exceeded, the OUT output is set to the value
of the MX input.
If the value at the MN input is greater than at the MX input, the result is undefined and the enable
output ENO is "0".
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   Enable input EN has the signal state "0".
•   The specified tags are not of the same data type.
•   An operand has an invalid value.
•   The value at the MN input is greater than the value of the MX input.
Parameters
The following table shows the parameters of the "Set limit value" instruction:
                                                    - 108 -
                                   LIMIT: Set limit value (S7-1200, S7-1500)
                                                       LTIME, TOD,
                                      bers, TIME,
                                                       LTOD, DATE,
                                      TOD, DATE
                                                       LDT
 The data types TOD, LTOD, DATE, and LDT can only be used if the IEC test is not enabled.
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                    - 109 -
                                      SQR: Form square (S7-1200, S7-1500)
Description
You can use the "Form square" instruction to square the value at the IN input and query the result at
the OUT output.
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   The EN enable input has the signal state "0".
•   The value at the IN input is not a valid floating-point number.
Parameters
The following table shows the parameters of the "Form square" instruction:
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                    - 110 -
                                  SQRT: Form square root (S7-1200, S7-1500)
Description
You can use the "Form square root" instruction to find the square root of the value at the IN input and
query the result at the OUT output. The instruction outputs a positive result if the input value is greater
than zero. If input values are less than zero, the OUT output returns an invalid floating-point number.
If the value at input IN is "0", then the result is also "0".
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   The EN enable input has the signal state "0".
Parameters
The following table shows the parameters of the "Form square root" instruction:
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                    - 111 -
                                 SQRT: Form square root (S7-1200, S7-1500)
                                                  - 112 -
                                     Move operations (S7-1200, S7-1500)
Move operations
                                                   - 113 -
                                    MOVE: Move value (S7-1200, S7-1500)
Description
You use the "Move value" instruction to transfer the content of the operand at the IN input to the oper‐
and at the OUT1 output. The transfer is always made in the direction of ascending address.
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   The EN enable input has the signal state "0".
•   The data type at the IN parameter does not correspond to the specified data type at the OUT1 pa‐
    rameter.
The following table lists the possible transfers for the S7-1200 CPU series:
                                                    - 114 -
                                   MOVE: Move value (S7-1200, S7-1500)
 Character of a
                   Character of a string          Character of a string CHAR
 string1)
 ARRAY2)           ARRAY                          ARRAY
 STRUCT            STRUCT                         STRUCT
 PLC data type
                   PLC data type (UDT)            PLC data type (UDT)
 (UDT)
 IEC_TIMER         IEC_TIMER                      IEC_TIMER
 IEC_SCOUNT‐
                   IEC_SCOUNTER                   IEC_SCOUNTER
 ER
 IEC_US‐
                   IEC_USCOUNTER                  IEC_USCOUNTER
 COUNTER
 IEC_COUN‐
                   IEC_COUNTER                    IEC_COUNTER
 TER
 IEC_UCOUNT‐
                   IEC_UCOUNTER                   IEC_UCOUNTER
 ER
 IEC_DCOUNT‐
                   IEC_DCOUNTER                   IEC_DCOUNTER
 ER
 IEC_UD‐
                   IEC_UDCOUNTER                  IEC_UDCOUNTER
 COUNTER
The following table lists the possible transfers for the S7-1500 CPU series:
                                                 - 115 -
                                MOVE: Move value (S7-1200, S7-1500)
                                              - 116 -
                                    MOVE: Move value (S7-1200, S7-1500)
 IEC_US‐
                    IEC_USCOUNTER                   IEC_USCOUNTER
 COUNTER
 IEC_COUN‐
                    IEC_COUNTER                     IEC_COUNTER
 TER
 IEC_UCOUNT‐
                    IEC_UCOUNTER                    IEC_UCOUNTER
 ER
 IEC_DCOUNT‐
                    IEC_DCOUNTER                    IEC_DCOUNTER
 ER
 IEC_UD‐
                    IEC_UDCOUNTER                   IEC_UDCOUNTER
 COUNTER
 IEC_LCOUNT‐
                    IEC_LCOUNTER                    IEC_LCOUNTER
 ER
 IEC_UL‐
                    IEC_ULCOUNTER                   IEC_ULCOUNTER
 COUNTER
1) You can also use the "Move value" instruction to transfer individual characters of a string to oper‐
ands of the CHAR or WCHAR data type. The number of the character to be transferred is specified in
square brackets next to the operand name. "MyString[2]", for example, transfers the second character
of the "MyString" string. It is also possible to transfer from operands of the data type CHAR to the
individual characters of a string. You can also replace a specific character of a string with the charac‐
ter of another string.
2)Transferring entire arrays (ARRAY) is possible only when the array components of the operands at
input IN and at output OUT1 are of the same data type.
If the bit length of the data type at input IN exceeds the bit length of the data type at output OUT1, the
higher-order bits of the source value are lost. If the bit length of the data type at input IN is less than
the bit length of the data type at output OUT1, the higher-order bits of the destination value will be
overwritten with zeros.
In its initial state, the instruction box contains 1 output (OUT1). The number of outputs can be exten‐
ded. The added outputs are numbered in ascending order on the box. During the execution of the in‐
struction, the content of the operand at the input IN is transferred to all available outputs. The instruc‐
tion box cannot be extended if structured data types (DTL, STRUCT, ARRAY) or characters of a
string are transferred.
You can also use the "Move block" (MOVE_BLK) and "Move block uninterruptible" (UMOVE_BLK) in‐
structions to move operands of the ARRAY data type. You can move operands of the STRING data
type with the instruction "Move character string" (S_MOVE).
Parameter
The following table lists the parameters of the "Move value" instruction:
                                                   - 117 -
                                   MOVE: Move value (S7-1200, S7-1500)
                                                    S5TIME,
                                                    TIME, LTIME,
                                                    TOD, LTOD,
                                     DTL, CHAR,
                                                    DTL, CHAR,
                                     STRUCT, AR‐
                                                    STRUCT, AR‐
                                     RAY, IEC data
                                                    RAY, TIMER,
                                     types, PLC da‐
                                                    COUNTER,
                                     ta type (UDT)
                                                    IEC data
                                                    types, PLC da‐
                                                    ta type (UDT)
                                                      Bit strings, in‐
                                                      tegers, float‐
                                                      ing-point num‐
                                     Bit strings, in‐
                                                      bers, DATE,
                                     tegers, float‐
                                                      DT, LDT,
                                     ing-point num‐
                                                      S5TIME,
                                     bers, DATE,                                       Operands to
                                                      TIME, LTIME,
                                     TIME, TOD,                                        which in the
 OUT1              Output                             TOD, LTOD,       I, Q, M, D, L
                                     DTL, CHAR,                                        source value is
                                                      DTL, CHAR,
                                     STRUCT, AR‐                                       transferred.
                                                      STRUCT, AR‐
                                     RAY, IEC data
                                                      RAY, TIMER,
                                     types, PLC da‐
                                                      COUNTER,
                                     ta type (UDT)
                                                      IEC data
                                                      types, PLC da‐
                                                      ta type (UDT)
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                   - 118 -
                                     MOVE_BLK: Move block (S7-1200, S7-1500)
Description
You can use the "Move block" instruction to move the content of a memory area (source area) to an‐
other memory area (destination area). The number of elements to be moved to the destination area is
specified at input COUNT. The width of the elements to be moved is defined by the width of the ele‐
ment at the IN input.
The instruction can only be executed if the source area and the destination area are of the same data
type.
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•    The EN enable input has the signal state "0".
•    More data is copied than is made available at the IN input or OUT output.
When a Array of BOOL is copied, the enable output ENO for an overflow is set to "1" until the byte
limit of the ARRAY structure is exceeded. If the byte limit of the ARRAY structure is exceeded by the
value at the COUNT input, the ENO enable output is reset to "0".
Parameters
The following table lists the parameters of the "Move block" instruction:
                                                     - 119 -
                                 MOVE_BLK: Move block (S7-1200, S7-1500)
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                  - 120 -
                                 MOVE_BLK_VARIANT: Move block (S7-1500)
Description
You can use the "Move block" instruction to move the content of a memory area (source area) to an‐
other memory area (destination area). You can copy elements of an array to another array of the
same data type. The size (number of elements) of the source and destination array may be different.
You can copy several elements within an array or individual elements.
If you are using the instruction, the array must not yet be known at the time the block is created, as
the source and the destination are transferred using VARIANT.
The counting at the parameters SRC_INDEX and DEST_INDEX always starts with the low limit "0",
regardless of the later declaration of the array.
If the VARIANT pointer (source or destination) is of the data type BOOL, it must be addressed abso‐
lutely and the length specified must be divisible by 8; otherwise the instruction is not executed.
The ENO enable output has the signal state "0" if one of the following conditions is fulfilled:
•   The EN enable input has the signal state "0".
Parameters
The following table lists the parameters of the "Move block" instruction:
                                                    - 121 -
                      MOVE_BLK_VARIANT: Move block (S7-1500)
                                                                           DEX parameter
                                                                           specifies the
                                                                           first element
                                                                           within the
                                                                           source area
                                                                           from which
                                                                           copying is to
                                                                           take place. This
                                                                           is independent
                                                                           of the declared
                                                                           array limits.
                                                                       •   If no Array is
                                                                           set at the SRC
                                                                           parameter or
                                                                           only an individ‐
                                                                           ual element of
                                                                           an array is
                                                                           specified, as‐
                                                                           sign the
                                                                           SRC_INDEX
                                                                           parameter the
                                                                           value "0".
                                                                       •   The DEST_IN‐
                                                                           DEX parameter
                                                                           is calculated
                                                                           zero-based. If
                                                                           an Array is
                                                                           specified at the
                                                                           DEST parame‐
                                                                           ter, the integer
                                                                           at the
                                                                           DEST_INDEX
                                                                           parameter
                                                                           specifies the
                                                                           first element
                                                    I, Q, M, D, L or       within the desti‐
DEST_INDEX   Input              DINT                                       nation area to
                                                    constant
                                                                           which copying
                                                                           is to take place.
                                                                           This is inde‐
                                                                           pendent of the
                                                                           declared array
                                                                           limits.
                                                                       •   If no Array is
                                                                           specified at the
                                                                           DEST parame‐
                                                                           ter, assign the
                                                                           DEST_INDEX
                                                                           parameter the
                                                                           value "0".
                                                                       Destination area
                                                                       into which the
DEST         Output             VARIANT             L                  contents of the
                                                                       source block are
                                                                       copied.
RET_VAL      Output             INT                 I, Q, M, D, L      Error information:
                                       - 122 -
                                 MOVE_BLK_VARIANT: Move block (S7-1500)
                                                                                   If an error occurs
                                                                                   during the execu‐
                                                                                   tion of the instruc‐
                                                                                   tion, an error code
                                                                                   is output at the
                                                                                   RET_VAL param‐
                                                                                   eter.
For additional information on valid data types, refer to "See also".
RET_VAL parameter
The following table lists the meaning of the values of the RET_VAL parameter:
Example
The following example shows how the instruction works:
                                                  - 123 -
                               MOVE_BLK_VARIANT: Move block (S7-1500)
The following table shows how the instruction works using specific operand values:
                                                - 124 -
                               Program control operations (S7-1200, S7-1500)
                                                   - 125 -
                                 ---( JMP ): Jump if RLO = 1 (S7-1200, S7-1500)
Description
You can use the "Jump if RLO = 1" instruction to interrupt the linear execution of the program and
resume it in another network. The destination network must be identified by a jump label (LABEL).
The name of this jump label is specified in the placeholder above the instruction.
The specified jump label must be in the same block in which the instruction is executed. The name
you specify can only occur once in the block. Only one jumping coil is permitted within a network.
If the result of logic operation (RLO) at the input of the instruction is "1", the jump to the network iden‐
tified by the specified jump label is executed. The jump direction can be towards higher or lower net‐
work numbers.
If the condition at the input of the instruction is not fulfilled (RLO = 0), execution of the program contin‐
ues in the next network.
Example
The following example shows how the instruction works:
If operand "TagIn_1" has the signal state "1", the "Jump if RLO = 1" instruction is executed. The linear
execution of the program is interrupted and continues in Network 3, which is identified by the jump
label CAS1. If the "TagIn_3" input has the signal state "1", the "TagOut_3" output is set.
                                                    - 126 -
                                ---( JMPN ): Jump if RLO = 0 (S7-1200, S7-1500)
Description
You can use the instruction "Jump if RLO = 0" to interrupt the linear execution of the program and
resume it in another network, when the result of logic operation at the input of the instruction is "0".
The destination network must be identified by a jump label (LABEL). The name of this jump label is
specified in the placeholder above the instruction.
The specified jump label must be in the same block in which the instruction is executed. The name
you specify can only occur once in the block. Only one jumping coil is permitted within a network.
If the result of logic operation (RLO) at the input of the instruction is "0", the jump to the network iden‐
tified by the specified jump label is executed. The jump direction can be towards higher or lower net‐
work numbers.
If the result of logic operation at the input of the instruction is "1", execution of the program continues
in the next network.
Example
The following example shows how the instruction works:
If operand "TagIn_1" has the signal state "0", the "Jump if RLO = 0" instruction is executed. The linear
execution of the program is interrupted and continues in Network 3, which is identified by the jump
label CAS1. If the "TagIn_3" input has the signal state "1", the "TagOut_3" output is set.
                                                    - 127 -
                                   LABEL: Jump label (S7-1200, S7-1500)
Description
You can use a jump label to identify a destination network, in which the program execution should
resume when a jump is executed.
The jump label and the instruction in which the jump label is specified must be located in the same
block. The name of a jump label can only be assigned once in a block. You can declare up to 32 jump
labels when you use a CPU S7-1200 and a maximum of 256 jump labels when you use a CPU
S7-1500.
Only one jump label can be placed in a network. Each jump label can jump to several locations.
Example
The following example shows how the instruction works:
If operand "TagIn_1" has the signal state "1", the "Jump if RLO = 1" instruction is executed. The linear
execution of the program is interrupted and continues in Network 3, which is identified by the jump
label CAS1. If the "TagIn_3" input has the signal state "1", the "TagOut_3" output is set.
                                                  - 128 -
                                 JMP_LIST: Define jump list (S7-1200, S7-1500)
Description
You can use the "Define jump list" instruction to define several conditional jumps and continue the
program execution in a specific network depending on the value of the K parameter.
You define the jumps with jump labels (LABEL), which you specify at the outputs of the instruction
box. The number of outputs can be expanded in the instruction box. You can declare up to 32 outputs
when you use a CPU S7-1200 and a maximum of 99 outputs when you use a CPU S7-1500.
The numbering of the outputs begins with the value "0" and continues in ascending order with each
new output. Only jump labels can be specified at the outputs of the instruction. Instructions or oper‐
ands cannot be specified.
The value of the K parameter specifies the number of the output and thus the jump label where the
program execution is to be resumed. If the value in the K parameter is greater than the number of
available outputs, the program execution is resumed in the next network of the block.
The "Define jump list" instruction is only executed if the signal state is "1" at the EN enable input.
Parameter
The following table shows the parameters of the "Define jump list" instruction:
Example
The following example shows how the instruction works:
                                                    - 129 -
                                JMP_LIST: Define jump list (S7-1200, S7-1500)
The following table shows how the instruction works using specific operand values:
                                                   - 130 -
                                 SWITCH: Jump distributor (S7-1200, S7-1500)
Description
You can use the "Jump distributor" instruction to define multiple program jumps to be executed de‐
pending on the result of one or more comparison instructions.
You specify the value to be compared in the K parameter. This value is compared with the values that
are provided by the various inputs. You can select the comparison method for each individual input.
The availability of the various comparison instructions depends on the data type of the instruction.
The following table shows the comparison instructions that are available depending on the selected
data type:
Parameters
The following table shows the parameters of the "Jump distributor" instruction:
                                                     - 131 -
                                SWITCH: Jump distributor (S7-1200, S7-1500)
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                    - 132 -
                               SWITCH: Jump distributor (S7-1200, S7-1500)
                                                 - 133 -
                                       --(RET): Return (S7-1200, S7-1500)
--(RET): Return
Description
You can use the "Return" instruction to stop the execution of a block. The results is three types
through which the block processing can be completed.
•   Without call of the "Return" instruction
    The block is exited after execution of the last network. The ENO of the function call is set to the
    signal state "1".
•   Call of the "Return" instruction with preceding logic operation (see example)
    If the left connector has the signal state "1", the block will be exited. The ENO of the function call
    corresponds to the operand.
•   Call of the "Return" instruction without previous logic operation
    The block is exited. The ENO of the function call corresponds to the operand.
        Note
        Only one jumping coil may be used in a network ("Return", "Jump if RLO=1", "Jump if RLO=0").
If the result of logic operation (RLO) at the input of the "Return" instruction is "1", program execution is
terminated in the currently called block and resumed after the call function in the calling block (for ex‐
ample, in the calling OB). The status (ENO) of the call function is determined by the parameter of the
instruction. This can assume the following values:
•   RLO
•   TRUE/FALSE
•   <Operand>
To set the parameter values, double-click the instruction and select the corresponding value in the
drop-down list.
The following table shows the status of the call function if the "Return" instruction is programmed in a
network within the called block:
                                                    - 134 -
                                      --(RET): Return (S7-1200, S7-1500)
Parameters
The following table shows the parameters of the "Return" instruction:
Example
The following example shows how the instruction works:
If operand "TagIn" has the signal state "1", the "Return" instruction is executed. Program execution is
terminated in the called block and continues in the calling block. The ENO enable output of the call
function is reset to signal state "0".
                                                   - 135 -
                                 Word logic operations (S7-1200, S7-1500)
                                                   - 136 -
                                 AND: AND logic operation (S7-1200, S7-1500)
Description
You can use the "AND logic operation" instruction to combine the value at the IN1 input and the value
at the IN2 input bit-by-bit by AND logic and query the result at the OUT output.
When the instruction is executed, bit 0 of the value at the IN1 input and bit 0 of the value at the IN2
input are logically ANDed. The result is stored in bit 0 of output OUT. The same logic operation is exe‐
cuted for all other bits of the specified values.
The number of inputs can be expanded in the instruction box. The added inputs are numbered in as‐
cending order in the box. When the instruction is executed, the values of all available input parame‐
ters are combined with AND logic (ANDed). The result is stored in the OUT output.
The result bit has signal state "1" only when both of the bits in the logic operation also have signal
state "1". If one of the two bits of the logic operation has signal state "0", the corresponding result bit
is reset.
Parameters
The following table shows the parameters of the "AND logic operation" instruction:
Example
The following example shows how the instruction works:
                                                   - 137 -
                                AND: AND logic operation (S7-1200, S7-1500)
The following table shows how the instruction works using specific operand values:
                                                  - 138 -
                                  OR: OR logic operation (S7-1200, S7-1500)
Description
You can use the "OR logic operation" instruction to combine the value at the IN1 input and the value
at the IN2 input bit-by-bit by OR logic and query the result at the OUT output.
When the instruction is executed, bit 0 of the value at the IN1 input and bit 0 of the value at the IN2
input are combined by OR logic operation. The result is stored in bit 0 of output OUT. The same logic
operation is executed for all bits of the specified tags.
The number of inputs can be expanded in the instruction box. The added inputs are numbered in as‐
cending order in the box. When the instruction is executed, the values of all available input parame‐
ters are combined with OR logic (ORed). The result is stored in the OUT output.
The result bit has signal state "1" when at least one of the two bits in the logic operation has the signal
state "1". If both of the bits of the logic operation have signal state "0", the corresponding result bit is
reset.
Parameters
The following table shows the parameters of the "OR logic operation" instruction:
Example
The following example shows how the instruction works:
                                                   - 139 -
                                 OR: OR logic operation (S7-1200, S7-1500)
The following table shows how the instruction works using specific operand values:
                                                  - 140 -
                            XOR: EXCLUSIVE OR logic operation (S7-1200, S7-1500)
Description
You can use the "EXCLUSIVE OR logic operation" instruction to combine the value at the IN1 input
and the value at the IN2 input bit-by-bit by EXCLUSIVE OR logic and query the result at the OUT out‐
put.
When the instruction is executed, bit 0 of the value at the IN1 input and bit 0 of the value at the IN2
input are combined by EXCLUSIVE OR logic operation. The result is stored in bit 0 of output OUT.
The same logic operation is executed for all other bits of the specified value.
The number of inputs can be expanded in the instruction box. The added inputs are numbered in as‐
cending order in the box. When the instruction is executed, the values of all available input parame‐
ters are combined with EXCLUSIVE OR logic. The result is stored in the OUT output.
The result bit has signal state "1" when one of the two bits in the logic operation has the signal state
"1". If both of the bits of the logic operation have signal state "1" or "0", the corresponding result bit is
reset.
Parameters
The following table shows the parameters of the "EXCLUSIVE OR logic operation" instruction:
Example
The following example shows how the instruction works:
                                                   - 141 -
                          XOR: EXCLUSIVE OR logic operation (S7-1200, S7-1500)
The following table shows how the instruction works using specific operand values:
                                                 - 142 -
                                INV: Create ones complement (S7-1200, S7-1500)
Description
You can use the "Create ones complement" instruction to invert the signal state of the bits at the IN
input. When the instruction is processed, the value at the IN input and a hexadecimal template
(W#16#FFFF for 16-bit numbers or DW#16#FFFF FFFF for 32-bit numbers) are combined by EX‐
CLUSIVE OR logic. This inverts the signal state of the individual bits that are then stored at output
OUT.
Parameters
The following table shows the parameters of the "Create ones complement" instruction:
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                    - 143 -
                                     Shift and rotate (S7-1200, S7-1500)
                                                   - 144 -
                                     SHR: Shift right (S7-1200, S7-1500)
Description
You can use the "Shift right" instruction to rotate the content of the operand at the input INbit-by-bit to
the right and query the result at the OUT output. You use the N parameter to specify the number of bit
positions by which the specified value is to be shifted.
When the value at the N parameter is "0", the value at the IN input is copied to the operand at the
OUT output.
When the value at the N parameter is greater than the number of available bit positions, the operand
value at the IN input is shifted by the available number of bit positions to the right.
In the case of unsigned values, the freed bit positions in the left area of the operand are filled with
zeroes when shifting occurs. If the specified value has a sign, the free bit positions are filled with the
signal state of the sign bit.
The following figure show how the content of an operand of integer data type is shifted four bit posi‐
tions to the right:
Parameters
The following table shows the parameters of the "Shift right" instruction:
                                                   - 145 -
                                     SHR: Shift right (S7-1200, S7-1500)
                                                                                            Number of bit
                                                   USINT, UINT,
                                      USINT, UINT,              I, Q, M, D, L or            positions by
 N                 Input                           UDINT,
                                      UDINT                     constant                    which the value
                                                   ULINT
                                                                                            is shifted
                                      Bit strings, in‐   Bit strings, in‐                   Result of the
 OUT               Output                                                   I, Q, M, D, L
                                      tegers             tegers                             instruction
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                   - 146 -
                                       SHL: Shift left (S7-1200, S7-1500)
Description
You can use the "Shift left" instruction to rotate the content of the operand at the IN input bit-by-bit to
the left and query the result at the OUT output. You use the N parameter to specify the number of bit
positions by which the specified value is to be shifted.
When the value at the N parameter is "0", the value at the IN input is copied to the operand at the
OUT output.
When the value at the N parameter is greater than the number of available bit positions, the operand
value at the IN input is shifted by the available number of bit positions to the left.
The bit positions in the right part of the operand freed by shifting are filled with zeros.
The following figure shows how the content of an operand of the WORD data type is shifted by six bit
positions to the left:
Parameters
The following table shows the parameters of the "Shift left" instruction:
                                                    - 147 -
                                      SHL: Shift left (S7-1200, S7-1500)
                                                                                            Number of bit
                                                   USINT, UINT,
                                      USINT, UINT,              I, Q, M, D, L or            positions by
 N                  Input                          UDINT,
                                      UDINT                     constant                    which the value
                                                   ULINT
                                                                                            is shifted
                                      Bit strings, in‐   Bit strings, in‐                   Result of the
 OUT                Output                                                  I, Q, M, D, L
                                      tegers             tegers                             instruction
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                   - 148 -
                                    ROR: Rotate right (S7-1200, S7-1500)
Description
You can use the "Rotate right" instruction to rotate the content of the operand at the IN input bit-by-bit
to the right and query the result at the OUT output. You use the N parameter to specify the number of
bit positions by which the specified value is to be rotated. The bit positions freed by rotating are filled
with the bit positions that are pushed out.
When the value at the N parameter is "0", the value at the IN input is copied to the operand at the
OUT output.
When the value at the N parameter is greater than the number of available bit positions, the operand
value at the IN input is nevertheless rotated by the specified number of bit positions.
The following figure shows how the content of an operand of DWORD data type is rotated three posi‐
tions to the right:
Parameters
The following table shows the parameters of the "Rotate right" instruction:
                                                     - 149 -
                                    ROR: Rotate right (S7-1200, S7-1500)
                                                                                              Number of bit
                                      USINT,
                                                        USINT, UINT,       I, Q, M, D, L or   positions by
 N                 Input              UINT,
                                                        UDINT, ULINT       constant           which the value
                                      UDINT
                                                                                              is rotated
                                      Bit strings,      Bit strings, inte‐                    Result of the
 OUT               Output                                                  I, Q, M, D, L
                                      integers          gers                                  instruction
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                     - 150 -
                                     ROL: Rotate left (S7-1200, S7-1500)
Description
You can use the "Rotate left" instruction to rotate the content of the operand at the IN input bit-by-bit
to the left and query the result at the OUT output. You use the N parameter to specify the number of
bit positions by which the specified value is to be rotated. The bit positions freed by rotating are filled
with the bit positions that are pushed out.
When the value at the N parameter is "0", the value at the IN input is copied to the operand at the
OUT output.
When the value at the N parameter is greater than the number of available bit positions, the operand
value at the IN input is nevertheless rotated by the specified number of bit positions.
The following figure shows how the content of an operand of DWORD data type is rotated three posi‐
tions to the left:
Parameters
The following table shows the parameters of the "Rotate left" instruction:
                                                     - 151 -
                                     ROL: Rotate left (S7-1200, S7-1500)
                                                                                              Number of bit
                                      USINT,
                                                        USINT, UINT,       I, Q, M, D, L or   positions by
 N                 Input              UINT,
                                                        UDINT, ULINT       constant           which the value
                                      UDINT
                                                                                              is rotated
                                      Bit strings,      Bit strings, inte‐                    Result of the
 OUT               Output                                                  I, Q, M, D, L
                                      integers          gers                                  instruction
You can select the data type of the instruction from the "<???>" drop-down list of the instruction box.
For additional information on valid data types, refer to "See also".
Example
The following example shows how the instruction works:
The following table shows how the instruction works using specific operand values:
                                                     - 152 -
                                      Additional instructions (S7-1500)
Additional instructions
                                                   - 153 -
                                     DRUM: Implement sequencer (S7-1500)
Description
You can use the "Implement sequencer" instruction to assign the programmed values of the
OUT_VAL parameter of the corresponding step to the programmed output bits (OUT1 to OUT16) and
the output word (OUT_WORD). The specific step must thereby satisfy the conditions of the program‐
med enable mask on the S_MASK parameter while the instruction remains at this step. The instruc‐
tion advances to the next step if the event for the step is true and the programmed time for the current
step elapses or if the value at the JOG parameter changes from "0" to "1". The instruction is reset if
the signal state on the RESET parameter changes to "1". The current step is hereby equated to the
preset step (DSP).
The amount of time spent on a step is determined by the product of the preset timebase (DTBP) and
the preset counter value (S_PRESET) for each step. At the start of a new step, this calculated value is
loaded into the DCC parameter, which contains the time remaining for the current step. If, for example
the value of the DTBP parameter is "2" and the preset value for the first step is "100" (100 ms), the
DCC parameter has the value "200" (200 ms).
A step can be programmed with a timer value, an event or both. Steps that have an event bit and the
timer value "0" advance to the next step as soon as the signal state of the event bit is "1". Steps that
are programmed only with a timer value start the time immediately. Steps that are programmed with
an event bit and a timer value greater than "0" start the time when the signal state of the event bit is
"1". The event bits are initialized with a signal state of "1".
When the sequencer is on the last programmed step (LST_STEP) and the time for this step has ex‐
pired, the signal state on the Q parameter is set to "1"; otherwise it is set to "0". When the parameter
Q is set, the instruction remains on the step until it is reset.
In the configurable mask (S_MASK) you can selected the separate bits in the output word
(OUT_WORD) and set or reset the output bits (OUT1 to OUT16) by means of the output values
(OUT_VAL). If a bit of the configurable mask is in the signal state "1", the value OUT_VAL sets or
resets the corresponding bit. If the signal state of a bit of the configurable mask is "0", the correspond‐
ing bit is left unchanged. All the bits of the configurable mask for all 16 steps are initialized with a sig‐
nal state of "1".
The output bit at the OUT1 parameter corresponds to the least significant bit of the output word
(OUT_WORD). The output bit at the OUT16 parameter corresponds to the most significant bit of the
output word (OUT_WORD).
When you insert the instruction in the program, the "Call options" dialog opens in which you can spec‐
ify whether the block parameters will be stored in a separate data block (single instance) or as a local
tag (multi-instance) in the block interface. If you create a separate data block, you will find it in the
project tree in the "Program resources" folder under "Program blocks > System blocks". For additional
information on this topic, refer to "See also".
Parameters
The following table shows the parameters of the "Implement sequencer" instruction:
                                                   - 154 -
                      DRUM: Implement sequencer (S7-1500)
                                    - 155 -
                                   DRUM: Implement sequencer (S7-1500)
                                                                 I, Q, M, D, L or   Previous system
 PREV_TIME            Static                DWORD
                                                                 constant           time
                                                                                    Preset count for
                                                                 I, Q, M, D, L or   each step [1 to 16]
 S_PRESET             Static                ARRAY of WORD
                                                                 constant           where 1 clock
                                                                                    pulse = 1 ms.
                                                                                    Output values for
                                                                 I, Q, M, D, L or
 OUT_VAL              Static                ARRAY of BOOL                           each step [1 to 16,
                                                                 constant
                                                                                    0 to 15].
                                                                                    Configurable
                                                                                    mask for each
                                                                 I, Q, M, D, L or
 S_MASK               Static                ARRAY of BOOL                           step [1 to 16,
                                                                 constant
                                                                                    0 to 15]. Initial sig‐
                                                                                    nal states are "1".
For additional information on valid data types, refer to "See also".
Parameters ERR_CODE
The following table shows the meaning of the values of the ERR_CODE parameter:
 ERR_CODE*                                 Explanation
 W#16#0000                                 No error
                                           The value at the LST_STEP parameter is less than 1 or
 W#16#000B
                                           greater than 16.
                                           The value at the DSC parameter is less than 1 or greater
 W#16#000C
                                           than the value of the LST_STEP parameter.
                                           The value at the DSP parameter is less than 1 or greater
 W#16#000D
                                           than the value of the LST_STEP parameter.
 *The error codes can be displayed as integer or hexadecimal value in the program editor. For infor‐
 mation on toggling display formats, refer to "See also".
- 156 -