SIMATIC and IEC 1131-3 Data Types

There are two circumstances under which you must understand and use data types when programming in STEP 7-Micro/WIN 32:

·If you are programming in IEC 1131-3 mode, you must make a data type selection for all values in the Global Symbol Table chart.

·If you are making assignments in a Local Variable Table, you must define a data type for each local variable.

When you explicitly assign a data type to a value, you provide STEP 7-Micro/WIN with unambiguous instructions about how much memory to allocate for the value (for instance, the value 100 could be stored as a BYTE, a WORD, or a DWORD) and how to represent the value (should 0 be treated as a BOOL or a numeric value?).

Every SIMATIC and IEC 1131-3 instruction or parameterized subroutine is identified by a precise definition. This definition can be referred to as a signature. For all standard instructions, the set of allowable data types for each instruction operand is obtained from the signature. For parameterized subroutines, the signature of the subroutine is created by the user through the Local Variable Table.

The STEP 7-Micro/WIN 32 V3.0 Programming software implements simple data type checking for SIMATIC mode, and strong data type checking for IEC 1131-3 mode. This means when a data type is specified for either a local or global variable, the software makes sure that the operand data type matches the instruction signature to the level specified below.

Elementary Data Types Data Type Size Description Range
BOOL 1 bit Boolean 0 to 1
BYTE 8 bits Unsigned Byte 0 to 255
BYTE 8 bits Signed Byte (SIMATIC mode for SHRB instruction only) -128 to +127
WORD 16 bits Unsigned Integer 0 to 65,535
INT 16 bits Signed Integer -32768 to +32767
DWORD 32 bits Unsigned Double Integer 0 to 4294967295
DINT 32 bits Signed Double Integer -2147483648 to +2147483647
REAL 32 bits IEEE 32 bit floating point +1.175495E-38 to +3.402823E+38

-1.175495E-38 to -3.402823E+38


Complex Data Types Description Range
TON On-Delay Timer 1 ms T32, T96

10 ms T33 - T36, T97 - T100

100 ms T37 - T63, T101 -T255

TOF Off-Delay Timer 1 ms T32, T96

10 ms T33 - T36, T97 - T100

100 ms T37 - T63, T101 - 255

TP Pulse Timer (See Note 1) 1 ms T32, T96

10 ms T33 - T36, T97 - T100

100 ms T37 - T63, T101 - 255

CTU Up Counter 0 to 255
CTD Down Counter 0 to 255
CTUD Up/Down Counter 0 to 255
SR Set Dominant Bistable N/A
RS Reset Dominant Bistable N/A

STEP 7-Micro/WIN 32 Has Three Levels of Data Type Checking

1.Strong Data Type Checking. In this mode, the parameter data type must exactly match the symbol or variable data type. To support strong data type checking, except for overloaded instructions, each formal parameter has only one data type. For example, the IN parameter of a SRW (Shift Right Word) instruction has the data type WORD. Under strong data type checking, only variables that are assigned the WORD data type compile successfully. Variables that are data typed as INT are not valid for WORD instruction parameters when strong data type checking is enforced. Strong data type checking is only performed within IEC 1131-3 modes.

User Selected Data Type Equivalent Data Type
BOOL BOOL
BYTE BYTE
WORD WORD
INT INT
DWORD DWORD
DINT DINT
REAL REAL

2.Simple Data Type Checking. In this mode, when a symbol or variable is given a data type it is also automatically assigned all data types that match the bit size of the selected data type. For example, if the user selects DINT as the data type, the local variable automatically assigns the data type DWORD because both are 32-bit data types. The data type REAL is not automatically assigned even though it is also a 32-bit data type. The data type REAL is defined as having no other data type equivalent: it is always unique. Simple data type checking is only performed within SIMATIC modes when using local variables.

User Selected Data Type Equivalent Data Type
BOOL BOOL
BYTE BYTE
WORD WORD, INT
INT WORD, INT
DWORD DWORD, DINT
DINT DWORD, DINT
REAL REAL

3.No Data Type Checking. This mode is only available for SIMATIC global variables where data types are not selectable. In this mode, all data types of equivalent size are automatically assigned to the symbol. For example, a symbol that is assigned the address VD100 is assigned the following data types automatically by the programming software: DWORD, DINT, and REAL.

Size Determined Data Type for SIMATIC Global Symbols

User Selected Address Assigned Equivalent Data Type
V0.0 BOOL
VB0 BYTE
VW0 WORD, INT
VD0 DWORD, DINT, REAL

Benefits of Data Type Checking

The benefit of data type checking is to assist the user in avoiding common programming mistakes. For example, if an instruction supports signed numbers, then there is a benefit when the software flags the use of an unsigned number for an instruction operand. For example, the relational comparison < I is a signed instruction. Obviously, -1 is less than 0 for signed data type operands. However, when the < I instruction is allowed to support an unsigned data type, the burden is on the programmer to make sure the following never occurs. During run-time program execution, an unsigned value of 40,000 is actually less than 0 for a < I instruction. It is up to the programmer to make sure that the use of the unsigned number for signed instructions does not cross the positive and negative boundary or unpredictable results will occur.

