Call a Sub-Program

A sub-program is called by another program.

  • Unlike function blocks, local variables of a sub-program are not instantiated and you do not need to declare instances.
  • A call to a sub-program processes the block algorithm using the specified input parameters.
  • Output parameters can then be accessed.

FBD and FFLD Languages

To call a sub-program in FBDClosed "Function Block Diagram" A function block diagram describes a function between input variables and output variables. A function is described as a set of elementary blocks or FFLDClosed "Free Form Ladder Diagram" languages, insert the block in the diagram and connect its inputs and outputs.

IL Language Example

To call a sub-program in the ILClosed "Instruction List" This is a low-level language and resembles assembly language, you must use the CAL instruction with the name of the sub-program, followed by the input parameters written between parentheses and separated by comas.

Alternatively, the CALC, CALCN or CALNC conditional instructions can be used:

CAL    Calls the sub-program
CALC   Calls the sub-program if the current result is TRUE
CALNC  Calls the sub-program if the current result is FALSE
CALCN  same as CALNC

Example

Op1: CAL  MySubProg (i1, i2)
FFLD MySubProg.Q1
ST Res1
FFLD MySubProg.Q2
ST Res2

ST Language Example

To call a sub-program in STClosed "Structured text" A high-level language that is block structured and syntactically resembles Pascal, you must specify its name, followed by the input parameters written between parentheses and separated by comas.

To have access to an output parameter, use the name of the sub-program followed by a dot . and the name of the parameter:

MySubProg (i1, i2); (* calls the sub-program *)
Res1 := MySubProg.Q1;
Res2 := MySubProg.Q2;

Alternatively, if a sub-program has one and only one output parameter, it can be called as a function in ST language:

Res := MySubProg (i1, i2);