Programming Manual for PLC FP-2
Ladder and FBD Editors
In the Ladder Diagram (LD) and Function Block Diagram (FBD) editors, programs are presented
graphically. The LD editor can portray everything the FBD can, but in addition the LD:
can incorporate Boolean variables in the form of contacts and coils
has a power rail that connects all networks and to which contacts, etc. are connected
within networks.
LD symbols include: contacts, coils, input variables, output variables, jumps and backward jumps. An
FBD program consists of blocks, jumps, input variables and output variables.
LD program, which includes a power rail and Boolean contact
Network info area with network number
Power rail
Network with Boolean contacts
Comment field
Programming window
FBD program.
1
2
3
Network info area with network number
Comment field
Programing Window
Each POU body consists of one or more networks. The network info area is displayed on the left.
Here you can find the network number, labels and statuses, e.g. for breakpoints (debug), network
selection and error messages. The program is displayed in the right of the programming window.
Comments can be inserted using the
symbol.
Connecting Objects
The LD and FBD contain two editing modes: selection mode (cursor = arrow) and
interconnector mode (cursor = pen). In selection mode, you can select programming symbols, e.g.
contacts, and position or edit them in the programming window. In interconnect mode, you can
draw the lines that connect the programming symbols to each other. The selection mode is the
default mode. You can change to the interconnect mode via:
Edit Draw Line, the "Draw Line" command is checked if active
Click
in the tool bar, or select the "Draw Line" command in the pop-up menu
(right mouse button)
Press <ESC> or double-click on an empty space within the programming window to leave the
interconnect mode. Programming symbols that do not have any connection points cannot be
selected in interconnect mode. Logical elements, input and output variables, jumps and
backward jumps can also be positioned in interconnect mode.
Time-saver features of the grafical editors:
When inserting functions, function blocks and operators in the POU body, these
programming symbols are automatically equipped with empty input/output variables
and name boxes ("?") if "Add input/output variables automatically" is activated under
Extras Options Program Options Editors LD/FBD Editor.
Press and hold <Shift> while connecting programming symbols, the connecting line is
automatically calculated.
Press and hold <Shift> while moving elements that are already connected, e.g. a coil, the
connection lines automatically shift when the element is moved.
When copying programming symbols (contacts, functions etc.) with Edit Copy/Paste
or the corresponding command buttons, the accompanying connecting lines are also
copied. If you copy a programming symbol by selecting it and keeping <Ctrl> pressed
while dragging it to the new position, the programming symbol and all of its
accompanying connection lines is duplicated and automatically equipped with contacts.
Useful Hints
The following hints facilitate programming and save programming time:
Press <Strg> + <a> to select all networks within one POE
Use <Tab> to jump within one network from a editing field, e.g. variable name to
another. Jump backwards with <Shift> + <Tab>.
Tools Minimize Network enables you to optimize the height of the network.
Double-click on an empty space within the programming window to change from the
interconnect mode to select mode and vice versa.
Press <ESC> to leave the interconnect mode.
Command Buttons in the Tool Bar
When you open an LD or FBD body, the following buttons appear in the tool bar:
IC
Description
ON
Inserts a new network before the selected network.
Inserts a new network after the selected network.
Deactivates/activates the selected network. Deactivated networks are treated like comments and
are therefore not compiled.
Switches between interconnect mode (Draw Line) and selection mode.
Opens the Variable Selection dialog box if a name box for an input/output variable is selected.
Opens the OP/FUN/FB Selection dialog box from which you can select operators, functions or
function blocks and insert them in the programming window with a left-click at the desired
position.
Inserts a name box for an variable in the programming window. Left-click at the desired
position.
Inserts a jump.
Inserts a backward jump (return).
Inserts a comment.
Changes the vertical distance.
Changes the horizontal distance.
In addition, LD includes the following symbols in the tool bar:
Inserts a contact in the programming window. Left-click at the desired position.
Inserts a coil in the programming window. Left-click at the desired position.
Pop-up Menu
When you click the right mouse button anywhere in the programming window, a pop-up menu opens.
This menu contains many useful commands. A list of the last operators, functions or function blocks
used appears in the bottom part of the pop-up menu.
Enable Input and Enable Output
In FBD and LD you can program for conditions by using EN/ENO functions and function blocks.
EN stands for enable input, ENO for enable output.
All IEC functions and function blocks are available both with and without EN and ENO. The
E_MOVE function does and the MOVE function does not have an EN/ENO, for example.
If you require an enable input (EN) and an enable output (ENO):
Insert the EN/ENO instruction by selecting [Insert with EN/ENO] from the OP/FUN/FB
selection in the LD, FBD and IL editors. To facilitate reusing the Enable (E_) instruction, it will then
appear as such under "Recently used" in the pop-up menu. EN and ENO are Boolean variables. When
EN is set (TRUE), the function or function block is processed. When the function or function block
has been successfully executed, the corresponding ENO is set to TRUE. At the ENO output of a
FUN/FB, you can connect the EN input to the next POU, which is then only processed when the
output ENO of the first POU is set to TRUE.
EN/ENO in a ladder diagram EN/ENO in a
function block diagram
EN/ENO in a ladder diagram EN/ENO in a
function block diagram
when creating a new POU (Edit New POU or
EN/ENO contacts"
at a later time with Object Properties...
) and selecting the option "With
The ENO output can be explicitly set in the body during programming:
If you do not explicitly set the ENO output within the body of the user-defined function or
function block, it will have the same value as the EN input.
If you set the ENO output within the body of the user-defined function or function block
to FALSE, the values of the output variables will not be transmitted to the outputs.
Editing Programming Symbols
In the Ladder Diagram and Function Block Diagram editors you can edit the programming
symbols in your program in selection mode as follows:
select and deselect
cut/copy and paste
shift (with and without connection lines)
change distance between programming symbols
enter/change variable names
extend functions and operators
negate contacts, define edges, set and reset
define graphic macros
Check a LD or a FBD Program
You can check your program any time with Object Check or
. The entire program defined up to
that point is checked for syntax errors as well as for declaration errors (e.g. whether a variable is used
that has not yet been declared). Each error is listed individually in the error list. Selection of any error
in the error list by double-clicking causes the error to be displayed in the POU body in the colour
defined for errors.
If applicable, please click on the displayed error and then [Show]. The program containing the error
will be displayed on your screen and the error will be highlighted.
Structured Text Editor (ST)
Structured Text is a text-based editor exempt from normal syntax. ST allows you to write complex
programs and control structures using an optimized programming language. It is available for all
PLCs and requires no more resources, e.g. steps, labels or calls, than other editors while doing
comparable programming.
IF SendTHEN
(* Copy characters of the variable SendString to the SendBuffer[1]
*)
(* SendBuffer[0] will be used by F144_TRNS. The number of bytes not
yet transmitted is stored in SendBuffer[0] at each transmission *)
F10_BKMV( s1_Start:= Adr_Of_VarOffs( SendString, StringHeaderSize),
s2_End:= AdrLast_Of_Var( SendString), d_Start:=
SendBuffer[1]);
(* Send the information of the SendBuffer *)
F144_TRNS( s_Start:= SendBuffer[0], n_Control:= LEN(SendString));
END_IF;
Expressions
When their rank is the same, processing proceeds from left to right.
With the values A:=1.0; B:=2.0; C:=3.0; and D:=4.0; for
X:=A+B-C*SQRT(D); the result is -3.
By inserting parentheses, the processing order can be changed, e.g. for
X:=A+(B-C)*SQRT(D); the result is -1.
Boolean expressions are always fully processed:
IF a<100 AND UserFun1(a) THEN
a:=a+1;
END_IF;
In this case, UserFun1 is also processed if a>=100.
When you wish to avoid processing UserFun1 for whatever reason, e.g. its too timeconsuming, or when
a>=100 an operation error occurs, or because the memory area will be overwritten, you
can write, for example:
IF a<100 THEN
IF UserFun1(a) THEN
a:=a+1;
END_IF;
END_IF;
Expressions can also indicate elements of an array:
X:=Array1[i+2];
Operands
The operands you can use in the ST editor are:
Name
Literal
Type
Numerical
Example
49 or 3,14159
Variable
String
'This is a text'
Time
Individual variable
T#8d_3h_23m
Var1
Element of an Array (see page
Array1[5]
58)
Dut1.Var1
Element of a DUT (see page
Dut1.Array1[i+5]
21)
Element of an Array or a DUT
Call function
Function
Fun1(a,b,c)
Operators
Operator
( )
-
Description
Parentheses, Call up function
Negation
NOT
**
Complement
Raise to a power
Multiplication
Division
MOD
+
Modulo (Remainder)
Addition
>,< >=,<=
=
Subtraction
Comparison
Equal
<>
&, AND
XOR
OR
Not Equal
Boolean AND
Boolean exclusive OR
Boolean OR
Precedence
High
Lowest
Instruction
The ST editors instructions are:
the assignment instruction :=
the specification instruction IF, CASE
he repeating instruction FOR, WHILE, REPEAT, along with the quit instruction EXIT
the return instruction RETURN
KeyWord
:=
Description
Assignment
Example
a:=87;b:=b+1;c:=SIN(x)
Explanation
The value on the right is assigned to
Calling
Functions
;
Y:=SIN(x);
Y:=LIMIT(MN:=0,IN:=X,
MX:=100);
Y:=LIMIT(0, X, 100);
Calling FBs
TON1(IN:= Start1,
PT:=T#300ms ,
Q=> End1,
EV=> EV_1);
Ton1(IN:=Start1,
PT:=T#300ms);
End1:=Ton1.Q;
Ev1:=Ton1.EV;
Ton1.IN:=Start1;
Ton1.PT:=T#300ms;
Ton1();
the identifier on the left
Functions argument in shorthand
Function arguments with formal
parameters
Note:
The order does not matter for arguments
with formal parameters.
With user functions, the EN input and
output can be omitted. Omitted EN will
be interpreted as TRUE.
Function arguments without formal
parameters
Note:
The order matters for arguments without
formal parameters.
The case of letters is not significant
Function block arguments with
formal parameters
Note:
The order does not matter for arguments
with formal parameters.
Function block arguments without
formal parameters
Note:
The order matters for arguments without
formal parameters.
The case of letters is not significant.
Unlimited use of formal parameters
in program called
IF
Ton1.QTHEN
....
IF
Conditional
divergence
CASE
Multiple
Selection
FOR
Loop Instruction
END_IF;
IF a>=0 AND a<=10 THEN
b:=0;
ELSIF a>=100 THEN
b:=1;
ELSE
b:=2;
END_IF;
CASE aOF
0: b:=0;
1,2: b:=1;
3,4,10...20: b:=2;
100..110: b:=3;
ELSE b:=4;
END_CASE;
FOR i:=0 TO 100 DO
SUM:=SUM+ a[i]
END_FOR;
FOR i:=0 TO 100 BY 10
DO
Divergence depends upon the
Boolean value of the expression
Multiple selection depending on the
variable
Defined number of loops with preset
step width 1
or with user-defined step width
Note:
IF a[i]>=100 THEN
EXIT;
END_IF;
END_FOR;
WHILE
Loop Instruction
REPEAT
Loop Instruction
EXIT
RETURN
Quit Instruction
Return Jump
i:=0;
WHILE i<=100 AND
a[i]<100 DO
i:=i+10;
END_WHILE;
i:=0;
REPEAT
i:=i+10;
UNTIL i>100 OR
a[i]>=100
END_REPEAT;
EXIT;
RETURN;
Do not use the value of the control
variable (i in this example) after the
loop is finished because different values
have been assigned to it.
Loop processing while checking the
loop condition before the loop
Loop processing while checking the
loop condition after the loop
Non-conditional exiting of the loop
The program returns to the called
POU.
Comments
You can enter comments anywhere you like in the ST Editor. Comments are enclosed by parentheses
with asterisks '(*' and '*)' and are not nested. They can extend over several lines.
(* this is a
comment on two lines *)
Invalid comment because there is no ending *)
(* this is an invalid comment
Nested comments, e.g. (* Level 1 (* Level 2 .... *) *) are allowed but not usual according to
IEC11313. These comments cause an error depending on the compiler settings. See Extras Options
Compile Options Additional Errors.
Checking your Program
You can check your program any time with Object Check or
. The entire program defined up to
that point is checked for syntax errors as well as for declaration errors (e.g. whether a variable is used
that has not yet been declared). Each error is listed individually in the error list. Selection of any error
in the error list by double-clicking causes the error to be displayed in the POU body in the colour
defined for errors.
If applicable, please click on the displayed error and then [Show]. The program containing the error
will be displayed on your screen and the error will be highlighted.
Insertion Shortcuts
The following shortcuts will save your time in programming.
Insertion template for OP/FUN/FB:
1. Enter the instruction into the programming window, e.g SHL
2. Press <Strg> + <F1>
With a function. e.g SHL, the following could appear:
SHL( IN:= ?ANY_BIT? , N:= ?ANY_BIT? );
3. Highlight the data types between the questionsmark, e.g. by double clicking.
4. Enter operands
For help, you can also place the cursor on the name of a function or a function block and then
press <F1>.
Insertion template for specification or repeating instructions:
For the instructions IF, CASE, FOR, WHILE, REPEAT, EXIT, RETURN, an insertion template is at
your disposal. This will ease your working with the ST Editor.
1. Place the cursor on or directly behind the instruction, e.g. IF
2. Press <Ctrl> + <F11>
With the instruction IF, the following could appear:
IF ?BOOL? THEN
ELSIF ?BOOL? THEN
ELSE
END_IF;
3. Highlight the parameter between the questionmarks, e.g. by double clicking
4. Enter the desired parameter
OP/FUN/FB Selection
You can enter the name of an operator a function directly in the editor. A function block is entered by
the name of its instance in the dialog variable selection.
Procedure.
1. Click
or Tools OP/FUN/FB Selection or <Shift> + <F2>
The dialog box OP/FUN/FB Selection is opened.
2. Choose OP, FUN or FB
3. Insert with [Insert -> Body] or by double-clicking in the editor
4. Create parameter list with the insertion template or enter parameters directly into the
editor
Insert Operands
You can enter the name of the variable or instances of function blocks as text into the editor or use the
Variable Selection dialog box.
Procedure.
1. Click in the programming window
2. Click on
or Tools Variable Selection or <F2>
The dialog box Variable Selection opens.
3. Select variable
4. Insert with [Insert -> Body] or by double-clicking in the editor
For instances of function blocks:
Create parameter list with the insertion template or enter parameters directly into the editor.
IL Editor
The instruction list editor is a text-based, non-syntaxed editor. Here you enter IL commands in
accordance with the IEC-61131 standard, which are listed under "Standard Operators" in the online
help, or in accordance with the basic instruction set.
e
Instruction list (IL) with three networks
1
2
3
Comments
Operands
Operators
Each POU body consists of one or more networks. In the left of the network info area, the labels
(Start: Stop: ) and statuses, e.g. for breakpoints, network selection and error messages, are displayed.
The program is displayed on the right in the programming window. It is subdivided into three
columns: Operators, Operands and Comments. The comments are restricted by brackets and asterisks
(* *). Comments can be several lines long and positioned anywhere in the programming window.
Empty lines in the body are permissible. Each body can contain 60kB maximum of ASCII source
texts. An IL network (see page 70) must always start with a load operation (LD). Linking results are
filed in the bit memory. They are lost, however, when transferred from one network to another.
Sequential Function Chart (SFC)
In the sequential function chart you can portray complex programs clearly. The entire task is
subdivided into part-tasks and the sequence portrayed step by step.
SFC Program
1
2
3
4
5
6
Initial Step
Transition
Step
Divergence
Convergence
Final Step
The following symbols are used:
1. STEP
A step is a part-task, e.g. switch on motor.
When you switch the PLC from PROG to RUN mode, the initial step is the first step to be
activated. The steps are processed one after the other. Once the final step has been processed,
the initial step is reactivated etc. You can assign one or more actions to each step. If you do
not assign an action to a step, the step has a wait function until the subsequent transition is
fulfilled. Actions are entered under Actions in the project navigator and can be Boolean
variables or programs in LD, ST, IL or FBD. They can be assigned to one or more steps.
Whenever a step is active, the actions assigned to it are executed.
2. ACTION
Create a new action in the navigator:
a. Select the POE or the respective Action pool of the SFC program
b. Edit New Action or
c. Choose a name and the programming editor
d. [OK]
Select the step you wish to associate with an action and click to open the respective window
"Action Association".
Monitor Monitor Header or
lets you monitor the status of a step flag. The name of
this flag is composed of the name of the step plus the extension .X, e.g. Step1.X.
3. MACRO STEP
Several steps can be summarized in a macro step. A macro step is marked by two extra
horizontal lines. Behind the "Ventilation" macro step, for example, there are several steps
which serve ventilation control.
4. TRANSITIONS
A transition is a conditional jump. Once the transition is fulfilled, the next step becomes
active.
A transition can be:
A Boolean variable or address (e.g. bVar or R0)
The transition is regarded as fulfilled once the assigned variable or address is TRUE.
A transition condition (e.g. "NOT bVar" or "bVar1 & bVar2")
The transition is regarded as fulfilled if the calculation result of the ST program code isTRUE.
A program in IL, FBD, LD or ST programming language
The transition is regarded as fulfilled once the variable with the name of the transition is
TRUE. The variable with the transition name is automatically declared by Control
FPWIN Pro.
5. PARALLEL DIVERGENCE
A parallel divergence is marked by a double horizontal line. When the transition is fulfilled
before the parallel divergence, two or more steps are executed in parallel (simultaneously).
After execution, all of the steps are reunited in a transition by a parallel connection.
The transition after a parallel convergence only takes effect once all of the previous steps
have been processed.
6. ALTERNATIVE DIVERGENCE
An alternative divergence is marked by a horizontal line. Depending on which transition is
fulfilled (GoToWords or GoToDoubles), the accompanying divergence is executed. When
both transitions are fulfilled at the same time, the execution priority of left to right applies, i.e.
in the following divergence, only the step to GoToWords is executed.
No matter which step is executed, both steps are reunited with the following symbol:
When programming with the SFC editor, not only the POEs but all actions and transitions for
entering an SFC program are displayed in the navigator under Actions.
PROGRAMMING
MANUAL FOR PLC FP-2