Warning

You should ensure that the use of the unsigned number for signed instructions does not cross the positive and negative boundary.

Failure to ensure that unsigned numbers for signed instructions do not cross the positive and negative boundary can create unpredictable results in your program or controller operation. Unpredictable controller operation can result in death or serious injury to personnel, and/or substantial property damage.

Always ensure that the unsigned number for a signed instruction does not cross the positive and negative boundary.


In summary, under the IEC 1131-3 editing mode, strong data type checking can help the programmer identify these errors during compilation by generating errors for data types that are illegal for the instruction. This capability is not available for the SIMATIC editors.

Porting Programs between SIMATIC and IEC 1131-3

Since IEC 1131-3 is strongly data typed and SIMATIC is not, STEP 7-Micro/WIN 32 does not provide the ability to move programs between the two different editing modes. The programmer must choose the preferred editing mode.

Overloaded Instructions

Overloaded instructions support a range of data types. Strong data type checking is still applied and so all of the operand data types must match before the instruction can successfully compile. For example, consider the following chart for the IEC overloaded ADD instruction.

Instruction Allowed Data Types

(Strong Data Type Checking)

Allowed Data Types

(Data Type Checking)

Compiled Instruction
ADD INT WORD, INT ADD_I (Add Integer)
ADD DINT DWORD, DINT ADD_D (Add Double Integer)
ADD REAL REAL ADD_R (Add Real)

When all of the operands have the data type DINT, an Add Double Integer instruction is generated by the compiler. A compilation error occurs if data types are mixed for the Overloaded Instruction. What is considered illegal depends on the level of data type checking. The following example generates a compiler error under strong data type checking but compiles successfully under simple data type checking.

ADDIN1 = INT, IN2 = WORD, IN3 = INT.

Strong Data Type Checking: causes a compile error.

Simple Data Type Checking: compiles successfully to ADD_I (Add Integer).

Simple data type checking does not keep common run-time programming errors from occurring. For instance, with simple data type checking, the compiler does not help to catch the following common programming error from occurring at run time: ADD 40000, 1 is interpreted as a negative number instead of as unsigned 40,001.

Using Direct Addressing in IEC for Overloaded Instructions

IEC 1131 programming modes also permit usage of directly represented memory locations as a part of instruction parameter configuration. Both variables and memory locations can be used within parameters. However, understanding of the data type implications must be clearly understood when using directly represented memory locations since these do not contain explicit type information. Additionally, type information can not be determined from any of the overloaded IEC instructions since overloaded instructions accept varying data types.

Data types for directly represented parameters are determined by examining other typed parameters included within the instruction. When an instruction parameter is configured to use a variable that is of a specific type, all directly represented parameters are assumed to be of that type.

Name Address Data Type Comment
Var1   REAL This is a floating point variable.
Var2   DINT This is a double integer variable.
Var3   INT This is an integer variable.

Example Description

VD100 and VD200 are assumed to be of type REAL since Var1 is typed as REAL.

VD300 and VD400 are of type DINT since Var2 is of type DINT.

VW500 and VW600 are assumed to be of type INT since Var3 is of type INT.

AC0 and AC1 are assumed to be of type REAL since Var1 is typed as REAL.

This configuration is treated as illegal since the type can not be determined. The type of data within the accumulators could be either DINT or REAL.

This configuration is treated as illegal since the type can not be determined. The type of data within the accumulator pointers could be either DINT or REAL.


Using Data Type Conversion Instructions

Conversion instructions permit the movement from one data type to another. STEP 7-Micro/WIN 32 supports the following conversion instructions for moving values between the simple data types.

Conversion Instruction Strong Data Type Checking

Allowed Operands

Data Type Checking

Allowed Operands

BYTE TO INT IN : BYTE

OUT : INT

IN : BYTE

OUT: WORD, INT

INT TO BYTE IN : INT

OUT : BYTE

IN : WORD, INT

OUT : BYTE

INT TO DINT IN : INT

OUT : DINT

IN : WORD, INT

OUT : DWORD, DINT

DINT TO INT IN : DINT

OUT : INT

IN : DWORD, DINT

OUT : WORD, INT

DINT TO REAL IN : DINT

OUT : REAL

IN : DWORD, DINT

OUT : REAL

REAL TO DINT (ROUND) IN : REAL

OUT : DINT

IN : REAL

OUT : DWORD, DINT


Under the IEC 1131-3 editing mode you can convert between INT and WORD, DINT and DWORD by using the overloaded MOVE instruction. The overloaded move instruction allows data types of the same size to be freely moved without the compiler generating errors.

IEC 1131-3 Overloaded MOVE IN OUT
MOVE (INT TO WORD) INT WORD
MOVE (WORD TO INT) WORD INT
MOVE (DINT TO DWORD) DINT DWORD
MOVE (DWORD TO DINT) DWORD DINT