PLC Basics: Data Types

 Data types refer to the organization format of data in a PLC (computer), encompassing the length of data and the supported operations for that data (which instructions it supports). When programming, specifying the data type for a variable, the compiler allocates a certain length of memory for that variable and clarifies the operation mode for the variable. A thorough understanding of data types is a fundamental requirement for programming.

Different PLC manufacturers may have slight variations in the support for data types, but the basic data types are almost the same (not only in PLC programming but also in programming with high-level computer languages). This article will use the Siemens S7 series PLC as an example to explain the basic data types in PLC.

Let's start with "bit." In the previous article discussing numeral systems (refer to: PLC Basics: Numeral Systems and Representation Methods), the concept of "bit" was mentioned multiple times. "Bit," short for "binary digit," is the smallest storage unit in a PLC (computer), with values of "0" and "1."

"Bit" is the storage unit, and data stored bit by bit, in data types, is referred to as "Boolean" type (Bool). The Boolean type data has values of "0" and "1," often represented as "TRUE" (true) and "FALSE" (false) in English.

In PLC programming, Boolean data is frequently used. For digital inputs or outputs, operations are performed in a "bit" (Boolean type) manner. For example, "I0.0" is a Boolean variable, representing the first bit of the input buffer (Input) in the 0th byte. "Bit," colloquially called a "point," often refers to input channels as "I points" and output channels as "Q points."

The second type: Byte. Eight "bits" make up a "byte," as shown below:









In PLCs, the channels of input and output modules are also arranged in byte order. For example, "I0.0~I0.7," these eight input "bits" constitute "IB0." For S7-300/400 PLCs, the Byte type is an unsigned number with a range of 0 to 255 (0xFF). For programming S7-1200/1500 PLCs (using the TIA Portal platform), the Byte type can be used as a signed or unsigned number. When used as a signed number, its range is "-128 to +127"; when used as an unsigned number, its range is 0 to 255 (0xFF).

The third type: Character (CHAR). Character-type data also occupies one byte, storing the ASCII code value of the character internally. For example, the character "A" has an ASCII code value of 65 (0x41). When the program identifies this data as character type and the internal stored value is 65, it will display the uppercase character "A" on the screen.

The fourth type: Integer (INT). Integer data occupies two bytes (Bytes) and is a signed number with a range of -32768 to +32767. The highest bit of integer data is the sign bit, where "0" indicates a positive number and "1" indicates a negative number. Since integer data consists of two bytes, there is an issue of byte order. Which byte is the high byte? The Siemens S7 series PLCs use big-endian storage, as shown below (for information on byte order, please refer to the article: "A Computer Story from Gulliver's Travels"):










The fifth type: Word (WORD). The "Word" type also occupies two bytes, but it represents an unsigned number with a range of 0 to 65535 (0xFFFF). Like integer data, it also uses big-endian storage.

In PLCs, "W" is used to represent a "Word" type variable. For example, the variable "MW0," where "M" indicates that the variable is stored in the "M" area, "W" indicates that it is a "Word" type variable, and "0" indicates its starting address is 0. "MW0" is composed of "MB0" and "MB1," where "MB0" is the high byte (big-endian byte order).

The sixth type: Double Word (DWORD). "Double Word" consists of two "Words," so it contains four bytes with a range of 0 to 4294967295 (0xFFFFFFFF). In PLCs, "Double Word" is represented by "D." For example, "MD0" represents four bytes starting from address 0 in the M storage area, i.e., MB0, MB1, MB2, and MB3, and the byte order is still big-endian.

The seventh type: Double Integer (DINT). "Double Integer" consists of two "Integers" and also occupies four bytes, representing signed numbers with a range of -2147483648 to +2147483647. In PLCs, it is represented by "DINT."

The eighth type: Real. "Real" data occupies four bytes and is used to represent floating-point numbers. Real data consists of a total of 32 bits and is divided into three parts:

  1. Sign bit (Sign): The highest bit (bit 31), "0" for positive numbers, "1" for negative numbers.

  2. Exponent bits (Exponent): Bits 23 to 30 are used to store the exponent data in scientific notation and use shift storage.

  3. Mantissa: Bits 0 to 22 represent the mantissa part of the floating-point number.

For the "Exponent bits," to accommodate negative exponents, the stored value is the actual exponent plus an offset of "127." For example, if the actual exponent is "0," the stored value is "127"; if the actual exponent is "-64," the stored value is "63."



Float-point data (real numbers) can use 4 bytes of space and can represent very large (10^38) and very small (10^-38) numbers. However, floating-point number operations are relatively slower than integer operations. In PLC programming, you can input a decimal point to represent a floating-point number. For example, "10" represents an integer, and "10.0" represents a floating-point number.

For the S7-1200/1500 series PLC, the TIA Portal development environment supports more data types. For instance, UDINT represents unsigned double integer, SDINT represents signed double integer, SINT represents signed integer, and LReal represents double-precision floating-point number (64 bits, 8 bytes). The basic data types introduced in this article mainly target the S7 series PLC, and there may be slight variations in other PLC products or computer program designs. In some high-level languages (e.g., VB), although the range of boolean variables is also "0" and "1," it may occupy 2 bytes (Bytes), and different operating systems may have different definitions of data types (e.g., 32-bit Windows and 64-bit Windows). To avoid confusion for beginners, it is recommended to first understand the basic data types in the Siemens PLC programming environment. If you need to program in other development environments in the future, you can consult the relevant manuals to draw parallels.

This concludes the discussion on basic data types. Siemens PLC also supports complex data types, which we will cover in future articles.

Related Reference Articles:

PLC Basics - Complex Data Types: Arrays and Strings

A detailed explanation of the POINTER data type in STEP7.