PLC Program Structure: OB, FB, FC and DB Explained
Back to Knowledge Hub
TIA PORTAL

PLC Program Structure: OB, FB, FC and DB Explained

Putting all machine logic into OB1 may seem simple at first. As motors, sensors, alarms and operating modes grow, maintenance becomes harder. OBs, FBs, FCs and DBs divide the program into understandable, reusable units.

12 MIN READElecnic technical guide
01 / ELECNIC KNOWLEDGE

OB: The interface between the CPU and user logic

Organization Blocks are called by the CPU operating system in response to defined events. OB1 is commonly the cyclic program block, while startup, time-interrupt, hardware-interrupt and error OBs handle other events where supported.

A useful design is to keep OB1 as an orchestrator that calls the logic for each machine area. Detailed pump, conveyor or station logic can live in dedicated FBs or FCs.

02 / ELECNIC KNOWLEDGE

FC: A function without instance memory

An FC is a callable code block that receives inputs and produces outputs but has no dedicated instance DB. It is useful for calculations, conversions and logic that does not require persistent instance state.

Pass required values through the interface where practical. Explicit interfaces make dependencies visible and improve reuse and testing.

03 / ELECNIC KNOWLEDGE

FB and Instance DB: Persistent state for each instance

An FB suits logic that must retain internal state across PLC cycles, such as a motor sequence, timer, latched fault or operating mode. Static data is stored in the instance DB for that call.

A reusable motor FB can control multiple motors. Each call needs its own instance data so timers, states and values remain independent. Multi-instances store nested FB data inside the parent instance DB.

04 / ELECNIC KNOWLEDGE

DB: Organized data storage—not a duplicate tag table

A Global DB stores data shared by multiple blocks, such as machine settings, recipes, HMI values or line status. An Instance DB stores data for a particular FB call.

A PLC tag and a DB variable are not duplicates. A PLC tag commonly names an address or signal; DB variables organize application data. You do not need to recreate every PLC tag inside a DB.

05 / ELECNIC KNOWLEDGE

A practical structured-program pattern

For a sample machine, OB1 might call FB_Motor, FB_Conveyor, FB_Alarm and FC_AnalogScaling. Each block has a clear interface and responsibility.

This is a design pattern, not a rigid rule. Keep small projects proportionate, and in larger projects pay attention to module boundaries, execution order, data exchange and fault handling.

06 / ELECNIC KNOWLEDGE

Designing block interfaces and managing dependencies

A block interface should make clear which data enters, which values are produced and which state must persist internally. Use meaningful parameter names and document units, valid ranges and default behavior. This makes handover and troubleshooting by another engineer much easier.

Avoid uncontrolled reads and writes to global variables from every block. Hidden dependencies make testing and reuse harder. Data belonging to one device should normally be grouped with that device, while shared line data should live in clearly documented global structures. Choose between a global DB, block parameters and an instance DB based on data ownership and lifetime.

Key takeaways

  • OBs organize execution events; OB1 commonly provides the main cyclic structure.
  • FCs have no instance memory; FBs retain per-instance data in an instance DB.
  • Global DBs and instance DBs serve different purposes; PLC tags do not need duplication.
ENGINEERING SUPPORT

Need help applying this in a real project?

Explore Elecnic engineering services for Siemens PLC programming and troubleshooting, HMI/SCADA implementation, SINAMICS drive integration and commissioning support.

References and further reading

This is an original Elecnic article based on the technical references below. Always verify model-, firmware- and software-version-specific details in the official documentation for your equipment.