Introduction
In TIA Portal, a PLC program is structured into modular componentsthat help organize logic, improve code reusability, and manage memory efficiently. The most fundamental elements include:
- Organization Blocks (OBs) – Define when and how code is executed by the CPU.
- Functions (FCs) – Reusable code blocks without memory retention.
- Function Blocks (FBs) – Reusable code blocks with memory retention.
- Data Blocks (DBs) – Hold data used by FBs or shared globally.
Organization Blocks (OBs)
Organization Blocks are the entry points for code execution. They are called by the operating system of the CPU and are executed according to predefined events or triggers (e.g. cyclic, startup, error, or time-based)
OB1 – Main Program Cycle
- Type: Cyclic OB
- Purpose: This is the main loop of the PLC program. It is executed continuously and cyclically as long as the CPU is in RUN mode
- Typical Use: General logic execution, calling FCs/FBs, reading inputs, writing outputs.
- Execution: After OB1 finishes executing, itstarts again immediately, creating the main PLC scan cycle.
OB100 – Startup OB
- Type: Startup OB
- Purpose: Executed once when the CPU transitionsfrom STOP to RUN.
- Typical Use: Initialization of variables, flags, timers, and starting conditions.
- Important Note: OB100 is not called on a cold restart unless explicitly configured. It is typically used to reset statuses or force certain startup values
OB35 – Cyclic Interrupt OB
- Type: Time-triggered (cyclic interrupt) OB
- Purpose: Executes at fixed time intervals, independently of the main OB1 cycle.
- Typical Use: Time-critical or synchronized tasks(e.g. reading fast analog signals, updating motion control values)
- Configuration: The execution interval (e.g., every 100ms) is set in the hardware configuration.
Tip: Since OB35 runs asynchronously to OB1, be careful when accessing shared variables — consider using consistent access or shared data blocks with appropriate data handling to avoid conflicts.
Functions(FC)
- No Memory Retention: FCs do not retain data between calls unless explicitly passed through parameters
- Usage: Bestsuited for general-purpose tasks like calculations, logic checks, conversions.
- Structure: Accept input, output, and in/out parameters, but have no associated data block.
Example: An FC can calculate the average of 3 sensor readings and return the result.
Function Blocks(FB)
- With Memory Retention: FBs maintain internal state using an Instance Data Block.
- Usage: Ideal for objects or devices that need to remember internal status — e.g. motor control, pump logic, debouncing, PID control.
- Structure: Also usesinput, output, and in/out parameters, plus internal static variables.
Example: An FB controlling a motor may retain the motor’s running state, error codes, or runtime counters.
Data Blocks (DB)
There are two main types
- Instance Data Blocks
- Automatically generated and linked to FBs.
- Store the internal data of a specific FB instance.
- Global Data Blocks
- Independent DBs accessible from any part of the program.
- Used to store shared configuration data, setpoints,statuses, flags, etc.
Best Practice: Avoid writing to global DBs from multiple sources unless coordinated — this reduces the chance of race conditions or inconsistent data.
Summary
| Block Type | Retains Memory | Triggered By | Purpose |
| OB1 | N/A | CPU cyclic scan | Main logic execution |
| OB100 | N/A | CPU startup | Initialization |
| OB35 | N/A | Time interrupt | Time-based logic |
| FC | Called manually | Statelessreusable logic | |
| FB | Yes (via DB) | Called manually | Stateful logic with memory |
| DB | Yes | Accessed by logic | Data storage |

Differente Types Of Blocks
Important Note: Calling Logic from OBs
In TIA Portal, the PLC only executes code that is explicitly called from an OB (Organization Block).
Creating an FC or FB does not automatically make it run. You must call it manually from an OB (typically OB1 or OB35), or from within another block that is already being executed.
Example
If you create an FB named FB_MotorControl and define all your motor logic inside it, nothing will happen unless you add a call to FB_MotorControl (with its instance DB) inside OB1 or another OB.
Wrong Assumption
“Since I wrote the code inside FB, the PLC will run it automatically.”
No – it will be ignored unless called. Best
Practice
- Use OB1 to structure your main logic and call all necessary FCs/FBs from there.
- For more modularity, you can group logic in multiple FCs/FBs and manage execution order inside OB1.
- For time-critical logic, consider calling blocksfrom OB35 or other cyclic interrupt OBs.
Understanding FB Calls and Automatic Data Block Creation
When you call an FB from an OB (e.g., OB1) for the first time, TIA Portal will automatically prompt you to create an Instance Data Block (DB). This DB is used to store the internal memory of the FB, such as variables, statuses, timers, counters, or any static data defined within the FB.
Note: If you don’t create the associated DB, the FB cannot be compiled or executed — because it has
nowhere to store its state
Multiple Instances:
If you want to control multiple motors using the same FB (e.g., FB_MotorControl), you can call the same FB multiple times but with different instance DBs
Summary Point to Add
- FBs always require a corresponding instance DB when called.
- TIA Portal automatically manages this and will prompt you to create one on first use.
- You can have multiple instances of the same FB, each with its own DB.
If you found this helpful, please consider supporting with a small donation. Thank you!
Leave a Reply