B&R Automation Studio Limit Instruction example in ANSI C

Published on Jun02, 2023 | Category: C Programming
Share this article:

Limit Instruction in a PLC limit input value to specified maximum and minimum range. we can LIMIT instructions in ladder. in ANSI we create a limit function because ANSI Don\'t have limit instructions. so i am creating a simple limit instructions example. we can discuss more what is function in ANSI. we create a limit function with the help of conditional statement (if else). limit function that limits a value between a minimum and maximum range so first we create a Limit function.

create a limit function in ANSI C

create a limit function in ANSI C

In the above example, limit function takes three input arguments

inside the The function checks we check range by conditional statement. if the value is less than minimum value than minimum value return as output value if the input value is greater than maximum value than maximum return the maximum value. Otherwise, input value return as output value.

Call limit Function in a main program

img/limit function in c/Call limit Function in a main program.webp

now we call a limit function in main program and pass function parameter by new variable or constant value. if the input value within the range of maximum and minimum range then output is equal to input value. for example if the maximum value is 12.30 and minimum value is 1.0 so output of limit instruction is not greater then 12.3 and not less then 1.0. if the input value is greater then 12.30 then output is 12.30 and if the input value is less then 1.0 so the output is set to 1.0. in this program we all real data type.

limit Function With constant Value

limit Function With constant Value

we can use same limit function multiple time so we in second line of program we use limit function for a constant value. in this declaration we pass constant value as function arguments.12.0 is minimum range, 98.0 is maximum value and 13.0 is a input value. limit instruction in ladder and Structured Text visit link