Program Blocks
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:
Organization Blocks
➢ Organization Blocks
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.
OB122 Handles access errors (invalid memory access). On access-related runtime errors.
• 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.
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
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.
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
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.
Data Block
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:
•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:
Summary Table
1 2 3
•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
Temporary Data
Temporary Data