26
Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell [email protected] Connecting a spindle controller (VFD) to Mach4 through the Modbus (RS-485 serial port) is not an easy task, since there is no formal Mach4 Modbus documentation yet, and no overall LUA script (that I could find) to support a VFD through Modbus. This post is a set of step by step instructions that hopefully will help someone else get their VFD up and running quickly. For reference I am using Windows 10, Mach4 V4.2.0.3804, and FDTI serial driver V2.12.16.0 The Huanyang VFD is popular on many Internet sites, however there are several models out there and most of them are not truly Modbus compatible. I chose the Huanyang GT series 2.2KW for my Spindle since it does support the Modbus protocol and interfaces with Mach4’s Modbus correctly. Other VFDs can easily be controlled as long as they are Modbus compliant. These steps will give you the necessary setup to do the following spindle commands: 1. M3 (CW spindle) 2. M4 (CCW spindle) 3. M5 (Stop spindle) 4. Sxxxxx (Set spindle speed) In addition the spindle will be controllable through the front panel buttons and executing G code. Step 1 Setup your VFD to control your particular spindle using the front panel on the VFD. This will include max frequency, min frequency, max current, max voltage, ramp parameters, etc. Refer to the VFD manual for the instructions on how to use the front panel controls on the VFD to modify these parameters. They will be saved across power on/off cycles, so this only needs to be done once. Please note once these settings are changed, you will no longer be able to control the motor from the VFD front panel.

Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell [email protected] Connecting a spindle controller (VFD)

  • Upload
    others

  • View
    41

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

ConnectingaVFDtoMach4throughModbus(RS485)

V2

June2019BillCaldwell

[email protected]

Connectingaspindlecontroller(VFD)toMach4throughtheModbus(RS-485serialport)isnotaneasytask,sincethereisnoformalMach4Modbusdocumentationyet,andnooverallLUAscript(thatIcouldfind)tosupportaVFDthroughModbus.

ThispostisasetofstepbystepinstructionsthathopefullywillhelpsomeoneelsegettheirVFDupandrunningquickly.

ForreferenceIamusingWindows10,Mach4V4.2.0.3804,andFDTIserialdriverV2.12.16.0

TheHuanyangVFDispopularonmanyInternetsites,howeverthereareseveralmodelsoutthereandmostofthemarenottrulyModbuscompatible.IchosetheHuanyangGTseries2.2KWformySpindlesinceitdoessupporttheModbusprotocolandinterfaceswithMach4’sModbuscorrectly.OtherVFDscaneasilybecontrolledaslongastheyareModbuscompliant.

Thesestepswillgiveyouthenecessarysetuptodothefollowingspindlecommands:

1. M3(CWspindle)2. M4(CCWspindle)3. M5(Stopspindle)4. Sxxxxx(Setspindlespeed)

InadditionthespindlewillbecontrollablethroughthefrontpanelbuttonsandexecutingGcode.

Step1

SetupyourVFDtocontrolyourparticularspindleusingthefrontpanelontheVFD.Thiswillincludemaxfrequency,minfrequency,maxcurrent,maxvoltage,rampparameters,etc.

RefertotheVFDmanualfortheinstructionsonhowtousethefrontpanelcontrolsontheVFDtomodifytheseparameters.Theywillbesavedacrosspoweron/offcycles,sothisonlyneedstobedoneonce.Pleasenoteoncethesesettingsarechanged,youwillnolongerbeabletocontrolthemotorfromtheVFDfrontpanel.

Page 2: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

OnceyoucanturnthespindleonandoffandsetthespeedfromthefrontpaneloftheVFDyouarereadytomodifytheVFDparametersnecessarytoenabletheModbuscommunicationsportontheVFDsocommandsandstatuscanbesentandreceivedbetweenthecomputerandtheVFD,disablingthefrontpanelmotorcontrol.

TheHuanyangGTVFDrequiredthreevaluestobemodifiedfromthedefaultvalues.

1. P0.01=2(defaultis1)RuncommandsourceistheRS485port2. P0.07=7(defaultis0)FrequencysourceistheRS485port3. PC.00=1(defaultis0)SettheModbusnodeaddressto1

