JSR, SBR, RET Jump To Subroutine, Subroutine, & Return Ladder Logic Instructions

JSR Definition

The JSR instruction is a ladder logic rung output instruction.  When the instruction is scanned program execution jumps to the subroutine named in the JSR instruction. After the called subroutine is executed the logic execution continues from the rung the subroutine was called from. The instruction is enabled when the preceding logic is true and disabled otherwise.

The JSR instruction can be used alone or with the SBR and/or RET instructions. At minimum the JSR instruction must contain the “Routine Name” that is to be called. In other words parameters and their associated instructions are not required.

SBR or Subroutine Instruction

 

SBR

      
                 

 

RET or Return From Subroutine Instruction

RET

 

 

 

To pass a parameter to a subroutine:

Parameters may be passed to subroutines called out by a JSR instruction. To do this the JSR instruction must contain an Input Parameter (Tag or Constant) and an SBR instruction with an Input Parameter (Tag) must be in the called subroutine.

The Input Parameter data from the JSR instruction is copied to the Input Parameter of the SBR instruction.

For instance it you call a subroutine named “Conveyor_01” with a JSR containing an Input Parameter (Tag or Constant), the first rung in the subroutine “Conveyor_01” must contain an SBR instruction with an Input Parameter (Tag) to receive the parameter.

       Note: The SBR instruction must be the first instruction of the first rung in the called subroutine.

INPUT PARAMETERS can be any combination of the following data types.  They are optional and multiple input parameters can be used.

  • CONSTANT When used as an Input Parameter on a JSR
  • BOOL
  • SINT
  • INT
  • DINT
  • REAL
  • STRUCTURE

To return a parameter to a subroutine:

Data can be passed back to the JSR instruction that called the subroutine. To do this the JSR instruction must contain a Return Parameter (Tag) and a RET instruction with a Return Parameter (Tag or Constant) must be in the called subroutine.

The Return Parameter data from the RET instruction is copied to the Return Parameter referenced in the calling JSR instruction.

For instance it you were to call a subroutine named “Conveyor_01” with a JSR  containing a Return Parameter (Tag), the subroutine “Conveyor_01” must contain a RET instruction with a Return Parameter (Tag or Constant).

Note: The RET instruction can be anywhere in the called routine. When enabled the RET instruction jumps back to the JSR that called the instruction.

RETURN PARAMETER can be any combination of the following data types. They are optional and multiple return parameters can be used.

  • CONSTANT             When used as a Return Parameter on a RET
  • BOOL
  • SINT
  • INT
  • DINT
  • REAL
  • STRUCTURE

Do not use the JSR instruction to call the main routine as it already runs unconditionally. Do not use the RET instruction in a main routine as a fault will occur.

The JSR, RET and SBR instructions can show or hide parameters. There is more than one way to do this, however only one will be covered here.

To add an input Parameter or Return Parameter to a JSR instruction: Right click on the Routine Name variable. From the pop up menu choose “Add Input Parameter” or “Add    Return Parameter”. Curiously enough if one or more Input or Return parameters are already visible you have to Right click on the visible parameter to display all the     selections. To remove a parameter right click on the parameter and choose “Remove Instruction Parameter” from the pop up window.

Note: Arithmetic status flags are affected (S:V, S:Z, S:N, S:C). Overflow, Zero, Negative, and Carry.

 

FSC(File Search & Compare) Ladder Logic Instruction

Definition

The FSC instruction is a ladder logic rung output instruction that compares data in an array, element by element. The instruction uses a Control data type in conjunction with a user defined expression.  The instruction is enabled when the preceding logic is true and disabled otherwise.

Insure the Length and Position does not travel outside the array boundaries.

List of possible arguments

CONTROL Must be a Control Data Type

  • Control.EN     High when the instruction is enabled.
  • Control.DN     When the .POS is equal to the .LEN
  • Control.ER      Error bit
  • Control.IN      Inhibit bit is set when a true comparison is detected. Clear the bit to continue the search operation.
  • Control.FD      Set when a true comparison is found. Similar to the Inhibit bit.
  • Cotnrol.LEN   The number of elements in an array to search.
  • Contol.POS     The current element the instruction is comparing.

LENGTH Number of elements in the array to be compared. Constant type no tags.

POSITION The current element in the array. Is an element of the control tag and can be used in the expression to step through arrays.

MODE Can be ALL or INCREMENTAL. Selecting ALL will enable the instruction to execute from the first element in an array to the last element in an array on a false to true transition. INCREMENTAL will enable the instruction to execute one element in an array for every false to true transition.

