Analog Control Blocks > Calculation/Logic function block

Calculation/Logic function block execution

The Calculation/Logic function block uses as many as 16 inputs and 16 outputs to evaluate its contained expression. In addition, the expression evaluator uses constants and external references that you specify to evaluate the expression. The calculated values are assigned to external references or outputs for use as parameters or inputs to the control strategy in other blocks.

The number of inputs and outputs in the Calculation/Logic function block are extensible parameters. The block default is two inputs and two outputs. You add inputs or outputs by right-clicking the function block diagram, clicking Extensible Parameters, and then modifying the number of inputs and/or outputs. This creates additional input/output connectors for the block.

Expressions

Expressions are structured text in a specific syntax and are made up of operands, operators, functions, constants, and keywords. You write expressions using the Expression Editor.

The Calculation/Logic function block supports IF-THEN-ELSE-END_IF structures.

When the IF {Expression} evaluates to True or non-zero, any commands following IF and prior to ELSE or END_IF (whichever occurs first) are executed.

When the IF {Expression} is False and ELSE is included, any commands after ELSE and before END_IF are executed.

When the IF {Expression} is False and ELSE is not included, all commands between IF and END_IF are ignored. In this case, program execution continues with the first command following END_IF.

You can nest an IF ... END_IF block within another IF ... END_IF block. Comments can be placed on the same line after IF, ELSE, and END_IF. Multiple statements can be placed between the THEN and ELSE keywords, as well as between the ELSE and ENDIF keywords.

In the following example, the condition tests whether '/Block1.mode.ACTUAL' is equal to manual. Notice that the '=' operator is not used as an assignment operator; it tests the two operands for equality. If the condition is True, the '/Block1.mode.TARGET' is set to AUTO; otherwise, OUT1 is set to the value of IN1.

IF '/Block1.mode.ACTUAL' = MAN THEN
   '/Block1.mode.TARGET' := AUTO;
ELSE
   OUT1 := IN1;
ENDIF;
Note

In the Calc/Logic block, the OUT(n) and IN(n) parameters refer to the OUT(n).CV and IN(n).CV fields respectively. 

It is not always necessary to use the ELSE portion of the statement. For example, if you want to set the MERROR parameter to True when the PV of LIC549 goes above 75, you write the expression as follows:

IF '//LIC549/PV.CV' > 75 THEN
   '//LIC549/MERROR.CV' := TRUE;
ENDIF;
Note

The CV extension in this example stands for current value. Some parameters also support a status value, ST.

If the CALC function block executes a divide by zero expression or calculates a result that is out of range (less than -3.40282e+038 or greater than 3.40282e038), the status of the output is set to Bad. In addition, if the expression divides by zero, the Configuration Error bit in the CALC block's BLOCK_ERR parameter is set.