You are on page 1of 10

APPLICATION OF PLC IN INDUSTRIAL AUTOMATION

Chapter VI
Transfer and program control functions
Transfer functions
With the transfer functions (Fig. 0.1) the data can be loaded to and transferred from the
central processing unit accumulators (ACCU) to operands and variables. These can also cause
data exchange between the accumulators. An accumulator is a special register in the
processing unit, which is used to buffer data processing. In a Siemens PLC the accumulator is
32 bits long and it has two accumulators. This is needed because in arithmetic and digital
operations two input operands are processed to one result. The first operand is loaded into
ACCU 1. When loading the second operand, the data in ACCU 1 is moved into ACCU 2 and
then the operand data is loaded into ACCU 1. In this process the previous content of ACCU 2
is lost. Then the desired operation is executed. The operation result is placed in ACCU 1,
from where it is transferred to output operand. Only the content from ACCU 1 can be
transferred to operands [6].
Data source

Load

ACCU 1

LD
L
Operand
(Bit, Byte, Word, Double
Word)

ACCU 2

Variable
(INT, DINT, REAL,
TIMER, COUNTER)

Transfer
ST
T

Data destination
Operand
(Bit, Byte, Word, Double
Word)
Variable
(INT, DINT, REAL,
TIMER, COUNTER)

Fig. 0.1. Data transfer functions

In IEC 61131 the commands LD and ST are used for load and transfer functions in IL
language. In STEP 7 these are L and T in STL language. In FBD and LAD languages a
MOVE function is used for transferring values between operands (combines load and transfer
commands together). In STEP 7 the transfer functions cannot be used with bit operands.
Table 0.1 shows the STEP 7 load and transfer commands with allowed operands in STL
language. n is the byte address of the operand in the memory area. x is the DB number.
STL language load and transfer function demands presented in Table 5.1 apply also to the
MOVE function.

a
Fig. 0.2. Transfer function in FBD (a) and STL (b) languages

APPLICATION OF PLC IN INDUSTRIAL AUTOMATION

Fig. 0.2 shows the transfer (MOVE) function in FBD and STL languages. In this example
operand IW 2 value is transferred to operand QB 6 if the input operand EN I 0.0 has signal
1.
Table 0.1. Overview of load and transfer function commands

Load from:
Transfer to:
Inputs

Outputs

Peripheral

Memory

Constant

Command for
load
L IB n

Command for
transfer
T IB n

L IW n

T IW n

L IW n

T ID n

L QB n

T QB n

L QW n

T QW n

L QW n

T QD n

L PIB n

T PQB n

L PIW n

T PQW n

L PIW n

T PQD n

L MB n

T MB n

L MW n

T MW n

L MW n

T MD n

L B#16#F5
L -50
L L#-400

Timer

L 2.5
L S5T#2S500MS
L C#250
LTn

Counter

LC T n
LCn
LC C n

Comment
Loading from/transferring to one input
byte
Loading from/transferring to one input
word
Loading from/transferring to one input
double word
The inputs values are changed by
transfer command only for one PLC
cycle. By new PLC cycle real digital
input values are there.
Loading from/transferring to one output
byte
Loading from/transferring to one output
word
Loading from/transferring to one output
double word
Loading from/transferring to one
peripheral byte
Loading from/transferring to one
peripheral word
Loading from/transferring to one
peripheral double word
Loading from/transferring to one
memory byte
Loading from/transferring to one
memory word
Loading from/transferring to one
memory double word
Loading a HEX number constant
Loading an integer number constant
Loading a double integer number
constant
Loading a real number constant
Loading a S5 time value constant
Loading a S5 counter value constant
Loading integer format value from timer
Loading BCD coding value from timer
Loading HEX format value from counter
Loading BCD coding value from
counter

APPLICATION OF PLC IN INDUSTRIAL AUTOMATION

Load from:
Transfer to:
Data

Variables

Command for
load

Command for
transfer

L DB x. DBB n

T DB x. DBB n

L DB x. DBW n

