CHARCURVE (FB) ¶ FUNCTION_BLOCK CHARCURVE Maps an input signal onto a characteristic curve The characteristic curve is given by an array of POINTs, which include a set of X-values with their corresponding Y-values. Example in ST: VAR CHARACTERISTIC_LINE : CHARCURVE ; KL : ARRAY [0..10] OF POINT := [(X:=0,Y:=0),(X:=250,Y:=50), (X:=500,Y:=150),(X:=750,Y:=400), 7((X:=1000,Y:=1000))] ; COUNTER : INT ; END_VAR COUNTER := COUNTER +10 ; supply CHARCURVE with for example a constantly increasing value CHARACTERISTIC_LINE ( IN := COUNTER , N := 5 , P := KL ); Illustration of the resulting curve InOut: Scope Name Type Comment Input IN INT Input signal N BYTE Number of points defining the characteristic curve : 2 <= N <= 11 Inout P ARRAY [0..10] OF POINT Array of points to describe the characteristic curve Output OUT INT Output variable, contains the manipulated value ERR BYTE 0 : No error 1 : Error in P : wrong sequence (completely tested, only if IN is equal to largest X-value of P ) 2 : IN outside of limits of P 4 : N invalid, number of points not within the allowed range 2..11
RAMP_REAL (FB) ¶ FUNCTION_BLOCK RAMP_REAL Limits the slope of a value to a certain value The function block is similar to RAMP_INT with the difference that the inputs IN , ASCEND , DESCEND and the output OUT are of the type REAL . RAMP_REAL takes more computing time but calculates more precisely than RAMP_INT . Note A reset of the function block ( RESET = TRUE ) stops the calculation and the last output value OUT is maintained. So if afterwards the ramp gets restarted by RESET = FALSE , it will start with this last output value! InOut: Scope Name Type Comment Input IN REAL Input value ASCEND REAL Maximum positive slope DESCEND REAL Maximum negative slope (non-negative!) TIMEBASE TIME Reference for ASCEND/DESCEND : t#0s : ASCEND/DESCEND defined per call Else : ASCEND/DESCEND defined per specified time RESET BOOL Resets the function block Output OUT REAL Fnction value with limited slope
Mathematical Functions ¶ DERIVATIVE (FunctionBlock) INTEGRAL (FunctionBlock) LIN_TRAFO (FunctionBlock) ROTATION_DIFFERENCE (FunctionBlock) STATISTICS_INT (FunctionBlock) STATISTICS_REAL (FunctionBlock) VARIANCE (FunctionBlock)
DERIVATIVE (FB) ¶ FUNCTION_BLOCK DERIVATIVE Approximates the derivative of a given value in its time course Four consecutive values are recorded and used in the calculation so that the resulting derivative is as accurate as possible. Example: Function block in FBD InOut: Scope Name Type Comment Input IN REAL Input value TM DWORD Time since last call in msec RESET BOOL TRUE : OUT is set to zero and saved values are set to the current input IN Output OUT REAL Derivative
INTEGRAL (FB) ¶ FUNCTION_BLOCK INTEGRAL determines approximately the integral over time. Example: Function block in FBD InOut: Scope Name Type Initial Comment Input IN REAL Input value TM DWORD Time since last call in msec RESET BOOL TRUE : OUT is set to zero and OVERFLOW to FALSE Output OUT REAL Value of the integral. This is done by summing all part integrals IN * TM OVERFLOW BOOL FALSE TRUE : The value of OUT is out of range of REAL variables. he function is blocked till it is new initialised by input RESET .
LIN_TRAFO (FB) ¶ FUNCTION_BLOCK LIN_TRAFO Performs a linear transformation The transformation is performed by using the minimum and maximum values of the inputs for a linear approximation of the output value. Application example: A temperature sensor provides Volt-values (input IN ). These are to be converted to temperature values in degree centigrade (output OUT ). The input (Volt) values range is defined by the limits IN_MIN=0 and IN_MAX=10 . The output(degree centigrade) value range is defined by the limits OUT_MIN=-20 and OUT_MAX=40 . Thus for an input of 5 Volt a temperature of 10 degree centigrade will result. InOut: Scope Name Type Comment Input IN REAL Input value IN_MIN REAL Minimum input value IN_MAX REAL Maximum input value OUT_MIN REAL Corresponding minimum output value OUT_MAX REAL Corresponding maximum output value Output OUT REAL Output value ERROR BOOL TRUE : IN_MIN = IN_MAX or IN out of input range
ROTATION_DIFFERENCE (FB) ¶ FUNCTION_BLOCK ROTATION_DIFFERENCE Computes the difference between two UINT values without rollover This function block receives two values e.g. from an motion encoder and calculates the difference between the two positions. If curValue := 65535 and lastValue := 15, a negative rotation is detected and diffValues := -16. If lastValue := 65535 and curValue := 15, a positive rotation is detected and diffValues := 16. InOut: Scope Name Type Comment Input curValue UINT Current value of rotation lastValue UINT Last value of rotation Output diffValues INT Difference between the two values without rollover
STATISTICS_INT (FB) ¶ FUNCTION_BLOCK STATISTICS_INT Calculates minimum, maximum, and average of an input value The calculation is done over time and can be reset in order to start a fresh caluclation/statistic. InOut: Scope Name Type Initial Comment Input IN INT Input value RESET BOOL TRUE : AVG set to 0, MN and MX to minimum and maximum possible integer values Output MN INT 32767 Minimum value MX INT -32768 Maximum value AVG INT Average value
STATISTICS_REAL (FB) ¶ FUNCTION_BLOCK STATISTICS_REAL Calculates minimum, maximum, and average of an input value The calculation is done over time and can be reset in order to begin a fresh caluclation/statistic. InOut: Scope Name Type Initial Comment Input IN REAL Input value RESET BOOL TRUE : AVG set to 0, MN and MX to minimum and maximum possible real values Output MN REAL 3.402823466E+38 Minimum value MX REAL -3.402823466E+38 Maximum value AVG REAL Average value
VARIANCE (FB) ¶ FUNCTION_BLOCK VARIANCE Calculates the mathematical variance of a variable over time In this case, over time means that the variance is extended for each call to the function block until a reset is done. InOut: Scope Name Type Comment Input IN REAL Input value RESET BOOL Reset Output OUT REAL Variance