Modbus

Modbus - Documentation

Common

The controller exposes a Modbus ‘Master’ at the specified TCP interface on port 502.

There are dedicated registers for the VFD, PIDs and internal values.

System Registers

Name Component ID Address RW Function Code Value Register Description
System 1 9 -W 0x6 1 Print Modbus Queue
System 1 9 -W 0x6 2 Print Component Modbus Registers
System 1 100 -W 0x6 1 Reset Controller
System 1 19 -W 0x6 1 Print PID controller states

Remarks

  • Implementation for these calls : short ModbusBridge::loop() ./ModbusBridge.cpp
  • It requires a USB cable connected, with 19200 bauds, 8 bits, no parity and 1 stop bit. You can use Arduino’s ‘Serial Monitor’ to see the output.

VFD Registers

The VFD (Omron - MX2) is being polled and controlled via RS485 at a defined Modbus slave address (Default 1). See more about the setup here.

Name Component ID Address RW Function Code Value Register Description
VFD 200 5 -W 0x6 1 Set VFD in RUN mode
VFD 200 5 -W 0x6 2 Set VFD in STOP mode
VFD 200 5 -W 0x6 3 Set VFD in RETRACT mode (stop and retract)
VFD 200 6 -W 0x6 0-100 VFD Target Frequency
VFD 200 2 -R 0x6 0-100 VFD Current Monitor
VFD 200 3 -R 0x6 - VFD Status
OMRON_STATUS_STOPPED=2
OMRON_STATUS_RUNNING=0
VFD 200 4 -R 0x6 - VFD State
OMRON_STATE_ACCELERATING=4
OMRON_STATE_DECELERATING=2
OMRON_STATE_RUNNING=3
OMRON_STATE_STOPPED=1
OMRON_STATE_ERROR=8

PID Registers

The PID controllers (Omron - EDC5) are being polled and controlled via RS485 at a defined Modbus slave address, starting by default from 4.

Name Component ID Address RW Function Code Value Register Description
PID 100 20 R- 0x6 0-Maximum Temperature (PV) PID-0 Temperature
PID 100 21 R- 0x6 0-Maximum Temperature / Set Point PID-0 Set Point (SP)
PID 100 22 R- 0x6 Status PID-0-Status / Default State : ‘Is Heating’
PID 100 23 R- 0x6 0-Maximum Temperature (PV) PID-1 Temperature
PID 100 24 R- 0x6 0-Maximum Temperature / Set Point PID-1 Set Point (SP)
PID 100 25 R- 0x6 Status PID-1-Status / Default State : ‘Is Heating’

Auxillary Registers (Sensors / Switches)

Name ID Address RW Function Code Number Addresses Register Description
OmronPID 100 20 R- 0x6 6
MB_Relay 300 41 RW 1 1
MB_Relay 301 42 RW 1 1
POT 400 51 R- 3 1
POT 401 52 R- 3 1
Pos3Analog 501 61 R- 3 1 - Read Position : Address=61(3D) -> [Up:1 Middle:0 Down:2]
Pos3Analog 502 62 R- 3 1 - Read Position : Address=62(3E) -> [Up:1 Middle:0 Down:2]
VFD 200 5 3 1
Stepper 601 70 RW -1 4
MotorLoad 210 2 R- 3 1
Status - LED 701 84 RW 3 1
Status - LED 702 85 RW 3 1

Stepper

Name ID Address RW Function Code Value Register Description
Stepper-0 601 70 RW 0x6 0-5000 Stepper-Speed
Stepper-0 601 71 RW 0x6 0-1 Stepper-Direction
Stepper-0 601 72 R- 0x6 - Stepper-Status
Stepper-0 601 72 0x6 - Stepper-User

Feed - Servo

Name ID Address RW Function Code Value Register Description
Feed - VFD - Ratio 601 16 -W 0x6 0-100 Stepper-Speed

The servo is turned on automatically as soon the VFD starts running.

Tools

To monitor and control the system, please open printhead-poll.mbp with MbPoll_v9.4.0.exe

Example Example Google Sheet

Simulate Modbus for Development

  • Please use MbSlave_v7.3.0.exe to start a Modbus-RTU master on TCP. You can use the ModbusPoll app to verify your code.

References

Subsections of Modbus

Modbus - VFD Control

VFD

Start & Stop

Starts or stops the VFD, be aware that a target frequency has to be set as well

  • Address : 5
  • Function : 6 (WRITE_REGISTER)
  • Values :
    • On : 1
    • Off : 2

TCP Sequence for Start

d2 8d 00 00 00 06 01 06 00 05 00 01
                   +  +  +    +
                   |  |  |    |
                   |  |  |    +----> Value (2 bytes) = 00 01
                   |  |  |
                   |  |  +----> Address (2 bytes) = 05 or 0x0005
                   |  |
                   |  +--> Function Code (Always 6)
                   |
                   +--> Slave - ID (Always 1)

