Skip to main content

Operators

The built-in standard functions that represent a subset of the standard IEC functions are called operators. User-defined functions cannot be created in the safety programming.

The operators have the same semantics as in CODESYS Standard.

They can be connected to both SAFExxx and Data types Standard.

Insertion of operators

The operators are inserted using the Insert Box or Insert Empty Box command.

The operators can also be added from the toolbox in the ToolBox view. The toolbox in the Safety FBD Editor contains the following categories:

  • Boolean operators

  • Mathematical operators

  • Other operators

Input Assistant

The following categories are displayed for operators in the Input Assistant:

  • Operators

  • Conversions (not in the Basic Level)

Extendable operators

. Operators extendable by additional inputs
  • AND

  • OR

  • ADD (only in the Extended Level)

  • MUL (only in the Extended Level)

  • MUX (only in the Extended Level)

The EQ, LT, LE, GT, and GE operators, which are likewise extendable in accordance with IEC, can be used only with two inputs (as in the case of standard ).

The Insert Input command adds a further input to an extendable operator box.

Operators in the Basic Level

. Boolean operators
  • AND (2 inputs)

  • AND (3 inputs)

  • OR (2 inputs)

  • OR (3 inputs)

All operands of the OR must be SAFEBOOL.

Operators in the Extended Level

. Boolean operators
  • AND (2 inputs)

  • AND (3 inputs)

  • OR (2 inputs)

  • OR (3 inputs)

  • XOR

  • NOT

Important

The careless use of the XOR and NOT operators can lead to the loss of the fail-safe property of SAFExxx variables. No warning is generated by the safety checker for such constructs.

The XOR and NOT operators can negate the fail-safe property of a SAFExxx variable, so that the SAFE variable loses its fail-safe property, i.e. it becomes "non-fail-safe". This can lead to unintentional starting of the plant.

Programming rule: The SAFExxx outputs of NOT and XOR must be determined. Subsequently, it must be ensured that these NOT/XOR outputs are not connected through to outputs (I/Os).

. Mathematical operators
  • ADD (2 inputs): Arithmetic ADD operator

  • ADD (3 inputs): Addition with three inputs

  • SUB: Subtraction

  • MUL: Multiplication

  • DIV: Division

  • EQ: Comparison for equality

  • NE: Comparison for inequality

  • LT: Comparison for "less than"

  • LE: Comparison for "less than" or "equal to"

  • GT: Comparison for "greater than"

  • GE: Comparison for "greater than" or "equal to"

. Other operators
  • SEL

  • MUX

. Conversions
  • BOOL_TO_INT

  • BOOL_TO_DINT

  • BOOL_TO_TIME

  • BOOL_TO_WORD

  • BYTE_TO_INT

  • BYTE_TO_DINT

  • BYTE_TO_TIME

  • BYTE_TO_WORD

  • DINT_TO_BOOL

  • DINT_TO_BYTE

  • DINT_TO_INT

  • DINT_TO_TIME

  • DINT_TO_WORD

  • DINT_TO_DWORD

  • DWORD_TO_DINT

  • DWORD_TO_TIME

  • INT_TO_BOOL

  • INT_TO_BYTE

  • INT_TO_DINT

  • INT_TO_DWORD

  • INT_TO_TIME

  • INT_TO_WORD

  • TIME_TO_BOOL

  • TIME_TO_BYTE

  • TIME_TO_INT

  • TIME_TO_DINT

  • TIME_TO_WORD

  • TIME_TO_DWORD

  • WORD_TO_BOOL

  • WORD_TO_BYTE

  • WORD_TO_DINT

  • WORD_TO_INT

  • WORD_TO_TIME

  • WORD_TO_DWORD

Operators with Safety characteristics

The characteristics of some operators specific to are described in the following sections

Runtime error in case of operator overrange in the Extended Level

Important

It is the developers responsibility to design the program logic such that no runtime errors occur.

Reacts to the following overranges with a runtime error, as a result of which the application is stopped and a log entry is generated.

Level

Language element

Runtime error in case of

Extended

DIV

Division by 0

Extended

MUX

Call with first input with a negative value or with a value N that is greater than the number of inputs minus 1. Example: MUX(2, 16#8000, 16#8001)

Extended

DINT_TO_INT,

TIME_TO_DINT,

TIME_TO_INT,

DINT_TO_TIME,

INT_TO_TIME,

DINT_TO_WORD,

TIME_TO_WORD,

DINT_TO_BYTE,

INT_TO_BYTE,

TIME_TO_BYTE, WORD_TO_BYTE

Output value is not in the value range of the target type: When converting between two ANY_MAGNITUDE types (INT, DINT, TIME), the numerical output value must lie within the range of values of the target type (where TIME values are counted as a number of milliseconds). When converting from/to bit string types (BYTE, WORD, DWORD), the bit pattern of the output value must be a bit pattern of the target type. Examples:

DINT_TO_INT(16#0000FFFF), because 216-1 is not an INT value,

likewise DINT_TO_TIME(-1), because there are no negative TIME- values

TIME_TO_DINT(t#365d), because 365 days = 3,153,600,000ms = 16#BBF81E00 and is therefore greater than the largest DINT number 231-1 = 16#7FFFFFFF

INT_TO_BYTE(-1), because BYTE encompasses only 0 to 255,

WORD_TO_BYTE(0xFFFF), because BYTE extends only to 0xFF.

Tip

The standard behavior of SEL/MUX (i.e. the maximum value is selected if the input value is too large and 0 is selected if the input value is negative) must be programmed in the safety application.

Figure 40. Programming of the standard behavior of SEL: for k<0
Programming of the standard behavior of SEL: for k<0


Figure 41. Programming of the standard behavior of SEL: for k>max, n...maximum value
Programming of the standard behavior of SEL: for k>max, n...maximum value


Figure 42. Programming of the standard behavior of MUX for k<0
Programming of the standard behavior of MUX for k<0


Figure 43. Programming of the standard behavior of MUX for k>0
Programming of the standard behavior of MUX for k>0