EXPRESSION can contain one or more of the following data types

  • SINT
  • INT
  • DINT
  • REAL
  • CONSTANT
  • STRING

Note: The REAL data type is supported for safety routines on the 1756-L7xS series of controllers.

The expression is defined using tags, math operators, and constants. Parentheses () are used to give priority to sections of an expression. Here is a list of logical operands.

Expressions are executed in a predetermined order of operation, not the order they are written in. The operation order may be changed by placing sections of the expression in parentheses as an expression enclosed in parentheses will execute first.

 

Order                                           Operation

  • 1                                            () Parentheses
  • 2                                            ABS, ACS, ASN, ATN, COS, DEG, FRD, LN, LOG, RAD,                                                                                                       SIN, SQR, TAN, TOD, TRN
  • 3                                            **
  • 4                                            –(negate), NOT
  • 5                                            *, /, MOD
  • 6                                            –(subtract), +(add)
  • 7                                            AND
  • 8                                            XOR
  • 9                                            OR

If the Position or Length is less than zero a major fault will occur. Make sure the length is less than or equal to the actual array size. If the Length value is set higher than the length of the array the destination value will be wrong.

Note: Arithmetic status flags are affected (S:V, S:Z, S:N, S:C). Overflow, Zero, Negative, and Carry.

 

SRT(Sort File) Ladder Logic Instruction

Definition

The Sort File instruction is a ladder logic rung instruction that sorts data in an array into ascending order.  The instruction is enabled when the preceding logic is true and disabled otherwise.

The Sort File instruction uses the Control data type to sort the data.

Insure the Length and Position does not travel outside the array boundaries.

List of possible arguments

ARRAY TAG & DIMENSION TO VARY must be an array and the dimension of the array must be pointed out.

ARRAY can be one of the following data types

  • SINT              
  • INT
  • DINT
  • REAL
  • DIM TO VARY Must be a Constant with one of these values 0,1,2
  • CONTROL Must be a Control Data Type
  • LENGTH The amount of elements in the array to average
  • POSITION Is the beginning position in the array to average

If the Position or Length is less than zero a major fault will occur. Make sure the length is less than or equal to the actual array size. If the Length value is set higher than the length of the array the destination value will be wrong.

Note: Arithmetic status flags are affected (S:V, S:Z, S:N, S:C). Overflow, Zero, Negative, and Carry.

 

STD (Standard Deviation) Ladder Logic Instruction

Definition

The Standard Deviation instruction is a ladder logic rung instruction that calculates the standard deviation of values in an array and places the calculated value in the Destination tag. The instruction is enabled when the preceding logic is true and disabled otherwise. Wikipedia has an excellent article detailing the theory and standard deviation formula.

The STD ladder instruction uses the Control data type to calculate the standard deviation.

Insure the Length and Position does not travel outside the array boundaries.

List of possible arguments

ARRAY TAG & DIMENSION TO VARY must be an array and the dimension of the array must be pointed out.

ARRAY can be one of the following data types

SINT              
INT
DINT
REAL

  • DIM TO VARY Must be a Constant with one of these values 0,1,2
  • DESTINATION can be one of the following data types
  • REAL
  • CONTROL Must be a Control Data Type
  • LENGTH The amount of elements in the array to average
  • POSITION Is the beginning position in the array to average

If the Position or Length is less than zero a major fault will occur. Make sure the length is less than or equal to the actual array size. If the Length value is set higher than the length of the array the destination value will be wrong.

Note: Arithmetic status flags are affected (S:V, S:Z, S:N, S:C). Overflow, Zero, Negative, and Carry.

 

TRN (Truncate) Ladder Logic Instruction

Definition

The Truncate instruction removes the fractional part of a number stored in a Real data type and places the truncated value in the destination. The Source data remains unchanged.

Example

  •             Source data =              357.06
  •             Destination data =      357      (After truncate)

List of possible arguments

SOURCE can be one of the following data types.

  • CONSTANT
  • REAL

DESTINATION can be any combination of the following data types.

  • SINT
  • INT
  • DINT
  • REAL

Note: Arithmetic status flags are affected (S:V, S:Z, S:N, S:C). Overflow, Zero, Negative, and Carry.

MCR (Master Control Reset) Ladder Logic Instruction

Definition

The MCR instruction is used as a soft emergency stop. Rungs placed between two MCR instructions can be disabled; or rather the outputs of the rungs are disabled when the MCR instruction is false and enabled when true.

