Data Types

Data types are defined within the common elements of IEC 61131-3.

Why Data Typing?

Data typing is implemented to define the type of any parameter used. This helps prevent errors early on in the programming phase (e.g., avoids dividing a Date by an Integer).

When you have defined whether the data is a string, a date, an integer or a 16-bit Boolean input, there is no longer any confusion, nor any conflict between different people using the textual representation (i.e., the name of the variable).

Different Data Types

  • Common Data Types: Boolean, Byte, Date, Integer, Real, String, Time_of_Day, Word.
  • Derived Data Types: Define personal data types based on the Common data types.
    • Example: Define an analog input channel as a data type and re-use it.

List of Data Types

Type

Prefix

Description

Values

BOOL

 

Boolean (bit)

  • FALSE, TRUE
  • Stored in 1 byte.

BYTE

 

Same as USINT.

 

DINT

 

Signed double precision integer in 32-bits.

-2147483648 to 2147483647

DWORD

 

Same as UDINT.

 

INT

INT#

Signed integer in 16-bits.

-32768 to +32767

LINT

LINT#

Long signed integer in 64-bits.

 

LREAL

LREAL#

Double precision floating point stored in 64-bits.

  • -1.7E308 to 1.7E308
  • 14 to 15 significant digits of accuracy

LWORD

 

Same as ULINT.

 

REAL

REAL# ‡‡

Single precision floating point stored in 32-bits.

  • -3.4E38 to 3.4E38
  • 6 to 7 significant digits of accuracy.

SINT

SINT#

Small signed integer in 8-bits.

-128 to +127

STRING

 

Variable length string with declared maximum length.

Each character is store on 1 byte (i.e., on 8-bits).

Maximum length cannot exceed 255 characters.

TIME

T# or TIME#

Time data type is used to specify a time variable.

  • Accuracy is 1ms.
  • See TIME.

0ms - 24hr

UDINT

UDINT#

Unsigned integer in 32-bits.

0 to +4294967295

UINT

UINT#

Unsigned integer in 16-bits.

0 to 65535

ULINT

ULINT#

Long unsigned integer in 64-bits.

 

USINT

USINT#

Small unsigned integer in 8-bits.

0 to 255

WORD

 

Same as UINT.

 

WSTRING

 

Do not use!

The WSTRING is not supported.

 


  • REAL variables are limited to 6 digits of accuracy.
    To achieve greater accuracy, a longer mantissa may be specified by prefixing LREAL with #.

    Example: To achieve an accuracy of 20 digits for the value of Pi, rather than what REAL provides (3.14159), set the type to LREAL#3.141592653589793238.


  • ‡‡ REAL is restrictive, but because it is the default, it is recommended to explicitly declare real constants with the LREAL# prefix.


  • Use 2#, 8#, or 16# prefixes to specify an integer in binary, octal or hexadecimal basis, respectively.