TIA Portal · S7-1200 · SCL · FB/DB Architecture

Case Study:
Multi-Motor Control
Using FB Instance Architecture

A production-representative implementation of a reusable Function Block motor control library in Siemens TIA Portal, demonstrating multi-instance Data Block patterns, fault-detection timers, and structured control hierarchies aligned with IEC 61131-3 and Siemens S7 programming standards.

Platform: Siemens TIA Portal (Cloud) CPU: S7-1200 / CPU 1212C DC/DC/DC Language: SCL (Structured Control Language) Architecture: FB + Instance DB + Multi-Instance Status: Compiled — 0 errors, 0 warnings
01 / Project Overview

From Flat Ladder Logic to Modular FB Libraries

This project extends the foundational start/stop motor control work into a fully modular, reusable architecture using Siemens Function Blocks (FBs) and Instance Data Blocks (DBs) — the standard structural pattern for scalable industrial automation programs on the S7 platform. The central design objective was not simply to control a motor, but to build a control library: a reusable software component that can be instantiated multiple times across a line, a plant area, or an entire facility, without duplicating logic.

Two Function Blocks form the core of the system. FB_Motor [FB1] encapsulates all logic and state for a single motor axis — start/stop latching, fault detection, run-time feedback monitoring, and a watchdog timer that flags a failure if the motor does not confirm running within a defined window. FB_LineControl [FB2] acts as the supervisory coordinator, instantiating two FB_Motor instances as multi-instance static variables, routing line-level signals to each motor, and managing a shared reset condition. The result is a two-motor production line managed by a single block call from OB1.

Design Intent
This architecture mirrors how Siemens programming is structured in real industrial environments: reusable FB libraries are developed once, validated, and then instantiated across equipment without modification to the underlying logic — reducing commissioning time and standardising fault behaviour across an entire installation.
02 / System Architecture

Block Hierarchy & Data Flow

The Siemens S7 execution model enforces a strict separation between logic (Program Blocks) and state (Data Blocks). Unlike CODESYS-based platforms where a function block's static data can be declared inline within the same compilation unit, TIA Portal allocates a dedicated Instance DB for every FB call — either as a standalone DB or as a nested static variable within a parent FB's own DB.

Execution hierarchy — OB1 scan cycle
OB1
Main [Organisation Block]
→ calls →
FB_LineControl [FB2]
Line supervisor
→ backed by →
DB1
FB_LineControl_DB
│ (multi-instance static vars)
Motor1 : FB_Motor [FB1]
← state stored in DB1.Motor1.*
Motor2 : FB_Motor [FB1]
← state stored in DB1.Motor2.*

The critical architectural decision here is using multi-instance design rather than creating separate DBs for each motor. When Motor1 and Motor2 are declared as static variables of type "FB_Motor" inside FB_LineControl, their instance data is embedded directly within DB1. This eliminates DB proliferation as motor count grows and keeps the entire line's state visible within a single data structure — which is advantageous for diagnostics, SCADA integration, and HMI variable mapping.

Pattern
Multi-Instance Static Variables
  • Motor instances declared inside FB_LineControl as Static → "FB_Motor"
  • Single parent DB stores all nested instance data
  • No separate DB per motor required — scales to N motors cleanly
  • Consistent with Siemens library design guidelines for scalable machinery
Memory Model
Instance DB Allocation
  • TIA Portal auto-generates the instance DB on first FB call placement in OB1
  • DB address space contains all static variables: LatchedRun, StartTimer, fault bits
  • DB is not programmer-managed — the runtime maintains consistency between the FB interface and DB layout
  • Re-downloading the DB after interface changes preserves retain variables
Execution
Scan Cycle Behaviour
  • OB1 executes once per CPU scan cycle (~1–10 ms depending on configuration)
  • FB_LineControl is called once; internally calls both motor instances sequentially
  • All static variables persist between scans — motor latch state survives regardless of input signal duration
  • TON timer instruction accumulates elapsed time across scans using the DB-resident timer structure
03 / FB_Motor [FB1]

Motor Control Function Block — Interface & Logic

FB_Motor is the atomic control unit — the reusable component that models a single motor axis with all associated control logic. Its interface was designed to be fully generic: it accepts hardware signals as Bool inputs and drives outputs independently, making it suitable for any actuator type that fits the start/stop/feedback paradigm (motors, pumps, fans, conveyors).

Block Interface

Input Parameters
Inputs
  • Start — Bool: momentary start command from operator or supervisory logic
  • Stop — Bool: stop command; evaluated before start on every scan
  • FaultReset — Bool: clears the latched fault condition and resets the fault output
  • RunFeedback — Bool: auxiliary contact or drive ready signal confirming motor is running
  • FaultInput — Bool: external fault signal — motor overload, drive trip, or E-stop
Output Parameters
Outputs
  • MotorRunning — Bool: latched run state; drives the output coil or drive enable
  • Faulted — Bool: latched fault flag; indicates motor is in a faulted, non-runnable state
