F270_MAX

Maximum value search in 16-bit data table

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

Parameters

Input

s1_Start (WORD, INT, UINT)

Beginning of data table

s2_End (WORD, INT, UINT)

End of data table

Output

Max (INT)

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 INT:=[4,7,-32,13,5];
		output_max: INT:=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 = 6 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 := 5 ;
        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_VAROUT,,maximum,15,2,17,4,);
B(B_F,F270_MAX,,7,0,15,5,,?DEN?D@'s1'?Ds2?AENO?Cmax?Cpos);
B(B_VAROUT,,position,15,3,17,5,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF start then
    F270_MAX( 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