Modbus Data Models

Modbus Data Models: Coils, Registers, and Data Addresses

Imagine you’re working with a massive spreadsheet that controls and monitors all the equipment in a factory. Each cell in this spreadsheet holds a specific piece of information—some cells are read-only, some can be changed, some store simple on/off values, and others store numeric measurements.

This spreadsheet analogy perfectly describes the Modbus data model. Modbus organizes device data into four distinct types, each with its own purpose and characteristics. Let’s break down this analogy to understand how Modbus stores and manages data.

The Spreadsheet Analogy: Modbus Data Organization

| Spreadsheet Concept | Modbus Concept | Description |

|————————-|——————–|—————–|

| Worksheet/Tab | Modbus Device | A single Modbus device (like a sensor or controller) |

| Cell | Modbus Data Point | A single piece of data within the device |

| Cell Address | Modbus Data Address | Unique identifier for each data point |

| Cell Type | Modbus Data Type | Determines if data is on/off or numeric, read-only or read-write |

| Formula Cell | Calculated Register | A register that contains computed values (not part of standard Modbus) |

The Four Modbus Data Types

Modbus defines four fundamental data types, each with specific characteristics and use cases. Think of them as different columns in your factory spreadsheet.

1. Discrete Inputs: Read-Only Switches

Spreadsheet Analogy: A column of cells that display sensor readings—you can look at them, but you can’t change them. Like a column showing whether doors are open or closed, or if a machine is running.

Modbus Details:

  • Function Codes: 02 (Read Discrete Inputs)

What They Store:

  • Diagnostic indicators

Practical Example: A temperature sensor that has a built-in “overheating” indicator. You can read whether it’s overheating (1=yes, 0=no), but you can’t reset this value from Modbus—you have to fix the temperature first.

2. Coils: Read-Write Switches

Spreadsheet Analogy: A column of checkboxes that control equipment—you can both look at their current state and change them. Like a column where you can check a box to turn a motor on or off.

Modbus Details:

  • Function Codes: 01 (Read Coils), 05 (Write Single Coil), 0F (Write Multiple Coils)

What They Control:

  • Process control bits

Practical Example: A motor controller with a coil that turns the motor on or off. You can read the current state (1=running, 0=stopped) and write to it to change the state.

3. Input Registers: Read-Only Numbers

Spreadsheet Analogy: A column of cells showing numeric measurements that update automatically—you can view them, but you can’t edit them. Like a column displaying real-time temperature readings from various sensors.

Modbus Details:

  • Function Codes: 04 (Read Input Registers)

What They Store:

  • Status codes

Practical Example: A temperature sensor that measures room temperature. It reports the value as a 16-bit number (e.g., 2350 = 23.5°C). You can read this value, but you can’t change it through Modbus—the sensor updates it automatically.

4. Holding Registers: Read-Write Numbers

Spreadsheet Analogy: A column of numeric cells that store settings and parameters—you can both view and edit them. Like a column where you set temperature setpoints or motor speeds.

Modbus Details:

  • Function Codes: 03 (Read Holding Registers), 06 (Write Single Register), 10 (Write Multiple Registers)

What They Store:

  • Output values (for analog outputs)

Practical Example: A PID controller that maintains temperature. It has a holding register for the temperature setpoint. You can read the current setpoint (e.g., 2500 = 25.0°C) and write a new value to change the target temperature.

Understanding Modbus Addressing: Spreadsheet Cell References

Modbus addresses can be confusing at first, especially because different documentation uses different numbering systems. Let’s clarify:

Address Numbering Systems

1. Decimal Addresses (Most Common):

– Discrete Inputs: 00001-09999

– Coils: 00001-09999

– Input Registers: 30001-39999

– Holding Registers: 40001-49999

2. Hexadecimal Addresses (Technical Documentation):

– Discrete Inputs: 0x0000-0x270F

– Coils: 0x0000-0x270F

– Input Registers: 0x7530-0x9C3F

– Holding Registers: 0x9C40-0xC34F

3. Zero-Based Addresses (Programming):

– Many programming libraries use zero-based addresses (starting at 0 instead of 1)

– For example, holding register 40001 becomes address 0 in zero-based systems

Address Offset Example

| Data Type | Decimal Address | Zero-Based Address | Hex Address |

|—————|———————|————————|—————–|

| Coil | 00001 | 0 | 0x0000 |

