January 9, 2025

PLC Programming Blocks: OB, FC, FB, and DB

Introduction

Programmable Logic Controllers (PLCs) are essential in industrial automation, and their efficient programming relies on different types of program blocks. In Siemens TIA Portal (Step 7) or similar PLC software, program organization is crucial for creating structured, reusable, and efficient control logic.

In this article, we will explore the four main types of PLC program blocks used in Siemens PLC programming:

  1. OB (Organization Block) – Main program execution blocks
  2. FC (Function) – Reusable logic without memory retention
  3. FB (Function Block) – Reusable logic with memory retention
  4. DB (Data Block) – Data storage for variables

Understanding these blocks will help you write better PLC programs that are scalable, modular, and easy to maintain.

1. Organization Block (OB)

What is an OB?

  • Organization Blocks (OBs) control the execution of a PLC program.
  • They define the priority, scan cycle, and error handling of a PLC.
  • The main cycle OB (OB1) is executed cyclically, while other OBs handle specific events.

Types of OBs

  1. OB1 – Main Program Cycle

    • This is the main cyclic program execution block.
    • The PLC continuously scans OB1 as long as it is in RUN mode.
    • All logic is usually called within OB1 using FCs and FBs for modular programming.
  2. OB10-OB17 – Time-Triggered OBs

    • These execute at specific time intervals.
    • Useful for timed operations, such as data logging or periodic checks.
  3. OB20-OB23 – Hardware Interrupt OBs

    • Triggered by hardware interrupts like sensor inputs.
    • Used for real-time critical operations.
  4. OB30-OB38 – Cyclic Interrupt OBs

    • Execute at fixed time intervals.
    • Ensure consistent execution of specific tasks.
  5. OB40-OB47 – Process Alarm OBs

    • Triggered by process alarms.
    • Used for fault handling.
  6. OB80-OB87 – Fault Handling OBs

    • Handle errors such as division by zero, power failure, or module faults.
    • Ensures the PLC can recover from errors gracefully.

2. Function (FC)

What is an FC?

  • Functions (FCs) are reusable blocks of logic that do not retain memory after execution.
  • They can take input parameters and return output values, but they do not have an internal memory.
  • Best suited for calculations, math operations, and temporary logic.

Key Features of FCs

No internal memory (stateless)
Accepts input parameters and returns output parameters
Used for simple, reusable logic

Use Case for FCs

  • Mathematical calculations
  • Signal processing
  • Data conversions


3. Function Block (FB)

What is an FB?

  • Function Blocks (FBs) are similar to FCs but retain memory (stateful execution).
  • Used when logic needs to store data across multiple cycles.
  • They require a Data Block (DB) for memory storage.

Key Features of FBs

Have internal memory (can store values between scans)
Require an Instance Data Block (DB)

Used for complex logic, motor control, and PID control

Example: FB for Motor Control

Use Case for FBs

  • Motor start/stop circuits
  • PID controllers
  • Alarm handling

4. Data Block (DB)

What is a DB?

  • Data Blocks (DBs) store global or instance-specific data.
  • Can be used to store sensor values, setpoints, or configuration parameters.
  • There are two types of DBs:
    • Global DB – Shared across multiple functions.
    • Instance DB – Used with FBs to store internal memory.

Best Practices for Using OBs, FCs, FBs, and DBs

Use OB1 only for function calls – Keep OB1 clean by calling FCs and FBs instead of writing logic directly inside it.
Use FCs for stateless logic – If the function does not need memory, use an FC to keep programs modular.
Use FBs for stateful operations – If the function needs to store past values, use an FB with an instance DB.
Organize data using DBs – Store configuration parameters in DBs to make programs easier to modify.

Conclusion

Understanding OBs, FCs, FBs, and DBs is essential for writing structured, efficient, and scalable PLC programs.

  • OBs define the execution cycle and event handling.
  • FCs provide reusable, stateless logic.
  • FBs allow memory retention for stateful processes.
  • DBs store important process data.

By using these blocks strategically, you can build flexible automation solutions that are easy to maintain and expand. 


Click here to watch video 

https://youtu.be/BmCGuHfOjp0