TCP Sequence for Stop

d2 8d 00 00 00 06 01 06 00 05 00 02
                   +  +  +    +
                   |  |  |    |
                   |  |  |    +----> Value (2 bytes) = 00 02
                   |  |  |
                   |  |  +----> Address (2 bytes) = 05 or 0x0005
                   |  |
                   |  +--> Function Code (Always 6)
                   |
                   +--> Slave - ID (Always 1)

Frequency

Sets the target frequency

  • Address : 6
  • Function : 6 (WRITE_REGISTER)
  • Values : 1 - 50

TCP Sequence for setting target frequency to 50 Hz

Remark : Please respect the max. main frequency setting on the inverter (settings)

d2 8d 00 00 00 06 01 06 00 05 00 32
                   +  +  +    +
                   |  |  |    |
                   |  |  |    +----> Value (2 bytes) = 00 32 (for 50Hz)
                   |  |  |
                   |  |  +----> Address (2 bytes) = 06 or 0x0006
                   |  |
                   |  +--> Function Code (Always 6)
                   |
                   +--> Slave - ID (Always 1)

Direction

Sets the rotation

  • Address : 7
  • Function : 6 (WRITE_REGISTER)
  • Values :
    • Forward : 1
    • Reverse : 2
    • Stop : 3

TCP Sequence for setting direction : Forward

d2 8d 00 00 00 06 01 06 00 07 00 01
                   +  +  +    +
                   |  |  |    |
                   |  |  |    +----> Value (2 bytes) = 00 01
                   |  |  |
                   |  |  +----> Address (2 bytes) = 07 or 0x0006
                   |  |
                   |  +--> Function Code (Always 6)
                   |
                   +--> Slave - ID (Always 1)

TCP Sequence for setting direction : Reverse

d2 8d 00 00 00 06 01 06 00 07 00 02
                   +  +  +    +
                   |  |  |    |
                   |  |  |    +----> Value (2 bytes) = 00 02
                   |  |  |
                   |  |  +----> Address (2 bytes) = 07 or 0x0006
                   |  |
                   |  +--> Function Code (Always 6)
                   |
                   +--> Slave - ID (Always 1)

Modbus - PID Control

PID Controllers

The PID controller target temperatures can be set as follows:

  • PID 1 : Address 10
  • PID 2 : Address 11
  • PID 3 : Address 12

Set Target temperature on PID 1 to 100Degc

  • Address : 10 (0x10)
  • Function : 6 (WRITE_REGISTER)
  • Values : 0 - Max Temperature (280)

TCP Sequence

d2 8d 00 00 00 06 01 06 00 0A 00 10
                   +  +  +    +
                   |  |  |    |
                   |  |  |    +----> Value (2 bytes) = 00 10 (16 Degc)
                   |  |  |
                   |  |  +----> Address (2 bytes) = 20 or 0x0014
                   |  |
                   |  +--> Function Code (Always 6)
                   |
                   +--> Slave - ID (Always 1)

Set Target temperature on PID 2to 100Degc

  • Address : 11 (0x0B)
  • Function : 6 (WRITE_REGISTER)
  • Values : 0 - Max Temperature (300)

TCP Sequence

d2 8d 00 00 00 06 01 06 00 0B 00 10
                   +  +  +    +
                   |  |  |    |
                   |  |  |    +----> Value (2 bytes) = 00 64 (100 Degc)
                   |  |  |
                   |  |  +----> Address (2 bytes) = 18 or 0x000B
                   |  |
                   |  +--> Function Code (Always 6)
                   |
                   +--> Slave - ID (Always 1)

Set Target temperature on PID 3 to 100Degc

  • Address : 12 (0x0C)
  • Function : 6 (WRITE_REGISTER)
  • Values : 0 - Max Temperature (300)

TCP Sequence

d2 8d 00 00 00 06 01 06 00 0C 00 10
                   +  +  +    +
                   |  |  |    |
                   |  |  |    +----> Value (2 bytes) = 00 10 (16 Degc)
                   |  |  |
                   |  |  +----> Address (2 bytes) = 0C or 0x000C
                   |  |
                   |  +--> Function Code (Always 6)
                   |
                   +--> Slave - ID (Always 1)

Testing with Modbus Poll

Testing with Hercules

Modbus - Errors

Error Codes

The system exposes the current error code as a Modbus register at address 0x00 (FunctionCode:0x3) :

  • E_VFD_TIMEOUT = 1002
  • E_PID_TIMEOUT = 2002
  • E_FEED_OVERLOAD = 4001
  • E_VFD_OVERLOAD = 1001

System Debug Commands

Name Component ID Address RW Function Code Value Register Description
System 1 9 -W 0x6 1 Print Modbus Queue
System 1 9 -W 0x6 2 Print Component Modbus Registers
System 1 100 -W 0x6 1 Reset Controller
System 1 19 -W 0x6 1 Print PID controller states

See more details in the PHApp::onError Implementation