Maximum value
MAX determines the input variable with the highest value.
Input
1st input: value 1
2nd input: value 2
Output
result, whichever input variable's value is greater
This function can be expanded to a maximum of 28 input contacts, see also modifying elements.
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
value_1: INT:=0;
(*all types allowed*)
value_2: INT:=0;
(*all types allowed*)
maximum_value: INT:=0;
(*all types allowed*)
END_VAR
In this example the input variables (value_1 and value_2) have been declared. Instead, you may enter a constant directly at the input contact of a function.
Value_1 and value_2 are compared with each other. The maximum value of all input variables is written in maximum_value.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_F,MAX-2!,Instance,7,0,12,3,,?D?D?C);
B(B_VARIN,,value_1,5,0,7,2,);
B(B_VARIN,,value_2,5,1,7,3,);
B(B_VAROUT,,maximum_value,12,0,14,2,);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
END_BODY
maximum_value:=MAX(value_1, value_2);
LD |
value_1 |
MAX |
value_2 |
ST |
maximum_value |