Skip to content

19Standard function blocks

SR and RS flip-flops: which one wins

The SR (set dominant) and RS (reset dominant) bistables, and the difference that only shows up when both signals arrive in the same scan.

Lesson 19 of 3410 minIEC 61131-3

Memory with two signals

The seal-in from lesson four:

Pump := (Start OR Pump) AND NOT Stop;

works fine, but it mixes memory and logic into one line. The standard gives you two blocks that separate the intent: set here, reset there.

SR · set dominant

VAR
  Run : SR;
END_VAR

Run(S1 := Start, R := Stop);
Pump := Run.Q1;

S1 sets, R resets. If both arrive TRUE in the same scan, Q1 stays true: set wins. Note the digit in S1; the standard puts the digit on the dominant pin.

RS · reset dominant

VAR
  Alarm : RS;
END_VAR

Alarm(S := LSH, R1 := Ack);
HiAlm := Alarm.Q1;

Here R1 is dominant. Event and acknowledge together, and the acknowledge wins: Q1 drops.

The table that settles it

S

R

SR · Q1

RS · Q1

0

0

holds

holds

1

0

1

1

0

1

0

0

1

1

1

0

That last row is the entire difference. In the other three the blocks are identical.

Which one to use

The rule comes from safety: pick the block whose dominant side is the safe side.

  • A motor or pump: use RS. Reset means stop, and stop is safe. Do not use SR to run a motor, or a start command outranks the stop.
  • An alarm that must be seen: use SR. Set means the alarm appears, and a momentary event must not be lost because the acknowledge landed on the same scan.
  • A fault latch: SR exactly. The fault is captured and holds until an acknowledge arrives on a later scan.

When to use a block instead of a seal-in

  • When set and reset conditions get long. (A OR B OR C OR Out) AND NOT (D OR E) stops being readable; the block splits it into two lines.
  • When the conflict is real and you want the winner declared in the code rather than in your head.
  • When the state is retained across a restart, since the memory lives in one named instance.

Latched alarms

A latched alarm stays visible after its cause has gone, until the operator acknowledges it. Every safety-relevant event needs this: a transient that clears before anyone looks at the screen must not vanish from the record.

Alarm(S1 := Level > 95.0, R := AckEdge.Q);

Put an R_TRIG on the acknowledge button, or a held-down button keeps the alarm from ever appearing.

Try it in the lab

The lab runs in your browser: an ST editor, a virtual process that suits the lesson, the same program as a live ladder diagram, a watch table, and export to Siemens SCL.

What to try

  1. Run the program and tap OPEN: the door rises and stops at the limit switch.
  2. Press CLOSE: it comes down. Turn on "car in doorway" while it moves: it stops at once, because RESET wins in an RS.
  3. Watch Up.Q1 and Down.Q1 in the watch table.
  4. Change Down to SR (inputs S1 and R) and download again: now a held CLOSE beats the beam, which is dangerous.

People find this lesson by searching

SR RS flip flop plcset dominant vs reset dominantbistable structured textIEC 61131-3 SR RSlatched alarm plcplc latch blockRS flip flop structured text

Course outline

  1. 01What is Structured Text, and when to use it instead of ladder
  2. 02How a PLC runs your code: the scan cycle and the process image
  3. 03Program structure: POUs, PROGRAM, FUNCTION and FUNCTION_BLOCK
  4. 04Your first program: starting a pump with seal-in logic
  5. 05Data types: BOOL, INT, REAL, TIME and the rest
  6. 06Declaring variables: VAR, VAR_INPUT and RETAIN
  7. 07Literals and constants: 16#FF, 2#1010 and T#5s
  8. 08Type conversion and scaling a 4-20 mA signal
  9. 09Assignment and arithmetic in ST: := and operator precedence
  10. 10Boolean logic, comparisons and bit operations
  11. 11Standard functions: ABS, SQRT, MIN, MAX, LIMIT, SEL, MUX
  12. 12IF, ELSIF and ELSE: the rules and when to avoid them
  13. 13The CASE statement and your first state machine
  14. 14The FOR loop and the watchdog
  15. 15WHILE, REPEAT, EXIT, CONTINUE and RETURN
  16. 16Edge detection: R_TRIG, F_TRIG and the "it fired every scan" bug
  17. 17Timers: TON, TOF and TP
  18. 18Counters: CTU, CTD and CTUD
  19. 19SR and RS flip-flops: which one wins
  20. 20Writing your own function
  21. 21Writing a function block
  22. 22Arrays in Structured Text
  23. 23Structs and enumerations
  24. 24References and pointers
  25. 25The state machine pattern: a batch sequence that cannot get stuck
  26. 26Alarm management to ISA-18.2: delay, deadband, latch, acknowledge, first-out
  27. 27Analogue signal processing: counts to engineering units, NE43 and filtering
  28. 28Closed-loop control in ST: hysteresis first, then a practical PID
  29. 29Motors and valves in practice: permissives, feedback and travel time
  30. 30The same ST on every platform: SCL, Studio 5000, CODESYS, TwinCAT
  31. 31Testing and debugging ST: the watch table, forcing and simulation
  32. 32An ST style guide: naming, comments, constants and version control
  33. 33Final project: a complete tank station with a state machine and alarms
  34. 3420 interview questions on ST and PLC programming, with answers