Cookies are important for this site to function properly, to guarantee your safety, and to provide you with the best experience. By clicking OK, you accept all cookies. For more information, please access our Privacy Policy.
Table of Contents
Tutorials / 
The Complete Practical Guide to Siemens Tia Portal Programming
Beginner

The Complete Practical Guide to Siemens Tia Portal Programming

PLC Programming
Siemens
TIA Portal
Function Blocks

Introduction

TIA Portal is a software and tools package developed by Siemens, which aims to integrate multiple development tools for automation devices from the unification and remodelling of preexisting software such as Simatic Step 7, Simatic WinCC, and Sinamics Starter. The environments are responsible for programming, developing, and configuring Siemens PLCs, HMIs, and frequency inverters. The user's programming logic in TIA Portal follows a structure of blocks, a facilitating agent for the development, maintenance, and diagnostics of machines and industrial processes when developed in a structured and organized way.

Step7 is used to program PLCs of the S7-1200, S7-1500, S7-300, and S7-400 families. WinAC and the latest S7-1500 Software Controller are alternative controllers for industrial computers. The available programming languages ​​are ladder, FBD (Function Block Diagram), SCL (Structured Control Language), STL (Statements List), and S7 GRAPH. The Development of HMI screens in WinCC is applied to supervisory systems on computers, isolated or SCADA, and Basic, Comfort, and Mobile operational panels. Profibus, PROFINET, and AS-I (Actuator Sensor Interface) communication protocols. For communication with PLCs, it is worth mentioning the existence of CMs (Communication Modules) with functions to establish communications in different industrial protocols, such as Modbus and CANOpen. The Figure below gathers the main features for SIMATIC STEP 7 and SIMATIC WinCC.

The monitoring of plant status and control of its actuator elements is done by devices connected to the controller's hardware. An operating system acts as an interpreter agent for the algorithms to run. PLC operating systems are responsible for translating logical instructions to the hardware according to the user program and hardware configuration of the PLC.

The controller programming is based on an architecture segmented into the blocks OBs (Organization Blocks), FCs (Functions), FBs (Function Blocks), and DBs (Data Blocks).

Understanding Organization Blocks in Tia Portal

Organizational blocks are closely linked to program execution cycles and interrupts, as their execution is linked to previously defined triggers, such as a time interval or hardware failure detection. The OB1, or simply main, is essential for the initialization and sequential scanning of the calls of the blocks corresponding to the implemented code, except for other OBs, because it is a cyclic and continuous execution block. According to the representation of the Figure, the program execution starts with the contents of OB1 linearly and synchronously, codes from left to right and from the beginning to the end of the block. At the end of the main, the CPU resumes the execution of the code from the start and this process repeats indefinitely.

Although the user creates several blocks of functions and data, the PLC will only execute the dictated instructions and in the stipulated sequence through OB1. The Figure below demonstrates the creation of subprograms as evidenced by the block calls, which may have nested calls.

Since the reproduction of instructions in the main function depends on the processing of all assigned functions, its cycle time may vary with the state of the plant and any unanticipated programming conditions. Therefore, to avoid logical crashes or to guarantee the cyclical execution with a continuous activation period of a certain logical treatment, the Cyclic Interruption OB is recommended.

Cyclic Interrupt blocks are also executed cyclically but with a predefined time interval between executions when creating the block.

‍

Thus, every 100ms, the current processing is interrupted so that the instructions contained in the Cyclic Interrupt block are carried out.

Understanding Functions (FCs) in Tia Portal

FCs compress the algorithm and return values to the variables defined as output, according to the input variables and the inspection performed inside the block.

The local variables declared in FC and their characteristics can be of type In (input), Out (output), InOut (input and output), Temp (temporary), or Constant (Constant).

  • Input: Input parameters of the function. It is essential to differentiate the states of different calls to the same function;
  • Output: Output parameters of the function. It is essential to differentiate the actuation of different calls to the same function;
  • Input and Output: Parameter that can be assigned as input and output at the same time. Useful for mitigating writing errors to input parameters;
  • Temporary: Temporary variables that are allocated to a random space of CPU memory when starting the block and overwritten at the end of it, without the possibility of retention or global referencing;
  • Constant: These are temporary variables whose values are fixed and defined in their declaration.

