Ladder Logic vs Function Block Diagram: Comparison, Code Examples, and Decision Guide
This is a free printable ladder logic vs function block: download the diagram as SVG or open it and print to paper or PDF.
Ladder logic (LD) and function block diagram (FBD) are both graphical IEC 61131-3 PLC languages, but they represent control logic through completely different metaphors — LD uses a current-flow relay circuit model while FBD uses a data-flow signal-routing model. This guide compares them with side-by-side AND, OR, TON timer, and PID examples, explains how each executes, and gives a clear decision guide for choosing the right language for your application.
IEC 61131-3 standardises five PLC programming languages. Among the three graphical languages (LD, FBD, and SFC), ladder logic and function block diagram are the two most widely used. Both are supported by all major PLC platforms — Siemens TIA Portal, Allen-Bradley Studio 5000, Codesys, and Schneider EcoStruxure all permit free mixing of LD and FBD within a single project.
The current-flow metaphor in Ladder Diagram:
In LD the programmer draws horizontal rungs — each rung is a row of contacts (input conditions) connected in series and/or parallel, terminated by a coil (output). The mental model is electrical: current flows from the left power rail through contacts to energise coils on the right rail. A TRUE contact passes current; a FALSE contact blocks it. This directly mirrors the relay panel circuits that PLCs replaced in the 1970s. The notation (XIC = normally open, XIO = normally closed, OTE = output energise) was designed to be immediately readable by relay-trained electricians.
The data-flow metaphor in Function Block Diagram:
In FBD the programmer places functional blocks (rectangular boxes with labelled input and output pins) on a canvas and connects them with signal wires. The execution model is data flow: a block computes its output pins from its input pins, and those output pins become inputs to the next connected block. There is no left-to-right power rail — data moves from left to right through the network, but the metaphor is signal processing, not electrical current.
The FBD paradigm feels natural to control engineers familiar with block diagrams from classical control theory (Bode plots, P&ID loops, signal processing chains). It is the language of choice for process automation, continuous control, and any application involving PID loops, signal conditioning, or multi-variable calculations.
Side-by-side AND gate comparison:
In LD: two XIC contacts in series — |--[XIC A]--[XIC B]--( OTE Y )--|. Current flows to Y only when A AND B are both TRUE.
In FBD: an AND2 block with A connected to input pin 1, B to input pin 2, and output pin Y. The AND block computes Y = A AND B. A wire segment connects A's source to IN1, B's source to IN2, and the OUT pin to Y's destination.
Both are equivalent. The LD version is more compact for a single gate; the FBD version becomes more legible when the gate is part of a larger data-flow network.
Side-by-side OR gate:
LD: two parallel branches each with one XIC contact feeding the same OTE coil. FBD: an OR2 block with two input pins and one output, connected identically to the AND2 example but with OR semantics.
Side-by-side TON timer:
In LD the TON is a graphical block placed inline on a rung: XIC Enable → [TON Timer, PT:=T#10S] → XIC Timer.Q → OTE Output. The enable rung must be TRUE continuously for the timer to run.
In FBD the TON appears as a function block with explicitly labelled pins: IN (enable), PT (preset time), Q (done bit output), and ET (elapsed time output). The programmer connects a BOOL variable wire to IN, a TIME constant to PT, and takes the Q output wire to any subsequent logic. The ET output wire can be connected to a display or threshold comparison block, making it easy to build timer-based ramp logic without additional rungs.
The FBD TON block is visually clearer about the timer's interface than the LD version because all four pins (IN/PT/Q/ET) are visible and labelled, whereas LD timer blocks typically show only the EN input and DN output prominently.
PID controller — where FBD is objectively the superior choice:
A PID (proportional-integral-derivative) controller requires three mathematical terms computed from a process variable and setpoint, summed with configurable gain coefficients, and output to a control signal. In FBD this is a single PID_Compact block (Siemens TIA Portal terminology) with clearly labelled pins: Setpoint, Actual_Value, Output, Mode, and parameter inputs. Two wires in, one wire out. The block encapsulates all the integration, differentiation, anti-windup, and bumpless transfer logic.
In LD, a PID would require: a subtraction rung (error = setpoint - PV), a multiplication rung (proportional term = Kp × error), an integration accumulator with multiple ADD rungs, a differentiation term using previous-scan value storage, a summation rung, and output limiting logic. This easily totals 15–25 rungs of pure math that are nearly impossible to read without knowing the PID algorithm in advance. In practice, no serious engineer implements PID in LD rungs; they call the manufacturer's PID function block from any language including LD — but using FBD exposes the block's signal connections in the most natural way.
Where LD excels over FBD:
For discrete I/O control — motor starters, valve control, conveyor sequencing — LD's rung-by-rung structure maps naturally to the list of conditions that must be TRUE before an output energises. The visual linear structure makes it immediately clear what interlocks are in place. Online monitoring in LD mode shows exactly which contact in a rung is blocking the output from energising, which is invaluable for maintenance troubleshooting in a factory environment.
FBD does not have a direct equivalent of the LD rung as a diagnostic unit. During online monitoring in FBD you can see the value on each wire, but tracing a fault through a network of connected blocks requires following multiple signal paths simultaneously, which is less intuitive for a maintenance electrician used to relay diagrams.
Execution model differences:
LD executes sequentially: rungs are evaluated one at a time, in order, from top to bottom. The output of Rung 1 is immediately visible to Rung 2 in the same scan. This sequential execution means that the order of rungs matters — a bug can be introduced by placing a rung in the wrong position.
FBD executes as a data-flow network: the runtime analyses the network graph and determines the computation order based on data dependencies (blocks whose outputs are not consumed by any other block in the same scan execute last). In practice most platforms evaluate FBD blocks left-to-right, top-to-bottom by default, but the programmer can override this with explicit execution order assignments.
Reusability and function block libraries:
This is FBD's most powerful feature that no competitor article clearly explains. In FBD, a custom function block is defined once — with its own variable declarations, internal logic, and pin interface — and can be instantiated (placed) multiple times in the project. Each instance has its own copy of internal state (called instance data). This means a PID block can be written once and used for twenty control loops simultaneously, each with independent tuning parameters and process variable connections. The LD equivalent would require copying 20 sets of rungs and carefully ensuring every address is different — a maintenance nightmare.
Edge detection in FBD vs LD:
LD uses OSR (one-shot rising, or P_TRIG in IEC notation) and OSF (one-shot falling) contact instructions for edge detection. FBD uses R_TRIG and F_TRIG function blocks with EN/Q/CLK pins. When migrating an LD program with OSR contacts to FBD, every OSR must be replaced with an R_TRIG instance — a common migration pain point because R_TRIG requires an instance declaration for each use.
Industry adoption: LD dominates discrete manufacturing (automotive assembly, packaging, machine tools) where PLC programs are maintained by electricians. FBD dominates process industries (oil and gas, chemicals, water treatment, pharmaceuticals) where DCS (distributed control system) engineers and control system designers maintain the programs. PLCopen's motion control function block library — the standard for servo and robotics control — is defined entirely in FBD, making FBD mandatory for any application using PLCopen motion.
Draw ladder rungs or function block networks in circuitdiagrammaker's free online tool — both styles are supported, and you can export clean SVG or PDF for IEC documentation at any stage.
How to wire ladder logic vs function block
- Choose your primary paradigm based on audience and application If maintenance will be performed by relay-trained electricians, use LD for all discrete I/O logic. If the program is maintained by control engineers or software developers and involves continuous control or data processing, use FBD or ST. For most industrial machines, LD is the pragmatic default.
- Map AND/OR logic: LD uses contacts, FBD uses AND/OR blocks In LD: series contacts = AND, parallel branches = OR. In FBD: place an AND2 or OR2 block, connect input variable wires to IN1 and IN2 pins, and take the OUT pin to the next block or variable. For 3+ inputs use AND3/OR3 blocks or chain two 2-input blocks.
- Implement timers: LD inline block vs FBD explicit pin connections In LD: place a TON block on a rung with an XIC enable contact. In FBD: declare a TON instance variable, place the TON block, connect a BOOL wire to IN, a TIME constant to PT. Read Q for the done bit and ET for the elapsed time — both outputs are immediately available as wires for further connections without additional rungs.
- Implement PID control: always use FBD or ST function block Declare a PID_Compact (TIA Portal) or PIDE (Studio 5000) instance. In FBD, place the block and connect wires: Setpoint, Actual_Value to input pins; read Output to drive the analog actuator. Configure Kp, Ki, Kd parameters in the block's property panel. Never attempt to implement PID as LD math rungs — use the manufacturer-provided FBD function block.
- Use FBD for reusable function block libraries Define a custom function block (e.g. a motor controller FB with Start, Stop, Speed inputs and Running, Fault outputs) once. Instantiate it once per motor in the FBD network. Each instance has independent internal state. This is far more maintainable than copying LD rung sets for each motor.
- Use LD for online fault tracing on the machine floor When commissioning or troubleshooting, switch the PLC software to online monitoring mode for LD POUs. Energised rungs and contacts highlight in real time. Identify the blocking contact by scanning left to right. This is the fastest method for a maintenance technician to diagnose a stuck output without a laptop and watch table.
- Interface LD and FBD POUs through global variables A global BOOL flag written by an LD POU (e.g. Motor_Running) can be read as an input pin on a FBD block in a different POU. Define all cross-POU interfaces in the global variable list before building either POU. Document the variable direction (writer POU → reader POU) in a comment.
Specifications
| IEC 61131-3 language designation | LD — Ladder Diagram; FBD — Function Block Diagram |
|---|---|
| Visual metaphor | LD: relay circuit (current flow, left-to-right rungs); FBD: signal network (data flow, blocks and wires) |
| AND logic representation | LD: series XIC contacts; FBD: AND2/AND3 block |
| OR logic representation | LD: parallel branches; FBD: OR2/OR3 block |
| NOT logic representation | LD: XIO (NC) contact; FBD: NOT block or negated pin (small circle on pin) |
| Timer representation | LD: TON block inline on rung; FBD: TON instance block with IN/PT/Q/ET pins explicitly wired |
| PID suitability | LD: poor (impractical in raw rungs); FBD: excellent (purpose-built for signal-flow control loops) |
| Code reuse mechanism | LD: copy-paste rung sets; FBD: instantiable function block libraries (instance data per use) |
| Online fault tracing | LD: native rung highlighting, immediate for electricians; FBD: wire value display, requires more interpretation |
| Execution model | LD: sequential rung-by-rung scan; FBD: data-flow network (dependency-ordered evaluation) |
| Edge detection | LD: OSR/OSF contact instructions; FBD: R_TRIG/F_TRIG instance blocks |
| Primary industry use | LD: discrete manufacturing, machine control; FBD: process control, motion (PLCopen), continuous loops |
Safety warnings
- Safety function blocks (SIL/PLe rated FBs such as ESTOP, DOOR_MON) must only be used in certified safety PLC projects (Siemens F-CPU, Allen-Bradley GuardLogix). Do not call safety FBs from a standard PLC project — the execution and diagnostics model differs.
- FBD execution order in feedback loops must be explicitly verified. An algebraic loop (cyclic data dependency) can cause the runtime to use stale values from the previous scan for one or more blocks, creating control errors that are difficult to detect in simulation.
- When converting LD programs to FBD, verify that the execution order of the FBD network matches the functional intent of the original LD rung order. Execution order changes can alter the behaviour of SET/RESET and edge-detection logic.
- PLCopen motion control FBDs (MC_MoveAbsolute, MC_MoveVelocity, MC_Stop) are safety-relevant. Always implement the MC_Stop function block in a higher-priority task and verify the axis deceleration behaviour meets the machine's safe stop time requirements per IEC 62061.
Tools needed
- IEC 61131-3 compliant PLC programming platform supporting both LD and FBD: Siemens TIA Portal, Allen-Bradley Studio 5000, Codesys, Schneider EcoStruxure, or OpenPLC
- circuitdiagrammaker.com for drafting and documenting LD rungs as SVG/PDF exports for functional design specifications
- Function block library documentation from the PLC manufacturer (list of available FBs, pin definitions, and usage examples)
- Instance variable naming convention: each FBD function block instance needs a unique variable name in the declaration table
- Signal flow diagram (block diagram drawn on paper or whiteboard) before building the FBD network — plan the data path before placing blocks
Common mistakes
- Implementing PID control as LD math instruction rungs instead of using the manufacturer's FBD PID function block — this produces fragile, unreadable code that is expensive to tune and maintain
- Forgetting to declare R_TRIG/F_TRIG instances when migrating OSR/OSF contacts from LD to FBD — each edge-detection point requires a separate instance variable declaration in FBD
- Connecting FBD block output pins to the same input variable as an LD OTE coil in the same scan — both will attempt to write the variable, and the last execution order wins, causing non-deterministic behaviour
- Using FBD for simple discrete on/off control in a maintenance-technician environment — the lack of intuitive rung-level fault tracing increases troubleshooting time and requires more specialised technician training
- Neglecting to configure FBD block execution order explicitly when the data-flow network contains feedback connections (output of block B feeds input of block A which feeds B) — this creates an algebraic loop that compilers handle differently per platform
Troubleshooting
- FBD PID block output drives the actuator but the process variable does not respond correctly
- Cause: Actual_Value input wire is connected to the wrong analog tag, or engineering unit scaling has not been applied to the raw AI value before connecting it to Actual_Value Fix: Verify the Actual_Value pin source using the cross-reference. Confirm the scaling block (or scaling parameters in the PID block) converts the 0-27648 (Siemens) or 0-32767 (AB) raw AI count to the correct engineering unit range.
- LD motor start rung energises but the equivalent FBD SR bistable does not latch when migrated
- Cause: The SR block SET and RESET pin connections are inverted — RESET has higher priority in SR but lower priority in RS bistable. Polarity is swapped from the expected LD seal-in behaviour. Fix: Verify whether the manufacturer's bistable block is SR (RESET priority) or RS (SET priority). For a standard motor start/stop where Stop takes priority, use SR. Check pin labels carefully — some platforms label them S1/R (SR) vs S/R1 (RS).
- R_TRIG FBD block fires on every scan instead of only once per rising edge
- Cause: A separate R_TRIG instance was not declared — the same instance variable name is being reused for multiple edge-detection points, causing state corruption Fix: Declare a unique R_TRIG instance variable for every edge-detection point in the project. Rename instances descriptively (e.g. Start_Edge : R_TRIG; Reset_Edge : R_TRIG). Never reuse an edge-detection instance for multiple signals.
- Online monitoring shows unexpected wire values in FBD — a TRUE wire appears to produce no effect on a connected block
- Cause: The block execution order places the reading block before the writing block in the same scan. The reading block sees the previous scan's output of the writing block, not the current one. Fix: Check and adjust the FBD block execution order numbers (available in the block properties of most platforms). Ensure writing blocks have a lower execution order number than the reading blocks that consume their output.
- Migrated LD timer program causes earlier-than-expected output when converted to FBD TON
- Cause: The LD TON was enabled by the output of another rung using a memory bit that is evaluated before the TON rung. In FBD the block order was reversed during migration, so the TON now uses the memory bit's previous-scan value Fix: In FBD, re-order the TON block to execute after the block(s) that produce its enable signal. Verify by single-stepping the scan and watching the ET and Q outputs update in the correct sequence.
Frequently asked questions
What is the main difference between ladder logic and function block diagram?
Ladder logic uses a current-flow relay circuit metaphor: conditions are contacts in series/parallel and outputs are coils. Function block diagram uses a data-flow signal-routing metaphor: rectangular blocks with input and output pins are connected by wires. LD is optimised for discrete on/off control and maintenance; FBD is optimised for continuous control, modularity, and algorithm reuse.
Which is better for PID control — ladder logic or function block diagram?
FBD is the clear choice for PID control. PID function blocks (TON, PID_Compact, PIDE) are defined with explicit input and output pins that map directly to the FBD block diagram paradigm. Implementing PID in LD math instruction rungs is technically possible but produces unreadable, unmaintainable code.
Can I convert a ladder logic program to function block diagram?
Yes. Series contacts become AND gates, parallel branches become OR gates, XIO contacts become NOT gates, OTE coils become wire connections to BOOL variable inputs. Timers, counters, and math blocks translate directly. Edge-detection OSR contacts become R_TRIG instance blocks. Some PLC software (TIA Portal, Studio 5000) can do partial automatic conversion.
Why do process industries prefer function block diagram over ladder logic?
Process industries (oil and gas, chemicals, water treatment) use continuous analog control loops that are naturally expressed as signal-flow networks. FBD's data-flow metaphor matches the P&ID diagrams that process engineers create. Additionally, DCS systems used in process industries (Honeywell, Emerson, ABB) have traditionally used FBD as their primary language, training an entire workforce in FBD notation.
Is function block diagram harder to learn than ladder logic?
For electricians with relay background, LD is easier. For control engineers with a signals and systems background, FBD is natural. For software developers, neither has a significant advantage — both are graphical and relatively simple once IEC 61131-3 variable types are understood.
Do all PLCs support both ladder logic and function block diagram?
Most modern mid-range and high-end PLCs support both (Siemens S7, Allen-Bradley CompactLogix/ControlLogix, Schneider Modicon M340/M580, Codesys-based PLCs). Some entry-level PLCs (LOGO!, certain Omron models, CLICK PLCs) support only LD. Always verify language support in the PLC's programming environment specifications.
Can I use ladder logic and function block diagram in the same PLC project?
Yes. IEC 61131-3 allows multiple languages in a single project. A common pattern is LD POUs for machine interlocks and discrete I/O control, FBD POUs for PID loops and analog signal processing, and ST POUs for data manipulation. All POUs share variables through the global variable list.
Which language does Siemens TIA Portal use by default?
TIA Portal supports all IEC 61131-3 languages. New Organisation Blocks default to LAD (Ladder) or FBD depending on the context: main OBs often default to LAD; function blocks and functions default to the last selected language. SCL (Structured Control Language, Siemens' name for ST) is also fully supported. The default can be changed in project settings.