There are a couple of rules to follow:

  •             Don’t jump into an MCR zone as unexpected action will occur.
  •             The zone must end with an unconditional MCR instruction usually (see last rule).
  •             Don’t nest one MCR zone within another MCR zone.
  •             If an MCR zone continues to the end of a routine it is not necessary to end the zone with an MCR instruction.

Note: The MCR is not a valid substitution for a hard-wired emergency stop circuit or master control relay. Use a hard-wired master control relay for emergency stop power shutdown.

 

IOT (Immediate Output) Ladder Logic Instruction

Definition

The IOT instruction is a ladder logic output instruction that updates output data immediately rather than waiting for the RPI of the module or tag to update the data.

Use the instruction to update the output data of an entire output module. For instance, when you use the instruction to update an output card, address the entire card, not the individual outputs.

Correct:           Local:3:O

Incorrect:         Local:3:O.Data.0

The instruction can also be used to update a produced tag. When using the instruction with a produced tag an Event Trigger is sent to the consuming processor. This allows the consuming processor to trigger an Event Task.

Note: When using the IOT instruction produced data is transferred immediately when the communication method is Ethernet I/P or the Backplane, and within the API (Actual Packet Interval) of the Consumed Tag over ControlNet.

TOD (To Binary-Coded Decimal BCD) Ladder Logic Instruction

Definition

The TOD instruction is a ladder logic rung output instruction that takes decimal value from the Source and places the Binary-Coded Decimal equivalent in the Destination.

The instruction is enabled when the preceding logic is true and disabled otherwise. The values can be constants, tags or any combination.

In BCD each byte represents a decimal numeral which is different than displaying decimal numbers in plain binary.

  •        Decimal                BCD
  •             0                      0000
  •             1                      0001
  •             2                      0010
  •             3                      0011
  •             4                      0100
  •             5                      0101
  •             6                      0110
  •             7                      0111
  •             8                      1000
  •             9                      1001

Before conversion:

The decimal number 99 displayed in Binary      0110_0011 (99)

After conversion:

The decimal number 99 displayed in BCD         1001_1001 (99)

The TOD instruction would convert the decimal 99 shown above into a BCD 99. Follow this link for a more detailed explanation of the Binary-Coded Decimal.

List of possible arguments

SOURCE and DESTINATION can be any combination of the following data types.

  • CONSTANT             Can’t be the DESTINATION obviously
  • SINT              
  • INT
  • DINT

Note: Arithmetic status flags are affected (S:V, S:Z, S:N, S:C). Overflow, Zero, Negative, and Carry.

 

FRD (From Binary-Coded Decimal BCD) Ladder Logic Instruction

Definition

The FRD instruction is a ladder logic rung output instruction that takes a binary coded decimal value from the Source and places the decimal equivalent in the Destination.

The instruction is enabled when the preceding logic is true and disabled otherwise. The values can be constants, tags or any combination.

In BCD each byte represents a decimal numeral which is different than displaying decimal numbers in plain binary.

  •        Decimal                BCD
  •             0                      0000
  •             1                      0001
  •             2                      0010
  •             3                      0011
  •             4                      0100
  •             5                      0101
  •             6                      0110
  •             7                      0111
  •             8                      1000
  •             9                      1001

Before conversion:

The decimal number 99 displayed in BCD          1001_1001 (99)

After conversion:

The decimal number 99 displayed in Binary      0110_0011 (99)

 

The FRD instruction would convert the BCD 99 shown above into a decimal 99. Follow this link for a more detailed explanation of the Binary-Coded Decimal.

List of possible arguments

SOURCE and DESTINATION can be any combination of the following data types.

  • CONSTANT             Can’t be the DESTINATION obviously
  • SINT              
  • INT
  • DINT

Note: Arithmetic status flags are affected (S:V, S:Z, S:N, S:C). Overflow, Zero, Negative, and Carry.

 

FLL (Fill File) Ladder Logic Instruction

Definition

The Fill File instruction is a ladder logic rung output instruction that copies data from the Source to the Destination x amount of elements long The Source data remains unchanged.

Insure the Length does not travel outside of the array boundaries. Use the SIZE instruction to determine how many elements are in an array.

The instruction is enabled when the preceding logic is true and disabled otherwise. The values can be constants, tags or any combination.

List of possible arguments

SOURCE and DESTINATION can be any combination of the following data types.

  • CONSTANT             Can’t be the DESTINATION obviously
  • SINT              
  • INT
  • DINT
  • REAL
  • STRUCTURE

LENGTH is type CONSTANT and determines the number of elements to fill.

Note: It is possible to write data into other members of a tag if the length is set too large. This can happen when executing the instruction on User Defined Tags. No major fault is flagged. Also check out the COP instruction as it is very similar.