IEC 61131-3 · Sequential Function Chart

SFC / GRAFCET Lab

Ladder shows the wiring and Structured Text the logic. A sequential function chart shows the sequence: the order in which a machine does things, and the condition that ends each step. The 16 lessons here take you from a two-step chart to a CIP wash, and scripted commissioning tests on the SFC engine in your browser check every one.

IDLEStartPB AND PartAtCLAMPClamp.T >= T#500msDRILL
Lessons
16
Completed
0/16
XP earned
0/1500
Chapters
4

The problem

A machine runs in sequences: load, clamp, drill, release, unload. In ladder you build that sequence out of latches and step bits. In SFC the steps are the program, and the active one is lit up on the screen.

What you will build

You build 16 charts, from a two-step lamp to a full CIP recipe. A scripted commissioning test in the browser proves each lesson before it counts as passed.

No PLC required

The SFC engine runs in your browser, so you need no hardware and no licence. Open a lesson, press Run and watch the token move.

Chapter 1: Steps and transitions

0/4 completeSiemens S7-GRAPH · CODESYS SFC · Schneider GRAFCET

The token, the guard and the scan cycle — how a chart actually executes.

  • Pass the previous lesson to unlock this one
  • Pass the previous lesson to unlock this one
  • Pass the previous lesson to unlock this one

Chapter 2: Action qualifiers

0/4 completeIEC 61131-3 action qualifiers, identical across vendors

All eleven IEC qualifiers — the difference between a command and a latch.

  • Pass the previous lesson to unlock this one
  • Pass the previous lesson to unlock this one
  • Pass the previous lesson to unlock this one
  • Pass the previous lesson to unlock this one

Chapter 3: Chart structure

0/4 completeIEC 61131-3 divergence and convergence · GRAFCET (IEC 60848)

Alternative and simultaneous branches, convergence, priority, and loops back to an earlier step.

  • Pass the previous lesson to unlock this one
  • Pass the previous lesson to unlock this one
  • Pass the previous lesson to unlock this one
  • Pass the previous lesson to unlock this one

Chapter 4: Real machines

0/4 completePatterns taken from installed plant

Complete sequences: a batch, a robot handshake, abort and recovery, a CIP wash.

  • Pass the previous lesson to unlock this one
  • Pass the previous lesson to unlock this one
  • Pass the previous lesson to unlock this one
  • Pass the previous lesson to unlock this one

Reference

SFC, GRAFCET and the vendor tools

What SFC and GRAFCET are

A sequential function chart (SFC) is one of the IEC 61131-3 PLC languages. You draw the machine as steps, which say what it is doing now, and transitions, which say what ends that step. An active step holds a token and its actions drive the outputs. A transition fires when every step above it is active and its condition is TRUE, and the token moves to the step or steps below.

GRAFCET is where SFC came from. It began as a French standard in the early 1980s and is now IEC 60848, a specification language: you use it to describe how a machine must behave, in a functional specification or on a drawing, before anyone chooses a PLC. SFC is the language that runs inside the controller, and it took its symbols from GRAFCET.

The two look alike, but their rules differ. GRAFCET clears every transition that can be cleared at the same moment, so two TRUE conditions under an alternative branch start both branches and the designer has to keep them exclusive; IEC 61131-3 settles the same case with a priority, left to right by default. GRAFCET reacts to input changes and keeps evolving until the situation is stable, passing through transient steps without running their continuous actions. A PLC runs its SFC once per scan and usually advances a token by one transition at a time. GRAFCET also has macro-steps, enclosing steps and forcing orders between partial grafcets, none of which IEC 61131-3 SFC defines; some vendors add versions of their own.

When to use SFC instead of ladder or ST

Reach for SFC when the machine is a sequence: clamp, drill, unclamp; fill, heat, drain; request, wait, release. The chart is the state diagram, so it is also the documentation, and online the active step shows a technician where the machine stopped without reading any code. Simultaneous branches give you two independent chains, each with its own step timers, without building two state variables by hand.

Stay with ladder for interlocks, permissives, motor starters and anything an electrician fault-finds from the drawing. Use ST for calculations, scaling, data handling and loops over arrays. Most projects mix them: SFC for the sequence, with ladder or ST inside the actions and in the logic that runs every scan whatever the step.

Without an SFC editor, the same sequence becomes a CASE statement on a step number. These pages cover that form and the design work behind it:

How the vendors implement it

