You are here: Core Reference > Coding > Logic > SR

SR

Function Block Name

SR

Description

SR is a reset latch where the Set is dominant over the Reset. It can be used to determine the state of a Boolean output based on the states of 2 Boolean inputs.

Arguments

S1 {BOOL}

The Set input S1 is dominant in the SR function block. When its input is True, the Q1 output is True; when the S1 input is False, the value of the Q1 output is dependent on the R input.

R {BOOL}

The Reset input R only affects the Q1 output when the S1 input is False. If the R input changes from False to True and the S1 input is False, the change to the R input will cause the Q1 output to become True. The Q1 output will then stay True until the S1 state changes; Q1 will not respond to the R input changing state again until S1 has become True and then changed to False again.

Returns

Q1 {BOOL}

The Q1 output is True when the S1 input is True. When the S1 input is False, the Q1 input can respond to the R input:

  • If the R input changes from False to True and the S1 input is False, the Q1 output becomes True.
  • If the R input changes from True to False while the S1 input is False, the Q1 output remains True.
  • If the S1 input is True, the Q1 output is True irrespective of the state of R.

Example - SR Function Block Diagram:

It is easier to understand the functionality of the SR function block if you imagine the S1 and R inputs as corresponding to power buttons, and the Q1 output as the result of those buttons being pressed.

The S1 input receives its value from a point that represents a 'power on' button on plant; the R input receives its value form a point representing the 'power off' button.The True state corresponds to the buttons being pressed (active) and the False state corresponds to the buttons not being pressed (inactive).

The power on button is pressed (S1 is True) and the power off button is not pressed (R1 is False), so the power is on (Q1 is True). As the power on button cannot turn the power off, further changes to the S1 input will not affect the output (as long as R remains False). The power remains on until the power on button is no longer pressed (S1 is False) and the power off button is pressed (R is True). This means that Q1 remains True until S1 becomes False and R becomes True.

The power on button is no longer pressed and so S1 becomes False. Both S1 and R are False as neither button has been pressed and the Q1 output is True as the S1 input was previously True.

As both inputs are False, pressing the power off button sets the Q1 output to False as the R input only has an effect when the S1 input is False.

If both buttons are pressed at the same time (S1 and R are both True), the S1 input is dominant and so the power is on (Q1 is True).

Example - SR ST Program:

The syntax for entering an SR function block in an ST program is:

  • VAR
    • S1_IN AT %M(.Digital Point1): BOOL;
    • R_IN AT %M(.Digital Point2): BOOL;
  • END_VAR
  • VAR
    • Q1_OUT: BOOL;
    • FB : SR;
  • END_VAR
  • FB( S1 := S1_IN, R := R_IN, Q1:= Q1_OUT );

The direct variables are declared in a separate VAR block to the indirect variables. The input and output variables for the SR function block are also allocated names that are different to the names of the inputs and outputs in the function block as this makes it easier to understand the ST program (for example, the R input variable is named R_IN). In this example, the direct va

riables for the S1 input (S1_IN) and R input (R_IN) reference digital points (the Boolean values for the inputs are taken from digital points in the database).

In the second VAR block, the internal variables are declared, including an FB variable that defines the type of function block.

The ST Program can then reference the variables as inputs and outputs for the function block:

  • FB( S1 := S1_IN, R := R_IN, Q1 := Q1_OUT );

So, the ST Program uses the S1_IN input as the S1 input for the FB function block (which has already been declared as an SR type). It uses the R_IN variable as the value for the R input and for the Q1 output it uses the Q1_OUT variable.


ClearSCADA 2015 R2