| **AUTO mode** | Steps advance immediately when advance condition is met |
| **INCREMENT mode** | Condition must be TRUE then operator presses `Cmd_Incr` to advance |
| **PAUSE** | Soft hold — all outputs frozen in place; resume resumes same step |
| **STOP (CAT2)** | Hard hold — requires `Cmd_Reset` to return to IDLE |
| **E-Stop CAT0** | Immediate: all outputs de-energised in the same scan |
| **E-Stop CAT1** | Controlled: current step finishes its "safe motion" then stops |
| **E-Stop CAT2** | Suspend: outputs frozen until reset (same as STOP) |
| **Skip Step** | Operator can force-advance any step NOT safety-locked |
| **Disable Step** | Individual steps can be permanently skipped (e.g. bypass unused stations) |
| **Safety-Locked Steps** | Steps 1, 5, 7 cannot be skipped — operator `SkipStep` is silently ignored |
| **Timer Advance** | Steps 4, 6, 8 advance on IEC timer expiry (no sensor needed) |
| **1-Sensor Advance** | Steps 2, 5, 7, 10 advance on single sensor |
| **2-Sensor Advance** | Steps 1, 3, 9 use FWD + BWD sensors with conflict detection |
| **Step Watchdog** | 30 s watchdog per step — faults if a step takes too long |
| **Cycle Counter** | Persistent `CycleCount` DINT increments on every completed cycle |
---
## 2. File Structure
```
📁 WeldSequencer/
├── FB_WeldSequencer.scl # Main Function Block — all sequencer logic
└── README.md # This file
```
> **Note:** In TIA Portal, create one **Instance DB** for the FB (e.g. `DB_WeldSeq`). The instance DB holds all internal state, timers, and configuration arrays.
---
## 3. I/O Map
### Digital Inputs (DI)
| Address | Tag Name | Description | Used in Step(s) |
|---|---|---|---|
| `%I0.0` | `Sen_HomeFwd` | Fixture at home position | 1 |
| `%I0.1` | `Sen_HomeBwd` | Fixture NOT in work zone (redundant) | 1 |
The sequence runs end-to-end without any operator input once started. Each step advances the instant its advance condition becomes TRUE. Intended for normal production operation.
### INCREMENT Mode (`Mode_Incr = TRUE`)
```
Cmd_Start ──→ Step 1 ──[cond met + Cmd_Incr]──→ Step 2 ──[cond met + Cmd_Incr]──→ ...
```
The sequencer waits at each step until:
1. The step's advance condition is `TRUE` (sensor or timer)
2.**AND** the operator presses `Cmd_Incr`
The `IncrWaiting` output goes `TRUE` when condition is met but waiting for the increment button — useful for an HMI indicator ("Ready to advance — press INCR").
**Use cases:** First article inspection, commissioning, slow-speed prove-out, fault recovery.
> **Mode switching:** Change modes between cycles only (while in IDLE or COMPLETE). Switching mid-cycle is accepted by the FB but may cause unexpected step dwell.
| **Outputs** | Held at current state | Held at current state |
| **Resume** | `Cmd_Start` → continues same step | `Cmd_Reset` → returns to IDLE |
| **Typical use** | Short interruption (fork truck, material feed) | Planned stop, shift change, part change |
| **From safety fault?** | Cannot resume if door open | Cannot reset if E-Stop active |
| **Step continuity** | Resumes mid-step (timer paused) | Restarts from Step 1 after reset |
> **Important:** In PAUSED state, step timers stop counting (their `IN` bit goes FALSE because `_state ≠ STATE_RUNNING`). When resumed, timers restart from zero for the current step. If this is undesirable for your application (e.g. partial gas purge time), modify the timer `IN` condition to also include `STATE_PAUSED`.
---
## 8. Step-by-Step Breakdown
### Step 1 — Home Position Verify 🔒 Safety-Locked
```
Sensors : Sen_HomeFwd (at home) + Sen_HomeBwd (NOT in work zone)
Actuators: NONE
Advance : Sen_HomeFwd = TRUE AND Sen_HomeBwd = FALSE
Lock : Safety-locked — SkipStep ignored
Purpose : Confirm fixture/robot is at safe starting co-ordinate before
clamping a part. Two-sensor logic eliminates single-sensor failure.
```
### Step 2 — Clamp Workpiece
```
Sensors : Sen_ClampClosed (1 sensor)
Actuators: Act_Clamp ON
Advance : Sen_ClampClosed = TRUE
Purpose : Engage pneumatic clamp jaw on the workpiece.
- Both TRUE simultaneously → **FaultCode 30** (wiring fault or sensor failure)
### Type B — Single Sensor
Used by: **Steps 2, 5, 7, 10**
```scl
// Step 2 example
_stepAdvReady := Sen_ClampClosed;
```
Simplest form. Step activates its actuator(s) and waits for confirmation feedback.
### Type C — Timer Only (no sensor)
Used by: **Steps 4, 6, 8**
```scl
// Step 4 example — timer resets automatically when step changes
_stepTimer[4](IN := (_activeStep = 4 AND _state = STATE_RUNNING),
PT := T#2S);
_stepAdvReady := _stepTimer[4].Q;
```
The timer `IN` is gated on `(_activeStep = N AND STATE_RUNNING)`. When the step changes, `IN` goes FALSE and the TON resets automatically — no manual reset logic required.
---
## 10. Skip / Disable / Safety-Lock
### Disable a Step (permanent skip every cycle)
Set in the instance DB or via HMI write to `_stepEnabled[N]`:
```scl
// Example: disable step 6 (weld travel) for a tack-weld-only mode
"DB_WeldSeq"._stepEnabled[6] := FALSE;
```
Disabled steps are silently skipped by the `WHILE` loop that finds the next enabled step. The step's actuator outputs are never energised.
### Skip Current Step (operator, one-time)
Rising edge on `Cmd_SkipStep`. The FB checks `_stepSafetyLocked[_activeStep]`:
```
Cmd_SkipStep (↑) ──→ Is step safety-locked?
YES → Ignore (no action, no feedback)
NO → _forceAdvance := TRUE → step advances next scan
```
### Safety-Locked Steps
Set during initialisation:
```scl
_stepSafetyLocked[1] := TRUE; // Home verify
_stepSafetyLocked[5] := TRUE; // Arc strike
_stepSafetyLocked[7] := TRUE; // Arc off
```
**Why lock these steps?**
| Step | Risk if skipped |
|---|---|
| 1 — Home Verify | Clamp closes on robot arm / fixture not in position |
| 5 — Arc Strike | Weld travel with no arc = cold weld, undetected failure |
| 7 — Arc Off | Moving head while arc still live = flash, fire, damage |
To add safety-locking to other steps, set `_stepSafetyLocked[N] := TRUE` in the `IF NOT _initDone` block.
---
## 11. Fault Codes
| Code | Name | Cause | Resolution |
|---|---|---|---|
| 0 | No fault | Normal | — |
| 10 | Safety door open | Door opened during RUN or PAUSED | Close door → `Cmd_Reset` |
Write to the instance DB directly (e.g. from HMI or during commissioning):
```scl
// Disable step 6 (bypass weld travel for testing)
"DB_WeldSeq"._stepEnabled[6] := FALSE;
// Change pre-purge time to 3 seconds
"DB_WeldSeq"._stepTimerPreset[4] := T#3S;
// Enable step 6 again
"DB_WeldSeq"._stepEnabled[6] := TRUE;
```
> **Note:** Timer preset changes take effect on the NEXT activation of that step (TON picks up the new `PT` value when it starts).
---
## 14. Adapting the Code
### Adding More Steps
1. Change array bounds: `Array[1..N]` in all 6 array declarations
2. Update `LAST_STEP` constant
3. Add a new `CASE` branch for each new step
4. Call additional step timers and watchdog timers explicitly
### Replacing Timer Advance with Robot Handshake
Step 6 uses a timer for weld travel. In a real system with a robot controller:
```scl
// Replace timer advance in Step 6 with robot "weld complete" signal
6:
Act_WeldEnable := TRUE;
Act_GasValve := TRUE;
_stepAdvReady := Robot_WeldComplete; // Add this DI to VAR_INPUT
```
### Adding More Sensor Types
For a step needing **analog threshold advance** (e.g. temperature):
```scl
// In step logic:
_stepAdvReady := (TempSensor_mV > 4500); // Weld pool temp threshold
```
### Multiple Sequencer Instances
Create multiple instance DBs for parallel lines:
```scl
"DB_WeldSeq_Line1"(...);
"DB_WeldSeq_Line2"(...);
```
Each instance is completely independent with its own state, timers, and counter.
### Changing CAT1 Timeout
```scl
// In VAR CONSTANT section:
CAT1_TIMEOUT : Time := T#15S; // Increase for slower machinery
```
Or make it configurable via VAR_INPUT if different cells need different values.
---
## 15. Safety Notes
> ⚠️ **This code is a demonstration template. It does NOT constitute a validated safety function and must NOT be used as-is for CE-marked or safety-certified applications without a proper risk assessment and SISTEMA analysis.**
### Minimum Requirements Before Deployment
- [ ] Full HAZOP / risk assessment per **ISO 12100**
- [ ] E-Stop circuit designed to **ISO 13850** — hardware safety relay, not PLC output
- [ ] Safety door interlocks to **ISO 14119** — use safety-rated sensors
MIT License — free to use and adapt for commercial or personal projects. Attribution appreciated but not required.
---
*Generated for S7-1500 / TIA Portal V18+. Tested syntax against SCL compiler rules. Always perform a full offline simulation before deploying to hardware.*