T DB x. DBW n

L DB x. DBD n

T DB x. DBD n

L DBB n

T DBB n

L DBW n

T DBW n

L DBD n

T DBD n

L #Speed

T #Speed

Comment
With data block address
Loading from/transferring to one data
byte
Loading from/transferring to one data
word
Loading from/transferring to one data
double word
Without data block address
Loading from/transferring to one data
byte
Loading from/transferring to one data
word
Loading from/transferring to one data
double word
Loading from/transferring to variable
Speed

If the transfer is allowed (input I 0.0 has signal 1), then the content of operand IW 2, with
the length of the word, is loaded (written right-aligned) to ACCU 1 (Fig. 0.3). The highest
addressed byte (byte 3) stays on the right. The remaining two bytes of ACCU 1 will be filled
with 0. Next the ACCU 1 content is transferred to operand QB 6, with length of one byte.
The content of the most right located ACCU 1 byte (byte 3) is written to the operand. So if the
operand IW 2 bit value was 0100 1001 1110 0110, then the operand QB6 value is 1110 0110.
Content: Byte 2

IW 2
Byte 3

7 ...0

ACCU 1
Content:

L IW 2

7 ...0

7 ...0

7 ...0

7 ...0

7 ...0

Byte 2

Byte 3
T QB 6
Content:

QB 6
7 ...0
Byte 3

Fig. 0.3. Loading and transferring steps by STEP 7

In the MOVE function the input EN can be empty. This means that the MOVE command is
executed by each PLC work cycle and it does not have to wait for the enable signal to be
present at the input EN.

APPLICATION OF PLC IN INDUSTRIAL AUTOMATION

Program control functions


In many PLC programs it is necessary to leave the linear program editing and execute
alternative program branches. This can be done within a block by jumps, loops or through
block operations. Conditional calls of functions and blocks or alternative branching are also
leading to a non-linear program editing [6].

Unconditional and conditional jump functions


With the jump functions the program editing can be moved to another part of the PLC
program. IEC 61131 uses command JMP with a label as a jump function. The label marks the
jump destination in a PLC program. The program jump can be executed unconditionally or
conditionally.
In Tables 0.2 and 0.3 jump functions in STEP 7 for STL and FBD languages are presented [6,
17]. In LAD language the boxes shown in Table 0.3 are replaced with contacts on the left side
and with coils on the right side. The status bits used in FBD and in LAD can be found under
Status bit folder in STEP 7.
Table 0.2. STEP 7 jump commands in STL language

Command
(operation)
JU
JC
JCN
JCB
JNB
JBI
JNBI
JO

Operand

Comment

Label
Label
Label
Label
Label
Label
Label
Label

JOS

Label

JZ
JN
JP
JM
JPZ

Label
Label
Label
Label
Label

JMZ

Label

JUO

Label

LOOP

Label

Jump unconditionally.
Jump if the result of logic operation (RLO) is 1.
Jump if the RLO = 0.
Jump if RLO = 1. Copy the content of the RLO bit into the BR bit.
Jump if RLO = 0. Copy the content of the RLO bit into the BR bit.
Jump if the status bit BR is 1.
Jump if the status bit BR is 0.
Jump if the previous arithmetic operation result exceeds maximum
range (oversize). The statues bit OV is 1.
Jump if one of the previous arithmetic operation results exceeds
maximum range (oversize). The status bit OS is 1.
Jump if the previous arithmetic operation result is equal to 0.
Jump if the previous arithmetic operation result is unequal to 0.
Jump if the previous arithmetic operation result is greater than 0.
Jump if the previous arithmetic operation result is less than 0.
Jump if the previous arithmetic operation result is greater than or
equal to 0.
Jump if the previous arithmetic operation result is less than or equal
to 0.
Jump if an illegal arithmetic operation occurred. Status bits CC 1
and CC 0 are 1.
Loop jump. Decrement ACCU 1-L content and jump if ACCU 1-L
content in unequal to 0.

