PG5 basic
AK 23.02.2012
2 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming - tools
What does program, program mean?
A program consists of one or more instructions that accomplish a task. It is possible to repeat as
many times as the programmer wants.
Programming a PLC is simply constructing a set of instructions. There are several ways to look at a
PLC program such as ladder logic, statement lists, or function block diagrams.
When you are programming SAIA PLC’s you can use the following “languages” to create program:
• Instruction List (IL)
• Function Plan (Fupla) together with Ladder Diagram (Kopla)
• version of Sequential Function Chart (Graftec)
3 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – Instruction List (IL)
Instruction List (IL)
Instruction list (IL) programming is
defined as part of the IEC
61131 standard. It uses very
simple instructions similar to
the original mnemonic
programming languages
developed for PLCs
The operation, what is to be done, is
shown on the left. The
operand, the item to be
operated on by the operation,
is shown on the right.
Instruction List (IL) is the low-level
macro-assembler language of
the SAIA PCD. All Fupla and
Graftec programs are compiled
into this language. Advanced
users can code directly in
Instruction List code.
Example code:
;**************************************************************************
;* AUTEUR: Dupond Fred *
;* DATE: 19.11.99 *
;* FICHIER: logic.SRC *
;**************************************************************************
;
COB 0 ;Begin of cyclic program
0
STH I 6 ; START / STOP with STOP priority
ANL I 5 ; _ ___________
SET O 35 ; START I6 ___¦ ¦___________¦ ¦_____
; ; __ __
STH I 5 ; STOP I5 __________¦ ¦_________¦ ¦_________
RES O 35 ; _______ ____ _________
; O 35 ___¦ ¦_______¦ ¦__¦
ECOB ; End of cyclic program
4 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – Graftec
Graftec is a graphical programming method for defining sequential
'state-driven' processes. It is based on the IEC "Sequential
Function Chart" standard. A Graftec diagram has two main
elements: Steps, and Transitions. These are connected together
alternately, in series and in parallel.
Graftec is the name of the graphical editor for sequential flow charts and
corresponds to the SFC language of IEC 61131-3. A Graftec
program is the pictorial representation of a sequential flow chart
using standardized function elements called Sequential Blocks,
Steps and Transitions.
The Fupla Editor can be called from the Graftec Editor to create the
logical code inside each step and transition.
5 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – Function Block (Fupla)
Fupla is an abbreviation of Function Plan and is similar to the FBD language of IEC 61131-3. A function plan is the
pictorial representation of a logical task using standardized functional elements such as gates, flip-flops,
counters, timers, displays, etc.
As one of the SAIA® programming tools, Fupla provides the graphical programming environment. One or more
screen pages are edited using graphical symbols and corresponding connections. When the graphical
program is complete, i.e. when the task has been formulated graphically, the Fupla compiler checks the
graphical representation and generates a standard source file. The Make Utility is then called to assemble,
link and load the program into the PCD. The program in the PCD can be run and viewed in Online mode.
6 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – Ladder Diagram (Kopla) Ladder Diagram
Ladder Diagram is the main programming method used for PLC’s. The Ladder Diagram has been developed to mimic
relay logic. The left vertical line of a ladder logic diagram represents the power or energized conductor. The output
element or instruction represents the neutral or return path of the circuit. The right vertical line, which represents the
return path on a hard-wired control line diagram, is omitted. Ladder logic diagrams are read from left-to-right, top-to-
bottom. Rungs are sometimes referred to as networks. A network may have several control elements, but only one
output coil.
Ladder Diagram (Kopla)
Kopla is an abbreviation of Contact Plan and corresponds to the LD language of IEC 61131-3.
A Contact Plan is the pictorial representation of a logical combination of binary elements using standardized functional
elements such as contacts and coils.
Ladder Diagram is a subset of Fupla. It means that Function Plan and Contact Plan can be edited with the same editor
(Fupla Editor) and even mixed on the same program page.
7 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
In the following pages we will look through the Fupla and Kopla programming techniques, the usage of the Fupla editor
and the integrated F-box libraries. We will use the new SAIA programming tool called PG5 Version 2.
What are the necessary steps for creating a new program:
It is possible to start the programming without hardware connection but we do not recommend you to do this. We
recommend you to have at least a demo PCD for programming and testing the subroutines you have written
immediately. We suppose that the complete PLC hardware is ready for programming or the programmer uses the
SAIA demo PCD.
Check the hardware, the power supply, and the programming cable connection. (Remember there can be a lots of way
to establish programming connection to the PCD but at the very beginning (factory default) is to use the USB
connection (in case of PCD3) or serial PGU port on the other PCD series. After downloading the hardware
configuration you would be able to establish other PGU connection via other communication port like Ethernet.)
First of all you should create a New project in the Saia
Project Manager. (Project, New, Project name –
Project1, OK)
Check the online settings. You must use correct settings
to go to online or to download the program.
8 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
Check the Device configurator. The necessary
hardware elements are set. The right PLC is
chosen, the right memory and communication
settings are set. If not, please upload the present
hardware and set the parameters as you need
save the settings and download into the PLC.
9 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
Check the Build Options. Check the
memory allocation is set correctly for
the Dynamic Flags, Registers,
Counters, Texts, DataBlocks.
10 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
If you are ready with the above mentioned checking you are ready to start
creating program. You can do this with right click on the Program files
tab in the Project tree window and choose New. In the popup window
you can give a name (Test) for the program and it is possible to choose
the type (Fupla File) of the program.
If the checkboxes are checked your new Fupla file will be linked to the
project which will be downloaded into the PLC and it will be opened
immediately with the Fupla Editor to start the programming.
You can see the new file in the Project tree Program Files tab with a small
tick which is indicating that the file is linked to the project.
You can remove the tick and the Fupla file will not be linked into the project
so it will not be included during the build and compile process. (Right
click on the file name and from the context menu choose Linked/Built.)
11 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
Now we have to stop and rethink and remember the following thing:
1. The PCD3.Mxxxx memory architecture
2. The available resources for programming
3. What are the main blocks of the program and what is the execution order between them.
4. Symbols (local, global)
To understand and these things are essential to build up a user program which has clear and
understandable structure and easy to debug.
12 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
The PCD3.Mxxxx and PCD2.M5xx memory
architecture
13 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
The available resources for
programming
14 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
The available resources for programming
Inputs and Outputs:
Normal inputs and outputs: The physical inputs and outputs are grouped into hardware modules and can be plugged into the
PCD. The address range can be assigned as required with the position of the module. Input states can only be read out.
Outputs can be set (switched on) and reset (switched off) and can also be read out.
A real-time clock: RTC is built into most PCD. The date and time can be loaded into a Register with an IL instruction or an FBox:
Time Related, Read time.
Interrupt inputs: Some PCD’s have interrupt input(s) called INB1 (and INB22). Whenever there is a rising edge on one of these
inputs, the normal program cycle is interrupted and the PCD executes a special program block called XOB 20 or XOB 25
(XOB 20 for INB1 and XOB 25 for INB2). These inputs are capable of reading digital signal which has frequency up to 1000
times per second.
Watchdog output: CPUs are fitted with a hardware watchdog as standard (Some PCDs have 2 watchdog outputs). A relay at I/O
address 255 (2nd WD add: 512) can be triggered. This remains activated as long as the status of O 255 changes
periodically at least every 200 ms. Within PG5, FBoxes are provided for this purpose. If for any reason the program
component with the watchdog FBox is no longer being processed at sufficiently short intervals, the watchdog relay will drop
out.
PWM output: Some PCDs (e.g. PCD1.M2120) equiped with Pulse Wide Modulation output the maximal operating frequency is 2
kHz (rise and falling time are 20 μs). This output can be programmed as standard output (Device Configurator).
15 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
The available resources for programming
Flags: Flags are 1 bit storage cells which can be treated like inputs / outputs,
e.g. they can be set or reset, and can be read out as to their state.
Accordingly flags are used for the storage of any suitable information.
By default, all the flags are no volatile. This means that if you turn off the
PCD when the flag is in the state “1”, it will still be in state “1” when you
turn the PCD back on (assuming the RAM backup battery isn't flat). All
volatile flags are reset to 0 when the PCD is turned off. The number of
nonvolatile flags is defined in the Build Options.
Registers: A register is a 32 bits storage cell which can hold any
information, individual binaries packed into register, decimal,
hexadecimal, floating-point (Motorola and IEEE format). You can
perform arithmetical operations on them, transfer information (from or
to: inputs, outputs, flags, timers, counters, registers). Registers can
hold positive as well as negative values.
All registers are non-volatile, which means that their values are not
lost when the PCD is powered off.
In Fupla, the "wires" or lines connected to registers have different
colours depending on the data type: yellow lines for a floating point
values and green lines for integer values. An integer value cannot
interact directly to a floating point value, one of the values must first
be converted into the format of the other.
16 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
The available resources for programming
Timers and Counters: Timers and Counters are programmable registers, they can hold a 31 bits value (0 - 2.147.483.647 in
decimal). They share the same address range from 0-1599. The number of timers and counters can be adjustable (the
default value is 32 timers from addresses 0 to 31 and 1568 counters from addresses 32 to 1599). The only difference
between a timer and a counter is that a timer is always decremented by “1” according to the time-base (default value is
1/10 sec).
The time base can be changed in the Build Options but there are Fboxes (especially HEAVAC, DDC Suite) which are using
which overwrite this setting.
Timers are volatile, counters are not.
Timers and counters can only contain positive values.
Their value can be changed by loading a new value with the LD instruction.
Timers and counters can also be used with binary instructions. When a timer or counter contains a non-zero value, its
state is High (1). When its content is zero, its state is Low (0).
100 timers will take about 2% of the PCD’s capacity / performance.
Constants: Several types of constant are used.
17 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
The available resources for programming
teXt: Texts are ASCII strings that can be memorized in the PCD for output on a serial communication line. Texts are used
for: messages for displays, transmissions to pagers, command strings for modems, text for e-mails etc.
Data Block: A "Data Block" is an area of memory which is used for storing 32-bit data, which can be transferred to and
from Registers, Timers and Counters. DBs are used for data logging, tables etc.
Texts and DBs share the same addresses. If Text 1 is defined, the there cannot be a DB 1.
Registers, flags, timers and counters are handled by the system and stored in a small RAM apart from the main
memory.
DBs and texts Texts and DBs from 0 to 3999 are in main program memory, which is read-only. Texts and DBs 4000 and
above are in extension memory, which is writable RAM.
In most cases you will not bother with this, but if you know that you are going to read and write from your DBs, then
make sure to use DBs which are stored in the extension memory => address 4000 and up. (This is the extension
memory and it is always RAM, which means you can read and write to it.)
18 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
The available resources for programming
COB Cyclic Organisation Blocks (COBs) are parts of a program that are executed without program loops and without waiting for
events that are internal or external to the PCD. When the PCD starts up, the program executes COB 0 first. COBs 1 to 15
are then executed consecutively, if present in the program. They are automatically called in succession, in a continuous
loop. All signals which need to be dealt with on a regular basis (e.g. end switches for motor movements, external power-cut
or emergency-stop signals, human protection devices, …) have to be inside a COB. There must to be at least one COB in
the PCD!
XOB Exception Organisation Blocks (0..31) Exception blocks are programs that are called automatically as soon as a particular
event occurs. Each hardware or software event is linked to an XOB. These events cannot be modified by the user.
However, the user is free to program the action to be taken inside each XOB.
PB Program Blocks (0..299). You may also work with Program Blocks. PBs offer a good way to organize your program in a
hierarchical manner. PBs are only activated if they are called from a COB, PB, FB or SB (Sequential Block). There are two
ways to call a PB: conditional call or unconditional call. Conditional calls depend on the result of a logical operation. You
can call the same PB several times in the program. One PB can call another PB and so on, up to seven levels of nesting.
Beyond the seventh nesting level, the PCD will call error handler XOB 10.
FB Function Blocks (0..999) Function blocks are nearly the same as PBs. Like PBs, FBs also contain program parts that can be
called from other blocks. This call can be conditional or unconditional. The unique difference is that FBs give you the
possibility to call the block with parameters, whereas with PBs you cannot. FBs offer an ideal solution for developing
libraries of programs that can be used for different projects, thereby reducing commissioning times. FBs with parameters
can only be called from an IL program. Function block calls can be nested within each other to a maximum of 7 levels.
Beyond 7 nesting levels, the PCD will call an XOB 10.
19 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
The available resources for programming
If an error occurs and the corresponding XOBs
have not been programmed, the error LED
on the front of the PCD will come on and
the user program will continue its work.
If an error occurs and the XOBs have been
programmed, the error LED on the front of
the PCD will remain off and the exception
routine will be called.
A prioritising mechanism ensures processing of
the most important XOBs. Priority level 4 is
highest.
20 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – Graftec
The available resources for programming
SB Sequential Blocks (0..96). Per CPU Sequential blocks SB are a collection of Steps and Transitions. In each step you execute
a part of your program and in each transition you wait for a condition to occur in order to continue with the following step.
This is known as a Graftec program. SBs can be called from any other block.
IST Initial Steps (0..5999). When you create a new Graftec file, the Graftec editor opens Sequential Block 0 with an initial step.
This is where the program will start when the block is called for the first time (coldstart). (The conditions inside of the
Transition block can be programmed either Fupla or Instruction List.)
ST Steps (0..5999). Steps normally contain the 'action' parts of a program, which are executed once when the preceding
Transition activates. (The conditions inside of the Transition block can be programmed either Fupla or Instruction List.)
TR Transitions (0..5999). The Transition block is a container for all of the conditions, which are needed to be fulfilled to execute
the following Step block. The transition always ends with an ETR FBox (End Transition). The transition is repeated
continuously if the ETR FBox input is low, or if the ACCU is low at the end of an instruction list transition. (The conditions
inside of the Transition block can be programmed either Fupla or Instruction List.)
21 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
What are the main blocks of the program and what is
the execution order between them.
The Saia® PCD Classic programming structures
There are different possibilities to build up a structure in FUPLA.
We have the following possibilities for structuring the program:
XOB - Exception Organization Blocks are called automatically on
special events.
COB - Cyclic Organization Blocks are executed cyclically.
PB - Program Blocks are executed when called from the user
program.
FB - Function Blocks are executed when called from the user
program.
SB - Sequential Blocks are executed when called from the user
program.
Most of the time you will only use COB´s in a FUPLA program. You
can put the whole program in one COB or you can split the
program to different COB´s for a better overview.
22 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
How to handle the resources (local, global,
system, network symbols)
So it is recommended before starting to write a program, all the elements to be used in it must first be declared
(number of inputs and outputs, number of timers, etc.).
All these elements have to be known by PG5. This is very helpful for finding elements inside program
files, reporting programming errors, or for help during the debugging process. All elements to be used
are therefore listed in a central tool called the Symbol Editor.
Why do we need symbols?
It is possible to use hard coded addresses for resources
inside the user program.
For example: I 0 (input 0), I 7 (input 7), O 18 (output 18). It is
not easy to decide which field signal is connected to
the I 0. If you give a symbol name for I 0 like E_Stop
(Emergency Stop) and you use this symbol in your
program instead of hard coded address (I 0) you can
write a much understandable program.
Imagine: if the electrical designer changed the wiring of the
Emergency Stop button and he connected it into e.g. I 7
you would only need to change the address of the
symbol in the symbol table. If you do not use symbols
you must look through all of your program and replace
the hardcoded address I 0 to I 7 at every place.
23 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
Scope of the symbols
You can find There are four levels of symbol definition, which are on different tabs of the symbol scope:
Local symbols - These are local to the module, and can only be accessed by code in the module in
which they are defined (e.g. Fupla.fup, IL_Program.src ...).
Public symbols - These symbols can be accessed from all modules in the CPU.
System symbols - These symbols are generated only after the first build. The table is read-only.
System symbols are generated by special F-Boxes are used on Fupla pages (e.g. Heavac Init
FBox), and also by certain hardware settings such as the CPU and Station numbers.
Network global symbols - These symbols are generated only by the network editors S-Net and S-
Prof. These symbols cannot be modified using the Symbol Editor, they are 'read-only', and can only
be changed using the network editor.
24 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Absolute addressing
It is applicable in case of Flags, Registers, Timers, Counters, Data Blocks and Text Blocks
The data is defined only with a type and address (e.g. 32), and an optional comment. Using absolute
addressing directly in the program is a disadvantage when changing the type or address. The user
program will not be updated by changes made in the symbol list. Changes must be made manually for
connector/line of the program. It is therefore preferable to use symbol names, with optional dynamic
addressing.
25 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Dynamic addressing
It is applicable in case of Flags, Registers, Timers, Counters, Data Blocks and Text Blocks
Dynamic address allocation is a powerful feature introduced to free you from having to specify a fixed
address for every workspace register and flag in the program.
Addresses are allocated if you define a symbol name and type, without specifying the address, this lets the
Build assign an unused address for the symbol.
The address range used for dynamic address allocation is configured from the device's Build Options.
If a build error like this occurs: Dynamic address overflow for type: R (F, T, C, DB, TEXT) increase the
number of dynamic addresses for that data type.
Basically PG5 is adjusting automatically the dynamic ranges for these Media but it can happen - in some
cases - that the programmer has to modify it.
26 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Absolute addressing with address definition
It is applicable in case of Flags, Registers, Timers, Counters, Data Blocks and Text Blocks
Using Symbol names + address definition
The data is defined with a symbol name, type, address and optional comment. Correction of symbol, type or
address is supported from the symbol list and each user program connector/line automatically updated if
the symbol is changed.
The data is defined with a symbol name, type, address and optional comment. Correction of symbol,
type or address is supported from the symbol list and each user program connector/line
automatically updated if the symbol is changed.
Absolute addresses must always be defined for inputs, outputs and XOBs.
27 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Symbol Editor
Opening Symbol Editor:
Symbol Definitions are saved in program files (IL/Fupla etc.), As soon as a program file is opened in an
editor, the symbol editor with the appropriate symbol list will also be opened. If not it is possible to open it
with “F5” or from the view menu.
28 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Symbol Editor Elements of a Symbol
Symbols are defined in program files
The symbol grid which is associated
with program file can be viewed
in the Symbol Editor by
selecting Tab named according
to the ‘Program file’.
Symbols can be edited from this tab
window.
Symbol Name
The first character is always a letter,
followed by other letters,
numbers, or the underscore
character. Symbols are not
case-sensitive unless they
contain accented characters.
MotorOn is the same as
MOTORON, but GRÜN is not
the same as grün.
Reserved words cannot be used as
symbol names, list of reserved
words are present
29 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Symbol Editor Grouping symbols together
If desired, symbols can be grouped together. This makes the program easier to read. Just use the right mouse button or
‘CTRL+G’ to add a new group to the symbol editor and then define/drag-and-drop the symbols you want into the folder.
Group names can be nested (up to 10 deep), e.g. Group1.Group2.Group3.Symbol.
Example: The Group named LotOne contains several symbols:
30 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Symbol Editor Restrictions around symbols and symbol groups.
The following words are reserved, and cannot be used as symbol names:
• Assembler instructions, PUBL, EXTN, EQU, DEF, LEQU, LDEF, MACRO, ENDM, EXITM…,
• Control codes and ID’s of the data types : I, O, F, R, C, T, K, M, COB, FB, TEXT, X, SEMA, DB,
• Special instructions MOV : N, Q, B, W, L, D,
• Conditional codes : H, L, P, N, Z, E,
• All instructions mnémonics,
• Predefined symbols
• Internal symbols reserved to the automatic resources allowance, begin with an underline char “ ______TEXT, _________F”
• Internal symbols __CSTART__, used with $$.
Too Short Symbol Name:
When only one (or none) character is entered as symbol Name, editor gives an error as ‘symbol Name too short (min. 2 Characters)’
Duplicate symbol Names:
When new Public symbol is added with the Name which is already used by another Public symbol then editor displays the error and both
symbols goes red.
When new Local symbol is added with the Name which is already used by another Local symbol in same module/file then editor displays
the error and both symbols goes red.
When new Local symbol is added with the Name which is already used by Public symbol then editor displays a warning.
To eliminate these errors or warnings one of the symbols Name needs to be changed!!!!!
31 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Symbol Editor Initialisation of a symbol
There are two ways to initialise symbols used by the PCD:
• initialization during a PLC coldstart (power-up)
• initialization when the program is downloaded into the PCD
During coldstart
The initialization of symbols during a coldstart is done in XOB
16. This function block is processed only once, during a
PCD coldstart. The user writes IL code to initialize symbols
in XOB 16.
When downloading program
To initialise a symbol when the program is being downloaded to
the PCD, the symbol address should be followed by :=
(colon equals), which is in turn followed by the initialisation
value.
!
32 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming –
FUPLA & Kopla
Creating user program
with Fupla editor
33 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Programming – FUPLA & Kopla
FBoxes for Fupla programming
You can find the most of the F-boxes under Standard
and Application tab in the F-box selector
window
Also the customer can write F-boxes and can place
under User tab in the F-box selector window.
Customer can write programs and save it as
templates. Templates can be used many times
later in the user program.
Kopla elements
34 PG5 basic
PG5 basic
PG5 v2.0 – Programming
Let us create a program !