Siemens S7-1500 series · Part 4

Siemens PLC Blocks Explained: OB, FB, FC and DB

Part 4 turns the conveyor project from Parts 2 and 3 into a structured program: which block runs when, which block remembers, and how one FB drives all 16 roller beds.

Beginner to Intermediate10 min readS7-1500 (also S7-1200)LAD, FBD or SCL
Write outputsRead inputsOB1 program #1scan cycle
OB30 cyclic
interrupt runs,
OB1 waits

OB1 calls, in order

FCRIO_Input_Mappingcopy inputs
FCFC_Scale_Levelcalculate
FBFB_Conveyor16 × FB_PRB inside
FCRIO_Output_Mappingcopy outputs
DBDB_HMIdata for MTP700

Six animated steps

  1. OB, FB, FC and DB at a glance
  2. OB: when the CPU runs your code
  3. FC vs FB: who remembers?
  4. One FB, many instance DBs
  5. Block picker game
  6. Program tree of the conveyor
  7. TIA Portal lab
  8. FAQs
01

OB, FB, FC and DB at a glance

Code blocks decide when and what runs; data blocks decide where values live. The bar under each card shows what happens to its memory.

OBOrganization blockStarted by the CPU: cycle, startup, time or hardware event.
event-driven
FCFunctionReusable logic. Temp memory starts empty at every call.
forgets after each call
FBFunction blockReusable logic that remembers, through its instance DB.
keeps its Static values
DBData blockStores data: recipes, setpoints, HMI values, FB instances.
holds data, no code

Quick rule: outputs depend only on current inputs → FC. Must remember a state, timer, edge or mode → FB.

Reference: comparison table
BlockMain purposeOwn memory?Typical use
OBRespond to a CPU event and organise executionNot an instance memory blockMain cycle, startup, cyclic interrupt, hardware interrupt, diagnostics
FCPerform reusable, usually stateless logicNo instance DB; TEMP data is not retainedCalculations, conversions, interlock evaluation, utility logic
FBPerform reusable, stateful logicYes, through an instance DBMotors, valves, pumps, sequences, equipment modules
DBStore program dataIt is a data areaRecipes, setpoints, HMI data, production values, FB instance data
02

Organization Block (OB): When the CPU Runs Your Code

The operating system starts an OB when its event happens. Power up the CPU, then fire a hardware or diagnostic event and watch OB1 get interrupted.

CPU 1511-1 PN · OB execution
OB100Startup
OB1Program cycle
OB30Cyclic interrupt
OB40Hardware interrupt
OB82Diagnostic error
0 ms2505007501000 ms

Demo timing: OB30 set to 100 ms, time slowed down 4×. Which OBs exist, and their priorities, depend on the CPU and firmware.

Reference: the main OB types
OB1

Program cycle

Runs repeatedly while the CPU is in RUN. Keep it readable by calling FCs and FBs in a clear sequence.

Use for: normal cyclic machine control
OB

Startup

Runs when the CPU changes to RUN. Initialise states only when startup behaviour is genuinely required.

Use for: safe initialisation and startup checks
OB

Cyclic interrupt

Runs at a configured interval and priority, independently of the ordinary OB1 scan.

Use for: deterministic sampling or control calculations
OB

Hardware / diagnostic event

Runs when a configured interrupt or diagnostic event occurs, subject to CPU capability.

Use for: fast event reaction and fault handling

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.

03

FC vs FB: Which Block Remembers?

The same start/stop latch, written once as an FC with a Temp variable and once as an FB with a Static variable. Press Start and watch each scan.

PRB_1 start/stop latch
FCFC_Motor_Latch
#StartFALSE
Temp #LatchFALSE
#RunFALSE
STOPPED
FBFB_PRB → DB_PRB_1
#StartFALSE
Static #LatchFALSE
#RunFALSE
STOPPED
Scan #0
#Latch := #Start OR (#Latch AND NOT #Stop);   // same line in both blocks
#Run   := #Latch;
Good FC applications

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;
Good FB applications

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.
04

Function Block (FB): One FB, Many Instance DBs

The FB code exists once. Every call gets its own instance DB, so four roller beds keep four separate sets of values. Or group them as multi-instances inside one parent FB.

