Physical AIUpdated 21 October 20268 min read

PLC Programme Structure: Modular Design Best Practice

Good PLC programme structure splits a machine into reusable blocks: a thin main cycle, function blocks per piece of equipment with their own instance data, functions for stateless maths, and data blocks for shared data. This guide shows a practical layout in Siemens TIA Portal, with naming, documentation and version control habits.

PLC ProgrammingSoftware DesignBest PracticesTIA PortalStructured CodeFunction Blocks
Engineer in a blue hard hat and orange hi-vis jacket measuring inside a control panel with a clamp meter

Key takeaways

  • A TIA Portal programme uses four block types: OBs (entry points), FBs (code with instance data), FCs (no static memory) and DBs (data).
  • Keep OB1 thin: it should only call blocks in a deliberate order, and write physical outputs in one place.
  • Write one FB per device type and instantiate it for each motor or valve, so one fix improves every instance.
  • Keep safety functions separate from standard logic, in safety-rated hardware and safety programme sections.
  • Archive projects at FAT, SAT and handover, and keep a change log with dates and reasons.

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.

BlockPurposeHas its own memory?Typical use
Organisation block (OB)Entry point called by the CPU's operating systemTemporary onlyMain cycle, startup, cyclic interrupts, diagnostics
Function block (FB)Reusable code with instance dataYes, in an instance data blockOne motor, valve, conveyor section, PID loop
Function (FC)Code with no static memory of its ownNoScaling, unit conversion, utilities
Data block (DB)Stores dataYesRecipes, 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.

Siemens SIMATIC S7-300 modular PLC, the platform on which the OB, FB, FC and DB block concept became widespread
Siemens SIMATIC S7-300 modular PLC, the platform on which the OB, FB, FC and DB block concept became widespreadPhoto: Ulli1105, CC BY-SA 2.5, via Wikimedia Commons
TIA Portal | Blocks in Siemens PLC- OB, FB, FC, DB | Difference between FB vs FC

How should the main cycle be organised?

Keep OB1 thin: it should only call other blocks in a deliberate order. A common pattern:

  1. Inputs and conditioning: copy raw I/O into tags, scale analogues, debounce.
  2. Mode management: manual, automatic, maintenance, and the permissives for each.
  3. Sequence control: a step sequencer or state machine that decides what happens next.
  4. Equipment control: one FB instance per motor, valve, cylinder or drive.
  5. Alarms and diagnostics: collect faults in one place for the HMI.
  6. 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.

ApproachStrengthsWeaknesses
Copy-pasted rungs per deviceQuick for one machineErrors multiply; every change is repeated everywhere
One FB per device type, many instancesConsistent behaviour, one place to fixNeeds upfront design and testing
Full type library with versioningScales across projects and teamsNeeds 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.

  1. Archive at milestones: before factory acceptance test (FAT), before site acceptance test (SAT) and at handover.
  2. Log changes with dates and reasons, so the next engineer knows why a block changed.
  3. Use version control where your tooling supports it, and archive the project file regularly; check what your TIA Portal version offers.
  4. Test blocks in simulation (PLCSIM or a free browser simulator) before they touch real equipment.
  5. 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.

Start free

Learn PLC programming free, then practise the job

Free job simulation

PLC Programmer

Write the I/O list, program the line, run the FAT and handle a change request.

The first five days are free, no card needed.

Live UK jobs

PLC and automation jobs in the UK

Updated daily, with licensed visa sponsors marked.

Browse all engineering jobs

Frequently asked questions

What is the difference between an FB and an FC in TIA Portal?

A function block (FB) has instance data, so it remembers values between calls, which suits devices like motors, valves and timers. A function (FC) has no static memory of its own and returns results from its inputs, which suits scaling and conversion. Use FBs for equipment with state, FCs for stateless utilities.

What does OB1 do in a Siemens PLC?

OB1 is the default organisation block for the main programme cycle. The CPU calls it repeatedly, and it should contain calls to your other blocks in a logical order. Other OBs handle startup, cyclic interrupts and diagnostic events. Check your CPU's documentation for exact behaviour and priorities.

Why use function blocks instead of copying ladder rungs?

Function blocks keep behaviour consistent and put each fix in one place. Copied rungs drift apart as people edit them, so a bug can survive in some copies. A tested FB used for every motor also speeds commissioning and gives the HMI one standard interface to bind to.

How should PLC tags and blocks be named?

Follow a written team standard: descriptive names, an equipment or area prefix, consistent type prefixes such as FB_ and DB_, and no ambiguous abbreviations. For example FB_Motor for the type and Conveyor1_Run for a tag. The specific convention matters less than everyone using the same one.

Sources

  1. IEC webstore: IEC 61131-3:2013 Programmable controllers, programming languages
  2. Siemens: SIMATIC S7-1500 PLC
  3. Wikipedia: Programmable logic controller

Share this article

About the author

EDWartens Team

EDWartens Instructional Team

The EDWartens instructional team brings together UK-based automation engineers, certified Siemens and Rockwell specialists, and industry practitioners with decades of combined experience in PLC programming, SCADA engineering, and industrial AI.

View all articles by EDWartens

Ready to become job-ready?

Start with a free course today, or train live in Siemens PLC, HMI and SCADA on the Professional Module.

Related articles

Career

PLC Engineer Job Description UK: Programmer vs Controls Engineer

In UK adverts the titles overlap heavily: a PLC programmer mainly writes and modifies control logic, a PLC engineer also commissions and supports systems, and a controls engineer designs wider control systems. ITJobsWatch shows a median advertised salary of £60,000 for PLC Engineer roles and £55,000 for Control Systems Engineer roles in the six months to 21 October 2026.

Read article
Physical AI

Siemens TIA Portal for Beginners: Your First PLC Project

TIA Portal is Siemens' single engineering environment for programming S7 PLCs, HMIs and drives. To start, install it, add an S7-1200 or S7-1500 CPU, write a start-stop rung in the Main [OB1] block and test it in a simulator. UK PLC Engineer adverts quoted a median of £60,000 in the six months to 21 October 2026 (ITJobsWatch).

Read article
Physical AI

PID Control Explained: Tuning Guide for Automation Engineers

PID control corrects a process by combining proportional, integral and derivative action on the error between setpoint and measurement. An ABB paper states that over 90% of process control systems use PID controllers. This guide explains each term, a worked Ziegler-Nichols tuning example, windup and derivative noise, and PID_Compact in TIA Portal.

Read article
Physical AI

PLC Programming Languages: LD, FBD, ST and SFC Explained

IEC 61131-3 defines four current PLC programming languages: ladder diagram, function block diagram, structured text and sequential function chart. Instruction list was deprecated in 2013. In the six months to 21 October 2026, ITJobsWatch counted 67 UK permanent adverts citing ladder logic, up from 22 a year earlier.

Read article