04Getting started
Your first program: starting a pump with seal-in logic
The first logic every control engineer learns: a momentary start button that keeps the pump running, and a stop that always wins.
The problem
Panel buttons are momentary: they give a signal only while your finger is on them. But the pump must keep running after you let go. The classic answer is seal-in (also called latch).
One line
Pump := (Start OR Pump) AND NOT Stop;Read it as: the pump runs if start was pressed or it is already running, and at the same time stop is not pressed. The OR Pump part is the seal: the output feeds its own condition.
Why stop goes last
Because AND NOT Stop multiplies everything before it: press stop and the result is FALSE whatever else is true. This is a general safety rule — the stopping condition beats the starting condition.
In the field, stop is wired NC
On a real panel the stop button is wired normally closed: if the wire breaks, the signal drops, the PLC reads zero and the pump stops. The failure goes to the safe side. The line then becomes:
Pump := (Start OR Pump) AND StopNC;because StopNC is TRUE when all is well. The lab simulates the button as NO to keep the experiment simple.
Add the interlock
Buttons are not enough. Add the conditions that prevent damage:
Pump := (Start OR Pump) AND NOT Stop AND Level < 95.0;Now the pump stops by itself before the tank overflows. That is an interlock, and it is what separates a hobby program from an industrial one.
And the drain
Valve := NOT Pump AND Level > 60.0;The drain valve opens above 60% only while the pump is off, so the two never fight each other.
Try it in the lab
The lab runs in your browser: an ST editor, a virtual tank with a pump and a valve, a watch table, and export to Siemens SCL.
What to try
- Press START for a moment and let go: the pump keeps running.
- Press STOP: it stops at once.
- Run again and let the level rise above 95%: it stops by itself, thanks to the interlock.
- Delete "AND NOT Stop" and try: the pump will never stop.
Terms in this lesson
People find this lesson by searching
seal in logic plcstart stop logic structured textlatch plc programmotor start stop plcfirst structured text programinterlock plc
Course outline
- 01What is Structured Text, and when to use it instead of ladder
- 02How a PLC runs your code: the scan cycle and the process image
- 03Program structure: POUs, PROGRAM, FUNCTION and FUNCTION_BLOCK
- 04Your first program: starting a pump with seal-in logic
- 05Data types: BOOL, INT, REAL, TIME and the rest
- 06Declaring variables: VAR, VAR_INPUT and RETAIN
- 07Literals and constants: 16#FF, 2#1010 and T#5s
- 08Type conversion and scaling a 4-20 mA signal
- 09Assignment and arithmetic in ST: := and operator precedence
- 10Boolean logic, comparisons and bit operations
- 11Standard functions: ABS, SQRT, MIN, MAX, LIMIT, SEL, MUX
- 12IF, ELSIF and ELSE: the rules and when to avoid them
- 13The CASE statement and your first state machine
- 14The FOR loop and the watchdog
- 15WHILE, REPEAT, EXIT, CONTINUE and RETURN
- 16Edge detection: R_TRIG, F_TRIG and the "it fired every scan" bug
- 17Timers: TON, TOF and TP
- 18Counters: CTU, CTD and CTUD
- 19SR and RS flip-flops: which one wins
- 20Writing your own function
- 21Writing a function block
- 22Arrays in Structured Text
- 23Structs and enumerations
- 24References and pointers
- 25The state machine pattern: a batch sequence that cannot get stuck
- 26Alarm management to ISA-18.2: delay, deadband, latch, acknowledge, first-out
- 27Analogue signal processing: counts to engineering units, NE43 and filtering
- 28Closed-loop control in ST: hysteresis first, then a practical PID
- 29Motors and valves in practice: permissives, feedback and travel time
- 30The same ST on every platform: SCL, Studio 5000, CODESYS, TwinCAT
- 31Testing and debugging ST: the watch table, forcing and simulation
- 32An ST style guide: naming, comments, constants and version control
- 33Final project: a complete tank station with a state machine and alarms
- 3420 interview questions on ST and PLC programming, with answers