Overview: Detecting Active Steps in an S7 Graph Sequence
Siemens S7 Graph is the STEP 7 / TIA Portal option package that implements the Grafcet sequential function chart (SFC) model defined in IEC 60848 and adopted as IEC 61131-3 element "Sequential Function Chart". Each chart is compiled into a function block (FB) of type FB_SQ_FB (or a project-specific name), backed by an instance data block (iDB) that the runtime uses to store step flags, transition states, timing values, and mode bits.
A recurring engineering requirement is to know, from outside the chart, whether any step is currently active. This bit is needed for:
- Handshake between two chains (machine A reaches step 7 only when chain B has reached step 12).
- Light stack / signal tower sequencing (Green ON while chain running, OFF when chain off).
- Energizing downstream actuators only when the producing chain is alive.
- HMI status display without polling every step number.
- Safety logic that must drop an enable line if the producing sequence stops mid-recipe.
S7 Graph already produces the bit, but it is hidden by default. The FB exposes a catalogue of optional output parameters in its user-defined interface, and the engineer decides which of them are generated into the iDB at compile time. Once declared, the bit is a normal BOOL in the instance DB and can be used anywhere in the user program: in LAD contact logic, in SCL, as an HMI tag, or in OPC UA published symbols.
The two parameters that solve the "is the sequence running?" question are SQ_ISOFF (off, no step active) and S_ACTIVE (at least one step is active). A third, SQ_HALTED, tells you the sequencer is paused or in fault. Each has a precise meaning and they are not interchangeable.
Prerequisites and Engineering Environment
Before changing block properties, confirm the following:
- S7 Graph option package is installed. In TIA Portal, this is the "S7-Graph" add-on matching the TIA Portal version (e.g., TIA Portal V18 requires the S7 Graph V18 option). In STEP 7 V5.x, install "S7-GRAPH for STEP 7 V5.x" from the standard installation media.
- CPU firmware must be recent enough to support the Graph FB version compiled. For S7-300/400, the FB is shipped with the option package. For S7-1500 (used in TIA Portal V16+), Graph is part of TIA Portal and uses firmware-agnostic code generation; no CPU firmware upgrade is required for new features, but always match the Graph option package to the TIA Portal version to avoid build errors.
- Project consistency: the chart FB and any caller FBs must compile together. If the iDB is referenced by other FBs as a multi-instance or static, the user-defined parameters will be reallocated and downstream code may break.
-
Know your representation: open the chart and check whether it was generated in Compact or Full view. The Compact view produces a much smaller iDB; certain parameters such as
SQ_HALTEDare not available and must be derived from other bits.
Built-in Sequence Status Parameters
S7 Graph offers the following optional output parameters. None of them are generated unless you explicitly enable them in the FB interface.
| Parameter | Type | Meaning |
|---|---|---|
SQ_ISOFF |
BOOL | Sequencer is OFF. Auto-generated comment: "Sequencer is off (no step active) (SEQUENCE_IS_OFF)". TRUE means the chart is in its initial state, has completed its final step, or has been reset. |
S_ACTIVE |
BOOL | At least one step is currently active. Equivalent to the logical OR of every step flag in the chain. The standard way to test "is the sequence doing something?" |
SQ_HALTED |
BOOL | The sequencer is halted. Set when HALT input is TRUE, when an error requires manual intervention, or when the chart has been switched into manual/jog mode. The chain is loaded but not advancing. |
S_NO |
INT | Number of the currently active step. With S_MORE set, multiple steps are active in parallel branches and only the lowest-numbered is reported. |
S_MORE |
BOOL | TRUE if more than one step is active at the same time (parallel / simultaneous branches). |
S_TIME |
TIME | Elapsed time in the currently active step. |
S_TIMESET |
TIME | Configured (target) time for the currently active step. |
S_CRITICAL |
BOOL | The currently active step is flagged as critical (service-mode only). The chain cannot run in automatic mode when a critical step is active. |
SQ_FAULT |
BOOL | A fault has been registered in the sequence. Latched until acknowledged with ACK_EF. |
ERR_FLT |
BOOL | An error occurred while processing a step or transition. Often paired with IL_ERR for interlock supervision failures. |
ACK_FLT |
BOOL | Acknowledge-fault input. Latch-clear for the SQ_FAULT bit. |
IL_ERR |
BOOL | Interlock error in one of the steps. The offending step is reported in S_NO. |
S_ZENTR |
BOOL | Centralized step bit. TRUE if the step number in S_NO is active. Provides a single bit that follows the chain when the user has not enabled the S0..S31 step bit array. |
S0..S31
|
BOOL | One bit per step number. Sn is TRUE when step n is active. Maximum 32 simultaneous steps exposed; if more are needed, switch from BOOL array to WORD/DWORD and use the centralized bit S_ZENTR. |
REG_ERR |
BOOL | Registration error: invalid operation attempted (e.g., step does not exist). |
For the "is something happening?" question, S_ACTIVE is the cleanest answer. For the "did it actually start?" question, negate SQ_ISOFF (NOT SQ_ISOFF) and combine with a time filter if you want to ignore the initial state. For "has it stopped but not finished?" use SQ_HALTED.
Enabling Output Parameters in STEP 7 V5.x (Classic)
STEP 7 V5.x is the environment referenced in the field report. Procedure:
- Open the S7 Graph chart (.sfc source) in the editor and select Options → Block settings.
- Switch to the Compile / Save tab.
- In the FB parameters section, change the mode from Minimum or Standard (compact) to User-defined.
- Click the Variables tab on the left side of the dialog, then expand Environment → Interface → OUT.
- Right-click the OUT section and choose New declaration row. The new row is added to the interface as a candidate output parameter.
- Rename the new row to
SQ_ISOFF. S7 Graph will auto-complete the comment "Sequencer is off (no step active) (SEQUENCE_IS_OFF)" from the internal parameter dictionary. Repeat forS_ACTIVEand any other status bits you need. - Confirm with OK and recompile the chart. The S7 Graph compiler will now generate the symbol into the instance DB.
SQ_HALTED is exposed only in the full representation. If you need a "halted" bit but you want to keep the smaller iDB footprint, derive it from SQ_FAULT OR (NOT S_ACTIVE AND NOT SQ_ISOFF AND <time_in_initial>), or switch to full view.
Enabling Output Parameters in TIA Portal V16+
In TIA Portal the workflow is editor-driven and is reset per FB instance.
- Open the S7 Graph FB in the project tree.
- Right-click the chart and select Properties → Compile / Save.
- Under Interface parameters switch the mode to User-defined.
- Use the parameter list to add the desired outputs (
SQ_ISOFF,S_ACTIVE,S_NO,S_MORE, etc.). - Click OK and compile. The new tags appear in the iDB's static section.
After compile, open the iDB in the project tree and confirm the new tags are listed. In TIA Portal the names appear with the prefix that the FB block wrapper applies (typically a static symbol like "MySeq".SQ_ISOFF). You can now drag the tag into a watch table, an HMI tag list, or an OPC UA server publisher.
Reading the Status from the Instance DB
Once enabled, the parameter is a normal static symbol in the instance DB. The byte/bit offset in the iDB's data view depends on:
- Whether the FB was generated in Compact or Full mode.
- The number and order of IN, OUT, and STAT parameters you have enabled.
- The TIA Portal / STEP 7 version, because the FB's internal UDT changes between minor versions.
For these reasons, the byte/bit address is not stable across versions. The field report mentions "DI 8.3" as one observed location for SQ_HALTED in compact view; treat that as a starting hint, not a contract. The robust approach is to use the symbolic name of the parameter, not an absolute address:
// STL (caller FB or OB)
A "Seq_Main".SQ_ISOFF // TRUE = no step active
AN "Seq_Main".S_ACTIVE // invert: TRUE = no step active
= #SequenceIdle // internal flag
If you must read the iDB from another CPU over PUT/GET or from a remote HMI, export the iDB as a CSV and pin the offsets in the receiver. The classic STRUCT offsets for the Graph FB can be inspected in the S7 Graph manual "S7-Graph V5.x Programming and Operating Manual" or the TIA Portal help under "S7-Graph parameter interface".
Programmatic Detection in STL, LAD, and SCL
STL — consume the bit in another FB
// Assume DB "Seq_Main" is the instance of the Graph FB
A "Seq_Main".S_ACTIVE // step is active
S #RunFlag // set my own run flag
A "Seq_Main".SQ_ISOFF // no step active
R #RunFlag // clear it
A "Seq_Main".SQ_HALTED // halted
S #HaltFlag
AN "Seq_Main".SQ_HALTED
R #HaltFlag
LAD — interlock another drive on the running bit
Place a normally-open contact on "Seq_Main".S_ACTIVE in series with the drive output coil. As long as the chart has any active step the drive is allowed to run. As soon as the chart resets or finishes, the contact opens and the drive drops out.
SCL — structured check in a function
// SCL example for a TIA Portal S7-1500 / S7-1200
IF "Seq_Main".SQ_ISOFF THEN
// Chart is OFF, in initial state, or has just completed
#state := 0;
ELSIF "Seq_Main".SQ_HALTED THEN
#state := 2; // paused / fault
ELSIF "Seq_Main".S_ACTIVE THEN
#state := 1; // running
#currentStep := "Seq_Main".S_NO;
ELSE
#state := 3; // transient between steps
END_IF;
Edge-triggered one-shot on the leading edge of S_ACTIVE
Sometimes you need a single pulse when the chain actually starts (transition from "no step" to "step active"). Detect it with a flag and FP (positive edge) in STL, or with an edge memory bit <seq>.S_ACTIVE & NOT <old> in SCL.
HMI and SCADA Integration
Once the tag is enabled, the iDB symbol is available to the rest of the engineering project. Practical patterns:
- WinCC Unified / TIA Portal HMI: drag the iDB symbol into an HMI tag list. The HMI updates at the configured acquisition cycle (default 1 s) and shows the status on a status display or as a Boolean tag driving a color animation.
- WinCC Professional / V7: import the iDB symbols through the PLC tag table. Use the symbol's name, not its absolute address; the OPC DA/UA server resolves it from the symbol table.
- OPC UA Publisher on S7-1500: enable the Graph FB's iDB in the publish list. The status bit is exposed as a Boolean node and can be subscribed by any OPC UA client.
- Profinet S7 connection: from a remote CPU, request the iDB symbolically with "Read S7 communication" using the symbol name. Never hard-code the byte offset.
For multi-chain projects, build a small orchestrator FB that loops through an array of iDB references and exposes a single DWORD in which each bit is the S_ACTIVE of one chain. This pattern keeps the HMI tag list short and the alarm system easy to configure.
Edge Cases: Compact vs Full Representation, Automatic vs Manual Mode
The "is the sequence active?" question has at least four interpretations, and the choice of parameter depends on which you mean:
| Question | Use this parameter | Behaviour |
|---|---|---|
| Is the chart in its initial state, or has it finished? | SQ_ISOFF |
TRUE when no step is active. Same value before the first start and after the last step. |
| Is at least one step currently active (running)? | S_ACTIVE |
TRUE between the moment a step becomes active and the moment it leaves. Includes hold time in the step. |
| Is the chart paused (HALT input, jog, fault)? |
SQ_HALTED (full view) or SQ_FAULT
|
TRUE when execution is suspended. Step is still active, but the chart will not advance to the next transition. |
| Is the chart in service / manual mode? |
SW_HALT / SW_AUTO / SW_MAN / SW_TAP (mode inputs visible on the FB) |
The chart is loaded but driven by an operator. Treat as "not running in automatic" for downstream interlocks. |
Compact view intentionally hides several parameters to reduce iDB size. The SQ_HALTED bit is a known casualty. In compact view, the same state can be reconstructed by combining SQ_ISOFF, S_ACTIVE, and the HALT input that you wired to the FB. For most new projects, prefer the full view: the iDB size difference is negligible on S7-1500 and the symbolic bits are worth the audit clarity.
Mode switching is a separate topic but is the most common source of confusion. If the operator toggles the chain to manual mode, SQ_ISOFF stays FALSE (a step is still active) and S_ACTIVE stays TRUE, so an interlock on those two will still let the downstream actuator run. If the safety logic must drop on mode change, also read the SW_AUTO input and combine it with S_ACTIVE.
Verification and Commissioning
- Recompile the Graph FB after enabling the desired outputs. Open the iDB and confirm the new tags are listed in the Static section with type
BOOLorINTas documented above. - Download the program to the target CPU (or run PLCSIM).
- Open the iDB online and force the input
OFF_SQorINIT_SQbriefly.SQ_ISOFFmust be TRUE;S_ACTIVEmust be FALSE. - Start the chain (set
AUTO_ONorSW_AUTO = TRUEas your project requires). The first step should become active;S_ACTIVEmust go TRUE andSQ_ISOFFmust go FALSE. The active step number appears inS_NO. - Step the chain forward through several steps.
S_NOshould advance;S_ACTIVEshould remain TRUE the whole time. - Drive
HALTinput high.SQ_HALTEDmust go TRUE whileS_ACTIVEstays TRUE. - Let the chain reach the final step and exit.
SQ_ISOFFmust return to TRUE;S_ACTIVEmust go FALSE. - Build a cross-reference from every consumer of the iDB symbol (other FBs, OB1 contacts, HMI tags) and confirm none of them reference an absolute address that the recompile will have moved.
Troubleshooting Matrix
| Symptom | Likely cause | Fix |
|---|---|---|
| Tag not visible in the iDB | Parameter not added to the user-defined OUT list, or chart still in "Minimum" mode | Open Block settings → Compile/Save → User-defined; add the parameter; recompile |
| Tag visible but always FALSE | Compact view was used; SQ_HALTED is not generated in compact view |
Switch to full view, or derive the state from other bits as documented in the edge-cases section |
| Tag flips but HMI shows wrong value | HMI tag bound to absolute address that shifted after a recompile | Rebind the HMI tag to the symbolic name; redownload the HMI |
| Tag address changes every compile | User-defined parameter list was edited between two compiles (e.g., one parameter added, one removed) | Finalize the OUT list before commissioning; document it; freeze it in the project version control |
S_ACTIVE is TRUE in manual mode but downstream should not run |
Interlock is on S_ACTIVE only and ignores SW_AUTO
|
Add SW_AUTO AND S_ACTIVE as the run condition; or interlock on a dedicated safety run flag |
| Tag visible in STEP 7 V5.x but missing in TIA Portal | Project was migrated and the Graph FB was not recompiled in TIA Portal | Open the chart in TIA Portal, repeat the "User-defined" step for the OUT parameters, recompile and download |
| Compile error: parameter already exists | Renamed a parameter to an internal S7 Graph reserved name with a typo | Compare against the official parameter list in the S7 Graph manual; revert to the exact spelling (case sensitive) |
Frequently Asked Questions
What is the difference between SQ_ISOFF and S_ACTIVE?
SQ_ISOFF is TRUE when no step in the chain is active — the chart is in its initial state, has completed its final step, or has been reset. S_ACTIVE is TRUE whenever at least one step is active. They are the inverse of each other only when the chart is in a steady state; during the brief moment a transition is being evaluated, both can be FALSE.
Can I use SQ_HALTED in the compact (small) representation?
No. SQ_HALTED is exposed only in the full representation. In compact view, derive the same state from SQ_FAULT OR the HALT input you wired to the FB. Alternatively, switch the chart to full view in Block settings; the iDB size difference is small on modern CPUs.
Where in the instance DB does the parameter live?
The byte and bit offset is not stable across versions. The robust way to access SQ_ISOFF, S_ACTIVE, and the other optional outputs is symbolically, using the iDB's structured name (for example, "Seq_Main".S_ACTIVE). If a remote system must read the iDB by absolute address, export the DB structure and pin the offsets in the receiver after every recompile.
How do I show the running state on an HMI?
Enable S_ACTIVE in the chart's OUT parameters, recompile, then drag the iDB tag into the HMI tag list using its symbolic name. On WinCC Unified and TIA Portal HMI it appears as a normal Boolean tag. On WinCC Professional and OPC UA Publisher it is also exposed automatically once the iDB is in the symbol table.
Why does the S_ACTIVE tag stay TRUE when I put the chain in manual mode?
Manual mode does not deactivate the current step; it only changes how the step is advanced. The chart still has a step active, so S_ACTIVE remains TRUE. If the downstream interlock must drop on mode change, AND S_ACTIVE with the SW_AUTO input (or your project's equivalent of the automatic-mode flag).