0% found this document useful (0 votes)
8 views

Program Blocks

The document provides an overview of program blocks in TIA Portal V18, including Organization Blocks (OBs), Function Blocks (FBs), Functions (FCs), and Data Blocks (DBs). It details the characteristics, usage, and types of each block, emphasizing their role in structuring PLC programs for efficient automation solutions. Key features include state retention in FBs, stateless operations in FCs, and various data management capabilities in DBs.

Uploaded by

Didouu Belhamidi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Program Blocks

The document provides an overview of program blocks in TIA Portal V18, including Organization Blocks (OBs), Function Blocks (FBs), Functions (FCs), and Data Blocks (DBs). It details the characteristics, usage, and types of each block, emphasizing their role in structuring PLC programs for efficient automation solutions. Key features include state retention in FBs, stateless operations in FCs, and various data management capabilities in DBs.

Uploaded by

Didouu Belhamidi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

PROGRAM BLOCKS

In TIA Portal V18, program blocks are essential building elements for developing
automation solutions. They provide a structured way to organize and manage the logic
for PLCs, making programming and debugging more efficient. Here's an overview of
the program blocks available in TIA Portal V18:

1. Organization Blocks (OBs)


2. Function Blocks (FBs)
3. Functions (FCs)
4. Data Blocks (DBs)
❑ System Function Blocks (SFBs)
❑ System Functions (SFCs)
❑ Temporary Data
❑ Libraries and Custom Blocks

Organization Blocks

➢ Organization Blocks

• Organization Blocks (OBs) are the entry points of a PLC program in


TIA Portal. They define the program's structure, control its execution,
and determine when and how specific parts of the program are executed.
OBs can respond to various events like cyclic tasks, time triggers,
hardware interrupts, or system errors.

Types of Organization Blocks (OBs)

1. Cyclic Obs
2. Time-Triggered Obs
3. Event-Triggered Obs
4. Startup Obs
5. Fault and Diagnostic Obs
6. Background Processing OB
7. Synchronous Cycle OBs
➢ 1. Cyclic OBs
•Description:
• Cyclic OBs are executed repeatedly in a continuous loop at regular intervals.
• The most common cyclic OB is OB1, which serves as the main program block.
•Execution Time: Determined by the cycle time of the PLC.
•Key Usage:
• General program logic.
• Reading inputs and writing outputs in a consistent loop.
•Example:
• Logic to control motors, conveyor belts, or production processes.

➢ 2. Time-Triggered OBs
•Description:
• Execute at specific time intervals defined by the programmer.
• Examples include OB10 to OB17.
•Execution Time: Triggered at fixed times (every 100 ms).
•Key Usage:
• Periodic tasks like data logging, monitoring sensor values, or regular system
checks.

➢ 3. Event-Triggered OBs
•Description:
• Execute in response to specific system or hardware events.
• Examples include OB35 (cyclic interrupt), hardware interrupts, or
communication interrupts.
•Execution Time: Depends on the event occurrence.
•Key Usage:
• Responding to fast-changing inputs or priority signals.
• Handling communication with external devices.

➢ 4. Startup OBs
•Description:
• Execute only once when the PLC starts or restarts after a power cycle.
• The most common startup OB is OB100.
•Execution Time: During PLC startup.
•Key Usage:
• Initializing variables.
• Resetting system states or equipment.
➢ 5. Fault and Diagnostic OBs
•Description:
• Handle errors and system faults during runtime.
• Examples include OB121 (programming error) and OB122 (access error).
•Execution Time: Triggered when a specific fault occurs.
•Key Usage:
• Logging errors.
• Implementing recovery actions or stopping the system safely.

➢ 6. Background Processing OB
•Description:
• Executes when no other higher-priority tasks are running.
• Example: OB90.
•Execution Time: When the PLC is idle.
•Key Usage:
• Low-priority tasks like maintenance routines or background calculations.

➢ 7. Synchronous Cycle OBs


•Description:
• Execute in synchronization with system cycles.
• Example: OB61 (alarm synchronization).
•Execution Time: Synced with specific system clock cycles.
•Key Usage:
• Coordinating alarm handling or ensuring synchronization with system timing.

Common Organization Blocks and Their Usage

OB Name Purpose Execution Condition

OB1 Main program execution. Continuous cyclic execution.

Time intervals defined in