Program blocks
FBFB_PRB Input: Start, Stop, Feedback · Output: Run, Fault · Static: Latch, Runtime_s
05

Data Block (DB): Global DB vs Instance DB

Instance DBs belong to one FB call. Global DBs hold shared data such as recipes and HMI values, ideally built from the UDTs in Part 3.

DB typeOwnershipBest useImportant note
Global DBAccessible by permitted program blocksRecipes, setpoints, HMI exchange, plant data and configurationDesign a clear structure and avoid turning one DB into an uncontrolled data dump
Instance DBAssigned to an FB callInput, output, InOut and Static data for that FB instanceNormally manage the values through the FB interface rather than unrelated direct writes
06

Block Picker: Choose the Right Siemens Block

Eight real jobs from the conveyor line. Pick the block for each one.

Block picker
Reference: the 5-question selection guide
  1. Is the CPU event starting this logic?
    Choose an OB for a program cycle, startup, timed interrupt, hardware event or supported diagnostic event.
  2. Does the logic only process current input values?
    Choose an FC for a stateless calculation or reusable operation.
  3. Must the logic remember anything between calls?
    Choose an FB with an instance DB for modes, states, timers, counters, edges or equipment history.
  4. Do several blocks or an HMI need shared structured data?
    Create a global DB with meaningful nested structures or PLC data types.
  5. Will the same equipment logic be reused?
    Build one FB and create a separate instance for each real device.
07

Recommended Program Structure: the Conveyor Call Tree

Short OB1, clear call order, one FB per equipment type. Press play to follow one cycle.

Conveyor_Line › Program blocks
OB100Startup [OB100]once at STOP → RUN: reset sequence steps
OB1Main [OB1]program cycle
FCRIO_1_Input_Mapping … RIO_3_Input_Mappingcopy station inputs
FCFC_Scale_Levelraw Int → Real mm
FBFB_Conveyor → DB_Conveyorone instance DB
FB#PRB[1..16] : FB_PRB16 multi-instances
FB#TT_1 : FB_TurnTablesequence
FCRIO_1_Output_Mapping … RIO_3_Output_Mappingcopy commands out
DBDB_HMI, DB_Recipeglobal DBs
OB30Cyclic interrupt [OB30]every 100 ms: level PID
  • Use consistent names: FB_PRB, FC_Scale_Level, DB_Recipe.
  • Pass values through block interfaces; keep global writes in a few clear places.
  • Safety logic belongs in the certified safety program; this tutorial covers standard logic only.

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.

  1. Create a project and add the correct CPU.
    Open Program blocks beneath the PLC in the project tree.
  2. Create FC_ScaleCurrent.
    Add raw input and engineering-range parameters, then return the scaled current. Use LAD, FBD or SCL.
  3. Create FB_Motor.
    Add Start, Stop, Permissive and Feedback inputs; RunCmd and Fault outputs; use Static data for remembered state or fault logic.
  4. Create an FB instance.
    Call FB_Motor in OB1 and let TIA Portal create DB_Motor01, or select an existing compatible instance DB.
  5. Create DB_ProcessData.
    Add structured tags for setpoints, measured values and HMI-visible status.
  6. Arrange OB1.
    Call FC_ScaleCurrent first, write the result to DB_ProcessData, then call FB_Motor with clearly mapped tags.
  7. 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

Why does an FC forget its value after the scan?

FC Temp variables only exist while the FC runs. At the next call they start again, so a latch or timer in Temp is lost. Use an FB with a Static variable, which is stored in the instance DB, when the value must survive between scans.

What is a multi-instance in TIA Portal?

A multi-instance is an FB declared as a Static variable inside another FB. Its data is stored inside the parent FB's instance DB, so 16 FB_PRB motors can live inside one DB_Conveyor instead of 16 separate DBs.

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.

Learn Siemens PLC programming with practical examples

Build structured S7-1200 and S7-1500 projects in TIA Portal with guided industrial exercises.

Siemens PLC & TIA Portal Learning Path

Continue with the related Siemens PLC tutorials in this practical learning series.

  1. SCL vs Ladder Logic
  2. Upload PLC Program
  3. TIA Selection Tool
  4. Analog Input Scaling
  5. PLC Counters
  6. PLC Timers
  7. Addressing & Data Types
  8. Hardware & PLC Tags
  9. OB, FB, FC & DB