All four tools draw steps, transitions and alternative and simultaneous branches the IEC 61131-3 way. They differ in the step data they expose, in how a step is supervised, and in how you reset or steer the chart. TwinCAT 3 uses the CODESYS SFC editor and its flags.

SFC in four engineering tools
ToolStep dataAlternative branchStep supervisionReset and control
Siemens S7-GRAPH (TIA Portal)Step.X active, Step.T time active, Step.U time active without disturbanceAlternative and simultaneous branches; jumps to another stepA supervision condition per step, often on Step.U, raises an error and holds the sequence until it is acknowledged (ACK_EF). An interlock condition blocks the interlocked actions but not the advance.INIT_SQ initialises, OFF_SQ switches the sequence off; modes SW_AUTO, SW_TAP, SW_TOP, SW_MAN; S_SEL with S_ON and S_OFF in manual
CODESYS SFC (also TwinCAT 3)step.x active this cycle, step._x active next cycle, step.t time since activationFirst transition of each branch checked left to right; the first TRUE one wins and the rest are not evaluatedMinimum and maximum time in the step properties. A timeout sets SFCError; SFCErrorStep and SFCErrorPOU say where, and SFCEnableLimit switches the check on and off.SFCInit holds the chart in the initial step without running it; SFCReset returns to the initial step and carries on. Jump and Macro elements in the editor.
Rockwell Studio 5000 Logix DesignerSFC_STEP tag per step: X active, FS first scan, LS last scan, T timer, PRE preset, DN set when T reaches PRESelection branch checked left to right by default; you can set your own order for each branchThe step preset PRE and its DN bit, used as a step watchdog in your own logicSFR restarts the chart at a chosen step and stops its stored actions; SFP pauses it
Schneider Electric Control ExpertSFCSTEP_STATE per step: x active, tminErr and tmaxErr flagsBehaviour depends on whether the chart runs in single-token or multi-token modeMinimum and maximum activation time per step (tmin, tmax); tminErr or tmaxErr is set on a violationMacro steps with their own sub-chart; SETSTEP activates steps in multi-token mode

Siemens S7-GRAPH in more detail

Every step and every transition carries a number as well as a name. In manual mode the S_SEL input picks a step by its number, so keep the numbering stable once the HMI and the maintenance documents refer to it.

Each step has two condition networks besides its actions. Supervision watches the step, for example Step.U > T#10s on a move that should take 4 s. When it trips, GRAPH reports an error and will not switch to the next step until the error is acknowledged, although the step actions keep running. Interlock guards the actions: while its condition is FALSE the interlocked actions are not executed, but the sequence can still advance.

Permanent pre-instructions and permanent post-instructions run on every call of the GRAPH block, before and after the sequencer, whichever step is active. Logic that must not depend on the step belongs there.

The block has four modes. SW_AUTO lets transitions fire on their own. SW_TAP (transition and push) fires a transition only when its condition is TRUE and T_PUSH gets a rising edge, which is how you inch a machine through its cycle. SW_TOP (transition or push) fires on the condition or on T_PUSH. SW_MAN fires nothing: you switch steps on and off with S_SEL, S_ON and S_OFF.

What this simulator runs

Supported

  • Steps, transitions, alternative and simultaneous branches, convergence, and loops back to any earlier step
  • Several initial steps, for charts that start with parallel chains
  • All eleven IEC 61131-3 action qualifiers: N, S, R, P, P1, P0, L, D, SD, DS, SL
  • Step.X and Step.T in guards and actions; BOOL, INT, REAL and TIME variables; standard functions such as ABS, LIMIT, MIN and MAX
  • Manual mode with the token placed by hand, forcing, and a scan-by-scan step trace
  • Warnings for an unsafe chart or a convergence that can never fire, and a Waiting on panel that shows what each transition out of an active step is waiting for

Not supported

  • Macro steps, enclosing steps and GRAFCET forcing orders
  • Vendor step supervision, interlocks and minimum or maximum step times. Build a watchdog from a D action and a fault transition instead.
  • Named action blocks with code of their own, and function block calls such as TON. An action is one or more assignments.
  • Numbered priorities. An alternative branch is resolved by the order the transitions are written in.
  • The GRAFCET search for a stable situation. The chart evaluates once per scan, and a token moves at most one transition per scan.

A chart is never a safety function. E-stops, guard doors and light curtains belong to a safety relay or safety PLC designed to ISO 13849-1 or IEC 62061; the sequence only reacts to their status.