Static Variables (DB-Resident)
Internal State
  • LatchedRun — Bool: internal latch bit holding the energised state between scans
  • StartTimer — TON_TIME: run-confirmation watchdog; triggers fault if feedback absent after start

Structured Text Logic (SCL)

The block is implemented in SCL (Structured Control Language), Siemens' IEC 61131-3 compliant structured text dialect. SCL is selected over Ladder here because the conditional logic — prioritised fault evaluation, timer management, and output assignment — is more legible and less error-prone in a textual language. The logic evaluates in strict priority order per scan:

(* Priority 1: Fault Reset clears the latched fault state *)
IF #FaultReset THEN
    #Faulted := FALSE;
END_IF;

(* Priority 2: External fault input or run-confirmation timeout latches fault *)
IF #FaultInput THEN
    #Faulted    := TRUE;
    #LatchedRun := FALSE;  (* Immediate de-energise on fault *)
END_IF;

(* Priority 3: Start/Stop latching logic — fault state blocks start *)
IF #Faulted THEN
    #LatchedRun := FALSE;
ELSIF #Start THEN
    #LatchedRun := TRUE;
ELSIF #Stop THEN
    #LatchedRun := FALSE;
END_IF;

(* Run-confirmation watchdog: timer starts with LatchedRun; fault if no feedback *)
#StartTimer(IN := #LatchedRun, PT := T#3s);
IF #StartTimer.Q AND NOT #RunFeedback THEN
    #Faulted    := TRUE;
    #LatchedRun := FALSE;
END_IF;

(* Output assignment *)
#MotorRunning := #LatchedRun;
#Faulted      := #Faulted;
Compiler Note — Warning Resolved
During initial compilation, TIA Portal raised a warning on the fault evaluation branch: "The parameter '#Faulted' might not be initialized." This occurs because the compiler cannot statically guarantee the variable is assigned on all code paths before first use in the IF condition on line 11 — specifically when FaultReset has not yet executed. The resolution is to provide an explicit default initialisation of Faulted := FALSE in the variable interface table's Default Value column, ensuring the DB initialises the variable to a known state at first download. The block compiled successfully with 0 errors and 0 warnings after this correction (visible in Screenshot 3 → Screenshot 6).

Why SCL Over Ladder for This Block

04 / FB_LineControl [FB2]

Line Supervisor — Multi-Instance Coordinator

FB_LineControl is the supervisory layer responsible for managing two independent motor instances as a coordinated production line. Its role is signal routing: it receives line-level inputs (Start1/Stop1, Start2/Stop2, feedback and fault signals for each axis, and a shared ResetAll) and maps them to the corresponding FB_Motor inputs at each scan. It does not implement its own latching or fault logic — all such behaviour is encapsulated within the FB_Motor instances it contains.

Interface Design

Input Set — Motor 1
Axis 1 Signals
  • Start1, Stop1 — operator push-buttons or SCADA commands for axis 1
  • RunFb1 — run feedback from motor 1 auxiliary contact
  • Fault1 — fault input from motor 1 overload or drive trip
Input Set — Motor 2
Axis 2 Signals
  • Start2, Stop2 — independent controls for axis 2
  • RunFb2 — run feedback from motor 2
  • Fault2 — fault input from motor 2
Shared Signal
Global Reset
  • ResetAll — Bool: a single reset command routed to both motor instances simultaneously, enabling a single operator action to clear faults across the entire line

Multi-Instance Static Variable Declaration

The key implementation detail visible in Screenshot 4 is the Static variable section of FB_LineControl: Motor1 and Motor2 are declared with data type "FB_Motor". This instructs TIA Portal to allocate the full FB_Motor interface — including all its static variables — as a nested structure within FB_LineControl's own DB. No separate DBs for Motor1 or Motor2 are created.

(* FB_LineControl SCL body — motor instance calls *)

#Motor1(
    Start       := #Start1,
    Stop        := #Stop1,
    FaultReset  := #ResetAll,
    RunFeedback := #RunFb1,
    FaultInput  := #Fault1
);

#Motor2(
    Start       := #Start2,
    Stop        := #Stop2,
    FaultReset  := #ResetAll,
    RunFeedback := #RunFb2,
    FaultInput  := #Fault2
);
Engineering Note
Routing ResetAll to FaultReset on both instances is an intentional design choice. In a real panel, a single reset push-button clears all motor faults simultaneously — the operator does not need to reset each axis independently. This mirrors standard MCC (Motor Control Centre) reset behaviour and reduces operator action count after a line trip event.
05 / OB1 Integration

Main Program Block — FB Call & DB Assignment

Organisation Block 1 (OB1) is the cyclic execution entry point for the S7-1200. In this project, OB1 contains a single ladder rung that calls FB_LineControl [FB2] with its assigned instance DB (FB_LineControl_DB [DB1]). All inputs are connected to their corresponding absolute or symbolic addresses — in the simulation environment, test values are wired directly as static literals (e.g., true, false) to validate the calling interface before hardware I/O is mapped.

