F271_DMAX

Maximum value search in 32-bit data table

The function searches for the maximum value and its position in a 32-bit data table.

Parameters

Input

s1_Start (DWORD, DINT, UDINT, DATE, TOD, DT)

Beginning of data table

s2_End (DWORD, DINT, UDINT, DATE, TOD, DT)

End of data table

Output

Max (DINT)

maximum value

Pos (INT)

position of maximum value

Remarks

  • Input s1_Start specifies the starting area of the data table, and s2_End specifies the end. The maximum value is returned at output Max and its position at output Pos.

  • The position Pos is relative to the position at the beginning of the data table to the first occurrence of the maximum value.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the area specified using the index modifier exceeds the limit.

  • if the address of the variable at input s1_Start > s2_End

  • if s1_Start and s2_End belong to different data areas.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the area specified using the index modifier exceeds the limit.

  • if the address of the variable at input s1_Start > s2_End

  • if s1_Start and s2_End belong to different data areas.

Example

POU header

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
		start: BOOL:=FALSE;
			(*activates the function*)
		data_array: ARRAY [0..4] OF DINT:=[4,7,-32,13,5];
		output_max: DINT:=0;
			(*the maximum value of 
data_array; here: 13*)
		output_pos: INT:=0;
			(*the position of the
maximum value; here: 3*)
	END_VAR

POU body

When the variable start is set to TRUE, the function is carried out.

It searches for the maximum value and its position in the data_field. The result is here: maximum_value = 222222 and position = 2.

LD body

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_VARIN,,output,5,1,7,3,);
B(B_VARIN,,data field[0],5,2,7,4,);
B(B_VARIN,,data field[4],5,3,7,5,);
B(B_F,F271_DMAX,,7,0,16,5,,?DEN?D@'s1'?Ds2?AENO?Cmax?Cpos);
B(B_VAROUT,,maximum,16,2,18,4,);
B(B_VAROUT,,position,16,3,18,5,);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF start then
    F271_DMAX( s1_Start:= data_field[0],
         s2_End:= data_field[4],
         Max=> maximum_value,
         Pos=> position);
END_IF;

IL body

Modified on: 2022-08-23Feedback on this pagePanasonic hotline