OB10-OB17 Time-triggered tasks (every 100ms, 500ms).
configuration.
Cyclic event at specified time
OB35 Cyclic interrupt.
intervals.
OB100 Startup initialization. Once at PLC startup.
On programming-related runtime
OB121 Handles programming errors.
errors.

OB122 Handles access errors (invalid memory access). On access-related runtime errors.

OB90 Background processing. When no other OB is running.


Function Blocks
➢ Function Blocks

• Function Blocks (FBs) in TIA Portal are reusable program modules with
memory that retain their state between executions. They allow for modular
programming and are especially useful in applications requiring stateful
logic. FBs help improve code reusability, maintainability, and scalability.

➢ Key Characteristics of Function Blocks (FBs)

1.Reusability:
1. FBs can be called multiple times in a program with different sets of data.
2.Memory Retention:
1. Unlike Functions (FCs), FBs retain their internal data across multiple
program cycles.
3.Instance Data Block (IDB):
1. Each FB call is associated with a unique Instance Data Block, which
stores the variables and state of that specific call.
2. Global DBs can also be used for shared data across FBs.
4.Parameter Interface:
1. FBs have input, output, and in-out parameters, allowing them to interact
with other program blocks and provide results.

➢ Components of an FB

1.Input Parameters:
1. Data that is passed into the FB from the calling block (OB1, another FB).
2. Example: Sensor values or control signals.
2.Output Parameters:
1. Data that the FB sends back to the calling block.
2. Example: Processed values or control commands.
3.In-Out Parameters:
1. Act as both input and output.
2. Example: Incremented counter values.
4.Static Variables:
1. Internal memory that retains its value between calls.
2. Example: Timers or counters within the FB.
5.Temporary Variables:
1. Used during the execution of the FB and do not retain their value after the
FB completes execution.
How FBs Work
1.When an FB is called, it uses the associated Instance Data Block (IDB) to store
its data.
2.The FB executes its logic using the input parameters and any internal static data
stored in the IDB.
3.Outputs are computed and returned to the calling block, while static variables
are updated and retained for future calls.

2
3

➢ Creating and Using FBs in TIA Portal


1.Creating an FB:
1. Open your TIA Portal project.
2. Right-click on Program Blocks and select Add New Block.
3. Choose Function Block (FB) and give it a name.
2.Define Parameters:
1. In the Interface section of the FB editor:
1.Add Input, Output, and In-Out parameters.
2.Define Static Variables as needed.
3.Program Logic:
1. Implement the FB’s logic using Ladder Logic (LAD), Function Block
Diagram (FBD), or Structured Text (ST).
4.Calling an FB:
1. In an OB (e.g., OB1) or another FB, insert the created FB.
2. Specify its Instance Data Block (IDB) or create a new one.
➢ Applications of FBs

1.Control Systems:
1. Implementing PID controllers where the state of the controller must
persist between cycles.
2.Equipment Control:
1. Managing stateful devices like motors, valves, or conveyors.
3.Reusable Logic:
1. Creating modular, reusable blocks for common operations like
calculations or signal conditioning.
4.State Machines:
1. Managing processes that involve multiple states or phases.

➢ Instance Data Blocks (IDBs)

1.Purpose:
1. Store the state of each FB call individually.
2. Allow multiple instances of the same FB to work independently.
2.Global vs. Instance DBs:
1. Instance DBs: Specific to an FB call; ensures separation of data for
multiple instances.
2. Global DBs: Shared across FBs for common data storage.
3.Example Use Case:
1. A single MotorControl FB can control multiple motors with each motor
having its unique IDB.

➢ Components of an FB

1.Input Parameters:
1. Data that is passed into the FB from the calling block (OB1, another FB).
2. Example: Sensor values or control signals.
2.Output Parameters:
1. Data that the FB sends back to the calling block.
2. Example: Processed values or control commands.
3.In-Out Parameters:
1. Act as both input and output.
2. Example: Incremented counter values.
4.Static Variables:
1. Internal memory that retains its value between calls.
2. Example: Timers or counters within the FB.
5.Temporary Variables:
1. Used during the execution of the FB and do not retain their value after the
FB completes execution.
➢ Advantages of FBs

1.State Retention:
1. Static variables in FBs retain their values between calls, enabling stateful
operations.
2.Modular Design:
1. Break complex programs into manageable and reusable blocks.
3.Encapsulation:
1. Protect the internal logic and variables of the FB, exposing only what is
necessary.
4.Scalability:
1. Easily scale applications by reusing FBs with different IDBs.
5.Debugging:
1. FBs are easier to test and debug due to their encapsulated design.

