Hello Guest it is May 14, 2021, 03:49:22 PM

Author Topic: Mach 4 Machtric 2.2kw VFD Modbus  (Read 13915 times)

0 Members and 1 Guest are viewing this topic.

Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #60 on: January 29, 2017, 05:16:31 AM »
Hi Zuxztah,
made some progress with the help of Daz-the-Gaz and Dude1....

The left-up script for the Stop button
Code: [Select]
Shutdown();
CycleStop();

The left-up script for the Reset button
Code: [Select]
Shutdown();
local inst = mc.mcGetInstance()
mc.mcCntlReset(inst)
mc.mcSpindleSetDirection(inst, 0)
mc.mcCntlSetLastError(inst, 'diagReset')

And this in the ScreenLoad script
Code: [Select]
---------------------------------------------------------------
--  Spindle Shutdown
---------------------------------------------------------------
function Shutdown();
    local inst=mc.mcGetInstance();
    mc.mcScriptExecute(inst,"m5.mcs",0);
end;
---------------------------------------------------------------
-- Cycle Stop function.
---------------------------------------------------------------
function CycleStop()
    mc.mcSpindleSetDirection(inst, 0);
    mc.mcCntlSetLastError(inst,"Cycle Stopped");
    mc.mcCntlCycleStop(inst);
end

---------------------------------------------------------------

And add this left-up script to the Enable/Disable button
Code: [Select]
Shutdown()
Not sure yet whether an Estop trap is required. Need to get to my machine, maybe later in the week.

Craig
My wife left with my best friend...
     and I miss him!
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #61 on: January 29, 2017, 05:35:58 AM »
Hi. It seems to be working good!  ::)
The physical estop won't stop the Spindle, it triggers the cycle stop button, and shows the message (E-Stop condition!)

Stop button stops the Spindle, I'll have to press Disable/Enable to get the Spindle running again,(with m3 or m4 command/button afterwards)
Reset button stops the Spindle and I'm able to start it again with m3 & m4 command/button

Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #62 on: January 29, 2017, 05:45:46 AM »
Hi Zuztah,
kool, awfully close now. Just an E-stop trap and you're done! If you had known at the outset what it was going to take would
you have bothered?

Probably need to write up the process, at least as a guide rather than a blow by blow account so others can follow it.

Craig

My wife left with my best friend...
     and I miss him!
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #63 on: January 29, 2017, 06:01:42 AM »
Hi, it's pretty easy but complicated at the same time, the code seems to be pretty simple if I had any programming experience beforehand, it is certainly worth the effort :) there will be other people that will encounter the same problems and the documentation gets  richer and richer:)

I don't know why, but I'm always choosing the hardest path to learn things, and it has for sure been fun and I've learned a lot on the way,

If you want you could write a guide, it would be much easier for other guys that's experimenting, my English isn't the best and try to write one would be disaster xD
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #64 on: February 05, 2017, 06:34:06 AM »
Hi!
Wired the physical E-stop to my VFD control panel button and it seems to work great :)
It behaves just like it should, smooth and nice deceleration and the only required action to get it running again is to press enable and then reset  ;)

but now I have another problem... came with no reason? haven't changed anything by mistake... my Z-probe touch of won't work? no response at all when clicking the touch button in Mach Router screens, and when I close the program a fault code shows up on the screen.

the attached photo shows the fault code...


Re: Mach 4 Automation Direct VFD Modbus
« Reply #65 on: January 03, 2018, 03:17:15 PM »
Hi,
I'm replying to this older thread as I used it as a guide to get an Automation direct VFD working via Modbus.  I had it working with Mach3 and struggled with Mach 4.  I figured I'd summarize the steps I took so future readers may have it a bit easier.  I'm no programmer and I have only a vague understanding of script code, so I probably won't be the best guy to offer support.

This is all based upon the work of joeaverage and Zuxztah, I appreciate the help!

First off, I set up the modbus (Configure>plugins>Modbus) as follows:




The registers for my particular VFD are:
2331  VFD Speed in Hz (includes an implied decimal place, so 4000 = 400Hz)
2332  VFD run command (0=stop, 1=run)
2333  VFD direction command (0=fwd, 1=rev)

