What’s covered
OB, FB, FC and DB at a glance
Siemens separates a PLC program into code blocks and data blocks. An OB is the entry point triggered by the CPU operating system. An FC or FB contains reusable logic. A DB stores values. The most important selection question is whether the logic needs its own persistent internal state.
| Block | Main purpose | Own memory? | Typical use |
|---|---|---|---|
| OB | Respond to a CPU event and organise execution | Not an instance memory block | Main cycle, startup, cyclic interrupt, hardware interrupt, diagnostics |
| FC | Perform reusable, usually stateless logic | No instance DB; TEMP data is not retained | Calculations, conversions, interlock evaluation, utility logic |
| FB | Perform reusable, stateful logic | Yes, through an instance DB | Motors, valves, pumps, sequences, equipment modules |
| DB | Store program data | It is a data area | Recipes, setpoints, HMI data, production values, FB instance data |
Quick rule: use an FC when outputs can be calculated entirely from the current inputs. Use an FB when the block must remember a state, timer, edge, operating mode or previous value between calls.
Organization Block (OB): when should you use it?
An Organization Block is the interface between the CPU operating system and your user program. The CPU starts an OB when its assigned event occurs. You do not normally use an OB as a reusable equipment module; you use it to define when other program logic runs.
Program cycle
Runs repeatedly while the CPU is in RUN. Keep it readable by calling FCs and FBs in a clear sequence.
Startup
Runs when the CPU changes to RUN. Initialise states only when startup behaviour is genuinely required.
Cyclic interrupt
Runs at a configured interval and priority, independently of the ordinary OB1 scan.
Hardware / diagnostic event
Runs when a configured interrupt or diagnostic event occurs, subject to CPU capability.
Available OB types and priorities depend on the selected CPU. Check the CPU properties and Siemens device documentation before assuming that a particular event OB is supported.
Function (FC): reusable logic without instance memory
An FC is a code block for a recurring task. It has an interface—typically Input, Output, InOut and Temp—but it does not have an associated instance DB. Temporary values exist only while the FC executes, so they should not be used as memory for the next scan.
Good FC applications
- Scale an analogue input from raw counts to engineering units.
- Convert temperature, pressure, speed or length units.
- Calculate an alarm limit or efficiency value.
- Evaluate a stateless permissive or interlock condition.
- Move, format or validate a group of values.
// SCL-style example: stateless scaling function
#SpanIn := #RawMax - #RawMin;
IF #SpanIn <> 0.0 THEN
#ScaledValue := ((#RawValue - #RawMin) / #SpanIn)
* (#EngMax - #EngMin) + #EngMin;
END_IF;
Avoid this mistake: an FC can still write to a global DB or other external memory, but doing so does not give the FC private instance memory. Excessive direct global access also reduces portability and testability.
Function Block (FB): reusable logic that remembers
An FB is a code block that stores its parameters and Static values in an instance DB. Each instance therefore has independent memory. The same Motor FB can be called for Motor 1, Motor 2 and Motor 3, with a separate instance for each motor.
Good FB applications
- Motor, pump, fan, conveyor and valve control.
- Sequences, state machines and operating-mode control.
- Logic using timers, counters, edge detection or stored faults.
- Equipment modules that need status and command data.
- Reusable objects connected to HMI faceplates.
The FB code is shared, but the two instance DBs keep their data separate. In an FB, another FB may also be declared as a Static variable to create a multi-instance. This groups nested instance data inside the parent instance DB and is useful for modular machine sections.
Data Block (DB): where program data lives
A DB contains data rather than executable networks. Siemens programs commonly use two DB categories:
| DB type | Ownership | Best use | Important note |
|---|---|---|---|
| Global DB | Accessible by permitted program blocks | Recipes, setpoints, HMI exchange, plant data and configuration | Design a clear structure and avoid turning one DB into an uncontrolled data dump |
| Instance DB | Assigned to an FB call | Input, output, InOut and Static data for that FB instance | Normally manage the values through the FB interface rather than unrelated direct writes |
For S7-1200 and S7-1500 projects, optimised data access and symbolic tags are usually the natural choice. Use non-optimised or absolute access only when a communication interface or legacy requirement makes it necessary, and document that decision.
How to select the correct Siemens block
- Is the CPU event starting this logic?
Choose an OB for a program cycle, startup, timed interrupt, hardware event or supported diagnostic event. - Does the logic only process current input values?
Choose an FC for a stateless calculation or reusable operation. - Must the logic remember anything between calls?
Choose an FB with an instance DB for modes, states, timers, counters, edges or equipment history. - Do several blocks or an HMI need shared structured data?
Create a global DB with meaningful nested structures or PLC data types. - Will the same equipment logic be reused?
Build one FB and create a separate instance for each real device.
Recommended program structure
A scalable project keeps OBs short and uses descriptive symbolic names. The OB decides execution order; equipment FBs own their behaviour and state; utility FCs perform stateless operations; global DBs hold shared configuration and process data.
- Pass values through block interfaces where practical.
- Use consistent names such as FB_Motor, FC_Scale, DB_Recipe and DB_Motor01.
- Keep safety logic in the appropriate certified safety environment; this tutorial covers standard logic only.
- Document each block’s purpose, interface and calling conditions.
Step-by-step lab: OB, FB, FC and DB in TIA Portal
This small exercise demonstrates all four block types with a motor and an analogue current value.
- Create a project and add the correct CPU.
Open Program blocks beneath the PLC in the project tree. - Create FC_ScaleCurrent.
Add raw input and engineering-range parameters, then return the scaled current. Use LAD, FBD or SCL. - Create FB_Motor.
Add Start, Stop, Permissive and Feedback inputs; RunCmd and Fault outputs; use Static data for remembered state or fault logic. - Create an FB instance.
Call FB_Motor in OB1 and let TIA Portal create DB_Motor01, or select an existing compatible instance DB. - Create DB_ProcessData.
Add structured tags for setpoints, measured values and HMI-visible status. - Arrange OB1.
Call FC_ScaleCurrent first, write the result to DB_ProcessData, then call FB_Motor with clearly mapped tags. - Compile and test.
Download to a test PLC or PLCSIM where suitable. Monitor the blocks and confirm that each FB instance retains independent state.
Expected result: the FC returns a calculation without private retained state, the FB controls the motor and remembers its instance values, the instance DB belongs to that motor call, and the global DB shares process data.
Frequently asked questions
What is the main difference between FB and FC in Siemens PLC?
An FB has an associated instance DB and can retain Static values between calls. An FC has no instance DB and its Temp values are not retained after execution.
Can an FC use a data block?
Yes. An FC can read or write permitted global data, but that DB is not private instance memory belonging to the FC.
Can the same FB control several motors?
Yes. Call the same FB once per motor and assign a separate instance DB—or separate multi-instance—for every motor.
Should all code be written directly in OB1?
No. OB1 should normally coordinate calls. Placing reusable equipment and utility logic in FBs and FCs makes the project easier to test, maintain and expand.
What is the difference between a global DB and an instance DB?
A global DB is a shared program data area. An instance DB is tied to an FB instance and stores that call’s interface and Static data.
Does every FB require a separate DB?
Every FB instance needs instance storage. It may use a single-instance DB or be declared as a multi-instance inside a parent FB’s instance DB.
Official Siemens references
Technical definitions were checked against Siemens STEP 7 documentation: Overview of the block types and Function block (FB). CPU features and supported OBs can vary by device and firmware.