Table 0.3. STEP 7 jump commands in FBD language

Command (operation)

Operand

Comment

APPLICATION OF PLC IN INDUSTRIAL AUTOMATION

Command (operation)

Operand
Label

Comment
Jump unconditionally

Label

Jump if the RLO is 1.

Label

Jump if the RLO is 0.

Label

Jump if the previous arithmetic operation result


is greater than 0. Under the state bits can be
found also < 0, == 0, <> 0, >= 0 and <= 0.
Jump if the previous arithmetic operation result
exceeds maximum range (oversize)
(OV = 1).
Jump if one of the previous arithmetic
operation results exceeds maximum range
(oversize). The status bit OS is 1.
Jump if an illegal arithmetic operation occurred
with floating-point variables.

Label

Label

Label
Label

Jump if the status bit BR is 1.


The jump destination. Here the jump label is
written.

The jump destination is marked with a jump label. A label consists of a maximum of four
characters. The first character must be a letter; the other characters can be letters, numbers or
underline (for example, M_01). Large and small letters have to be considered by writing jump
labels. By jump instruction the label is written in STL behind the jump command and in FBD
above the jump command box. The jump destination is marked in STL with jump label
followed by a colon (for example, M_01: A I1.0) or in FBD with a box (label is written in the
box) at the beginning of a network. The jump label can have only one jump destination, but
jumps to the same location can be executed from different places. Jump commands are
executed only within the same block. Jumps can be made forward or backward in one block.

APPLICATION OF PLC IN INDUSTRIAL AUTOMATION

Fig. 0.4. Sample program with jump functions in FBD (a) and STL (b) languages

Fig. 0.4 shows a program written in FBD and STL languages, where jump functions are used.
The operand QB 6 obtains value from operand IW 2 if the input operand I 0.0 has signal 1.
The value of operand QB 6 is set to 0 if the input operand I 0.0 has signal 0.
It is important to know that in such program parts the assignments of variables stay as they
were set by the last program part execution, even if this program part is not executed anymore
(program jumps over this part) and the assignment condition has changed.

Block call functions


IEC 61131 uses the command CAL to open function blocks unconditionally or conditionally.
Functions in the PLC program cannot be opened with this command.
Tables 0.4 and 0.5 present the block call functions in STEP 7 for STL and FBD languages.
With the command CALL the blocks are opened and the block handover parameter values are
exchanged (updated). The handover parameters are listed below the command CALL (Fig. 0.5
b). Commands UC and CC are used to call blocks without handover parameters.
Table 0.4. Block call functions in STEP 7 by STL language

Command
(operation)
CALL
UC
CC

Operand

Comment

FB, FC, SFB, SFC


FB, FC
FB, FC

Unconditional call of blocks


Unconditional call of blocks without parameters
Conditional call of blocks without parameters

APPLICATION OF PLC IN INDUSTRIAL AUTOMATION

OPN

DB, DI

Opening of Data blocks

In LAD language boxes shown in Table 0.5 are replaced with coils.
Table 0.5. Block call functions in STEP 7 by FBD language

Command
(operation)

Operand

Comment

FC, SFC

Unconditional call of functions without parameters

DB

Opening of DBs

In FBD and LAD languages the block call function is the block box itself (Fig. 0.5 a). Inside
the box are the block name and handover parameters. In STEP 7 the FBs are called together
with instance DBs (these belong to the FB). Compared to FC, the FB handover parameters do
not have to be connected with operands. Handover parameters not connected retain their
current values.
The command OPN is executed without any conditions. The opened DB remains active until a
different DB is opened.

Fig. 0.5. Block call up in FBD (a) and STL (b) languages

