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:
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.
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)