TIA Portal Β· Track 04 Β· the four block types

Blocks & the memory between calls

A TIA program is organised into blocks that call each other. There are four kinds. To understand which one you need, start by asking where its data lives between calls.

🧠 β€œDoes it remember anything between scans?”
πŸ“… OB βž— FC 🧠 FB πŸ“¦ DB
4
block types
2
live simulators
πŸŽ“
exam + cert
πŸ“…OB
βž—FC
🧠FB
πŸ“¦DB
01 Β· The block types

Four blocks, one question

Memory is the dividing line. An FC (function) takes inputs and returns results without an instance DB of its own. An FB (function block) gets a private instance DB to remember state across scans. An OB is where the OS calls in. A DB is just data.

πŸ“…
OB
Organization Block
The operating system calls these entry points, including OB1 and the interrupt OBs. Execution of your program starts with those calls.
βœ“ remembers via DBs
βž—
FC
Function
Pass inputs in and get a result out, as with sqrt(). It has no private instance memory to keep between calls.
βœ— no instance memory
🧠
FB
Function Block
Behaviour plus a private instance DB, so it can hold timers, counters, states.
βœ“ has instance DB
πŸ“¦
DB
Data Block
Storage for data such as recipes, setpoints or an FB's instance. The DB holds values; it contains no executable logic.
βœ“ IS the memory
02 Β· Memory, made visible

Compare temporary and instance data

Here OB1 calls two blocks every scan, both trying to count a pump's run-hours. FC_Hours is a plain function. Its working number is a temp that does not retain its value between calls, so this example cannot accumulate the total there. FB_Pump has an instance DB, so its total survives scan after scan. Run the pump and watch only one meter climb.

βž— FC_Hours Β· called by OB1, no instance
"Add this scan's time to #runHours." But #runHours is a temp, initialized to 0 on each call in this simulation.
πŸ›’οΈ
0.0 h
total run-hours (FC)
#runHours (TEMP)value
at call start0.000
at call end0.000
after return not retained
🧠 FB_Pump · instance "Pump_1" (DB30)
The same calculation runs here, but #runHours is a static var in the instance DB, so it persists.
πŸ›’οΈ
0.0 h
total run-hours (FB)
"Pump_1".runHours (STATIC)value
last scan0.000
this scan0.000
kept for next scanβœ“ retained
scan #0

An FB gives its instance a place to remember data such as a timer value, a counter, a step number or a state machine's state. The instance DB keeps that data between calls. Use an FC for a calculation that does not need its own instance memory.

03 Β· Reuse

Reuse a block with separate instances

Write FB_Pump once, then call it for every pump on the site. Give each pump its own instance DB to keep the same behaviour with separate memory. A bug fix in the FB applies to all of those instances, while Pump_1's hours remain separate from Pump_2's.

FUNCTION_BLOCK "FB_Pump"
  VAR running:Bool; runHours:Real; END_VAR   // VAR = static = remembered

// call it three times β€” three private instance DBs:
"Pump_1"(running := %I0.0);   // DB30
"Pump_2"(running := %I0.1);   // DB31
"Pump_3"(running := %I0.2);   // DB32

The three pumps use one block of code and keep their data in three separate instance DBs. The Execution Model lesson introduced those DBs; this example shows how you use them when the same equipment appears several times in a project.

04 Β· The scan, block by block

Watch one scan walk the call tree

During execution, blocks call each other. The operating system starts that chain by calling the OB. Press Run one scan and follow the execution: OB1 calls FC_Scale (which forgets), then FB_Conveyor (which remembers, in its instance DB), which reads a recipe from a global DB. The call-stack and memory ledger update as the scan proceeds, letting you see exactly where each value lives and what survives to the next scan.

πŸ“…
OB1
main cyclic block: the OS entry point
OB
βž—
FC_Scale
scales %IW64 β†’ % Β· stateless
FC
🧠
FB_Conveyor Β· "Conv_1"
TON + step, kept in DB30
FB
πŸ“¦
DB_Recipe
global setpoints Β· read-only here
DB

Memory ledger after each scan

FC_Scale · #scaledTEMP: local to each call not retained
"Conv_1".timer.ETSTATIC: in instance DB300.00 s
"Conv_1".stepSTATIC: in instance DB301
DB_Recipe.targetSpeedGLOBAL DB: persistent data1500 rpm

πŸ”΄ TEMP is not retained between calls Β· 🟒 STATIC lives in the instance DB from scan to scan Β· 🟑 a global DB holds data for the program.

call stack β†’
Press Run one scan to step through the call tree.
scan #0

Follow the execution and storage in this example: the OS calls an OB, the OB orchestrates FCs and FBs, and they read/write DBs. The calls show which block runs next. The DBs show where the values are stored and which ones remain available on the next scan.

05 Β· Going deeper

Block behaviour to check in a project

Once you know the four block types, check the timing, instance layout and addressing choices in your project:

πŸ“… OBs are more than OB1

OB100 runs once at startup (init values). OB30–38 are cyclic interrupts that fire on a fixed time base. Use them for PID logic that needs a defined interval independent of OB1's scan time. Hardware-interrupt OBs fire on an input edge; error OBs (OB82/121…) let your program react to a fault. Whether a missing error OB sends the CPU to STOP depends on the event: an S7-1500 stays in RUN with no OB82 loaded.

🧠 Multi-instance: an FB inside an FB

A TON is itself an FB. When you declare it as a static var inside your FB, its memory nests inside your instance DB, without a separate DB for each timer. This is multi-instance: one tidy instance DB holds your FB's state and all its sub-instances.

πŸ“¦ Optimized vs standard DB

Optimized DBs (the S7-1200/1500 default) have no fixed byte addresses. The CPU packs them for speed, and you access each variable by name only. Standard DBs keep classic %DBx.DBWy offsets for legacy access. Inserting a tag in a standard DB shifts the addresses below it, which can break a client that uses those addresses.

βž— Use an FC for a stateless calculation

An FC needs no instance DB for stateless work such as scaling, a CRC or unit conversion. You can call that calculation wherever it is needed without creating a DB for each use. Choose an FC when the answer depends only on its inputs, and an FB when each instance needs to keep its own state.

06 Β· Check yourself

Which block?

You need a reusable conveyor controller that holds its own state machine and a TON timer, callable for each of 12 conveyors. What do you build?