LIMIT

Limit value for input variable

In LIMIT the 1st input variable forms the lower and the 3rd input variable the upper limit value. If the 2nd input variable is within this limit, it will be transferred to the output variable. If it is above this limit, the upper limit value will be transferred; if it is below this limit the lower limit value will be transferred.

Parameters

Input

MN (INT, DINT, UINT, UDINT, REAL, LREAL)

1st input: lower limit

IN (INT, DINT, UINT, UDINT, REAL, LREAL)

2nd input: value compared to upper and lower limit

MX (INT, DINT, UINT, UDINT, REAL, LREAL)

3rd input: upper limit

Output

VAR_OUT (INT, DINT, UINT, UDINT, REAL, LREAL)

Output as input: result, 2nd input value if between upper and lower limit, otherwise the upper or lower limit

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
		lower_limit_val: INT:=0;
			(*all types allowed*)
		comparison_value: INT:=0;
			(*all types allowed*)
		upper_limit_val: INT:=0;
			(*all types allowed*)
		result: INT:=0;
			(*all types allowed*)
	END_VAR

In this example the input variables (lower_limit_val, comparison_value and upper_limit_val) have been declared. Instead, you may enter a constant directly at the input contact of a function.

LD body

lower_limit_val and upper_limit_val form the range where the comparison_value has to be, if it has to be transferred to result.

  • If the comparison_value is above the upper_limit_val, the value of upper_limit_val will be transferred to result.

  • If it is below the lower_limit_val, the value of lower_limit_val will be transferred to result.

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,,lower_limit_val,9,1,11,3,);
B(B_VARIN,,comparison_value,9,2,11,4,);
B(B_VARIN,,upper_limit_val,9,3,11,5,);
B(B_VAROUT,,result,16,1,18,3,);
B(B_F,LIMIT!,Instance,11,0,16,5,,?DMN?DIN?DMX?C);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

result:=LIMIT(MN:=lower_limit_val, IN:=comparison_value, MX:=upper_limit_val);

IL body

LD

lower_limit_val

LIMIT

comparison_value, upper_limit_val

ST

result

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