Structured Text Language Overview
Structured Text Language Overview
Chapter 10
Structured text
10.1 Expressions
The Structured Text language is a Pascal-type high-level language,
which incorporates the fundamental concepts of a modern high-level
language, in particular the most important principles for the structuring of
data and instructions. The structuring of data represents a common con-
stituent of all five programming languages; the structuring of instructions,
however, is an important feature of ST only.
An expression is an elementary constituent for the formulation of instruc-
tions. An expression consists of operators and operands. Frequently
occurring operands are data, variables or function invocations. However,
an operand may also be an expression itself. The evaluation of an ex-
pression supplies a value corresponding to one of the standard data
types or to a user data type. For instance, if X is a number of the type
REAL, then the expression SIN(X) also supplies a REAL type number.
Table B10.1 contains an overview of operators.
Equality =
Inequality <>
Boolean AND &, AND
Boolean exclusive OR XOR
Boolean OR OR lowest
Example A, B and C are variables of data type INT; A assumes the value 1, B the
value 2 and C the value 3. The evaluation of expression A+B*C supplies
the value 7. If a sequence other than that specified by the precedence is
desired, this is possible by using brackets. Using the above numeric
values, the expression (A+B)*C supplies the value 9.
If an operator has two operands, the leftmost operand is to be evaluated
first. The expression SIN(X)*COS(Y) is therefore evaluated in the se-
quence: Calculation of the expression SIN(X), calculation of the expres-
sion COS(Y), followed by the calculation of the product of SIN(X) and
COS(Y).
As demonstrated in the previous paragraph, a function may only be in-
voked within an expression. The invocation is formulated by specifying
the function name and the parenthesised list of arguments.
10.2 Statements
Table B10.2 contains a list of statements possible in the Structured Text
language. A statement may extend beyond one line, whereby the line
break will be treated in the same way as a blank space.
REPEAT Total := 0;
I := 0;
REPEAT
I := I + 1;
Total := Total + I;
UNTIL I = 5
END_REPEAT;
WHILE Total := 0;
I := 0;
WHILE I < 5 DO
I := I + 1;
Total := Total + I;
END_WHILE;
Assignments
An assignment is the simplest form of an instruction. This replaces the
actual value of the variable to the left of := with the value of the expres-
sion to the right of :=. Each assignment ends with a semicolon. One
possible assignment (table B10.2) is A := B; whereby the value of the
variable B is assigned to the variable A. As a result of the assignment
CV := CV + 1, the variable CV is increased by 1 as a result of the ex-
pression CV+1.
IF X < 0 THEN
Value := -1;
Error := 1;
RETURN;
END_IF
Y := LOG(X);
IF-Statement
The general form of an IF statement is:
The parts in square brackets are optional, i.e. these may occur in an IF
statement, but need not do so.
The simplest IF statement consists of an IF-THEN construct (simple
branch).
This is demonstrated by the following example
Error := 0;
IF Part_ok THEN Number := Number + 1;
ELSE Error := 1;
END_IF;
The statements following the keyword THEN are executed, if the condi-
tion following the keyword IF is met; if the condition is not met, the
statements formulated after the keyword ELSE are executed.
The example given deals with production parts. If the part is good
(Part_ok = 1), the THEN part is executed, in this case the number of
correctly produced parts is increased by 1; otherwise a bit is set for error
detection.
If a branch is to be programmed for more than 2 branches, an IF-THEN-
ELSIF construct may be employed. Table B10.2 illustrates this by way of
an example, whereby the solutions of the quadratic equation AX2 + BX +
C = 0 are established. If the discriminant – in this case variable D – is
less than 0, the subsequent THEN part is executed: there is no solution,
i.e. Number_Sln := 0.
If the first condition is not met, i.e. D is greater or equal to 0, the condi-
tion following ELSIF will be evaluated: If it is met, i.e. D equals 0, the
statements following the keyword THEN will be executed: The only exist-
ing solution is specified as X1.
Otherwise (D being greater than 0), the lines following the keyword
ELSE will be executed: The two possible solutions X1 and X2 are speci-
fied.
CASE-Statement
If a selection of several possible statement groups is to be made, the
CASE statement may be used.
The standard form for the multiple selection with CASE is:
CASE Selector OF
Value1: statement(s)1;
Value2: statement(s)2;
...
Valuen: statement(s)n;
[ ELSE
statement(s); ]
END_CASE;
With the evaluation of the CASE statement, the value of the selector is
determined first, followed by the execution of the first group of state-
ments, for which the computed value of the selector applies. If the value
of the selector is not contained in any of the statement groups, the
statements following the keyword ELSE are executed. If ELSE does not
occur, no statements are executed.
In the example given in table B10.2, the text for a statement is selected
in relation to the available measured value. The values for the selection
of the statement are of the INT type.
FOR loop
The standard representation of the FOR loop is:
The test for the termination condition is made at the beginning of each
iteration, so that the statements are not executed if the initial value ex-
ceeds the final value. A further characteristic of FOR loops is that these
may be nested at any time.
An example of the application of a FOR loop is given in table B10.2. In
this example, an addition of numbers 1 to 5 is realised via the loop.
When the loop is executed for the first time, I has the initial value 1, the
value of the variable Total is also 1. For the second loop execution, I has
the value 2, the variable Total reaches the value 1+2=3 etc. After the
fifth and last loop execution, the value for Total is 15, the counter vari-
able has reached the final value 5, and processing of the loop is thus
completed.
REPEAT loop
Unlike the FOR loop, with the REPEAT loop the number of iterations is
not defined in advance via a specified final value. Instead, a condition –
the so-called termination condition – is used.
REPEAT
statement(s);
UNTIL boolean expression
END_REPEAT;
The termination of the REPEAT loop is tested after the execution of the
loop statements. The loop is therefore executed at least once. The ter-
mination condition must be changed in the loop, since the loop will oth-
erwise be executed indefinitely. It is therefore important to ensure that
the loop has actually been completed. The following is to be checked:
Does the termination condition actually include a variable, so that the
condition can supply the value 1 (true)?
Is the termination condition ever reached?
An example of the use of the REPEAT loop is demonstrated in table
B10.2. Here too, the first five non-negative integers are added.
In the first loop execution, I has the value 1, the value of Total is also 1.
A check of the termination condition shows, that this is not met, whereby
the loop is executed again. The loop is executed repeatedly until the
termination condition is true. This will be the case after the fifth loop exe-
cution and the loop is ended. Here too, the result for the variable Total is
15L.
WHILE loop
The WHILE loop represents a second option for the formulation of itera-
tions by specifying a termination condition. The standard representation
of a WHILE loop is:
S := 0;
FOR I := 1 TO 2 DO
FOR J := 1 TO 3 DO
IF Error THEN EXIT;
END_IF;
S := S + J;
END_FOR;
(* If EXIT statement is executed then jump to this point
is executed *)
S := S + I;
END_FOR;
If the EXIT statement is within a nested loop, exit shall be from the in-
nermost loop in which the EXIT is located. The next statement to be
executed is the statement immediately after the loop end (END_FOR,
END_WHILE, END_REPEAT). In the example is the statement "S := S
+I;".
The following applies in the case of the above example: If the value of
the boolean variable Error is equal to 0, the algorithm for the variable S
provides the value 15. If the variable Error has the value 1, the value
computed for S is 3.
Step_3
e) Alternative branch
E F
Step_4 Step_5
Step_6 Step_7
f) Junction of alternative paths
G H
Step_8
Table B11.1:
Elements of the sequential
g) Parallel (simultaneous) branch Step_3 function chart
(graphic representation)
B
Step_4 Step_5
Step_8
The step
A step contains a number of execution parts of the control program. In-
puts and outputs may only be set or reset in a step. This also means that
all correcting variables issued to the connected plant by a control pro-
gram, can only be programmed in such steps.
The execution part assigned to a step, the so-called actions, are formu-
lated within action blocks.
A step is either active, with the associated action being executed at the
time, or inactive. In this way, the status of the connected system is de-
fined at any given moment by the set of active steps in the control pro-
gram.
As shown in table B11.1a, a step is represented graphically by a block.
Each step has a symbolic name, which can be freely selected by the
user. The same set of rules applies for the step name as those already
mentioned for symbolic identifiers: a symbolic name may consist only of
capital and lower case letters, digits and the underline and always starts
with a letter or the underline.
Fig. B11.1:
Steps with step names
Motor_3_on Vacuum_off
The evaluation of the above data can be useful with regard to monitoring
the connected system. Applications may also arise, which require the
use of variables in the control program itself.
A special case within the step element is the so-called initial step (table
B11.1b). This is drawn graphically by a double line.
Each network in a sequential function chart has precisely one initial step,
which is executed as the first step within a network.
As already mentioned, the importance of a sequential function chart lies
in its clearly structured graphic representation of a control program. It
may however also be useful to represent sequence structures textually.
The EN 61131-3 (IEC 61131-3) standard provides an equivalent textual
representation of SFC elements for this, which is as follows for the step
element:
STEP Vacuum_off
(*Contents of step*)
END_STEP
The transition
A transition or step enabling condition contains the logic condition per-
mitting the transition, according to the program, from one step to the
next.
As can be seen from table B11.1dh, the transition is represented by a
horizontal line across the vertical directed link. Each transition has a
transition condition, which is the result of the evaluation of a single boo-
lean expression. The transition condition can be formulated in any of the
EN 61131-3 (IEC 61131-3) languages such as LD, FBD, IL or ST.
A transition condition is either true and then has the value 1, or false,
when it has the value 0. Only if the condition is true, is the execution of
the program or the function block continued at this point.
If a condition is always true, it can simply be identified by the number 1
at the transition. Transition conditions of this type which are always true
may occur frequently in a program or function block in a sequential func-
tion chart.
Table B11.3:
Special transitions 1
Always true
transition condition
Transition condition
never true 0
Fig. B11.3:
Steps and
transitions in sequence Step_5
Step_6
Step_7
Here, the transitions and steps must continually alternate. The logic path
via this representation is always from top to bottom. The following be-
haviour can be seen in the example shown in fig. B11.3:
Assuming that step Step_5 is active, Step_5 remains active until transi-
tion D is true. Clearing of the transition results in the deactivation of the
preceding step Step_5 and the activation of the successive step Step_6.
As soon as step Step_6 is active, transition E of the controller is exam-
ined. If transition E is true, step Step_6 is ended and step Step_7 is
processed, etc.
Fig. B11.4:
Alternative branch:
Processing of transitions Step_3
from left to the right
D E F
G H I
Step_7
However, the EN 61131-3 (IEC 61131-3) standard also offers the facility
for the user to define the priority during the execution of the transitions.
The definition of the functionality of alternative branches in IEC 60848,
which requires a user programmed mutual exclusion of transition condi-
tions, is also supported by EN 61131-3 (IEC 61131-3) as a third method.
In contrast with the previous examples the numbers in the path in fig.
B11.5 indicate a user-defined priority of the transition evaluation. The
path with the lowest number has the highest priority.
Fig. B11.5:
Alternative branch with
user-defined priority Step_7
2 1
D E
Step_8 Step_9
Fig. B11.6:
Representation of a loop
Step_3
Step_4
Step_5
E F
Step_6
In fig. B11.6 the program flow evolves from step Step_5 to step Step_4,
if transition F is true and E is false. The evolution of step sequence
Step_4, to Step_5 may be repeated in this way.
Parallel branch
A completely different functional element of the sequential function chart
is parallel branching.
This is represented by a double line and a transition above this line (ta-
ble B11.1g). As soon as transition B is fulfilled, an evolution from step
Step_3 to step Step_4 and Step_5. These two steps are executed simul-
taneously.
A parallel branch determines that all connected paths are to be activated
simultaneously and evolved independently of one another. In the case of
the matching counterpart, and the joining of parallel paths, the transition
is always represented underneath the horizontal double line.
Fig. B11.7:
Representation of a
triple parallel branch F
Step_7
When step enabling condition F has been fulfilled, the three paths with
steps Step_4, Step_5 and Step_6 and Step_7 must be evolved simulta-
neously.
Depending on the contents of transition G between the two stepsStep_6
and Step_7, the control program may have to wait until transition G is
fulfilled. The lower transition H is therefore only examined if the right
path has been evolved completely. This can only be the case, if transi-
tion G in this path is true.
11.3 Transitions
Each transition is assigned a transition condition (step enabling condi-
tion). This provides the result of a boolean value.
In the simplest case, a step enabling condition can be specified by the
interrogation of an input of the controller or another boolean variable. It
is however also possible to program considerably more complex step
enabling conditions.
The contents of the transition condition are either specified directly at the
transition (see fig. B11.8) or linked with the transition via a transition
name (see fig. B11.9)
Fig. B11.8:
Direct specification of a
a) Transition condition Step_3 transition condition
in LD - language %IX3 %MX1
Step_4
%MX1
Step_4
Step_4
Here, two results are connected via a logic AND function, whereby the
transition condition will not be met until both input %IX3 and flag %MX1
assume the value 1.
The power or signal passes from left to right in the graphic languages LD
and FBD, the LD or FBD network part is defined on the left, next to the
transition symbol (horizontal line).
The boolean expression in ST languages is defined to the right of the
transition symbol.
Fig. B11.9:
Assignment of a
transition condition to the
transition by specifying
Step_3
a transition name
Transition name Tran_3_4
Step_4
END_TRANSITION
END_TRANSITION
11.4 Steps
A step represents the execution part of a sequential function chart. Only
within steps can a program or a function block within a controller influ-
ence the connected system via its outputs, by setting or resetting the
outputs.
Action blocks
The graphic programming of steps is effected via individual action
blocks. Each action is thereby connected with a particular characteristic.
An action block is represented in tabular format, which contains fixed
positions for the specification of the action qualifier, the name of the ac-
tion and the action content. In addition, a feedback variable may also be
entered.
Fig. B11.11:
Graphic representation
of action block
a b c
d
Fig. B11.12:
List of action blocks
Step_8 L
Action_1 Var_1
T#10s
Var_1
P Action_2
N Action_3
The contents of an action, i.e. the action itself, may be defined by means
of several methods:
Specification of a boolean variable
Programming in instruction list
Programming in structured text
Ladder diagram
Function block diagram
Sequential function chart
Fig. B11.14:
Formulation of actions: Action_2
graphic declaration in FBD
%IX0.5 >=1 %QX1.2
%MX1 &
%MX3
Fig. B11.15:
Formulation of actions: Action_2
graphic declaration in
LD language %IX0.5 %QX1.2
%MX1 %MX3
Fig. B11.17:
Action_4 Formulation of actions:
Inclusion of SFC elements
in an action
Start
Part_present
Color L Color_determine
T#1s
C_ok
If individual fields of an action block are not required, such as for in-
stance if a boolean variable is used as action content, a further simplifi-
cation in the representation of an action block is permissible.
Fig. B11.18:
Short representation
S %QX12 of an action block
Fig. B11.19:
Use of
feedback variables
Pos_1
Step_3 S Cylinder_2
S Vacuum_on Vac_on
Vac_on
Pos_2
N Non-stored
the action is executed for as long as the step is active.
Fig. B11.20:
Non-stored action
N %QX12
Step 1
active 0
1
%QX12
0
In the above example, the output %QX12 is set for as long as the step
containing this action is active. On completion of the step, i.e. as soon
as the subsequent enabling condition is met, the output is automatically
reset.
S Set (stored)
the execution of the action is executed permanently set (set stored).
Fig. B11.21:
Set (stored) action
S %QX12
Step 1
active 0
1
%QX12
0
In this example, the output %QX12 is set for as long as the step contain-
ing this action is active. The output also remains set, when the subse-
quent step enabling condition is met and the step being considered is no
longer active. The output can only be reset in another step, in another
action, defined with qualifier R.
R Reset
a previously set action (in another step) executed with the qualifier S,
DS, SD, L or SL is cancelled.
Fig. B11.22:
Reset action
R %QX12
Step 1
active 0
1
%QX12
0
Output %QX12 has been set in another step in an action with one of the
qualifiers S, DS, SD, L or SL and reset again via this action.
P Pulse (unique)
unique execution of the action.
Fig. B11.23:
Unique action
P %QX12
Step 1
active 0
1
%QX12
0
During the initial execution of the action via the controller within the
processing of the step, output %QX12 is set exactly once and then reset
again. The output is reset uniquely again only after the exiting the step
and a fresh re-entry into the step.
L Time limited
the action is executed for a specific time.
Fig. B11.24:
Time limited action
L
%QX12
T#10s
Step 1
active 0
1
%QX12 10s 10s
0
Output %QX12 is set for 10 seconds and subsequently reset again. This
requires the step containing this action to be active for a period of at
least 10 seconds. If the subsequent step enabling conditions are met
prior to this time, the action time of the output is reduced also, since it is
reset at the end of the step in any case.
D Time delayed
the execution of the action is delayed until the end of the step.
Fig. B11.25:
Time delayed action
D
%QX12
T#10s
Step 1
active 0
1
%QX12 10s 10s
0
Here, output %QX12 is not set until 10 seconds have expired and re-
mains set until the step becomes inactive. If the duration during which
the step is activated is less than 10 seconds, the output will not be set
during the processing of this step.
Fig. B11.26:
Time delayed and
stored Action DS
%QX12
T#10s
Step 1
active 0
10s 10s
1
%QX12
0
R 1
active 0
(in another step)
In this example too, output %QX12 is set after 10 seconds have expired.
However, it remains set after completion of the step. It must be reset
explicitly via another action with the qualifier R (in another step). If the
duration of the step is not sufficiently long, in this case less than 10 sec-
onds long, the output will never be set.
Fig. B11.27:
Stored and
SD time delayed action
%QX12
T#10s
Step 1
active 0
10s 10s
1
%QX12
0
R 1
active 0
(in another step)
Here too, output %QX12 is set after the expiry of 10 seconds. It remains
set following the end of the step and can only be explicitly reset via an-
other action with the qualifier R in another step. Unlike the mode of ac-
tion of the DS qualifier, it is not necessary for the step to remain active
beyond the duration of the delay for the output to be set.
Fig. B11.28:
Stored and
SL time limited action
%QX12
T#10s
Step 1
active 0
10s 10s
1
%QX12
0
The output is set for 10 seconds and then reset again. In contrast with
the mode of action of the L qualifier, it is not necessary for the step to be
active for a minimum of 10 seconds.
If the subsequent step enabling condition is met prior to this time expir-
ing, i.e. if the step is active for less than 10 seconds, the active period of
the output remains unaffected by this. The output can be reset at any
time via another action with the qualifier R.
The mode of action of the individual qualifiers has been illustrated in the
example of a boolean variable as an action. If more complex, i.e. non
boolean actions are required, the type of execution is marginally different
to the previously examined boolean variables. The networks are con-
tinually processed for as long as the step is active. As soon as the sub-
sequent step enabling condition is met, however, the last, unique,
execution of the networks is carried out once more.
This definition enables the targeted resetting of variables at the end of
the processing of an action, when the N qualifier is used for more com-
plex actions.
Fig. B11.29:
Complex action
in FBD language
Step_5 N Action_1
&
%IX1.0 %QX1.0
%MX12
Step_5.X
SR_1
SR
%IX1.5 S1 Q1 %QX1.5
R
11.5 Example
Problem description
Components are transported together on a conveyor belt to a dual proc-
essing station. The drilling and countersinking units then move down-
wards as soon as a component is present. Two cylinders 1A1 and 2A1
are used to move the two machine tools. The conveying device is in-
dexed by one working position via a third cylinder 3A1.
Two sensors B4 and B5 are provided to detect whether a workpiece is
located underneath the drill or the countersink. The required drilling and
countersink depths are sensed via two end position sensors 1B2 and
2B2. The initial positions of the transport cylinder, drill and countersink
can be detected via the values of sensors 1B1, 2B1 and 3B1. Sensor
3B2 indicates an extended transport cylinder.
The system cannot always guarantee that a workpiece will be deposited
underneath both the drill unit and the countersink after each transport
movement. Processing should then be interrupted in the case of a miss-
ing workpiece. If both workpieces are missing at the same time, neither
of the two tools should be lowered.
Fig. B11.30:
Positional sketch
1A1 2A1
1B1 2B1
1B2 2B2
B4 B5
3A1
3B1 3B2
Allocation list
Table B11.4: Equipment PLC input/ Task
Allocation list designation PLC output
Problem
A control program is to be designed for this task. The solution is to
achieve a configuration by means of a sequential function chart. The
conditions and actions are then to be applied to the steps and transi-
tions. The program is to be executed cyclically.
To simplify matters, you may assume that there is no need to use timers
to compensate for positioning tolerances.
Solution
Fig. B11.31:
Program in
sequence language
Start R 1Y1
R 2Y1
1B1 2B1 3B1 R 3Y1
B4 B4 B5 B5
/ /
Transport S 3Y1
3B2
All cylinders are brought into their initial position in one initial step. At the
end of the program, this step is also used to retract the cylinder ex-
tended during the last step for the transport device.
When all the cylinders are in their initial position, a parallel branch with
two sequences is started for drilling and countersinking. Both sequences
in this example contain the same tasks, but use different tools. The left-
hand sequence lowers the drill unit and lifts it again, and the righthand
sequence evolves identically for the countersinking. The sequences
merely differ in their use of sensors and actuators. A void step is incor-
porated at the top and bottom of both sequences to maintain the neces-
sary sequence steps and transitions.
The program for the drilling unit evolves as follows. It detects whether a
workpiece is available via the value of sensor B4. If this value is equal to
1, the workpiece is in the required position and the drilling process
starts. Otherwise the entire drilling process is bypassed in an alternative
path. Drilling of the hole starts with the lowering of the drill by setting
1Y1. When the lower end position is reached, i.e. drilling of the hole has
been completed, sensor 1B2 signals the end of drilling. In the next step,
the drill is returned to its normal position at the top. This part of alterna-
tive branching ends when the drill has reached the top. The program
follows the same procedure for countersinking.
When both parallel sequences have been completed, a transition takes
place in the program to the transport step. The necessary synchronisa-
tion – i.e. drilling and countersinking ready – is ensured by the sequen-
tial function chart and therefore does not require special treatment. A
true step enabling condition is always inserted at this point in order for
the steps and transitions to alternate.
In the last step Transport, the cylinder of the transport device is ex-
tended and the awaited completed action in the next transition condition.
Thereafter, the whole process starts anew.
Negation
The output signal assumes the value 1, if the input signal has the value
0 and vice versa.
Example Lamp H1 is illuminated as long as switch S1 is not actuated; it is extin-
guished, if the switch is closed. The purpose of S1 is therefore to switch
off the lamp.
Fig. B12.1:
Description methods
Function table Boolean equation
S1 H1 H1 = S1
0 1
1 0
Fig. B12.3:
Negation
a) LD b) FBD
S1 H1
/ S1 NOT H1
c) IL d) ST
LDN S1 H1 := NOT S1;
ST H1
AND-operation
The output signal only assumes the value 1, if all input signals have the
value 1.
Lamp H1 is to be switched on only if the two switches S1 ad S2 are ac- Example
tuated.
Fig. B12.4:
Function table Boolean equation Description methods
S1 S2 H1 H1 = S1 S2
<
0 0 0
0 1 0
1 0 0
1 1 1
Fig. B12.6:
AND operation a) LD b) FBD
S1 S2 H1
S1 & H1
S2
c) IL d) ST
LD S1 H1 := S1 AND S2;
AND S2
ST H1
OR-operation
The output signal assumes the value 1, if at least one input signal has
the value 1.
Example Lamp H1 is to be switched on, if at least one switch, S1 or S2 is actu-
ated.
Fig. B12.7:
Description methods Function table Boolean equation
S1 S2 H1 H1 = S1 S2
<
0 0 0
0 1 1
1 0 1
1 1 1
Fig. B12.9:
a) LD b) FBD OR operation
S1 H1
S1 >=1 H1
S2
S2
c) IL d) ST
LD S1 H1 := S1 OR S2;
OR S2
ST H1
Fig. B12.10:
Function table Boolean equation Description methods
S1 S2 S3 H1 H1 = (S1 S2 S3)
0 0 0 0 (S1 S2 S3)
0 0 1 0 (S1 S2 S3)
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 0
Fig. B12.12:
Combination of a) LD b) FBD
boolean operations
S1 S2 S3 H1 S1 &
/ S2
S3
S1 S2 S3
S1 & >=1 H1
/ S2
S3
S1 S2 S3
S1 &
/
S2
S3
c) IL d) ST
LD ( S3 H1 := (NOT S1 AND S2 AND S3)
AND S2 OR (S1 AND NOT S2 AND S3)
ANDN S1 OR (S1 AND S2 AND NOT S3);
)
OR ( S1
ANDN S2
AND S3
)
OR ( S1
AND S2
ANDN S3
)
ST H1
Function block SR
Fig. B12.13:
Function block SR,
SR primarily setting
BOOL S1 Q1 BOOL
BOOL R
Function block RS
Fig. B12.14:
Function block RS,
primarily resetting RS
BOOL S Q1 BOOL
BOOL R1
In the languages FBD and ST, memory operations are realised by invok-
ing a copy of the RS function block. The copy in this example has the
name RS_H1. The invocation in FBD is effected by means of graphically
linking the current transfer parameters with the inputs of the function
block copy. Since the value of the function block copy is relevant, the
output of the function block copy is connected correspondingly.
Fig. B12.16:
a) LD b) FBD Use of function blocks RS
B1 H1 RS_H1
S RS
B1 S Q1 H1
S1 H1
S1 R1
R
c) IL d) ST
LD B1 RS_H1 (S := B1, R1 := S1);
S H1 H1 := RS_H1.Q1;
LD S1
R H1
or
Fig. B12.17:
Rising and falling edge rising rising
edge edge
1
0
falling falling
edge edge
Rising edges
mark the instants, in which a signal level changes from 0 to 1.
Falling edges
mark the exact instants, when a signal level changes from 1 to 0.
Fig. B12.18:
Function block R_TRIG,
R_TRIG rising edge
BOOL CLK Q BOOL
Fig. B12.19:
Function block F_TRIG,
F_TRIG falling edge
BOOL CLK Q BOOL
Fig. B12.21: a) LD
Use of function blocks
R_TRIG S1 1Y1 1Y1
P / S
S1 1Y1 1Y1
P R
b) FBD
RS_1Y1
R_TRIG_S1 1Y1 & RS
R_TRIG S Q1 1Y1
S1 CLK Q R1
&
1Y1
c) IL
CAL R_TRIG_S1 (CLK := S1)
LD R_TRIG_S1.Q
ANDN 1Y1
S 1Y1
LD R_TRIG_S1.Q
AND 1Y1
R 1Y1
d) ST
R_TRIG_S1 (CLK := S1);
RS_1Y1 (S := R_TRIG_S1.Q & NOT 1Y1,
R1 := R_TRIG_S1.Q & 1Y1);
1Y1 := RS_1Y1.Q1;