- Posts: 51
- Thank you received: 0
Setting up USB -> Modbus (CH340) for VFD control
Ok, i got awesome help in my previous thread on how i would tackle my journey into LinuxCNC, so off i went and got a ASRock card with db25 connector, a BOB etc.
And i was expecting a rough entry but, i got the Live CD, followed the installation guide, got it working, did the StepConf Wizard, plugged in the BOB and amazingly it worked, i can detect Estop, limit switches etc. so i'm impressed!
However my next task on my to-do list got me pulling my hair a little bit so i would need some guidance :silly:
i was recommended to go for a USB -> Modbus dongle for VFD control and i thought it sounded great, so i got a CH340 dongle, and i thought i would need to tick a box in the configuration "Use Modbus" but to my great surprise it is much more complicated and out of my existing knowledge zone.
I have searched the forum, wiki, docs, google but it is still not clear for me. should i use HAL? or Classic Ladder?
i have read wiki.linuxcnc.org/cgi-bin/wiki.pl?VFD_Modbus and wiki.linuxcnc.org/cgi-bin/wiki.pl?ModbusToHal
this chapter got me stucked:
Create a directory under "/home/my_home/emc2" such as "/home/my_home/emc2/my_vfd" (this line i understnad
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
sample vfd.c, modbus.c modbus.h are these empty documents i create? what is Makerfile?
So if somebody could help me get thru this it would be very appreciated!
The below link is a couple pages on the modbus section from my ENC EN600 VFD.
VFD Modbus manual
Thanks!
// Victor
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
linuxcnc.org/docs/html/drivers/mb2hal.html
I'm sure there are some sample MB2HAL configs floating around in the forum that you could look up. (I know I've posted a couple of them). If you can't find anything let me know and I'll see if I can dig up a simple example. (What I have running on the machine would not be considered a simple example as it is controlling 8 VFDs.)
If you still have questions please ask.
Please Log in to join the conversation.
i will check some examples out and see if i can make any sense from it

Thanks!
Victor
Please Log in to join the conversation.
a .ini file for the MB2hal component?
i have named my .ini file to "mb2hal.ini" and posted the below code frome the linuxcnc.org/docs/html/drivers/mb2hal.html page
and then i need to put the following lines in my custom.hal file:
loadusr -W mb2hal config=mb2hal.ini
loadusr -Wn mymodule mb2hal config=config_file.ini <- i guess i should make a .ini file for my vfd like "enc_vfd.ini" ?
so the second line should perhaps be: loadusr -Wn enc_vfd mb2hal config=enc_vfd.ini ?
and in this "enc_vfd.ini" file i need to put the modbus translation code?
i looked for some examples and i found one on a X200 Hitachi inverter,
some of it makes sense to me but i'm uncertain what i need to change for my application?
below is the X200 .ini file
Thanks!
Victor
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
and then i need to put the following lines in my custom.hal file:
loadusr -W mb2hal config=mb2hal.ini
loadusr -Wn mymodule mb2hal config=config_file.ini <- i guess i should make a .ini file for my vfd like "enc_vfd.ini" ?
No, those are 2 possible options for the line of code you need in your hal file.
Keep it simple and only use the top line.
You only need one modbus ini file, so you only need to keep your mb2hal.ini or your enc_vfd.ini (not both).
If you use enc_vfd.ini for the config file name you will need to change the line in your hal file to" loadusr -W mb2hal config=enc_vfd.ini"
Just remember the mb2hal.ini file has a lot of unnecessary info, lots of comments, optional settings, and commented out examples included. It can be difficult to sort through it all to see just what you need and don't need. That is where other examples like the X200 one you posted come in handy. You are going to have to carefully read through the manuals for your drive to determine what all the settings are going to be both in mb2hal and in the drive its self. Every drive manufacturer uses different protocols so you can't just copy what works for a different drive.
It took me a couple of weeks to sort it all out for the drives I was using, even with decent manuals. If you can't get the modbus manuals for your drives you might be out of luck.
Please Log in to join the conversation.
So i should go
loadusr -W mb2hal config=enc_vfd.ini
do i need antything else in the .hal file?
this was a chapter in the X200 thread (code from the .hal file) that catched my eye:
net x200-run x200.run.00 <= motion.spindle-on
net x200-dir x200.direction.00 <= motion.spindle-forward
net x200-RPM x200.frequency.00 <= motion.spindle-speed-out
net x200-at-speed x200.at-speed.00 <= motion.spindle-at-speed
setp x200.direction.00 0
Well the manual is really good for my vfd, i separated the modbus part that can be located here: 1drv.ms/b/s!AnY9CcWCLBtalGev69rQ1UOUzZXn
i just don't understand how i should apply the information from the manual, if we look at this chapter from the X200 code for example:
i have this table in the manual:
Attachment not found
Victor
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
Such as my drives need to have a certain register written to to unlock the drive. Then another had to be read periodically to prevent a communications shut down... I'm a little jealous if you only need to write to one register and read 2 contiguous ones. (Did i mention the drives I had to work with were a complicated mess.)
Please Log in to join the conversation.
Would be super if you could explain how i would need to code for one function like running clockwise
Victor
Please Log in to join the conversation.
- Todd Zuercher
- Offline
- Platinum Member
-
- Posts: 4739
- Thank you received: 2
The first thing you need to do is figure out what the drives current modbus parameter settings are, and what you need to set them to.
You need to figure out what the address of your little USB dongle is. (It should be something like SERIAL_PORT=/dev/ttyUSB0 (or 1,2 3...) Mine was 0 as it it the only USB device on that computer.
Please Log in to join the conversation.
I have the following pages with diffrent protocols if that is what you mean?
Attachment not found
Attachment not found
Attachment not found
Please Log in to join the conversation.
