You can use the Calculation/Logic function block for a wide variety of applications, including complex calculations, signal conditioning, or functionality not available in standard function blocks.
Application example: signal correction
Assume you need to apply the following nonlinear equation to an input value to calculate a corrected signal:
y = 3*x^3 + 2*x^2 + x + 1
Where:
y = corrected signal
x = raw input signal
This is an ideal application for the Calculation/Logic block. The following figure is the function block diagram for this application.
You configure the following expression in the Calculation/Logic block for this application:
OUT1 := 3 * expt( IN1, 3.0 ) + 2 * expt ( IN1, 2.0 ) + IN1 + 1.0;
Application example - signal ordering
Assume you want to arrange four input measurements in ascending order based on value and you want to write the sum of the four measurements to another function block. The following figure is the function block diagram for this application:
You could wire the Analog Input function blocks to the Calculation/Logic block and write the expression to utilize IN1 - IN4. However, this example illustrates the syntax for external references within a module. You configure the expressions as follows:
The expressions sort four external reference inputs from lowest to highest and writes the sorted values to the four outputs. The fifth output is set equal to the sum of the four external reference inputs.
OUT1 := '/FI101.CV';
OUT2 := '/FI102.CV';
OUT3 := '/FI103.CV';
OUT4 := '/FI104.CV';
OUT5 := '/FI101.CV' + '/FI102.CV' + '/FI103.CV' + '/FI104.CV';
swap := FALSE;
REM First pass swap check
IF (OUT1 > OUT2) THEN
temp := OUT1;
OUT1 := OUT2;
OUT2 := temp;
swap := TRUE;
END_IF;
IF (OUT2 > OUT3) THEN
temp := OUT2;
OUT2 := OUT3;
OUT3 := temp;
swap := TRUE;
END_IF;
IF (OUT3 > OUT4) THEN
temp := OUT3;
OUT3 := OUT4;
OUT4 := temp;
swap := TRUE;
END_IF;
REM Second pass swap check
IF swap then
swap := FALSE;
IF (OUT1 > OUT2) THEN
temp := OUT1;
OUT1 := OUT2;
OUT2 := temp;
swap := TRUE;
END_IF;
IF (OUT2 > OUT3) THEN
temp := OUT2;
OUT2 := OUT3;
OUT3 := temp;
swap := TRUE;
END_IF;
IF (OUT3 > OUT4) THEN
temp := OUT3;
OUT3 := OUT4;
OUT4 := temp;
swap := TRUE;
END_IF;
END_IF;
REM Third pass swap check
IF swap then
swap := FALSE;
IF (OUT1 > OUT2) THEN
temp := OUT1;
OUT1 := OUT2;
OUT2 := temp;
swap := TRUE;
END_IF;
IF (OUT2 > OUT3) THEN
temp := OUT2;
OUT2 := OUT3;
OUT3 := temp;
swap := TRUE;
END_IF;
IF (OUT3 > OUT4) THEN
temp := OUT3;
OUT3 := OUT4;
OUT4 := temp;
swap := TRUE;
END_IF;
END_IF;
REM Fourth pass swap check
IF swap then
swap := FALSE;
IF (OUT1 > OUT2) THEN
temp := OUT1;
OUT1 := OUT2;
OUT2 := temp;
swap := TRUE;
END_IF;
IF (OUT2 > OUT3) THEN
temp := OUT2;
OUT2 := OUT3;
OUT3 := temp;
swap := TRUE;
END_IF;
IF (OUT3 > OUT4) THEN
temp := OUT3;
OUT3 := OUT4;
OUT4 := temp;
swap := TRUE;
END_IF;
END_IF;