Skip to content

Bistable function blocks (latches)

Both SR and RS are set/reset latches with one Boolean output Q1. They differ in which input wins when set and reset are asserted at the same time.

DirectionNameTypeMeaning
InputS1BOOLSet (dominant)
InputRBOOLReset
OutputQ1BOOLLatch output

When both S1 and R are TRUE, set wins and Q1 stays TRUE.

FUNCTION_BLOCK SR
VAR_INPUT
S1 : BOOL;
R : BOOL;
END_VAR
VAR_OUTPUT
Q1 : BOOL;
END_VAR
END_FUNCTION_BLOCK
VAR
latch : SR;
END_VAR
latch(S1 := startCmd, R := stopCmd);
running := latch.Q1;
DirectionNameTypeMeaning
InputSBOOLSet
InputR1BOOLReset (dominant)
OutputQ1BOOLLatch output

When both S and R1 are TRUE, reset wins and Q1 becomes FALSE.

FUNCTION_BLOCK RS
VAR_INPUT
S : BOOL;
R1 : BOOL;
END_VAR
VAR_OUTPUT
Q1 : BOOL;
END_VAR
END_FUNCTION_BLOCK
VAR
safeLatch : RS;
END_VAR
safeLatch(S := startCmd, R1 := emergencyStop);
running := safeLatch.Q1; // emergency stop always wins