The rung visible in Screenshot 7 shows the standard Siemens FB call block representation in Ladder: the function block name and its instance DB are shown above the block boundary, input parameters are listed on the left with their connected signal sources, and EN/ENO flow controls execution. The FB runs on every OB1 scan as long as the enable rung is satisfied.

Scalability Observation
Adding a third motor axis to this architecture requires three actions: add Motor3 : "FB_Motor" to FB_LineControl's static section, add the corresponding input signals to its interface, and add the FB_Motor call with signal routing in the SCL body. OB1 and FB_Motor itself require zero changes. This demonstrates the library-oriented design philosophy in practice.
06 / Project Screenshots

Implementation Evidence

07 / Engineering Challenges

Problems Encountered & Resolved

1. Compiler Warning — Uninitialized Static Variable

The initial FB_Motor compilation produced a static analysis warning: "The parameter '#Faulted' might not be initialized." This surfaced because TIA Portal's SCL compiler performs conservative flow analysis — it traces all code paths and flags any variable that could be read before a guaranteed write. In the fault evaluation block, #Faulted is read in the condition of the outer IF statement before it is written in the FaultInput branch. Although the DB initial value of FALSE ensures correct runtime behaviour, the compiler correctly identified that this is not provable from the code structure alone. Resolution: explicit default value assignment in the interface table, ensuring the variable is always initialised at DB creation time. This also improves maintainability — future developers can see the intended initial state without tracing the code logic.

2. Navigating the FB/DB Coupling Model

Understanding that TIA Portal requires the DB to be re-generated and re-downloaded whenever the FB interface changes was a key operational learning. Adding or removing a parameter from an FB's interface renders the associated DB stale — the portal marks it with a warning indicator, and the program will not download cleanly until the DB is re-compiled. This is a tighter coupling than CODESYS, where interface changes are handled more transparently. Managing this sequence — change FB interface → compile FB → compile DB → download — is an essential operational habit in Siemens projects.

3. Cloud Simulation Constraints

PLCSIM Advanced, available in the local TIA Portal installation, provides full I/O simulation including force tables and watch tables for live variable monitoring. The TIA Portal cloud environment used here does not support PLCSIM, which meant the simulation phase — where inputs would be forced and output states observed in real time — could not be executed. This required a shift in validation strategy: logic correctness was verified through structured code review, compilation output analysis, and conceptual walkthrough of each code path rather than live forcing. This approach — design-by-review rather than design-by-debugging — is actually representative of how safety-critical code is validated in regulated environments where live simulation may not be available.

4. Multi-Instance Type Resolution

Declaring a Static variable as type "FB_Motor" inside FB_LineControl requires that FB_Motor is already compiled and its interface is consistent. During development, an out-of-order compile sequence caused TIA Portal to report an unresolved type reference on the Static variable declaration. The resolution was straightforward — compile FB_Motor first, then FB_LineControl — but this dependency order is worth documenting: in larger projects with deeper FB nesting, a dependency graph of block compilation order is a useful project management artefact.

08 / Learning Outcomes & Competencies

Skills Demonstrated

Siemens FB/DB architecture. Designed and implemented a two-level FB hierarchy with correct instance DB allocation, demonstrating understanding of how Siemens separates program logic from state persistence — a fundamental difference from CODESYS and Allen-Bradley PAC platforms.
Multi-instance design for scalable systems. Implemented the multi-instance static variable pattern, embedding FB_Motor instances within FB_LineControl's DB — the standard Siemens technique for building scalable machinery libraries without DB proliferation.
SCL programming with IEC 61131-3 compliance. Wrote structured, priority-ordered control logic in SCL with explicit fault hierarchy, named FB parameter calls, and deliberate code structure chosen for maintainability and review clarity.
TON timer integration inside Function Blocks. Implemented a run-confirmation watchdog using a DB-resident TON_TIME timer, understanding how the timer structure persists across scan cycles within the instance DB and accumulates elapsed time correctly.
Fault detection and latching architecture. Designed a priority-evaluated fault model — external fault input, run-confirmation timeout, and reset — that reflects real-world motor protection requirements and integrates with a global reset signal.
Compiler diagnostic interpretation and resolution. Identified, understood, and resolved a static analysis initialisation warning — demonstrating the ability to engage with compiler output analytically rather than treating warnings as ignorable noise.
Structured program organisation in TIA Portal. Maintained a clean project tree with logically separated program blocks, consistent naming conventions, and a compile-order awareness appropriate for hierarchical FB libraries.

Tools & Technologies

Siemens TIA Portal (Cloud)
S7-1200 CPU 1212C DC/DC/DC
SCL — IEC 61131-3 Structured Text
Function Blocks (FB)
Instance Data Blocks (DB)
Multi-Instance Architecture
TON Timer (IEC 61131-3)
LAD — Ladder Diagram (OB1)
Symbolic Addressing
PLCSIM (Conceptual Validation)
×
Expanded screenshot