Understanding Function Blocks (FBs) in Tia Portal

Below we see the simplified diagram of the FBs, which have the same structure and function as the FCs, with the addition of the creation of iDBs (instance Data Blocks) related to each FB call.

‍

The variables supported in FC are also available for FB, but FB has one more type, called static. Variables of type static are retentive memories stored in the CPU's non-volatile memory that can be referenced throughout the program (they are global). When a FB is called in a programming routine, it is necessary to assign a DB instance to that call is necessary. Thus, different calls of the same FB have different memory spaces.

The Figure exemplifies the use of multiple calls from the same FB. Assuming an FB named Motors, this call being in two different lines of code is assigned two unique iDBs related to its specific call. Thus, a static variable called Motor_On indicates the state of that motor, related to its DB.

‍

This way, it is possible to indicate that Motor A is connected through DB1 and that Motor B is connected through the variable allocated in DB2.

Understanding User Data Types in Tia Portal

Besides the usual data types (Integer, Real, Boolean…) a variable in Tia Portal can be of a predefined data type called User Data Type. Its structure is mutable and can be composed of any combination of other data types available and arrays, for example. The use of UDTs helps in data structure organization and replication, making it easier to develop and diagnose programs.

Practical Example: Motors Actuation

In this example, we will utilize Function Blocks, Functions, Data Types, and Data Blocks to address and optimize a simples task of actuating motors. At first, we should create a “Motor” data type, which includes all necessary information to be interchanged to the HMI.

For our Motor Actuation FC, the inputs and outputs parameters should cover every physical equipment needed to operate the motor. Such as local and remote selectors, start and stop buttons, and motor running feedback sensor. The parameter “Data”, of the data type “Motor” we’ve just created and the output (to actuate the motor contactor) should be defined as InOut since we’ll be utilizing them both as input and output parameters over the program as well.

Our motor “Data,” of the data type “Motor”, needs to be stored in a global Data Block, being one variable of that data type for each motor to be operated. Therefore, it’s helpful to create an array of the data type “Motor” with the length equal to the desired number of motors.

The function is able to monitor the feedback sensor and the motor output states to diagnose possible faulty scenarios. In the event of the feedback going on with no command from CLP to start the motor, we can identify a defective sensor or contactor. The second and third conditions are activated when the motor doesn’t move, even if the PLC command energizes the contactor coil, which can be diagnosed as an overload current trip, defective sensor, or defective contactor. The Motor Fault memory remains on until the operator requests a fault reset from the HMI.

Once there’s no motor fault, our function treats the conditions to actually turn the motor on. The motor can be actuated from Local push-button inputs, Remote Manual on and off commands, and Remote Automatic commands. Once the motor and its feedback are evaluated for the predefined monitoring time, a feedback memory “Motor Running” is actuated for information and status display in the HMI.

Next, let’s link the first Motor Call to our first motor. All that’s needed to be done is to input the Input and input parameters corresponding to the equipment and signals resultant from that specific motor actuation.

One of the prime advantages of using functions is replicating the logic for similar sub-systems. For example, to address the actuation of a similar (when it comes to process functionality) motor, it’s as easy as replicating the block call and inputting the parameters for the respective motor.

Another possible logical structure for the program would be to make use of a FB, instead of an FC block. This way, it wouldn’t be necessary to create a Data Block to accommodate the Motors Data, utilizing Statics tags(an Instance Data Block) from the calling environment associated with that specific motor. The FB parameter structure would be pretty similar, the only difference being the type of the parameter Data to be now defined as Static.

As soon as the Motor FB is dragged into the user program to create the Motor 3 Call, a wizard is initialized to help create a Data Block to be associated with that FB call.

It’s also feasible to link the DB to a multi-instance Data Block, defined as a tag of the “Motor_FB” data type in the FB “Motors_Calls” static parameters. This strategy comes in hand with certain program structures where multiple equipment and operations are fragmented into function blocks, making it easy for replication and memory organization, as it condensates all multi-instance DBs in a single DB from the original function call.

Conclusion

There are many features inside the TIA Portal development tool that facilitates development, data structurization, maintenance intervention, and scalability of industrial process and equipment. Even though there are many different ways to accomplish the same results in PLC programming, it’s always beneficial to seek the most efficient one.