FUNCTION_BLOCK FB67
TITLE ='rate limiter'
AUTHOR : hdhosseini
VERSION : '1.0'
// Block Parameters
VAR_INPUT
// Input Parameters
input:REAL;
rst:BOOL:=false;
step:REAL:=0.1; //100ms call
factor:REAL:=1.0;
high:REAL:=100;
low:REAL:=0;
END_VAR
VAR_IN_OUT
// I/O Parameters
first:BOOL:=true;
END_VAR
VAR_OUTPUT
// Output Parameters
out:REAL;
END_VAR
VAR_TEMP
// Temporary Variables
END_VAR
VAR
// Static Variables
buffer:REAL:=0;
in:REAL;
END_VAR
// Statement Section
IF rst=true THEN
buffer:=0;
//first:=true;
out:=0;
in:=0;
;
ELSE
IF first= true THEN
buffer:=in;
first:=false;
END_IF;
IF input >= high THEN
in:=high;
END_IF;
IF input <= low THEN
in:=low;
END_IF;
IF (input > low) AND (input<high) THEN
in:=input;
END_IF;
IF in > (buffer+step) THEN
buffer:= (buffer+(step* factor));
END_IF;
IF in < (buffer-step) THEN
buffer:= (buffer-(step*factor));
END_IF;
IF in = buffer THEN
buffer:=in;
END_IF;
;
out:= buffer;
END_IF;
;
END_FUNCTION_BLOCK