The original communication setup between the control system and the PLC of the UOP3 distillation column was based on a basic HTTP server running directly on the PLC. While simple to implement, this solution suffered from limited speed, low flexibility, and insufficient reliability—critical drawbacks in a real-time laboratory control environment.

Fig. 1: UOP3 distillation column

The aim of my project was therefore to design and implement a fast, reliable and scalable communication interface between MATLAB/Simulink and the Simatic S7 PLC, utilizing the Modbus TCP protocol, a widely adopted standard in industrial automation.

System Architecture

A key component of the system is the bidirectional communication setup, which allows MATLAB/Simulink to both read from and write to the Simatic S7 PLC in real time.

Fig. 2: Bidirectional communication setup

This enables:

  • Receiving live measurements (temperatures, pressures, flow rates, reflux measurement) from the process
  • Sending control commands (e.g., heater power, reflux ratio, feed pump, cooling water flow) directly to the PLC

This architecture is built upon a stable Ethernet-based TCP/IP connection and operates through a symbolic, tag-based structure for data access. The core implementation relies on a custom MATLAB class named MBConnector, which abstracts the low-level communication logic and provides a flexible interface for reading and writing process data. Communication is tightly coupled to the Simulink simulation cycle via a Level-2 S-function, enabling deterministic and timestep-aligned data exchange with the PLC.

MBConnector Class and Tag-Based Signal Mapping

At the core of the system lies the MBConnector class, a custom MATLAB implementation that manages all Modbus TCP communication. It leverages MATLAB’s built-in modbus() function to establish and maintain connections with the PLC. This class is responsible for sending and receiving process values and control commands, minimizing redundant transmissions using internal caching.

All exchanged signals are defined symbolically in a centralized file named ProcessTags.m, which groups variables into categories such as measurements, control outputs, and binary flags.

Efficient and Selective Data Exchange

The MBConnector class optimizes data exchange by using a selective update mechanism — it only sends values that have changed since the last cycle. This minimizes communication load and maintains real-time performance.

Fig. 3: Data flow

This process is illustrated in the diagram, showing two main data flows: from the PLC to MATLAB for measurements, and from MATLAB to the PLC for control.

On the measurement (read) side, the PLC stores real-time process data—such as temperatures, pressures, and flow rates—in predefined Modbus holding registers. The MBConnector retrieves these values using functions like readProcess() and getTagValue(), which rely on symbolic tags defined in the ProcessTags.m file.

On the control (write) side, Simulink calculates actuation commands that are sent to the PLC using methods such as writeControls(), updateProcessReal(), and updateProcessBool(). These methods ensure that only updated values are transmitted, keeping communication efficient and synchronized with the simulation cycle.

Register Mapping of Floating-Point and Boolean Signals

In order to transmit process data between the Simatic S7 PLC and MATLAB via the Modbus TCP protocol, both floating-point and boolean values must be adapted to the 16-bit word format that Modbus uses.

Float signals (e.g., temperatures or flow rates) are stored in the PLC as IEEE 754 32-bit REAL types. Since Modbus supports only 16-bit words, each float is split into two consecutive registers using MOVE instructions — one for the low word, the other for the high word. These registers are then exposed via the Modbus TCP server.

The MBConnector reads the two 16-bit Modbus registers and reconstructs the corresponding 32-bit floating-point value using MATLAB’s 'single' precision.

Fig. 4: Data flow from sensor to MATLAB using Modbus TCP

Boolean control signals are packed into a single 16-bit Modbus holding register, with each bit representing a separate actuator or function. For instance, Bit 0 controls reflux, Bit 1 toggles the preheater, Bit 2 triggers a reset and Bit 15 selects the control mode.

Fig. 5: Boolean control mapping

In MATLAB, updateProcessBool() modifies individual bits based on symbolic tags. The PLC decodes these bits and routes them to corresponding logic, enabling efficient and synchronized digital control over multiple functions through a single register.

Integration on the PLC and Simulink Sides

On the PLC side, two routines — CopyToReg and CopyToMB — handle data exchange. CopyToReg moves internal process values into Modbus holding registers, making them accessible to MATLAB. CopyToMB reads incoming control commands from Modbus and applies them to the PLC logic.

Fig. 6: CopyToReg
Fig. 7: CopyToMB

In Simulink, the communication logic encapsulated in the MBConnector class is integrated through a custom Level-2 S-function block. This block ensures that all data exchange with the PLC is synchronized with the simulation’s timestep. Signals are directly mapped to Simulink ports, enabling seamless real-time interaction with the physical system.

Fig. 8: Simulink scheme

This setup provides students and researchers with the ability to run control algorithms directly on hardware, modify parameters during simulation, and log real-time process data — all within a unified environment, with minimal latency and configuration effort.

Conclusion

The developed communication interface successfully replaces the outdated HTTP-based system with a robust Modbus TCP solution, enabling fast and reliable real-time interaction between MATLAB/Simulink and the Simatic S7 PLC. The core MBConnector class, combined with symbolic tag mapping and efficient update routines, allows for seamless integration of control algorithms and live data exchange.

Through the use of structured Modbus registers, PLC routines, and a Simulink Level-2 S-function, the system enables real-time data acquisition, control signal transmission, and seamless interaction with the UOP3 distillation column. This flexible and scalable architecture now serves as a modern platform for both educational training and research in process automation.

Categories: Projects