Functions

➢ Functions (FCs) in TIA Portal

• Functions (FCs) in TIA Portal are reusable program blocks designed to


perform logic or computations without retaining state between executions.
They are ideal for operations where data retention is not required, such as
mathematical calculations, logical operations, or signal processing. FCs are
essential for creating efficient and modular PLC programs.

Key Characteristics of Functions (FCs)


1.Stateless:
1. Unlike Function Blocks (FBs), FCs do not retain internal data between calls.
2. All variables inside an FC are temporary and are reset with each execution.
2.Reusability:
1. FCs can be called multiple times in a program and perform consistent
operations.
3.Parameter Interface:
1. FCs have input, output, and in-out parameters for exchanging data with
the calling block.
4.Memory Efficiency:
1. Since FCs do not use instance data blocks (IDBs), they consume less
memory.
5.Execution Speed:
1. FCs are faster to execute compared to FBs as they do not need to manage
persistent data.
Components of a Function (FC)
1.Input Parameters:
1. Accept values or data from the calling block.
2. Example: Input signal levels, constants, or variables.
2.Output Parameters:
1. Provide results or processed data back to the calling block.
2. Example: Computed values like temperature or speed.
3.In-Out Parameters:
1. Serve as both input and output for the FC.
2. Example: Incremented or modified values passed back to the caller.
4.Temporary Variables:
1. Declared inside the FC and used only during its execution.
2. These variables are not accessible outside the FC.

How FCs Work


1.Call and Execution:
1. An FC is called from an Organization Block (OB) or another program block
(FB or FC).
2.Data Processing:
1. The FC processes its logic using the input parameters and temporary variables.
3.Return Results:
1. Results are returned through the output parameters or in-out parameters.
4.No Memory Retention:
1. All temporary variables are cleared after the FC completes execution.

Creating and Using FCs in TIA Portal


Steps to Create an FC:

• Open your TIA Portal project.


• Right-click on Program Blocks and select Add New Block.
• Choose Function (FC) and provide a name.
• Define the input, output, and in-out parameters in the Interface
tab.
• Write the logic in the program editor using Ladder Logic
(LAD), Function Block Diagram (FBD), or Structured Text
(ST).
• Calling an FC:
• Insert the FC into an OB (OB1) or another block (FB or FC).
• Assign values to the FC’s parameters during the call.
2
3

Applications of FCs

1.Mathematical Operations:
1. Performing calculations like addition, subtraction, or scaling of values.
2.Logical Processing:
1. Implementing decision-making logic or conditional operations.
3.Signal Conditioning:
1. Normalizing or filtering input signals from sensors or devices.
4.Data Conversion:
1. Converting values between formats (e.g., integer to real, or scaling
analog signals).
5.Utility Functions:
1. Operations like data formatting, string manipulation, or checksum
calculations.t
Advantages of FCs
1.Efficiency:
1. Require less memory and are faster compared to FBs.
2.Modularity:
1. Promote structured and reusable programming.
3.Flexibility:
1. Easily integrate into OBs, FBs, or other FCs.
4.Memory Management:
1. No need for additional instance data blocks.
Disadvantages of FCs
1.No State Retention:
1. Cannot store values between executions, limiting their use in state-dependent
logic.
2.Dependency on Parameters:
1. All required data must be passed in as parameters, which may complicate
parameter management for large applications.

Differences Between FCs and FBs

Aspect Function (FC) Function Block (FB)


State Retention Does not retain state between calls. Retains state using static variables.
Does not use Instance Data Blocks
Memory Usage Requires IDBs for each instance.
(IDBs).
Faster due to lack of state
Execution Speed Slightly slower due to IDB handling.
management.
Stateless computations and
Use Case Stateful operations and modular logic.
operations.
Typical Applications Scaling, calculations, and signal processing. PID controllers, motor control, and process logic.

Data Block

➢ Data Blocks (DBs) in Tia Portal

In Siemens TIA Portal and other PLC programming environments, Data Blocks
(DBs) are essential components used for data storage and management within a
PLC program. They act as memory containers that allow structured and organized
storage of data related to variables, process parameters, or configuration settings.
Here's an in-depth look at Data Blocks:

1. Purpose of Data Blocks

•Data Storage: They store variables and their values for use during
program execution.
•Persistence: Retain data across PLC cycles or even during power loss
(non-volatile memory).
•Organization: Provide a structured way to organize and manage data.
•Isolation: Allow modular design by encapsulating data for specific
program parts.
2. Types of Data Blocks
There are two main types of Data Blocks in Siemens TIA Portal:

a. Global Data Blocks (DBs)


•Accessible by all parts of the program.
•Typically used to store variables that need to be shared across multiple
functions or organizational blocks.
•Ideal for general-purpose or configuration data, such as setpoints,
counters, or flags.
b. Instance Data Blocks (IDBs)
•Created automatically when an FB (Function Block) is called.
•Tied specifically to the corresponding FB instance.
•Store the variables and internal states of the FB for that particular instance

There are total 7 types of Data Blocks

▪ Global Data Blocks


▪ Instance Data Blocks
▪ Shared Data Blocks
▪ Optimized Data Blocks
▪ Standard Data Blocks
▪ Retentive Data Blocks
▪ Non-Retentive Data Blocks

Summary Table

Type Scope Access Usage


Shared and global
Global Data Blocks Entire program By all program parts
variables.
Encapsulation of FB-
Instance Data Blocks Specific FB Tied to FB instance
specific data.
Optimized for shared
Shared Data Blocks Multiple programs High-speed access
memory access.
Memory-efficient,
Optimized Data Blocks Entire program Symbolic-only
modern programming.
Legacy systems,
Standard Data Blocks Entire program Symbolic & absolute flexible memory
access.
Critical data to retain
Retentive Data Blocks Configurable Persistent
post-restart.
Non-Retentive Data Data reset after a
Configurable Temporary
Blocks restart.
3. Configuring a Data Block

Steps to create a Data Block in TIA Portal:


1.Navigate to the project tree.
2.Right-click on "Program Blocks" and select "Add new Data Block."
3.Assign a name to the DB and choose its type (global or instance).
4.Define the variables and their data types.
5.Initialize the values if required.
6.Save and compile the DB.

1 2 3

4. Accessing Data in a Data Block


Data stored in Data Blocks can be accessed in the following ways:

•Direct Access: Using the symbolic name, e.g., DB1.VariableName.


•Indirect Access: Using pointers or indexed addressing.
•HMI Access: Data Blocks can be linked to HMI elements for user interaction.

5. Using Data Blocks

•Modular Design: Use Instance Data Blocks with Function Blocks for
modular programming.
•Naming Convention: Use clear and descriptive names for DBs and their
variables.
•Minimize Global Access: Prefer instance over global DBs for better
encapsulation and reduced interdependencies.
•Memory Optimization: Be mindful of memory usage by defining
appropriate data types and sizes.
•Documentation: Document the purpose and content of each DB for better
maintainability.
6. Features of Data Blocks

•Data Types: Support various data types, including basic types


(INT, REAL, BOOL) and complex types (arrays, structures, or
user-defined types).
•Initialization: Values can be pre-initialized or left to be set
during runtime.
•Symbolic Naming: Variables within a DB can be given
symbolic names for easy reference.
•Access Protection: Access to DBs can be restricted to specific
blocks or operations for security.
•Editable Online: Data within the DB can be modified while the
program is running.

7. Practical Applications of Data Blocks

•Process Variables: Storing sensor readings, setpoints, and


calculated values.
•Configuration Settings: Retaining machine configurations or
user preferences.
•Alarms and Status Flags: Managing system alarms, warnings,
and operational statuses.
•Recipes: Storing parameters for production recipes in
manufacturing.
System Function Blocks (SFBs)

System Function Blocks (SFBs)

•Predefined reusable blocks provided by Siemens for specific system operations.


•Used for tasks like timers, counters, communication, and diagnostic functions.
•Example: SFB4 for a TON (On-Delay Timer).

System Functions (SFCs)


System Functions (SFCs)
•Built-in functions in the PLC firmware for executing specific system-level
operations.
•Do not retain internal states between calls (unlike SFBs).
•Example: SFC20 for data block copying (BLKMOV).

Temporary Data
Temporary Data

•Data stored in the local memory of a block during program execution.


•Exists only while the block is running; cleared after the block finishes
execution.
•Example: Intermediate calculations in Function or Function Block logic.

Libraries and Custom Blocks

Libraries and Custom Blocks

•Libraries: Predefined or user-created collections of reusable blocks, functions,


and data structures.
•Custom Blocks: User-designed program blocks for specific tasks, ensuring
modularity and reuse.
•Example: A library containing custom FBs for motor control or HVAC
systems.

You might also like