[Home]VFD Modbus

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

VFD and Modbus

So far, there are two options for using a Modbus VFD interface. One option is to create a HAL component as a driver. This would present the VFD's I/O as halpins. modbus.c and modbus.h are used to support the driver. Another option is to use Classic Ladder which has Modbus built in.

Below are links to some example configurations using VFD's with Modbus:











Parker AC10

VFD Parker AC10

Hardware Overview

Typically a VFD with a Modbus option will offer a half-duplex RS-485 port for use with a single twisted wire pair cable. The port may use an RJ11 or RJ45 connector, so a telephone or network cable may be used. On the PC end, the cable connects to an RS-485 to RS-232 adapter on a serial port. Most half-duplex adapters should work if the RS-232 RTS signal is used to control the send/receive mode of the adapter. The adapter I've used cost just under $5 and is powered by the serial port pins. For long cable runs, an adapter with external power connection may be better.

Driver Method

The software consists of an HAL user component and libmodbus. libmodbus contains the functions needed talk to a serial port, convert serial data into Modbus packets and control the communication. The HAL component provides an interface between LinuxCNC and libmodbus. On the linuxcnc side, it creates HAL input or output pins for sending or receiving VFD control signals. On the VFD side, using libmodbus, it controls the serial port connection. In between, the HAL pin data is converted from or to VFD usable form, such as converting the HAL pin, motion.spindle-speed-out from a float to an unsigned integer then scale from RPM to frequency. Being a user component, it runs as a user process in Linux and not RTAI. Some functions of the component may run only once, such as initializing and reading VFD configuration data. During normal operation, a loop regularly reads the VFD pins, processes the new data, then sends new data out to the VFD. Typically the loop can run up to ten times a second, depending on the serial port Baud rate and the amount of data to send and receive.

Because each VFD maker implements Modbus differently, a custom HAL component will most likely be needed for each VFD model. Typical VFD HAL components will not be .comp files, which can be compiled and documented with the comp utility, but a C file needing its own Makefile and manual documentation. For compiling the C file, the emc2-dev (or linuxcnc-dev) package will need to be installed. This should be available using Synaptic. A Makefile can be copied from an existing sample and modified to use the new component name. The mobus.c and modbus.h files may be copied from existing examples, but it may be better to download the latest libmodbus package from the libmodbus website:

Roughly, the procedure might be...
Create a directory under "/home/my_home/emc2" such as "/home/my_home/emc2/my_vfd"
Copy into "my_vfd" a sample vfd.c, modbus.c, modbus.h, and Makefile
Edit my_vfd-x.c and Makefile
Run "cp my_vfd-x my_vfd.c", "make", "sudo make install"
Copy sample linuxcnc config files in "/home/my_home/emc2/configs/myCNC/"
Edit the .hal file in "...myCNC/myCNC.hal" to "loadusr my_vfd ..." and connect HAL pins
Invoke emc2 and enjoy

Notes on using vfs11_vfd.c as the base for a new Modbus device C component -> New file from vfs11.

Classic Ladder Method

I know nothing about CL. If you know how to use Classic Ladder with a VFD using Modbus, now is your chance to become famous.

(Draft 2011/03/01 Kirk Wallace)

(Update 2014/02/21 Zeeshan M.)

Sumitomo HF-430 | Hitachi SJ300 | Hitachi L300P

These drives can be communicated using a python userspace component. First ensure the files comms.py and vfd.py are placed in $PATH.

Here is a typical configuration that needs to be added to custom.hal:

loadusr -W vfd.py
loadrt scale count=1
addf scale.0 servo-thread
setp scale.0.gain 0.0767
setp scale.0.offset 0

net spindle-on <= vfd.spdvfd.run
net spindle-cw <= vfd.spdvfd.forward
net spindle-vel-cmd-rpm-abs => scale.0.in
net spindle-speed vfd.spdvfd.freqset <= scale.0.out

These drives use a custom serial protocol. The minimalmodbus library has been modified to include this custom protocol. Set the serial mode to MODE_CUSTOM. BCC checks are automatically performed.

The following function codes are supported:
00 - forward/rev/stop/start/run
01 - set frequency
03 - read entire monitoring data (this data cannot be accessed with function code 06!)
06 - read data from a specific register

Additionally, vfd.py demonstrates how to communicate with NFX9000 VFDs using the standard modbus protocol over ascii.






This is a driver written in c. It is based off the MVX9000rtu code above.

LinuxCNCKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited October 14, 2018 5:39 pm by Chaotix (diff)
Published under a Creative Commons License