PLC Programming Fundamentals: Ladder, ST, FBD, SFC
PLC Programming Fundamentals: Ladder, ST, FBD, SFC
Programmable Logic Controllers (PLCs) remain the backbone of industrial automation because they combine deterministic control, maintainability, and standardized programming. Yet many projects still suffer from poor language selection, inconsistent coding style, weak diagnostics, and insufficient attention to safety and compliance. For electrical engineers, automation engineers, panel builders, and SCADA architects, the challenge is not simply “how to program a PLC,” but how to choose the right IEC 61131-3 language, structure the logic for lifecycle maintenance, and align the implementation with European compliance expectations.
This guide explains the four principal PLC programming languages used in modern automation: Ladder Diagram (LD), Structured Text (ST), Function Block Diagram (FBD), and Sequential Function Chart (SFC). It focuses on practical engineering use, with references to IEC 61131-3 and related standards where relevant.
1. The PLC Programming Model
PLC programming is defined primarily by IEC 61131-3, which standardizes programming languages, program organization, data types, and execution concepts. In practice, a PLC application is built from:
- Tasks: cyclic, event-driven, or time-triggered execution.
- Programs: top-level control logic assigned to tasks.
- Function blocks: reusable logic with internal state.
- Functions: stateless operations returning a value.
For industrial projects, the standard’s value is interoperability and maintainability. IEC 61131-3 also defines the semantics of execution order, variable scope, and language behavior. When designing a control system, it is important to understand that language choice affects readability, debugging, and testability more than raw performance in most modern PLCs.
In European projects, PLC logic often sits within a broader compliance framework including the Machinery Directive 2006/42/EC or the newer Machinery Regulation transition path, EN ISO 13849-1 for safety-related control, and IEC 60204-1 for electrical equipment of machines. Cybersecurity requirements increasingly reference IEC 62443 and, for critical sectors, NIS2 governance expectations.
2. Ladder Diagram (LD): The Electrical Engineer’s Language
Ladder Diagram is the closest to relay logic and remains the most familiar language for electrical engineers and maintenance technicians. It represents logic as horizontal “rungs” between power rails.
Where LD excels
- Discrete control: motors, valves, interlocks, permissives.
- Simple diagnostics: easy to trace energized conditions.
- Maintenance readability: clear for electricians and technicians.
- Commissioning speed: intuitive for panel-based control systems.
Engineering considerations
LD is ideal for contactor logic, permissive chains, alarm latching, and start/stop circuits. However, it can become unwieldy for arithmetic-heavy algorithms, string manipulation, or data processing. Complex nested branches often reduce readability. For this reason, many teams use LD for field I/O and machine permissives, while delegating calculations or recipe management to ST.
From a standards perspective, LD is defined in IEC 61131-3, and its use in machine control must still respect safety architecture rules. If the logic is safety-related, it should not be assumed that “Ladder looks safe.” Safety function design must be validated against the required performance level or safety integrity level, not merely implemented in a familiar language.
3. Structured Text (ST): The Engineer’s Algorithmic Tool
Structured Text is a high-level, Pascal-like language suitable for calculations, loops, state logic, array handling, and data transformations. It is often the best choice when the control problem resembles software more than relay logic.
Where ST excels
- Mathematics and scaling.
- State machines and mode management.
- Batch, recipe, and data handling.
- Communication parsing and protocol logic.
Engineering considerations
ST improves expressiveness and reduces code volume for nontrivial logic. It is especially useful when implementing reusable algorithms such as PID supervision, energy calculations, or alarm filtering. However, it can be harder for maintenance personnel to troubleshoot if coding standards are weak. Good ST should be modular, commented, and structured with explicit naming conventions.
IEC 61131-3 defines ST syntax and execution. In practice, teams should avoid hidden side effects, deeply nested conditionals, and unbounded loops in cyclic tasks. Deterministic scan time is essential. If a loop can execute unpredictably, it may violate the timing assumptions of the task.
4. Function Block Diagram (FBD): Visual Logic for Process Control
FBD represents control logic as interconnected blocks. It is common in process automation, analog control, and signal conditioning. It is especially useful when the logic is naturally block-oriented: timers, comparators, arithmetic blocks, filters, and PID controllers.
Where FBD excels
- Analog control loops and interlocks.
- Signal conditioning and scaling.
- Reusable function blocks from vendors.
- Control logic that benefits from visual traceability.
Engineering considerations
FBD is often preferred in process plants because engineers can visually inspect signal flow. It can be easier to review than long text-based routines when the logic is composed of standard blocks. Nevertheless, large FBD networks can become cluttered. Good engineering practice is to keep each network small and functionally coherent.
IEC 61131-3 standardizes FBD, and many PLC platforms provide certified or vendor-validated blocks for timers, filters, and PID control. When using vendor blocks, verify parameter ranges, scaling assumptions, and execution order. In safety-related applications, confirm whether the block is suitable for the intended safety function and whether it is part of a certified safety library.
5. Sequential Function Chart (SFC): Best for Machine Sequences
SFC is used to model stepwise sequences, transitions, and actions. It is particularly effective for machines with distinct phases such as start-up, automatic cycle, fault handling, and shutdown.
Where SFC excels
- Packaging machines and material handling.
- Batch processes and recipe-driven operations.
- Equipment with clear states and transitions.
- Sequence logic requiring traceability and step diagnostics.
Engineering considerations
SFC helps separate sequence control from action logic. Each step can activate outputs or call subroutines, while transitions define when the process advances. This improves readability and troubleshooting during commissioning. However, SFC should not be used as a substitute for robust interlock design. If a transition condition is unsafe or incomplete, the sequence can advance incorrectly.
IEC 61131-3 defines SFC as a formal method for sequencing. For machine safety, sequence logic must still be integrated with safety-rated architecture. A common best practice is to keep safety functions independent of standard sequence logic, with the safety chain removing power or enabling conditions regardless of program state.
6. Worked Example: Motor Start Sequence with Interlocks and Analog Monitoring
Consider a 15 kW, 400 V, three-phase motor with assumed power factor $\\cos\\varphi = 0.85$ and efficiency $\\eta = 0.90$. Estimate the full-load current and use that value to define overload and alarming thresholds.
The approximate current is:
$$I = \\frac{P}{\\sqrt{3} \\cdot V \\cdot \\cos\\varphi \\cdot \\eta}$$
Substituting:
$$I = \\frac{15000}{1.732 \\cdot 400 \\cdot 0.85 \\cdot 0.90}$$
$$I \\approx \\frac{15000}{530.8} \\approx 28.3\\,A$$
Assume the project standard sets:
- Warning alarm at 110% of rated current.
- Trip request at 125% of rated current for the PLC logic, with final protection handled by the motor protection device.
Then:
$$I_{warn} = 1.10 \\times 28.3 = 31.1\\,A$$
$$I_{trip} = 1.25 \\times 28.3 = 35.4\\,A$$
A practical implementation might use:
- LD for start/stop pushbuttons, overload contact, E-stop permissive, and seal-in logic.
- ST for current scaling, alarm thresholds, and runtime accumulation.
- FBD for analog filtering and comparator blocks.
- SFC for the sequence: Idle → Starting → Running → Stopping → Fault.
Example logic structure:
- Idle: all outputs off, waiting for start command.
- Starting: energize contactor, verify auxiliary feedback within a timeout.
- Running: monitor current, temperature, and permissives.
- Stopping: de-energize contactor and confirm motor stopped.
- Fault: latch alarm, require reset after fault clearance.
This example illustrates why language mixing is often the best engineering approach. LD provides clear permissive logic, ST handles the arithmetic, FBD handles analog signal conditioning, and SFC organizes the sequence.
7. Comparison Matrix: Choosing the Right Language
| Language | Best Use | Strengths | Limitations | Typical Users |
|---|---|---|---|---|
| LD | Discrete machine control | Readable, intuitive, maintenance-friendly | Poor for complex math and data handling | Electrical engineers, technicians |
| ST | Algorithms, data, calculations | Compact, powerful, flexible | Less intuitive for non-programmers | Automation engineers, software-oriented teams |
| FBD | Analog and process control | Visual, modular, block-based | Can become cluttered at scale | Process engineers, control engineers |
| SFC | Sequenced operations | Clear step logic, strong diagnostics | Not ideal for dense interlock logic | Machine builders, system integrators |
8. Standards and Compliance Notes
For European projects, PLC programming is not only a software issue; it is part of the machine’s technical file and validation evidence. Relevant references include:
- IEC 61131-3: PLC programming languages and program organization.
- IEC 60204-1: Electrical equipment of machines; important for control circuits, stop functions, and emergency stop integration.
- EN ISO 13849-1: Safety-related parts of control systems; performance level design and validation.
- IEC 62061: Safety-related control systems in machinery; SIL-oriented approach.
- IEC 62443: Industrial automation and control system cybersecurity.
- NFPA 79: Electrical standard for industrial machinery, often relevant in North American projects or global harmonization.
- ISA-88: Batch control models, especially useful where SFC and recipe management are combined.
Clause-level interpretation depends on the edition in use, but the engineering principle is consistent: program logic must be documented, validated, and aligned with the risk assessment. Safety functions should be designed from the risk reduction target backward, not added as an afterthought.
9. Practical Engineering Rules for Better PLC Code
- Use LD for simple discrete logic and maintenance-friendly interlocks.
- Use ST for calculations, data structures, and state machines.
- Use FBD for analog processing and block-based control.
- Use SFC for machine sequences and phase-based operations.
- Keep safety logic separate from standard control logic unless a certified safety architecture is being used.
- Document scan-time assumptions, task priorities, and watchdog settings.
- Standardize naming, comments, and alarm handling across projects.
Conclusion
The most common PLC programming mistakes are not syntax errors; they are engineering errors. Teams often choose one language for everything, creating unreadable logic and difficult commissioning. Others mix standard and safety functions without clear separation, violating good practice and complicating validation. Another frequent problem is poor handling of timing, where long loops, unnecessary calculations, or unclear task scheduling cause scan-time instability. To avoid these issues, select the language that best fits the control problem, document assumptions, validate against the required standards, and keep the logic modular enough for both commissioning and long-term maintenance. In industrial automation, good PLC code is not only functional; it is diagnosable, deterministic, and compliant.
Frequently asked questions
When should I choose Ladder Diagram (LD) over Structured Text (ST) for a PLC project on a European industrial site?
Use Ladder Diagram for discrete control, interlocking, and maintenance-friendly logic such as motor starters, permissives, and alarms, because it maps well to relay schematics and is widely understood by electricians and panel technicians. IEC 61131-3 defines LD and ST as standard PLC languages, and many EPC teams use LD for hardwired-equivalent logic while reserving ST for complex calculations, data handling, and algorithmic tasks.
How do Structured Text and Ladder compare for implementing PID-related sequencing and analog control in SCADA-integrated systems?
Structured Text is typically better for analog scaling, setpoint management, state calculations, and reusable function blocks because it supports clear expressions and loops. In IEC 61131-3 environments, PID control is often implemented in function blocks, while IEC 61511 projects commonly separate safety functions from basic process control to avoid mixing control and SIS logic.
What are the practical differences between Function Block Diagram (FBD) and Ladder for packaging or process skids with many interlocks?
FBD is often preferred when the application uses many reusable blocks such as timers, comparators, selectors, and analog conditioning, because signal flow is visually clear and modular. IEC 61131-3 supports both FBD and LD, and FBD is especially useful in process automation and skid packages where engineers need block-level reuse across multiple identical units.
How should Sequential Function Chart (SFC) be used for machine or process sequences in EPC projects?
SFC is best for step-based operations such as start-up, purge, fill, heat, and shutdown sequences because it separates sequence logic from action logic and improves commissioning clarity. IEC 61131-3 defines SFC for sequential control, and it is commonly paired with LD or ST actions to keep sequence states, transitions, and interlocks maintainable during FAT and SAT.
What coding practices improve portability between PLC brands in international projects?
Use IEC 61131-3-compliant language constructs, avoid vendor-specific instructions where possible, and encapsulate logic in standard function blocks with clear interfaces. Portability is improved when tag naming, data types, and library dependencies are documented consistently, which helps when projects move between platforms from Siemens, Schneider Electric, Rockwell, or Beckhoff.
How do I structure PLC code to support panel testing, FAT, and later SCADA integration?
A good structure separates hardware I/O mapping, device control, sequence logic, and alarm handling into distinct program layers or function blocks. This makes FAT more efficient because panel testers can simulate inputs at the I/O layer, while SCADA engineers can map status, commands, and alarms consistently using standard tag conventions and alarm philosophy aligned with ISA-18.2.
What standards should I reference when programming PLCs for industrial panels in Europe?
IEC 61131-3 is the primary standard for PLC programming languages, including LD, ST, FBD, and SFC, and IEC 60204-1 is commonly referenced for machinery electrical equipment and control circuits. For functional safety, IEC 61508 and IEC 62061 are relevant, while NFPA 79 may apply on projects with North American requirements or mixed compliance scopes.
What are the most common PLC programming mistakes that cause commissioning delays on global automation projects?
Common issues include mixing safety and basic control logic, poor tag naming, undocumented interlocks, and using overly complex ST where simpler LD or FBD would be easier to verify. Commissioning delays also occur when SFC transitions are not fully defined or when alarm and state logic are not aligned with the SCADA philosophy, which creates ambiguity during SAT and operator training.
Related services
Related industries
- Manufacturing & Process Industry
Discrete and process manufacturing plants — assembly, packaging, machining, batching — where PLC/SCADA, drives, and standardized panels run production lines and OEE drives investment decisions.
Read → - Food & Beverage
Hygienic-design automation and panels for dairies, breweries, beverage lines, and food processing — IP65/IP69K enclosures, washdown-rated control cabinets, traceability, and FSMA/EU 178/2002 compliance.
Read →