166
ST-language Program Example Section 5-6
• ST-language Algorithm
If bCheck is true, function block 2 is called to calculate the average value.
The 3 values data1, data2, and data3 are passed to function block 2 input
variables input1, input2, and input3 respectively. The result of the calcula-
tion (average) is returned to AVG.
Note The following diagram shows the Average_FB function block called
with specification method A (both function block’s variables listed).
IF bCheck = TRUE THEN
Average(input1:=data1,input2:=data2,input3:=data3,aver-
age=>AVG);
ELSE
RETURN;
END_IF;
Function Block 2
• Variable Table
• ST-language Algorithm
Calculates the average value of input1, input2, and input3 and stores the
result in average.
average:=(input1+input2+input3)/3;
5-6 ST-language Program Example
5-6-1 Using an ST Program in a Function Block
Converting an Integer
to BCD and
Outputting It as a Text
String
Input Variable
INT Input_Num;
Input-Output Variable
STRING Output_String;
Internal Variable
WORD Num_BCD;
(*Check Input_BCD input parameter (BCD data)*)
IF(Input_BCDNum>=0 & Input_BCD<=16#Num<=9999) THEN
Variable type Variable name Data type Passage to/from FB1
Input variable EN BOOL ---
Input variable input1 INT Received from data1
Input variable input2 INT Received from data2
Input variable input3 INT Received from data3
Output variable ENO BOOL ---
Output variable average INT Passed to AVG
FB
(BOOL)
EN
(BOOL)
ENO
(INT)
Input_Num
(STRING) (STRING)
Output_String−Output_String