Search maximum value in data table
This FP instruction determines the maximum value and its position in a data table.
Input
Beginning of data table
End of data table
Output
Maximum value
Position of maximum value
Input s1_Start specifies the beginning of the data table, and s2_End specifies the end. The maximum value is returned at output d1_Max and its position at output d2_Pos.
The position d2_Pos is the position of the first occurrence of the maximum value relative to the beginning of the data table.
if the area specified using the index modifier exceeds the limit.
if s1_Start > s2_End
if s1_Start and s2_End belong to different data areas.
if the area specified using the index modifier exceeds the limit.
if s1_Start > s2_End
if s1_Start and s2_End belong to different data areas.
All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.
VAR
bStart: BOOL:=FALSE;
(*activates the function*)
adiDataField: ARRAY [0..4] OF DINT:=[2,3,222222,-333333,1];
diOutputMax: DINT:=0;
(*the maximum value of
data_array; here: 222222*)
diOutputPos: DINT:=0;
(*the position of the
maximum value; here: 2*)
END_VAR
When the variable bStart is set to TRUE, the function is carried out.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_F,FP_DATA_MAX_POS!,,12,1,22,6,,?DEN?Ds1_Start?Ds2_End?AENO?Cd1_Max?Cd2_Pos);
B(B_CONTACT,,bStart,5,2,7,4,);
B(B_VARIN,,adiDataField[0],10,3,12,5,);
B(B_VARIN,,adiDataField[4],10,4,12,6,);
B(B_VAROUT,,diOutputMax,22,3,24,5,);
B(B_VAROUT,,diOutputPos,22,4,24,6,);
L(1,3,5,3);
L(7,3,12,3);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF bStart then
FP_DATA_MAX_POS(s1_Start := adiDataField[0],
s2_End := adiDataField[4],
d1_Max => diOutputMax,
d2_Pos => diOutputPos);
END_IF;