(6/29/2019update)MostGTseriesVFDsdefaulttoRTUmode1start,8data,noparity(1N8)at19.2KBPS.However,Ihavebeentoldthatsomedonot,somakesuretocheckalltheseparametersintheVFDandcorrectthemasnecessary.

TheVFDisnowsettoreceivecommandsandsendstatusto/fromtheserialModbus(RS-485port)at19.2Kbaud,noparityinRTUmode.

PleasenotethatcomputersdonotimplementRS-485directly.YoumustpurchaseaUSBtoRS-485converter.AllRS-485datawillbesentouttheselectedUSBportonthecomputerthroughtheconverter,acrosstheRS-485cabletotheVFD.TheRS-485protocolimplementsadifferentialelectricalconnectionthatprovidesagreatdealofcommonmodenoiseimmunity,whichisusefulintheCNCenvironment.

ConnecttheVFDtotheRS485converterwiththedifferentialRS485signalsconnectedD+toD+andD-toD-ontheVFD.Ifthesignalsarecrossed,nocommunicationswilloccur.

PlugintheUSBcablefromtheRS485convertortothecomputer.

TheHuanyangGTVFDusesthefollowingregisteraddressesandcommandbits.Inthefollowingstepsyouwillbereferencingthoseaddresses.

Commandregisteraddress4096decimalStatusregisteraddress4097decimalSpeedregister8192decimalThecommandregisterissetto:Runforward1Runreverse2Stop5TheStatusregisterreturns:Forward1Reverse2Standby3Fault4

Page 3: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Powergoingoff5IfyouuseadifferentVFDmostlikelytheseaddressesandvalueswillneedtobechangedintheModbusfunctionsandtheLUAcode.

Step2

ItisnecessarytoinstalltheUSBtoRS-485windowsdriverneededfortheconvertor.Followtheinstructionssuppliedwithyourconvertortoinstallthedriver.Oncethedriverisinstalled,notethecomportnumberitisassociatedwith(Com3inthiscase).

Page 4: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Step3

ThisstepsetsuptheMach4ModbuscontrollertosendcommandstotheselectedVFDandreceivestatusbackfromtheselectedVFD.OncethesechangesaremadetheywillbepermanentlystoredintheMach4profileyouarecurrentlyrunning.

Intheconfiguration/controlmenu,selectthePluginstabandenablethefollowingplugins.

Page 5: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

SelectthespindletabandfillintheMaxRPMasshownbelow.

Page 6: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

IntheConfigure/Controlmenu,selectthePluginspulldownmenuthenselecttheModbusplugin.

Page 7: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

BegincreatingthecommunicationspathfromtheComporttotheMach4Modbuscontroller.Fillintheboxexactlyasseeninthefollowingscreen.

ThiscreatesaninstanceoftheModbuscontrollercalledmodbus0settoRTUmode.Generallythedefaultvalueswillwork.Makesuretocheckthezerobasedregisteraddressingmodebox.

Page 8: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

SelecttheporttocorrespondtotheportattachedtotheUSBtoRS484convertershownintheWindowsdevicemangerwindow(Com3inthisexample).Continuesettingtheparametersasshownbelow.

Page 9: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Whenyouaredonewiththisstepyouwillseetheconfirmationwindowasseenbelow.Yourcomportmaybedifferentthanshowninthisexample.

Page 10: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

YouwillnowseetheModbuscontroller,justcreated,intheleftcolumnandasummaryoftheModbussettingsjustselectedontheright.SelectOK.

Page 11: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Step4

ThenextstepscreatethreenecessaryModbusfunctionstowritetotheVFDcommandregister,writetotheVFDspeedregister,andreadtheVFDstatusregister.Pleasemakesurethefunctionnamesareenteredexactlyasshown.TheyneedtomatchthecorrespondingfunctionnamescontainedintheLUAscripttofollow.

HighlighttheModbuscontrollerandselectthecreatefunctionbutton.Fromthepulldowncommandlist,select(0x06).Fillinthevariousparametersexactlyasshownbelow.Thenameofthisfunctioniswrtvfdcmd(typedin2places).Pressnext.

Page 12: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Thenextscreenconfirmsyoursettingsforthefirstfunction.PressOK

