Training Curriculum: TIA Portal Module 005
Training Curriculum: TIA Portal Module 005
177
TIA Portal Module 005
TABLE OF CONTENTS
1 Goal................................................................................................................................................. 179
2 Prerequisite...................................................................................................................................... 179
3 Required hardware and software..................................................................................................... 179
4 Theory.............................................................................................................................................. 180
4.1 Operating system and application program..............................................................................180
4.2 Organization blocks.................................................................................................................. 180
4.3 Process image and cyclic program processing........................................................................182
4.4 Functions.................................................................................................................................. 183
4.5 Function blocks and instance data blocks................................................................................183
4.6 Global data blocks.................................................................................................................... 184
4.7 Library-compatible code blocks................................................................................................ 185
4.8 Programming languages.......................................................................................................... 186
5 Task................................................................................................................................................. 187
6 Planning........................................................................................................................................... 187
6.1 EMERGENCY STOP................................................................................................................ 187
6.2 Automatic mode - Conveyor motor........................................................................................... 188
7 Structured step-by-step instructions................................................................................................. 188
7.1 Retrieve an existing project...................................................................................................... 188
7.2 Create a new tag table............................................................................................................. 189
7.3 Create new tags within a tag table............................................................................................191
7.4 Import "Tag_table_sorting_station"........................................................................................... 192
7.5 Create function block FB1 "MOTOR_AUTO" for the conveyor motor in automatic mode.........194
7.6 Define the interface of FB1 "MOTOR_AUTO"..........................................................................195
7.7 Program FB1: MOTOR_AUTO................................................................................................. 197
7.8 Program organization block OB1 – Control of the forward belt tracking in automatic mode.....204
7.9 The result in the LAD (Ladder Logic) programming language has the following appearance...208
7.10 Save and compile the program................................................................................................. 209
7.11 Download the program............................................................................................................. 209
7.12 Monitor program blocks............................................................................................................ 210
8 Checklist.......................................................................................................................................... 213
178
TIA Portal Module 005
BASICS OF FB PROGRAMMING
1 Goal
In this chapter, you will get to know the basic elements of a control program – the
organization blocks (OBs), functions (FCs), function blocks (FBs) and data blocks
(DBs). In addition, you will be introduced to library-compatible function und function block
programming. You will get to know the Function Block Diagram (FBD) programming
language and use it to program a function block (FB1) and an organization block (OB1).
2 Prerequisite
This chapter builds on the hardware configuration of SIMATIC S7 CPU1516F-3 PN/DP.
However, other hardware configurations that have digital input and output cards can be used.
2 SIMATIC STEP 7
Professional (TIA
1 Engineering station
Portal) as of V1X
4 Ethernet connection
Control panel
3 SIMATIC S7-1500 controller
179
TIA Portal Module 005
4 Theory
4.1 Operating system and application program
Every controller (CPU) contains an operating system, which organizes all functions and
processes of the CPU that are not associated with a specific control task. The tasks of the
operating system include the following:
Performing a warm restart
Updating the process image of the inputs and outputs
Cyclically calling the user program
Detecting interrupts and calling interrupt OBs
Detecting and handling errors
Managing memory areas
The operating system is an integral component of the CPU and comes pre-installed.
The user program contains all functions that are necessary for executing your specific
automation task. The tasks of the user program include the following:
Checking the basic requirements for a warm restart using startup OBs
Processing of process data, i.e. activation of output signals as a function of the input
signal states
Reaction to interrupts and interrupt inputs
Error handling during normal program execution
180
TIA Portal Module 005
Figure 1:
Start events in the operating system and OB calls
When a start event occurs, the following reactions are possible:
If an OB has been assigned to the event, this event triggers the execution of the assigned
OB. If the priority of the assigned OB is greater than the priority of the OB that is currently
being executed, it is executed immediately (interrupt). If not, the assigned OB waits until
the higher-priority OB has been completely executed.
If an OB is not assigned to the event, the default system reaction is performed.
Table 1 gives a couple of examples of start events for a SIMATIC S7-1500, their possible OB
number(s) and the default system reaction in the event the organization block is not present in
the controller.
181
TIA Portal Module 005
PIQ
Last instruction
Note: The time the CPU needs for this sequence is called cycle time. This depends, in turn,
on the number and type of instructions and the processor performance of the controller.
182
TIA Portal Module 005
4.4 Functions
Functions (FCs) are logic blocks without memory. They have no data memory in which
values of block parameters can be stored. Therefore, all interface parameters must be
connected when a function is called. To store data permanently, global data blocks must be
created beforehand.
A function contains a program that is executed whenever the function is called from another
code block.
Functions can be used, for example, for the following purposes:
Math functions – that return a result dependent on input values.
Technological functions – such as individual controls with binary logic operations.
A function can also be called several times at different points within a program.
Organization block
Main [OB1]
183
TIA Portal Module 005
Function blocks are always executed when called from another code block. A function block
can also be called several times at different points within a program. This facilitates the
programming of frequently recurring complex functions.
A call of a function block is referred to as an instance. Each instance of a function block is
assigned a memory area that contains the data that the function block uses. This memory is
made available by data blocks created automatically by the software.
It is also possible to provide memory for multiple instances in one data block in the form of a
multi-instance. The maximum size of instance data blocks varies depending on the CPU. The
tags declared in the function block determine the structure of the instance data block.
Figure 4: Function block and instance with call from organization block Main [OB1]
184
TIA Portal Module 005
Function_10
Global DB
Access for all blocks
(DB_Global)
Function_11
185
TIA Portal Module 005
186
TIA Portal Module 005
You can thus use simple instructions, for example, to control binary outputs, evaluate edges
and execute jump functions in the program.
Program elements such as IEC timers and IEC counters provide complex instructions.
The empty box serves as a placeholder in which you can select the required instruction.
Enable input EN (enable)/ Enable output ENO (enable output) mechanism:
An instruction without EN/ENO mechanism is executed independent of the signal state at
the box inputs.
Instructions with EN/ENO mechanism are only executed if enable input "EN input has
signal state "1". When the box is processed correctly, enable output "ENO" has signal
state "1". As soon as an error occurs during the processing, the "ENO" enable output is
reset. If enable input EN is not connected, the box is always executed.
5 Task
The following functions of the sorting station process description will be planned, programmed
and tested in this chapter:
Automatic mode - Conveyor motor
6 Planning
The programming of all functions in OB1 is not recommended for reasons of clarity and
reusability. The majority of the program code will therefore be moved into functions (FCs) and
function blocks (FBs). The decision on which functions is to be moved to the FB and which is
to run in OB 1 is planned below.
187
TIA Portal Module 005
Output
BOOL Control of the conveyor motor in automatic
Conveyor_motor_automatic_mode
mode
Static
BOOL Memory used for start/stop automatic mode
Memory_automatic_start_stop
The Memory_automatic_start_stop is latched with Start but only if the reset conditions are not
present.
The Memory_automatic_start_stop is reset if Stop is present or safety shutoff is active or
automatic mode is not activated (manual mode).
The Conveyor_motor_automatic_mode output is controlled when
Memory_automatic_start_stop is set and the enable conditions are met.
188
TIA Portal Module 005
The next step is to select the target directory where the retrieved project will be stored.
Confirm your selection with "OK". ( Target directory OK)
189
TIA Portal Module 005
190
TIA Portal Module 005
Change the address to %Q0.0 (Q 0.0) by entering this directly or by clicking the drop-
down arrow to open the Addressing menu, changing the operand identifier to Q and
confirming with Enter or by clicking the check mark. ( %I0.0 Operand identifier Q
)
Enter the "Conveyor motor M1 forwards fixed speed" comment for the tag.
Add a new Q2 tag in line 2. TIA Portal has automatically assigned the same data type as
in line 1 and has incremented the address by 1 to %Q0.1 (Q0.1). Enter the comment
"Conveyor motor M1 backwards fixed speed".
191
TIA Portal Module 005
Select the desired symbol table (e.g. in .xlsx format) and confirm the selection with
"Open".
( SCE_EN_020-100_Tag_table_sorting_station… Open)
When the import is finished, you will see a confirmation window and have an opportunity
to view the log file for the import. Click OK.
192
TIA Portal Module 005
You can see that some addresses have been highlighted in orange. These are duplicate
addresses and the names of the associated tags have been numbered automatically to
avoid confusion.
Delete the duplicate tags by selecting the lines and pressing the Del key on your
keyboard or by selecting "Delete" in the shortcut menu.
You now have a complete symbol table of the digital inputs and outputs in front of you.
Save your project under the name 032-100_FCProgramming.
193
TIA Portal Module 005
Rename your new block to: "MOTOR_AUTO", set the language to FBD and keep
automatic assignment of the number. Select the "Add new and open" check box. You are
then taken automatically to your created function block in the project view.Click "Add".
194
TIA Portal Module 005
You can find the interface description of your function block in the upper section of your
programming view.
195
TIA Portal Module 005
A binary output signal is needed for controlling the conveyor motor. For this reason, we
first create local output tag #Conveyor_motor_automatic_mode of the "Bool" type. Enter
the comment "Control of the conveyor motor in automatic mode" for the parameter.
Add parameter #Automatic_mode_active as the input interface under Input and confirm
the entry with the Enter key or by exiting the entry field. Data type "Bool" is assigned
automatically. This will be retained. Next, enter the associated comment "Automatic mode
activated".
The conveyor is started and stopped with pushbuttons. We therefore need a "Static" tag
as a memory. Under Static, add tag #Memory_automatic_start_stop and confirm the entry
with the Enter key or by exiting the entry field. Data type "Bool" is assigned automatically.
This will be retained. Enter the associated comment "Memory used for start/stop
196
TIA Portal Module 005
For purposes of program documentation, assign the block title, a block comment and a
helpful network title for Network 1.
197
TIA Portal Module 005
You can see a list of instructions you can use in the program on the right side of your
programming window. Under Basic instructions Bit logic operations, find function
symbol .
( Conveyor_motor_automatic_mode)
198
TIA Portal Module 005
Click the icon in your logic toolbar to insert an AND logic operation before your
assignment block.
Use drag-and-drop to move input parameter #Enable_OK onto the second input of the &
199
TIA Portal Module 005
Use drag-and-drop to move the Set/reset flip-flop function from the list of
instructions under Basic instructions Bit logic operations onto the first input of the &
operation .
200
TIA Portal Module 005
The SR flip-flop requires a memory tag. For this, use drag-and-drop to move static
The #Memory_automatic_start_stop will be set with input tag #Start. Click twice on the
S input of the SR flip-flop <??.?> and enter "Start" in the field that appears in order to see
a list of available tags starting with "Start".Click the #Start tag and apply with Enter.
201
TIA Portal Module 005
Note: When assigning tags in this way, there is a risk of a mix-up with the global tags from the
tag table. The previously presented procedure using drag and drop from the interface
description should therefore be used preferentially.
Multiple conditions are to be able to stop the conveyor. An OR block is therefore needed
at the R1 input of the SR flip-flop. First, click the R1 input of the SR flip-flop so that the
input line has a blue background.
202
TIA Portal Module 005
The OR block has 2 inputs initially. In order to logically combine an additional input tag,
click the yellow star of the OR block.
clicking .
203
TIA Portal Module 005
Under "General" in the properties of the block, you can change the "Language" to LAD
(Ladder Logic) (Properties General Language: LAD)
204
TIA Portal Module 005
205
TIA Portal Module 005
Assign Network 1 the name "Control conveyor tracking forward in automatic mode"
Use drag-and-drop to move your "MOTOR_AUTO [FB1]" function block onto the green
line in Network 1.
206
TIA Portal Module 005
The instance data block for this call of FB1 is created automatically. Assign a name and
apply it with OK. ( MOTOR_AUTO_DB1 OK)
A block with the interface you defined, the instance data block and connections EN and
ENO are inserted in Network 1.
To insert an AND before input parameter "Enable_OK", select this input and insert the
AND by clicking the icon in your logic toolbar ( ).
To connect the block to the global tags from "Tag_table_sorting_station", we have two
options:
207
TIA Portal Module 005
Either select the "Tag_table_sorting_station" in the project tree and use drag-and-drop to
move the desired global tag from the Details view to the interface of FC1 (
Tag_table_sorting_station Details view. S0 Automatic_mode_active)
Or, enter the starting letters (e.g. "S") “-S”of the desired global tag for <??.?> and select
the global input tag "-S0" (%I0.2) from the displayed list. ( Automatic_mode_active S
-S0)
Insert the other input tags "-S1", "-S2", "-K0", "-B1" and "-A1" and insert output tag "-Q1"
(%Q0.0) at output "Conveyor_motor_automatic_mode".
208
TIA Portal Module 005
Negate the querying of input tags "-S2" and "-A1" by selecting them and clicking .
( -S2 -A1 )
7.9 The result in the LAD (Ladder Logic) programming language has
the following appearance.
209
TIA Portal Module 005
click the "Program blocks" folder and select the icon for compiling in the menu
( Program blocks ).
The "Info", "Compile" area shows which blocks were successfully compiled.
( ).
210
TIA Portal Module 005
211
TIA Portal Module 005
Note: The monitoring here is signal-related and controller-dependent. The signal states at the
terminals are indicated with TRUE or FALSE.
The "MOTOR_AUTO" [FB1] function block called in the "Main [OB1]" organization block
can be selected directly for "Open and monitor" after right-clicking ( "MOTOR_AUTO"
[FB1] Open and monitor).
212
TIA Portal Module 005
multiple times is to be monitored, this can be performed using the icon. There are two
alternatives available for specifying the call environment: using the call environment or
213
TIA Portal Module 005
8 Checklist
No. Description Completed
214