Usage and Differences of (D)WORD and (D)INT Data Types in Omron NJ Series PLCs

OmronNJ Series PLC programming requires a thorough understanding of different data types for effective program development and data processing. This article focuses on the WORD, DWORD, INT, and DINT data types, analyzing their characteristics, differences, and application scenarios.

1. Overview of Basic Data Types

1.1 WORD (Word) Data Type

WORD is a 16-bit unsigned integer data type with a value range from 0 to 65535 (from 0 to 2^16-1). In the Omron NJ Series PLC, WORD is commonly used for processing bit sequences or representing values that do not require negative numbers.

// WORD type example

VAR

sensorValue : WORD; // Declare a WORD variable

END_VAR

sensorValue := 45000; // Valid assignment

// sensorValue := -100; // Error: WORD type cannot be negative

// sensorValue := 70000; // Error: Exceeds WORD range

1.2 DWORD (Double Word) Data Type

DWORD is a 32-bit unsigned integer data type with a value range from 0 to 4294967295 (from 0 to 2^32-1). DWORD can store larger positive values and is commonly used in scenarios requiring a wide range of unsigned values.

// DWORD type example

VAR

largeValue : DWORD; // Declare a DWORD variable

END_VAR

largeValue := 3000000000; // Valid assignment

// largeValue := -1; // Error: DWORD type cannot be negative

1.3 INT (Integer) Data Type

INT is a 16-bit signed integer data type with a value range from -32768 to 32767 (from -2^15 to 2^15-1). INT can represent both positive and negative values, suitable for most mathematical operations requiring signs.

// INT type example

VAR

temperature : INT; // Declare an INT variable

END_VAR

temperature := 2500; // Valid assignment

temperature := -150; // Valid assignment (negative value)

// temperature := 40000; // Error: Exceeds INT range

1.4 DINT (Double Integer) Data Type

DINT is a 32-bit signed integer data type with a value range from -2147483648 to 2147483647 (from -2^31 to 2^31-1). DINT provides a greater range for representing signed values.

// DINT type example

VAR

bigNumber : DINT; // Declare a DINT variable

END_VAR

bigNumber := 2000000000; // Valid assignment

bigNumber := -1500000000; // Valid assignment (negative value)

2. Comparison of Data Types

Data Type

Bit Count

Value Range

Sign

Main Uses

WORD

16 bits

0 to 65,535

Unsigned

Bit manipulation, unsigned data processing

DWORD

32 bits

0 to 4,294,967,295

Unsigned

Large range of unsigned data, bit manipulation

INT

16 bits

-32,768 to 32,767

Signed

General mathematical operations, counters

DINT

32 bits

-2,147,483,648 to 2,147,483,647

Signed

Large range of signed data, precise calculations

3. Differences and Selection of Data Types

3.1 Signed vs Unsigned

INT and DINT are signed types that can represent negative values, suitable for scenarios requiring the concept of both positive and negative (e.g., temperature changes, position offsets, etc.). WORD and DWORD are unsigned types that can only represent non-negative values, suitable for scenarios with only positive values (e.g., counters, raw data, etc.).

3.2 Data Range

When selecting a data type, consider the possible range of data:

  • For small positive values (0-65535), use WORD
  • For large positive values (0-4294967295), use DWORD
  • For small signed values (-32768-32767), use INT
  • For large signed values (approximately ±2.1 billion), use DINT

3.3 Memory Usage

WORD and INT occupy 2 bytes (16 bits) of memory, while DWORD and DINT occupy 4 bytes (32 bits) of memory. In large projects, choosing the right data type can optimize memory usage.

3.4 Operation Efficiency

On most processors, the processing speed of 16-bit data is generally faster than that of 32-bit data, but this difference has become minimal in modern PLCs. However, for large data operations, selecting the appropriate data type can still improve efficiency.

Note: In the Omron NJ Series PLC, assigning values between different data types requires explicit type conversion; otherwise, it may lead to compilation errors or data truncation.

4. Practical Application Examples

// Device status monitoring example

VAR

deviceStatus : WORD; // Use bits to represent 16 device statuses (0/1)

productionCount : DINT; // Production count may be large, use DINT

temperatureSetting : INT; // Temperature setting may have positive and negative values

errorCode : DWORD; // Error codes are usually unsigned

END_VAR

// Check the 3rd bit of device status

IF (deviceStatus AND 2#0000_0000_0000_0100) <> 0 THEN

// Device 3 is running

END_IF

// Increment production count

productionCount := productionCount + 1;

// Set temperature

temperatureSetting := 250; // Positive temperature

temperatureSetting := -50; // Negative temperature (cooling)

// Set error code

errorCode := 16#0000FF0A; // Use hexadecimal representation

Leave a Comment