In FBD and LAD languages the FBs (Fig. 0.5 a), FCs and many standard functions (Fig. 0.2
a) have the release input EN (enable) and the release output ENO (enable output), which
influence their execution. If the release input EN is unconnected or it has signal 1, then the
block is called up or the function is performed. The release output ENO has also a signal 1.
If a fault occurs during block or function execution, then the release output ENO signal is set
to 0 even though the release input has signal 1. If the release input EN has signal 0,
then the block is not called up or the function is not performed and the release output ENO
signal is also 0 [6].
It is important to know that during the PLC operation (PLC is in RUN mode) all the called
and opened blocks in the program have to be in the PLC. Otherwise, the program execution is
interrupted and the CPU goes into the STOP mode.

APPLICATION OF PLC IN INDUSTRIAL AUTOMATION

Block end functions


IEC 61131 uses the command RET to return (close) from FCs or from FBs unconditionally or
conditionally. When returning to the interrupted block, the program execution continues from
where the call function was executed.
Table 0.6 shows the block end functions in STEP 7 for STL and FBD languages. In LAD
language the box shown in Table 0.6 is replaced with a coil. With commands BEU, BEC and
RET the block program editing can be terminated prematurely. With BEC and RET the
program editing is terminated if the RLO before the commands is 1. With the command
BEU the executable program termination can be prevented with jump functions (jumping over
the command).
Table 0.6. STEP 7 block end functions in STL and FBD languages

Command
(operation)
STL
BE
BEC
BEU

Command (operation) FBD

Comment

Marks block end


Marks conditional block end (RLO = 1)
Marks unconditional block end
Marks conditional block end (RLO = 1)

In Fig. 0.6 an example PLC program in STL language is shown. The program has been
structured into different blocks. Jump, block call and end functions have been used in the
program. In this example block FB 1 is always called up by OB 1 and the program inside it is
executed. If the memory M 0.1 has signal 1, then the FB 1 program execution is terminated
by the command BEC. Blocks FC 4 and FB 5 are called up only if the call conditions in OB 1
are true. This means that for executing program in FC 4 the input I 0.0 signal has to be 1
and for FB 5 the input I 0.1 signal has to be 0. In both blocks other blocks (in FC 4 the FB 4
and in FB 5 the FC 1) are called up unconditionally. The FB 4 program execution is
terminated by the command BEU if the jump function JC M001 is not carried out. This means
that the jump JC condition is not fulfilled (the memory M 12.1 signal state is 0) and the FB
4 program execution ends before block end BE. In FC 1 data block DB 10 is opened to save
some information in it (transfer function).

APPLICATION OF PLC IN INDUSTRIAL AUTOMATION

OB 1

CALL FB 1, DB 1

FB 1

A M 0.1
BEC

A I 0.5
S Q 0.2
BE

FC 4
A I 0.0
CC FC 4

UC FB 4, DB 4

BE

FB 5
AN I 0.1
CC FB 5, DB 5

CALL FC 1

BE

BE

FB 4

A M 12.1
JC M001
BEU
M001: L MW 20
L MW 22
+I

BE

FC 1

OPN DB 10
L MW 50
T DBW 60

BE

Fig. 0.6. Structured PLC program written in STL language

Self check
1. An accumulator is ...
a. a register in the central processing unit used to buffer processing data
b. a register in which a PLC program result is stored
c. a memory area where the user program can be stored
d. signal change from 0 to 1
2. Which data types exclude the use of the MOVE function?
a. BYTE
b. BOOL
c. WORD
d. INT
3. The JMP function presented below is executed

a. always if some conditions are before it


b. only when the condition before it is false
c. always if there are no conditions

APPLICATION OF PLC IN INDUSTRIAL AUTOMATION

d. only when the condition before it is true


4. Which function is used to open a data block (DB) in STEP 7?
a. OPN
b. OPEN
c. DB 1
d. CALL
5. How does the release input EN influence the blocks and functions execution?
a. Not at all.
b. If a condition is connected to it, then the blocks and functions are executed if
the condition is false.
c. If a condition is connected to it, then the blocks and functions are executed if
the condition is true.
d. If a condition is connected to it, then the blocks and functions are executed
always.
6. Which function can be used in LAD language to end a block execution before it has
been accomplished?
a. BE
b. BEC
c. RET
d. BEU

You might also like