8456  Feedback of actual motor speed in RPM (not required, I'm working on a DRO to display this)

Before you do anything else, make sure modbus comms are working by looking at the modbus diagnostic window (Diagnostic>Modbus-Newfangled Solutions)
The following scren shot shows my system running in reverse at 24000 RPM (400HZ):
The green indicators are good, if anything is red you need to fix it.


To make the above communication work, you need to modify the following paramiters in the VFD (via the VFD keypad, this is straight out of the VFD manual):

P3.00: 03 or 04 Operation Determined by RS-485 interface.
Keypad STOP is enabled (03) or disabled (04).

P4.00: 05 Frequency determined by RS-485 communication
interface.

P9.00: xx Communication address 1-254

P9.01: 01 9600 baud data transmission speed

P9.02: 05 MODBUS RTU mode
<8 data bits, odd parity, 1 stop bit>.

To be continued....
« Last Edit: January 03, 2018, 03:32:41 PM by gidyupp »
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #66 on: January 03, 2018, 03:29:59 PM »
Part 2:
The code to make it work
NOTE: SOME OF THIS HAS BEEN MODIFIED FROM THAT POSTED EARLIER IN THIS THREAD TO WORK FOR MY SITUATION, PARTICULARLY THE NAMES I GAVE THE MODBUS REGISTERS AND THE FACT THAT MY VFD USES SEPARATE REGISTERS FOR RUN AND DIRECTION. Again, I'm no programmer so if someone sees an error, please let me know.
 
Replaced leftup code for CW/Stop button:
Code: [Select]
--SpinCW()
--local inst = mc.mcGetInstance();
--local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
--local sigState = mc.mcSignalGetState(sigh);
--if (sigState == 1) then
--    mc.mcSpindleSetDirection(inst, 0);
--else
--    mc.mcSpindleSetDirection(inst, 1);
--end

local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then;
    local rc = mc.mcCntlGcodeExecuteWait(inst,"m5");
else;
    local rc = mc.mcCntlGcodeExecuteWait(inst,"m3");
end;

Replaced leftup code for CCW/Stop button:
Code: [Select]
--SpinCCW()
--local inst = mc.mcGetInstance();
--local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
--local sigState = mc.mcSignalGetState(sigh);
--if (sigState == 1) then
--    mc.mcSpindleSetDirection(inst, 0);
--else
--    mc.mcSpindleSetDirection(inst, -1);
--end

local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then;
    mc.mcCntlGcodeExecuteWait(inst,"m5");
else;
    mc.mcCntlGcodeExecuteWait(inst,"m4");
end;

Added line to leftup code for stop button:
Code: [Select]
Shutdown();
CycleStop();

Added line to leftup code for reset button:
Code: [Select]
Shutdown();
local inst = mc.mcGetInstance()
mc.mcCntlReset(inst)
mc.mcSpindleSetDirection(inst, 0)
mc.mcCntlSetLastError(inst, 'diagReset')

Added lines to the end of the screenload script:
Code: [Select]
---------------------------------------------------------------
--  Spindle Shutdown
---------------------------------------------------------------
function Shutdown();
    local inst=mc.mcGetInstance();
    mc.mcScriptExecute(inst,"m5.mcs",0);
end;
---------------------------------------------------------------
-- Cycle Stop function.
---------------------------------------------------------------
function CycleStop()
    mc.mcSpindleSetDirection(inst, 0);
    mc.mcCntlSetLastError(inst,"Cycle Stopped");
    mc.mcCntlCycleStop(inst);
end

---------------------------------------------------------------

Added to the Up Script for the enable button:
Code: [Select]
Shutdown()

Added lines to the end of the PLC script
This was added after the existing “end” statement and before the “--this is the last thing we do….” Line:
Code: [Select]

---------------------------------------------------------
--          set Target RPM DRO
---------------------------------------------------------

RPM=mc.mcCntlGetPoundVar(inst,2132);
local OVRenable=mc.mcSpindleGetOverrideEnable(inst);
  if OVRenable then;
    local OVR=mc.mcSpindleGetOverride(inst);
    RPM=RPM*OVR;
  end;
local range=mc.mcSpindleGetCurrentRange(inst)
if RPM>mc.mcSpindleGetMaxRPM(inst,range) then RPM=mc.mcSpindleGetMaxRPM(inst,range) end;
if RPM<mc.mcSpindleGetMinRPM(inst,range) then RPM=mc.mcSpindleGetMinRPM(inst,range) end;
local freq=RPM/6;
local hfreq=mc.mcRegGetHandle(inst,"modbus0/speed");
mc.mcRegSetValue(hfreq,freq);
scr.SetProperty('dro(128)','Value',tostring(RPM));

Added three macro files to the Profile/Macros folder:
m3.mcs:
Code: [Select]
function m3();
local inst=mc.mcGetInstance();
local hcont=mc.mcRegGetHandle(inst,"modbus0/run"); --run command (0=stop, 1=run)
local hcont1=mc.mcRegGetHandle(inst,"modbus0/direction");--added for direction control (0=fwd, 1==rev)
mc.mcSpindleSetDirection(inst,1);
mc.mcRegSetValue(hcont,1); --set to 1 to run
mc.mcRegSetValue(hcont1,0); --set to 0 for fwd
end
if (mc.mcInEditor() == 1) then
    m3()
end

m4.mcs:
Code: [Select]
function m4();
local inst=mc.mcGetInstance();
local hcont=mc.mcRegGetHandle(inst,"modbus0/run");--run command (0=stop, 1=run)
local hcont1=mc.mcRegGetHandle(inst,"modbus0/direction"); --added for direction control (0=fwd, 1==rev)
mc.mcSpindleSetDirection(inst,-1);
mc.mcRegSetValue(hcont,1); -- set to 1 to run
mc.mcRegSetValue(hcont1,1); --set to 1 for reverse
end
if (mc.mcInEditor() == 1) then
    m4()
end

m5.mcs:
Code: [Select]
function m5();
local inst=mc.mcGetInstance();
local hcont=mc.mcRegGetHandle(inst,"modbus0/run");
mc.mcSpindleSetDirection(inst, 0);
mc.mcRegSetValue(hcont,0);
end
if (mc.mcInEditor() == 1) then
    m5()
end

NOTE: I do not know if the hardwired E-stop function will stop the VFD through software.  Mine has a hardwired E-stop connected to the VFD to force it to shutdown so I'm set.  If your's is not hardwired to the VFD you may need to experiment.

I think that's all of it.
Good luck!
« Last Edit: January 03, 2018, 03:43:35 PM by gidyupp »
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #67 on: January 03, 2018, 03:40:13 PM »
One thing I should have mentioned, The automation Direct VFD uses Modbus decimal registers starting at the standard address of 40,001, M4 assumes the address start at 40,000 so you only enter the index number, so 40001 becomes "1", 42331 becomes "2331", etc.  In other words, subtract 40,000 from the addresses shown in the AD manual.
DRO Modbus Question
« Reply #68 on: January 03, 2018, 03:49:06 PM »
Now for a question for the Gurus:
I am trying to add a DRO to show the actual spindle speed as reported by the VFD.  As shown a couple of posts above, I have a modbus register setup (modbus0/actualRPM) that is working, but I need help with the code.
I have a DRO created named 'droTrueSpindle', and have the following code at the end of the PLC script:

Code: [Select]
local vfdspeed=mc.mcRegGetHandle(inst,"modbus0/actualRPM");
scr.SetProperty('droTrueSpindle','Value',tostring(vfdspeed));

What am I doing wrong?
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #69 on: January 09, 2018, 09:26:22 AM »
I have been checking that reset button, and it doesnt stop my spindle, only lowers RPM to 6000 for some reason.

So i added to the button when clicked


local inst=mc.mcGetInstance();
local hcont=mc.mcRegGetHandle(inst,"modbus0/cntrl");
mc.mcSpindleSetDirection(inst, 0);
mc.mcRegSetValue(hcont,01);

This tells spindel to stop on my VFD, might need to adjust to your VFD's (mactric VFD)

Steppes i have done as to solving Emergency button:

Connected S2 VFD innput to a relay on my controller board (pokeys57cnc)
Set S2 as an emergency swith (P318 - option 17)

Relay is active high and set to react after if mach4 is active or not (If you push emergency button, Mach4 will go inactive)
If it is active, it turns on the relay, and ofc the other way around if not.
so if i turn off my controller, spindle will be locked out in Emergency mode.
« Last Edit: January 09, 2018, 09:42:35 AM by Xillianto »