9. Arithmetic Functions
9.1. F_LIN
Type Function: REAL
Input X : REAL
A : REAL
B : REAL
Output REAL (F_LIN = A*X + B)
The function F_LIN returns the Y value of a linear equation.
F_LIN = A*X + B
9.2. F_LIN2
Type Function: REAL
Input X : REAL
X1, Y1: REAL (frst coordinate)
X2, Y2: REAL (second coordinate)
Output REAL (value on the line passing through the above 2 points
defned.)
The function F_LIN2 returns the Y value of a linear equation.
The straight line here is defned by the specifcation of two coordinate
points (X1, Y1, X2, Y2).
9.3. F_POLY
Type Function: REAL
Input X: REAL (input)
C: ARRAY[07] of REAL (polynomial coefcients)
Output REAL (result of the polynomial equation)
F_POLY calculates a polynomial of 7th degree.
F_POLY = C[0] + C[1] * X^1 + C[2] * X^2 + .C[7] * X^7
9.4. F_POWER
Type Function: REAL
Input A : REAL
X : REAL
N : REAL
Output REAL (result of the equation F_POWER = A * X^N)
F_Power calculate the power function according to the equation F_POWER
= A * Xn.
9.5. F_QUAD.
Type Function: REAL
Input X : REAL
A, B, C: REAL
Output REAL (F_QUAD = A * X² + B * X + C)
F_QUAD calculates the result of a quadratic equation using the formula
f_QUAD = A * X ² + B * X + C.
9.6. FRMP_B
Type Function: BYTE
Input START: BYTE (start value)
DIR: BOOL (direction of the ramp)
TD: TIME (Elapsed time)
TR: TIME (rise time for ramp from 0255)
Output BYTE (output)
FRMP_B calculates the value of a ramp at a given time TD. The module en-
sures that no bufer overrun or underrun can take place at the output. The
output value is limited in all cases to 0 255. TR sets the time for a full
ramp 0 255 and TD is the elapsed time. If DIR = TRUE, a rising ramp is
calculated and if DIR = FALSE a falling edge. With the start value an edge
can be calculated from any starting point.
9.7. FT_AVG
Type Function module
Input IN: REAL (input signal)
E: BOOL (enable input)
N: INT (number of values over which the average is calculated)
RST: BOOL (Reset input)
Output REAL (moving average over the last N values)
The function module FT_AVG calculates a moving average over each of
the last N values. By the input RST, the stored values can be deleted. N is
defned from 0 32. N = 0 means that the output signal = input signal. N
= 5 is the average over the last 5 values. The average is calculated over a
maximum of 32 values. With input E can be control when the input is read.
This allows a simple way to connect a sample and a hold module, such as
SH_1 with FT_AVG can be linked. The frst call to FT_AVG the bufer load
the input signal to avoid that a Ramp-up takes place.
The following example reads SH_1 once a second the input value Signal_In
and passes these values once per second to FT_AVG, which then forms out
of the last 8 values the mean value.
9.8. FT_MIN_MAX
Type Function module
Input IN: REAL (input signal)
RST: BOOL (Reset input)
Output MX: REAL (maximum value of the input signal)
MN: REAL (minimum value of the input signal)
FT_MIN_MAX stores the minimum and maximum value of an input signal
IN and provides these two values at the outputs of MN and MX until clea-
red by a reset. A reset sets MN and MX on the reset applied input values.
9.9. FT_RMP
Type Function module
Input RMP: BOOL ( Enable Signal)
IN: REAL (input signal)
KR: REAL (rate of increase in 1 / seconds)
TV: REAL (speed of the drop in 1 / seconds)
Output OUT_MAX: REAL (upper output limit)
BUSY: BOOL (Indicates if the output rises or falls)
UD: BOOL (TRUE, when output is rising and false if
Output drops)
The output OUT follows the input with a linear ramp with defned rise and
fall speed (KR and KF). K = 1 means that the output increases with 1 unit
per second, or falls. The K factor must be greater than 0. The output of UD
is TRUE if the output is rising and FALSE if it drops. When the output rea-
ches the input value is BUSY FALSE, otherwise BUSY is TRUE and indicates
that a rising or falling ramp is active.
The output follows the input signal as long as the rise and fall speed of the
input signal is smaller than that by KR and KF defned maximum increase
or decrease speed. Changing the input signal faster, the output runs at
the speed of KR or KF after the input signal. The ramp generation is real-
time, which means that FT_RMP calculates every time where the output
should be and sets this value to the output. The main change is therefore
dependent on the cycle time and is not in equal steps. If a ramp out of
sheer same steps are required, are the modules RMP_B and RMP_W are
available. The module is only active when the input RMP = TRUE.
The following chart shows the profle of the output as a function of an in-
put signal:
9.10. LINEAR_INT
Type Function
Input X: REAL (input)
XY: ARRAY [120,01] (Ascending sorted values pairs)
PTS: INT (number of pairs of values)
Output REAL (output)
LINEAR_INT is a linear interpolation module. A characteristic is described
by a maximum of 20 coordinate values (X, Y) and is cut up to 19 linear
segments. The defnition of the coordinate values is passed in an array
which describes the characteristic with individual X, Y describes value
pairs. The value pairs must be sorted by the x_value. If an X value is called
outside range which is described by the value pairs, then the frst respecti-
ve last linear segment is extrapolated and the corresponding value Issued.
To keep the number of defnition points fexible, at the input PTS is given
the number of points. The possible score is in the range from 3 to 20, whe-
rein each individual dot is shown with X-and Y-value.
Example:
VAR
BEISPIEL : ARRAY[120,01] := -10,-0.53, 10,0.53, 100,88.3,
200,122.2;
END_VAR
for the above defnition, the following results are valid:
LINEAR_INT (0, example, 4) = 0;
LINEAR_INT (30.0, example, 4) = 20.0344;
LINEAR_INT (66.41, example, 4) = 55.54229;
LINEAR_INT (66.41, example, 4) = 55.54229;
9.11. POLYNOM_INT
Type Function
Input X: REAL (input)
XY: ARRAY [15,01] (Ascending sorted values pairs)
PTS: INT (number of pairs of values)
Output REAL (output)
POLYNOM_INT interpolates a number of pairs of values with a polynomial
of N times degree. The number of pairs is PTS, and N is the number of
pairs of values (PTS). Any characteristic is described by a maximum of 5
coordinate-values (X, Y) and internally described by a polynomial. The de-
fnition of the coordinate values is passed in an array which describes the
characteristic with individual X, Y describes value pairs. The value pairs
must be sorted by the x_value. If an X value is queried outside the descri-
bed range by value-apairs, so that is calculated according to the determi-
ned polygon. It is noted, that here can occur oscillations above and below
the area of defnition by a polynomial of higher degree , and calculated va-
lues mostly are not useful in this area. Before the application of a polyno-
mial it is essential for this purpose to read the basics, for example, in Wiki-
pedia. To keep the number of defnition points fexible, at the input PTS is
given the number of points. The possible score is in the range from 3 to 5,
wherein each individual dot is shown with X-and Y-value. A Polynomial with
more than 5 points leads to an increased tendency to oscillate and is for
this reason refused.
The following example shows the defnition for the array XY and some va-
lues:
VAR
EXAMPLE : ARRAY[15,01] := -10,-0.53, 10,0.53, 100,88.3, 200,122.2;
END_VAR
for the above defnition, the following results are valid:
POLYNOM_INT(0, example, 4) = -1.397069;
POLYNOM_INT(30.0, example, 4) = 11.4257;
POLYNOM_INT(66.41, example, 4) = 47.74527;
POLYNOM_INT(800.0, example, 4) = -19617.94;
When the results of the example is clearly seen that the value of
-19617.94 for the input X = 800 makes no sense, since it is outside the
defned range of -10 to +200.
The following trace recording shows the variation of output to input. Here,
clearly, the overshoot of the polygon with respect to a linear interpolation
can be seen. Green = input X, Red = linear interpolation, Blue = polynomi-
al interpolation.