SIEMENS SIMATIC S7 + WINCC

Programming Blocks




Data types of PLC tags


Addressing data types

Data typeo

BOOL – tags with data type BOOL are addressed with a byte number and a bit number. The numbering of the bytes begins in each area of operands from 0. The numbering of the bits ranges from 0 to 7. Example: M 1.0.

BYTE, CHAR, SINT, USINT – tags with data type BYTE, CHAR, SINT or USINT are addressed with a byte number. Example: MB 1.

WORD, INT, UINT, DATE, S5TIME – tags with data type WORD, INT, UINT, DATE or S5TIME consist of two bytes. They are addressed with the lowest byte number. Example: IW 1.

DWORD, DINT, UDINT, REAL, TIME – tags with data type DWORD, DINT, UDINT, REAL or TIME consist of four bytes. They are addressed with the lowest byte number. Example: MD 1.

LWORD, LINT, ULINT, LTIME, LTOD, LDT, LREAL– tags with data type LWORD, LINT, ULINT, LTIME, LTOD, LDT or LREAL consist of eight bytes. They are addressed with the lowest byte number. Example: IL 1.0.

User program blocks

Linear and Structured Programming

Linear Programming

Solutions for small automation tasks can be programmed linearly in a program cycle OB (Organization Block executed cyclically). This is only recommended for small programs. The figure below shows the outline of a linear program: The program cycle OB “Main1” contains the complete user program.



Structured Programming

Complex automation tasks can be more easily controlled and managed by dividing them into small sub-tasks that correspond to technological process functions or that can be reused. These sub-tasks are represented in the user's program by blocks. Each block is then an independent section in the user program.

Structuring the program offers the following advantages:

• Extensive programs are easier to program using a structure.

• Individual program sections can be standardized and used repeatedly with changing parameters.

• The organization of the program is simplified.

• Debugging is simplified since separate sections can be tested.

• Commissioning is simplified.

The image below shows the outline of a structured program: The OB “Main1” program cycle calls subprograms one after another to execute defined subtasks.



Block Types

Different types of blocks are used to perform tasks within an automation system. The types of blocks are:

Organization Blocks(OB)

Organization Blocks define the user's program structure. They interface between the operating system and the user program. They are called by the operating system and control, for example, the following operations:

• Automation system startup characteristics

• Cyclic program processing

• Execution of program interruption

• Error control

Various types of Organization Blocks are allowed depending on the CPU.

Functions (FC)

Functions contains program routines for repeated tasks. They have no “memory”, as they do not have a data memory in which the block parameters can be stored. When a function is called, all formal parameters must be given values. Functions can use Global Data Blocks to store data permanently.

Function Blocks (FB)

Function Blocks are blocks of code that store their input, output and input-output parameters permanently in Instance Data Blocks. Function Blocks can also use temporary tags. Temporary tags are not stored in the Instance Data Block and are stored during a single cycle (scan).

Function Blocks contain subroutines that are always executed when a function block is called from another code block. A Function Block can be called up several times at different points in the program.

A function block call is referred to as an instance. An Instance Data Block is required for each instance of a Function Block. The Instance Data Block contains the same structure as the formal parameters declared in the Function Block.

Instance Data Blocks

Instance Data Blocks are assigned to a Function Block when it is called for the purpose of storing program data.

Globa Data Blocks

Global Data Blocks are data areas for storing data that can be accessed by any block. The maximum size of the data blocks depends on the CPU. There is an option to use PLC data types (UDT) as a template to create Global Data Types.

Each Function Block, Function or Organization Block can read and write data to/from a Global Data Block.

A imagem abaixo mostra os diferentes acessos a data blocks:



Block calls

For a block to be called in the user program, it needs to be called from another block.

When a block calls another block, the instructions of the called block are executed. Only when the execution of the called block is finished will the calling block resume its execution. Execution is resumed in the instruction following the block call.

The image below shows the sequence of a block call within the user program:



Program Editor

The Program Editor is an integrated development environment for programming functions, functions blocks and organization blocks.

Program Editor structure