TIA Portal Basics

In this module, the TIA Portal environment for PLC-programming is introduced.

Learning Outcome

  • You will get familiar with the TIA Portal environment.

  • You will be able to program Siemens PLCs using FBD, LAD, and SCL programming languages.

Introduction

TIA Portal is a Siemens software that provides a programming environment for PLCs. Different programming languages, like FBD, LAD, and SCL (a variant of ST), are supported in TIA Portal.

This module will go through the basics of starting a new project in TIA Portal.

Requirements

What you need

Software

  • TIA Portal V15 or newer

  • PLCSIM Advanced V2.0 or newer

TIA Portal

TIA Portal is a Siemens software for programming PLCs. Also, PLCs can also be simulated using PLCSIM Advanced.

../../_images/tia-umgebung.png

Fig. 41 Part of the TIA Portal environment - a new project

The TIA Portal environment includes a networks window. Networks act like code lines; code (each network) is run by the CPU from up to down every PLC cycle (i.e., network 1, then network 2, and so on). Programming in networks is useful for good code organization, especially if the programming language used is LAD or FBD.

Programming Blocks

The design of PLC codes in TIA Portal is done with modular blocks. There are divided into 4 types according to their use.

These are:
  • Organizational block: These provide structure to program. They serve as a link between the user program and the OS of PLC. Main [OB1] is a type of this block.

  • Function block: This type of block is used to create code snippets which has its own data storage i.e., it has its own variable memory where the values are stored after the code snippet finishes its intended task.

  • Function code: This type of block is generally used to create a reusable code structure. This block does not have a database linked to it i.e., it does not save values it calculates. Thus, a local stack of temporary values is used and gets deleted once the code snippet is exited (after executing its intended task).

  • Data block: This is used to store data received from the code snippets. The data block can be either global DB or can be an instance DB.

../../_images/add_new_block.png

Fig. 42 Types of Programming blocks

Creating a new function block

A new project will only have a block called Main [OB1]. This is the project’s main function. All user created functions and function blocks will be called inside the main function.

The block Main [OB1] in TIA Portal can be written using either LAD or FBD standard programming languages. In the context of this module, LAD will be used.

Note

The programming language of Main [OB1] can be changed through right click on Main [OB1] -> Switch programming language.

To create a block, click on Add new block under Program blocks.

../../_images/add_new_block_with_info.png

Fig. 43 Creating a new block

Note

Blocks are useful for organizing and structuring a program.

The following figure shows a new function block that is named State_machine.

../../_images/fb_with_info.png

Fig. 44 TIA Portal function block environment

Variables can be declared and used inside the function block.

../../_images/blink_switch_ex1.png

Fig. 45 Example Function Block

To run this FC, you will have to include it inside the Main [OB1] block.

To do so, drag and drop the function block into a Main [OB1] network to create instance of the function block. Once you drag it on the rail of Main, a pop-up to create a DB would appear. Click OK to create the DB. This data block stores all the instance variables related to that instance of the FC.

../../_images/fb_in_main_r1.jpg

Fig. 46 A function block instance in Main

Note

All types of Functions have to be called in Main [OB1] to execute them. If they are not in Main [OB1], they won’t run or do their task.

A data block is not created to save variables of function code / functions. No instances of function code / functions exist.

Function blocks, however, are initiated as instances. Variables that belong to a specific instance of a function block are saved in a data block that specifically stores variables of that instance only. Creating another instance of the same function block type will create another data block for the new instance. Hence DB instance for LED_1 will be different from LED_2 and will operate separately.

Note

Functions with inputs have to have inputs connected to them in Main [OB1]. If no inputs are connected to the function, a compilation error will occur.

Function blocks, on the other hand, do not require inputs to be connected to them in Main [OB1]. Each instance of a function block has its own Data block, in which the inputs of that specific instance is saved.

Using Predefined Functions

TIA Portal provides various predefined functions ready for use. These can be found on the right side under Basic instructions.

For example, if you need a Mathematics based function, expand Math functions and select the required function.

../../_images/add_funct_example.png

Fig. 47 An example of a standard function.

Note

User-defined functions and function blocks are used in the same way in LAD.

Watch and Force Tables

Watch and force tables are tables that are used to monitor variables in real-time while the PLC is running. Watch and force tables can also be used to overwrite variables in real-time. Because they can change variables’ values, they are useful for testing a program. In this module, watch tables will be used to monitor and set variables while the program is running.

Deep Dive: Watch vs Force Tables

Force tables manipulate the peripherals. In this module, watch tables will be used to monitor and test the program. Watch tables are recommended for testing the program. For big programs, every scenario of inputs and outputs could be summed up in a watch table.

../../_images/watch_force.jpg

Fig. 48 The stage at which watch and force tables manipulate the signals

Creating Watch Tables

To create a new watch table, select Add new watch table under Watch and force tables in the Project tree.

Add the variables you need in the rows.

Set the PLC in Online mode (using Online -> Go online) and in RUN mode (Online -> Start CPU)

Once done, select the Monitoring tool from the menu above. Now you can watch the changes in the variables and also modify their values if required.

Hint

Watch tables are on PC hence you do not have to download the code again to the PLC.

../../_images/wtables_r.jpg

Fig. 49 An example set-up of a watch table

Note

All the variables shown in this watch table are part of a created data block called IMS_4_DB, hence the "IMS_4_DB". at the beginning of the variables’ names. The address column is empty because these variables in this example were not mapped to a PLC I/O module, but are rather variables that belong to an instance of a user-defined function block called IMS_4.

../../_images/wtables_setting_r.jpg

Fig. 50 An example watch table in action

Danger

Using a watch or a force table to manipulate variables influence the real system and overrides the program on the PLC. Be sure that it is safe to do so when working with a real PLC as it may be connected to moving parts or could unintentionally release liquids through valves.

Timers

There are various types of timers available according to IEC standard. Here are the commonly used timers with their timing diagram.

../../_images/timers.png

Fig. 51 Timers (ref: Siemens S7-1200 Programmable controller System Manual)

Monitoring runtime values

You can monitor runtime values using Monitor Tool. It looks like the image below. You will find it at various locations.

../../_images/monitor_values_button.png

Fig. 52 Monitor Tool