| Discrete Input | 00001 | 0 | 0x0000 |

| Input Register | 30001 | 0 | 0x7530 |

| Holding Register | 40001 | 0 | 0x9C40 |

Visualizing the Modbus Data Model

“`

┌─────────────────────────────────────────────────────────────────┐

│ MODBUS DEVICE (SPREADSHEET) │

├───────────────┬───────────────┬────────────────┬────────────────┤

│ DISCRETE │ COILS │ INPUT REGISTERS │ HOLDING │

│ INPUTS │ (WRITE-ABLE │ (READ-ONLY │ REGISTERS │

│ (READ-ONLY │ SWITCHES) │ NUMBERS) │ (WRITE-ABLE │

│ SWITCHES) │ │ │ NUMBERS) │

├───────────────┼───────────────┼────────────────┼────────────────┤

│ 00001: Door 1 │ 00001: Motor │ 30001: Temp │ 40001: Temp │

│ Open? │ On/Off │ Sensor 1 │ Setpoint │

│ 00002: Door 2 │ 00002: Valve │ 30002: Pressure│ 40002: Motor │

│ Open? │ A On/Off │ Sensor │ Speed Set │

│ 00003: Alarm │ 00003: Light │ 30003: Flow │ 40003: PID │

│ Active? │ Status │ Rate │ Gain │

└───────────────┴───────────────┴────────────────┴────────────────┘

“`

Practical Examples: How These Data Types Work Together

Let’s look at a real-world example of how these data types might be used in a simple industrial system—a temperature control loop for a heating oven.

System Components

  • PID Controller: Maintains the desired temperature

Data Flow and Usage

1. Input Register (30001): The temperature sensor reports the current oven temperature (e.g., 2250 = 22.5°C) as a read-only input register.

2. Holding Register (40001): The PID controller stores the desired temperature setpoint (e.g., 2500 = 25.0°C) as a read-write holding register.

3. Holding Register (40002-40004): The PID controller stores its tuning parameters (proportional gain, integral time, derivative time) as read-write holding registers.

4. Coil (00001): The PID controller sets this coil to 1 when the heating element should be on, and 0 when it should be off.

5. Discrete Input (00001): The heating element controller reports its actual status (on/off) as a read-only discrete input.

Communication Flow

1. The PLC reads the current temperature from input register 30001

2. The PLC compares this value to the setpoint in holding register 40001

3. Using PID algorithm, the PLC calculates whether the heating element should be on

4. The PLC writes the result to coil 00001

5. The PLC reads discrete input 00001 to confirm the heating element’s actual status

Common Addressing Confusions: Clearing Up Misconceptions

“Why do coils and discrete inputs share the same address range?”

While they share the same numerical address range, Modbus uses different function codes to distinguish between them. Coils use function code 01 for reading, while discrete inputs use function code 02. It’s like having two different spreadsheets with the same cell addresses—you specify which spreadsheet you want by using the right function code.

“Can I have more than 9999 data points of one type?”

Yes! The standard address ranges are just conventions. Many devices support extended address ranges, especially in Modbus TCP implementations. Think of it as adding more columns to your spreadsheet beyond the initial 9999 cells.

“How do I handle 32-bit values?”

Modbus natively supports 16-bit values, but you can combine two consecutive registers to store 32-bit values (like large numbers or floating-point values). This is called “register pairing” and is handled in your application code, not by Modbus itself.

“What’s the difference between a coil and a discrete input that controls something?”

The key difference is access: coils are read-write, discrete inputs are read-only. If you can turn a device on/off through Modbus, it’s a coil. If you can only read its status (like a physical limit switch), it’s a discrete input.

Choosing the Right Data Type

When designing a Modbus system or interpreting device documentation, remember these simple guidelines:

  • Numeric values that you can set: Holding Registers

Conclusion: The Power of Structured Data

The Modbus data model is like a well-organized spreadsheet for industrial devices. It provides a clear, consistent way to access and control equipment data, regardless of the manufacturer or device type.

By understanding the four data types—discrete inputs, coils, input registers, and holding registers—you can effectively communicate with any Modbus device. The spreadsheet analogy helps demystify these concepts, making it easier to design, configure, and troubleshoot Modbus systems.

Next time you’re working with Modbus devices, think of them as interconnected spreadsheets—each with its own cells, addresses, and data types. This mental model will help you navigate the world of industrial communication with confidence.