Calculator object

You can use the computer object to perform arithmetic operations with operands or to link operands. The following functions are possible:

  • AND, OR, Exclusive OR combinations with bit operands, SR flip flop, RS flip flop
  • Addition, Subtraction
  • Multiplication
  • Modulo
  • Decimal-to-BCD for byte operands
  • BCD-to-decimal for byte operands
  • Comparisons: Greater than, Greater than or equal to, Less than, Less than or equal to, Equal to
  • Areas: In range, Out range
  • Assemble UInt32 from bytes

A maximum of 4 operands can be specified for the function. The result of the function is written into an operand. If the operand with the result is a bit operand, it can be inverted.

Evaluation of positive and negative edges when using bit operands

If bit operands are used as input operands, the positive or negative edge of such an operand can also be included in the operation. First the bit operand at the desired input is specified and then the input cursor is placed before the operand specification. Then press the key combination [CTRL] + [P] for the positive edge or [CTRL] + [N] for the negative edge. As a result, an up arrow (pos. edge) or a down arrow (neg. edge) is displayed in front of the operand.

Negated query of a bit operand (from V1.7.0.0)

If bit operands are used as input operands, the negated state of the operand can also be included in the logic operation. The negated query is reached via the character '!', which must be specified before the operand and the device name. Example: "!Sim.I0.0"

AND, OR, Exclusive OR combinations with bit operands, SR flip flop, RS flip flop

AND, OR, and Exclusive OR

All 4 input operands can be assigned. If fewer operands are specified, the unused input operands must be assigned the constants '1' or '0'. This depends on which constant is neutral for the operation.

SR flip flop

The first input is the set-input. The second input is the reset-input.

RS flip flop

The first input is the reset-input. The second input is the set-input.

A bit operand must be specified on the operand for the function result. This can be inverted via the property "Invert result".

Addition, Subtraction, Multiplication

All 4 input operands can be assigned. If fewer operands are specified, the unused input operands must be assigned constants. This depends on which constant is neutral for the operation.

Subtraction

With subtraction, the values of the operands of inputs 2 to 4 are subtracted from the value of the operand at the first input.

You have to specify an operand at the function result which is able to receive the value of the result. Otherwise there will be no write operation in the operands.

Modulo

Only the first two input operands are used for this operation. The function result is determined from: Operand 1 [Modulo] Operand 2

You have to specify an operand at the function result which is able to receive the value of the result. Otherwise there will be no write operation in the operands.

Decimal-to-BCD for byte operands

Only the first input operand is used for this operation. Only the lowest-value byte of the operand is evaluated. The calculated value is then converted to BCD and the result is written to the operands of the function result.

BCD-to-Decimal for byte operands

Only the first input operand is used for this operation. Only the lowest-value byte of the operand is evaluated. The calculated value is then converted from BCD to decimal and the result is written to the operands of the function result.

Comparisons: Greater than, Greater than or equal to, Less than, Less than or equal to, Equal to

Only input operands 1 and 2 are used in the comparison operations. The operands can have different widths, i.e. the contents of a byte operand can be compared with the contents of a word operand.

The operations are executed as follows:

  • Greater than: Value operand 1 > Value operand 2
  • Greater than or equal to: Value operand 1 >= Value operand 2
  • Smaller than: Value operand 1 < Value operand 2
  • Less than or equal to: Value operand 1 <= Value operand 2
  • Equal: Value operand 1 == Value operand 2

The function result is usually to be written into a bit operand. If a byte, word, or double word operand is specified, then the values '0' or '1' are written.

Areas: In range, Out range

Only input operands 1, 2, and 3 are used in the area operations. The operands can have different widths, i.e. the contents of a byte operand can be compared with the contents of a word operand.

The operand whose value is checked must be specified at input operand 2. The minimum value of the area must be specified at input operand 1. This can be either an operand or a constant. The maximum value of the area must be specified at input operand 3. This can be either an operand or a constant.

The evaluation is as follows:

  • In range: Value input operand 1 <= Value input operand 2 <= Value input operand 3
  • Out range: Value input operand 1 > Value input operand 2 or Value input operand 2 > Value input operand 3

The function result is usually to be written into a bit operand. If a byte, word, or double word operand is specified, then the values '0' or '1' are written.

Assemble UInt32 from bytes

This function can be used to specify bytes (operands or constants) at the inputs, which are then copied into a double word at the function result. The following rule applies:

  • Input 1: is copied into the HiByte of the HiWord.
  • Input 2: is copied into the LoByte of the HiWord.
  • Input 3: is copied into the HiByte of the LoWord.
  • Input 4: is copied into the LoByte of the LoWord.

This function is especially useful when the color of a geometric object or a fluid object is specified by a double word. This is described under the following link: Influence color via double word operands

Using the calculator object

You can use the calculator object in many different ways.

You can use it, for example, to equip a liquid object with an additional fill level sensor. To do this, you would use the "In range" function. If, for example, you want to set the operand IM.M10.1 to '1' as soon as the liquid object's fill level is between 800 and 1000 increments, set the computer object as follows. Here we assume that the current fill level is stored in the word operand IM.MW2.

The "In range" function can also be used if the position of linear or rotary movements needs to be detected by sensors. Here the calculator object is used in a similar way as shown in the above example with the fill level.

An additional possible use is the triggering of events in the virtual system in order to imitate the behavior of the real system. This is often achieved by linking operands of the internal memory area of PLC-Lab (IM).