5 BEST PRACTICES
FOR STRUCTURING YOUR PLC APPLICATION IN TIA PORTAL
Hans Schrynemakers
Hey there!
Thanks for downloading this free guide. Here are 5 best practices when structuring your PLC
application in TIA Portal. Happy reading!
1. Create groups to structure Program blocks, PLC tags, and PLC data types
Please take a look at Fig.1 to the right.
Here we´ve added 2 groups to Program blocks -
a ‘00 Machine’-group and a ‘01 Equipment’-group.
Furthermore, we´ve added a group for Global Data.
The Equipment group contains all logic/functionality related to
the equipment on the line like e.g. a supply module consisting of
roups
a tank and valve, or a process module consisting of a tank, a G
pump and a valve.
The Machine group contains all logic/functionality that is not
directly related to the production process but are default
functions for any machine like e.g. a statehandler, recipe
roups
handling, networking, etc... G
Finally, the Global Data group contains the data (DBs) used
globally for this application. G roups
For PLC tags, and PLC data types, we have created the same Fig.1 Creating groups
groups here for a consistent overal look.
2. Add main function calls to group functions together
Function blocks can be used for two purposes:
A. to create structure in your program
B. to group a (reusable) encapsulated block of functionality
In our example here (Fig.2), we have added:
• an ‘FB - Machine Modules’ to our ‘00 Machine’ group
in Call
for grouping all functions related to our machine logic
Ma
• an ‘FB - Equipment Modules’ to our ‘01 Equipment’ group
for grouping all functions related to our equipment modules Functions
related to
machine logic
The actual module functions are then created under a separate Ma in Call
‘Functions’ group for each Machine/Equipment group.
Functions
related to
equipment logic
Fig.2 Add function blocks
PLCSKILLTREE
www.plcskilltree.com
3. Use multi-instances to prevent over-usage of DBs
When a function block (FB) is called in TIA Portal, an instance is created. This instance contains the
data of the block interface (Input,Output,InOut,Static,Temp,Constant) of the called function block.
If the instance is created as a single-instance -> the instance is created as a separate, new
datablock (DB) that will appear under your Program blocks.
If the instance is created as a multi-instance -> the instance is created in the Static area of the block
interface of the higher-level function (where the function with multi-instance is called). No new DB
will be created.
The advantage of using multi-instances over single-instances whenever possible is
that you minimize the number of DBs created in your user program. By creating
fewer DBs, your application will read more easy, and seem less cluttered.
In our example (Fig.3 below) we are calling the main function calls ‘FB - Machine Modules’ and ‘FB -
Equipment Modules’ in our OB1 with single-instances (OB1 does not have a Static area so the only
option here is single-instance).
The functions inside our main functions calls are then called using multi-instances. In our example
below, we are calling 3 functions inside the ‘FB - Equipment Modules’ - Supply, Refill process 1 and
refill process 2. All 3 of those calls are created with multi-instances.
Main calls for equipment modules
Multi-instance
Single-instance
Fig.3 Multi-instances vs. single-instances
PLCSKILLTREE
www.plcskilltree.com
4. Build tag-structures for optimized data usage and coherency
One way to create tags for your application is by using single data-types like bool, int, real,...
What if I told you there is a much more gracious way to organize your data in 2 easy steps?
Step 1: Create user-defined-types (UDT) for each module
Step 2: Build tag-structures in global data-blocks (DB) using these UDTs
In Fig.4.1 below, we have created UDTs for each module of our machine and equipment modules. If
we take UDT_Refill for example, you can see that a tag structure has been created using status tags
(Sts), command tags (Cmd), parameter tags (Par), configuration tags (Cfg) and fault tags (Flt).
Going over to Fig.4.2, we have then used those UDTs to created tag data-structures in our global
data-blocks ‘DB - Equipment’ and ‘DB - Machine’.
The advantage of grouping single tag data-types together in a tag data-structure is
that all tags belonging to a certain module can be grouped logically together
depending on their function (Sts, Cmd, Par,...). Adding more tags to the structures
afterwards is a very easy process in TIA Portal.
Status structure
Command structure
Parameter structure
User-defined-types Configuration structure
Fault structure
Fig.4.1 Create user-defined data types (UDTs)
Global data-blocks
Fig.4.2 Build coherent tag-structures in global DBs using UDTs
PLCSKILLTREE
www.plcskilltree.com
5. Clarify you logic using comments and descriptions
So you´ve done all the previous steps, and your application is starting to look sleek, coherent, and
structured. Great work so far!
But before we call it a day, there is one final step that we can take to give our application that extra
layer of polish - adding comments and descriptions.
Clarifying your logic becomes extremely important if you´re not the only one working with an
application. If someone for example takes over your PLC application, why not give that person a
fighting chance by explaining what you´ve programmed? :-D
In Fig.5 below, we have clarified our ‘FB - Supply’ block by adding a block title and a description.
Furthermore, we have added a short description to each network title with a comment below each
title to share more details about the network.
Keep your titles short and to the point (less clutter) - use the comment section below
TIP each title to write a more detailed description of the block or the network
Block title and description
Network title and description
Fig.5 Add comments and descriptions to your logic
Want to learn even more about creating structured PLC applications in TIA Portal?
Then click the
button below. Hope to see you on the inside!
...Hans
LEARN MORE ABOUT PLC PROGRAMMING BASICS IN TIA PORTAL
PLCSKILLTREE
www.plcskilltree.com