A well-structured PLC programme separates what the machine does (mode and sequence control) from how each device behaves (motors, valves, drives), using reusable blocks with clear interfaces. The result is shorter commissioning, safer changes and faster fault finding. This guide uses Siemens TIA Portal terms (OB, FB, FC, DB), but the principles apply to any IEC 61131-3 environment.
What blocks make up a Siemens PLC programme?
A TIA Portal project is built from four block types, each with a distinct job.
| Block | Purpose | Has its own memory? | Typical use |
|---|---|---|---|
| Organisation block (OB) | Entry point called by the CPU's operating system | Temporary only | Main cycle, startup, cyclic interrupts, diagnostics |
| Function block (FB) | Reusable code with instance data | Yes, in an instance data block | One motor, valve, conveyor section, PID loop |
| Function (FC) | Code with no static memory of its own | No | Scaling, unit conversion, utilities |
| Data block (DB) | Stores data | Yes | Recipes, parameters, shared machine data |
Common OBs: OB1 is the default main programme cycle, OB100 is the usual startup block on S7-1500, OB35 is a cyclic interrupt (a default of 100 ms) and OB82 handles diagnostic interrupts. Interrupt numbers and priorities are configurable, so confirm exact behaviour for your CPU in the Siemens manual or TIA Portal help; Siemens documentation pages were not accessible for this article, so verify there before relying on specific numbers.
How should the main cycle be organised?
Keep OB1 thin: it should only call other blocks in a deliberate order. A common pattern:
- Inputs and conditioning: copy raw I/O into tags, scale analogues, debounce.
- Mode management: manual, automatic, maintenance, and the permissives for each.
- Sequence control: a step sequencer or state machine that decides what happens next.
- Equipment control: one FB instance per motor, valve, cylinder or drive.
- Alarms and diagnostics: collect faults in one place for the HMI.
- Outputs: write results to physical outputs in one location.
Writing outputs in a single place avoids two blocks fighting over the same output, which is one of the most common causes of "ghost" behaviour. Time-critical loops such as PID should live in a cyclic interrupt OB so they run at a fixed interval regardless of how long the main cycle takes. The scan principle behind this is explained in What is a PLC?.
How do you design a reusable equipment block?
Design each block as a small, testable component with a defined interface: inputs for commands and interlocks, outputs for status, and internal state in its instance data. A motor FB might include:
- Start and stop commands, with interlock and permissive inputs.
- Running feedback with a timeout fault (command given, no feedback within a set time).
- Overload and fault handling, with a reset input.
- Operating hours counter.
- Interface data for an HMI faceplate (mode, status, alarms).
A valve FB typically has open and close commands, position feedback, a travel-time fault for stuck valves, and a maintenance override. Write the block once, instantiate it for every motor or valve, and a fix to the type improves every use. TIA Portal's library features are designed to help manage shared types across projects; check your version's documentation.
| Approach | Strengths | Weaknesses |
|---|---|---|
| Copy-pasted rungs per device | Quick for one machine | Errors multiply; every change is repeated everywhere |
| One FB per device type, many instances | Consistent behaviour, one place to fix | Needs upfront design and testing |
| Full type library with versioning | Scales across projects and teams | Needs governance and discipline |
What naming and documentation habits matter?
Consistent names and comments are what let a stranger fix your machine at 3 am.
- Use a written standard that the whole team follows. For example FB_Motor, FC_ScaleAnalogue, DB_Recipe, and tags such as Conveyor1_Run.
- Prefix by area or equipment so tags sort and search well.
- Avoid ambiguous abbreviations.
- Comment each network with its purpose, and put a header in each FB describing inputs, outputs and behaviour.
- Keep a revision log with date, author and reason.
- Reference the source documents: P&ID, electrical schematic and functional design specification.
The same discipline applies to the HMI. See HMI design best practices.
How should you handle data, state and safety?
Keep data in structured types (PLC data types, or UDTs) rather than loose tags, so one structure describes a motor everywhere it appears. Keep persistent machine settings in clearly named data blocks and decide which values must be retentive. Keep safety functions separate from standard logic: they belong in safety-rated hardware and safety programme sections designed to the relevant machinery safety standards, not mixed into ordinary rungs. The free machine safety course and our functional safety guide cover the basics.
How do you manage versions and testing?
Treat PLC code like software.
- Archive at milestones: before factory acceptance test (FAT), before site acceptance test (SAT) and at handover.
- Log changes with dates and reasons, so the next engineer knows why a block changed.
- Use version control where your tooling supports it, and archive the project file regularly; check what your TIA Portal version offers.
- Test blocks in simulation (PLCSIM or a free browser simulator) before they touch real equipment.
- Test failure cases: feedback lost, sensors stuck, comms dropped, power-cycle recovery.
What does a typical machine programme look like?
A mid-size packaging machine might be organised as: OB1 (calls everything), OB100 (initialises states), OB35 (fixed-rate PID and motion tasks), FB_Mode (mode manager), FB_Sequence (state machine), FB_Motor and FB_Valve instances, FC_Scale for analogue inputs, FB_Alarms, and DBs for recipes and HMI exchange. Whatever the size, the aim is the same: any block can be understood, tested and replaced on its own. For hands-on practice with block calls and simulation, try the free Siemens TIA Portal course, then read Getting started with Siemens TIA Portal.
How should a function block interface be designed?
In TIA Portal an FB interface has sections for inputs, outputs, in/out parameters, static variables and temporary variables. Use inputs for commands and settings, outputs for status, and static variables for internal state that must persist between calls. Avoid reaching into global tags from inside a block: if everything the block needs arrives through its interface, you can test it alone, copy it to another project, and read it without hunting through the rest of the program.
A motor block outline in plain text:
- Inputs: Cmd_Start, Cmd_Stop, Interlock_OK, Feedback_Running, Reset, Timeout_Time.
- Outputs: Run_Output, Status_Running, Fault_NoFeedback, Fault_Active.
- Static: Run_Timer (on-delay timer), Hours_Counter, Fault_Latch.
- Logic: Run_Output is on when a start has been commanded, Interlock_OK is true and no fault is latched. If Run_Output is on and Feedback_Running has not arrived within Timeout_Time, latch Fault_NoFeedback until Reset.
Each instance of FB_Motor gets its own instance data block, so ten motors share the same logic but keep separate timers and faults. Siemens also allows an FB to call another FB as a multi-instance, which keeps a composite device, such as a pump with a valve, in a single block. Confirm the exact interface sections and options in the TIA Portal help for your version.
What does a clean project tree look like?
A tidy project makes the structure visible before anyone opens a block. One common arrangement is folders such as 01_Main, 02_Modes, 03_Sequences, 04_Equipment, 05_Alarms, 06_Comms and 07_Data, each holding the blocks for that concern. The exact scheme matters less than the habit: a newcomer should find the motor block, the recipe data and the alarm logic without asking anyone. Pair this with consistent HMI naming so screen objects and PLC tags line up, as discussed in HMI design best practices.
How EDWartens can help
The Professional Module is a five-day live online class on Siemens TIA Portal (certificate states V19): S7 PLC hardware, ladder logic, simulation and testing, then HMI and WinCC SCADA, followed by self-paced Basic Engineering modules. Structure and block habits are part of building working projects, but the course does not replace years of project experience. It carries a CPD certificate recording 80 hours of learning, not a regulated qualification, and simulation-based. £2,140 + VAT (£2,568), £100 deposit option, weekly Monday starts, up to 10 learners. See the course or sign up.