Page 13: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

HighlighttheModbuscontrollerandselectthecreatefunctionbutton.Fromthepulldowncommandlist,select(0x03).Fillinthevariousparametersexactlyasshownbelow.Thenameofthisfunctionisrdvfdstatus(typedin2places).Pressnext.

Page 14: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Thenextscreenconfirmsyoursettingsforthesecondfunction.PressOK

Page 15: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

HighlighttheModbuscontrollerandselectthecreatefunctionbutton.Fromthepulldowncommandlist,select(0x06).Fillinthevariousparametersexactlyasshownbelow.Thenameofthisfunctioniswrtvfdspeed(typedin2places).Pressnext.

Page 16: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Thenextscreenconfirmsyoursettingsforthethirdfunction.PressOK

Page 17: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Thisisthefinalconfirmationscreen.Ifeverythinglooksasitshould,pressOK

Page 18: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Step5

SetupthediagnosticswindowstotesttheModbustoVFDconnection.

FromthediagnosticsmenuselectModbusandRegfile.

Page 19: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Thiswillopentwowindows.TheModbuswindow,onceexpanded,willshowyouthethreefunctionsyoujustcreatedandtheircurrentstatusalongwithsometiminginformation.TheRegfilewindow,onceexpanded,willshowyouthecurrentModbusregistercontentsforthecommand,status,andspeedregistersfortheVFD.ThestatusregisterisreadingtheVFDstatusregisterbasedonthepollratesetintheModbussetup.ThewriteregisterscontainthevaluessetbyMach4tobesenttotheVFD.Onceavalueisputintoeitherwriteregister,itwillbesenttotheVFDbasedonthePollrate.

Page 20: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

DoubleclickontheModbusspeedregisterandenterthevalue10000.Thisrepresents100.00%ofthemaximumspeedsetintheVFDpreviously(maxspeedis400HZ).400Hz*60sec=24,000RPM.

Page 21: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Doubleclickonthecommandregisterandenterthevalue1.Thespindleshouldrunclockwiseatfullspeed.

Page 22: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Enterthevalue5tostopthespindle.

Enterthevalue2toreversethespindle.

Atthispointyoushouldbeabletosetthespeedtoanyvaluebetween0and10000andrunthespindleineitherdirection.

Page 23: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

Step6

DownloadtheLUAscriptfromthefollowinglocation:

https://code.porkrind.org/david/mach4-vfd/blob/master/Huanyang_GT_VFD.lua

ThiscodewasoriginallywrittenwiththePMCeditor,butwasmodifiedbymyson,DavidtoaddthenecessarylogicandvaluesthatIcouldn’tgetthePMCeditortodo.

PlacethedownloadedcodeinthePMCfolderinsidetheMach4mainfolderasshownbelow.

NotethefiletypeandmakesureitisaLUAfileandnotatextfile.Sometimesthingsgetalteredwhendownloadingtodifferentmachines.

ThiscodewillneedtobeslightlymodifiedifthecommandbitsinyourVFDaredifferentthantheHuanyangGT.

Page 24: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

RestartMach4andselectthescreeneditorintheoperatormenu.

Selectthetop-levelscreeninthelefthandcolumn.GotothebottomleftandlocatethePMCline.Clickonthe3dotsontheright.SelecttheHuanyang_GT_VFD.Besuretochecktheboxnexttothename.Exitthescreeneditorbyclickingitsbuttonintheoperatormenu.

Page 25: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)

YoucannowcontrolthespindlefromeitherthebuttonsorwiththeMcommandsthroughtheMDIinterface.TheMDIinterfacenowrequiresthatthestartbuttonbepressedtoenterthecommands.ThespeedcanonlybeenteredthroughtheScommandthroughtheMDIinterface.

AllsupportedcommandsexecutefromGcode.

Questions,Comments,andimprovementsarewelcome.([email protected])

HaveFunwithyournewspindlecontroller!

Page 26: Connecting a VFD to Mach4 through the Modbus-v5...Connecting a VFD to Mach4 through Modbus (RS485) V2 June 2019 Bill Caldwell bill@caldwellfam.net Connecting a spindle controller (VFD)