Basic Data Types in Siemens PLC with TIA Portal Software

PROFINET communication between S7-1500 PLC and drives Click the link above to read previous content

Basic Data Types

When writing programs, the format of variables must match the data type of the instructions. The data types of the S7-1500 PLC are mainly divided into basic data types, composite data types, parameter types, system data types, and hardware data types.

The basic data types are divided into bit data types, mathematical data types, character data types, and time data types. Each basic data type has attributes such as keywords, data length, value range, and constant expression format. For example, the keyword for the character data type is “char”, the data length is 8 bits, the value range is the ASCII character set, and the constant expression format is a character enclosed in two single quotes, such as ‘A’. Examples of data length, value range, and constant expression format for basic data types are shown in the table below.

Basic Data Types in Siemens PLC with TIA Portal SoftwareBasic Data Types in Siemens PLC with TIA Portal Software

Bit Data Types

Bit data types mainly include Boolean (Bool), Byte, Word, Double Word (DWord), and Long Word (LWord).

Bit data types only indicate whether each bit in memory is 0 (False) or 1 (True). The data length can be one bit (1 bit), one byte (Byte, 8 bits), one word (Word, 16 bits), one double word (Double Word, 32 bits), or one long word (Long Word, 64 bits), corresponding to Bool, Byte, Word, DWord, and LWord types, respectively. Bit data types are usually expressed in binary or hexadecimal, such as 2#01010101, 16#283C, etc. It is important to note that a single bit Boolean data type cannot be directly assigned a constant value.

The constant representation of bit data types requires adding B#, W#, DW#, or LW# (except for Bool) before the data according to the length of the storage unit (Byte, Word, DWord, LWord). The range of values that can be represented is shown in the table.

Basic Data Types in Siemens PLC with TIA Portal Software

The following figure shows the representation method for Word bit data types.

Basic Data Types in Siemens PLC with TIA Portal Software

Mathematical Data Types

Mathematical data types mainly include integer types and real number types (floating-point types).

1. Integer Types

Integer types are divided into signed integer types and unsigned integer types. Signed integer types include short integer (SInt), integer (Int), double integer (DInt), and long integer (LInt); unsigned integer types include unsigned short integer (USInt), unsigned integer (UInt), unsigned double integer (UDInt), and unsigned long integer (ULInt).

Short integer, integer, double integer, and long integer data are signed integers, respectively 8 bits, 16 bits, 32 bits, and 64 bits, represented in memory using binary two’s complement, with the highest bit as the sign bit (0 for positive, 1 for negative), and the remaining bits as value bits. Unsigned short integer, unsigned integer, unsigned double integer, and unsigned long integer data are all unsigned integers, with each bit being a valid value.

The following figure shows the representation method for positive integer type Int.

Basic Data Types in Siemens PLC with TIA Portal Software

2. Real Number Types

Real number types include real (Real) and long real (LReal), both of which are signed floating-point numbers, occupying 32 bits and 64 bits, respectively. The highest bit is the sign bit (0 for positive, 1 for negative), the next 8 bits (or 11 bits) are the exponent bits, and the remaining bits are the mantissa bits, together forming the real number value. The characteristic of real numbers is that a large number or a very small number can be represented using a limited 32 bits or 64 bits.

The representation method for negative integer type Int is shown in the figure.

Basic Data Types in Siemens PLC with TIA Portal Software

A Real type number occupies 4 bytes of space. The Real type in the S7-1500 PLC conforms to the IEEE754 standard for floating-point numbers, including the sign bit S, exponent E, and mantissa M, as shown in the figure.

Basic Data Types in Siemens PLC with TIA Portal Software

The bit numbers and weights of exponent E and mantissa M are shown in the table.

Basic Data Types in Siemens PLC with TIA Portal Software

Character Data Types

The data length of character data types (Char) is 8 bits, and the operand occupies one byte in memory, stored in ASCII character set format for a single character. When represented as a constant, single quotes are used, for example, the constant character A is represented as ‘A’ or CHAR#’A’. The table lists the attributes of character data types.

Basic Data Types in Siemens PLC with TIA Portal Software

The S7-1500 PLC also supports wide character types (WChar), with an operand length of 16 bits, occupying 2 bytes (Byte) in memory, stored in Unicode string format for a single character in the extended character set, but only involving part of the entire Unicode string. When represented as a constant, the WCHAR# prefix and single quotes are required, for example, the constant character a is represented as WCHAR#’a’. Control characters are represented by a dollar sign when input. The table lists the attributes of wide character data types.

Basic Data Types in Siemens PLC with TIA Portal Software

Time Data Types

Time data types mainly include IEC time (Time) data types, S5 time (S5Time) data types, and long time (LTime) data types.

1. IEC Time (Time) Data Type

IEC time (Time) data type is a 32-bit IEC timer type, represented in milliseconds (ms) as a double integer, which can be positive or negative. The information represented includes days (d), hours (h), minutes (m), seconds (s), and milliseconds (ms). The table lists the attributes of IEC Time data types.

Basic Data Types in Siemens PLC with TIA Portal Software

2. S5 Time (S5 Time) Data Type

The variable length of S5 time (S5 Time) data type is 16 bits. Among them, the highest two bits are unused, the next two bits are time base information (00 for 0.01s, 01 for 0.1s, 10 for 1s, 11 for 10s), and the remaining 12 bits are BCD coded time values, ranging from 0 to 999, as shown in the figure.

Basic Data Types in Siemens PLC with TIA Portal Software

The represented time is the product of the time constant and the time base. The constant format for S5 Time data types is to add S5T# before the time, for example, S5T#16sl00ms, where the time constant represented by the time base of 0.1s is 161, so the corresponding variable content is 2#00010001 01100001. The table lists the attributes of S5 Time data types.

Basic Data Types in Siemens PLC with TIA Portal Software

3. Long Time (LTime) Data Type

Long time (LTime) data type is a 64-bit IEC timer type, with operand content represented as a long integer in nanoseconds (ns), which can be positive or negative. The information represented includes days (d), hours (h), minutes (m), seconds (s), milliseconds (ms), microseconds (μs), and nanoseconds (ns). The constant representation format is to add LT# before the time, such as LT#11ns.

Basic Data Types in Siemens PLC with TIA Portal Software

Leave a Comment