Hello Guest it is April 22, 2021, 06:50:38 PM

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

0 Members and 1 Guest are viewing this topic.

Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #20 on: January 24, 2017, 06:50:44 AM »
I tried input registers with the numbers I got from the manual but didn't work, don't know what to try and what to do.. there must be a way to read the motor speed, but how? Try to read the manual and see if you understand?
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #21 on: January 24, 2017, 10:56:10 AM »
Hi,
I agree the manual is not clear, by my reading the address should be 0004hex. What I suspect is that you have to
prepend with another number to get the data address. Try emailing the manufacturer.

May I suggest don't bother with reading the speed at the moment, just concentrate on controlling the spindle.

Craig
My wife left with my best friend...
     and I miss him!
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #22 on: January 24, 2017, 11:09:42 AM »
Hi!
I'm currently waiting for skype contact, they will probably answer tonight as usual, China time zone and all
they say that it is standard protocols but that doesn't help, because we don't know what registers they use for their functions? It's may be possible to figure that out?.
I could try to use a modbus sniffer? And se what data it transmits? I may only work if I call for that function first?

I made one modbus function with 16 (registers read output holding)  and then checked modbus diagnostics and found a bunch of 1-0s in a row for every Reg?

0
0
0
0
1
0
0
0
0
1
1
1
0
0

Something like that? And they changed when I started the Spindle / changed frequency? Any idea what it could be? Binary?
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #23 on: January 24, 2017, 02:28:24 PM »
Hi Zuxztah,
not sure but don't think so. You may have noted in one of the examples included in the communication pdf you posted
it wrote to and address 2102 hex. Can you find anywhere in the lists such an address? I can't and yet it used as an example,
ie it must exist. My guess it that if you wish to write to the parameters, ie set some feature of the VFD, then you use the
command address as listed. If you wish to read data from the VFD addresses will be in the range 2100 hex to who knows.

This is from my Delta VFD manual:
Code: [Select]
2103H Output frequency (H)
2104H Output current (A*********.X)
2105H DC-BUS Voltage (U*********.X)
2106H Output voltage (E*********.X)
2107H Step number of Multi-Step Speed Operation
2108H Step number of PLC operation
2109H Content of external TRIGGER
210AH Power factor angle
Status
monitor
Read only 210BH Estimated torque ratio (*********.X)
210CH Motor speed (rpm)
210DH PG pulse (low word) /unit time (Pr.10-15)
210EH PG pulse (high word) /unit time (Pr.10-15)
210FH Output power (KW)
2110H Reserved
2200H Feedback Signal (*********.XX %)
Chapter 5 Parameters

Note the address block of 2100 hex to 2200 hex. I very much suspect your VFD is the same.

Still recommend you don't get hung up on it. You stated earlier that you had this VFD working over Modbus with Mach3 but without speed
feedback. With current knowledge you don't have speed feedback in Mach4 either, big deal.

You still have to write the LUA scripts necessary to give you programmatic control of your spindle.

To date you have really only used the Modbus and Refile plugins to set up your 485 comm link. You have yet to write any code and I suspect
you will find it rather harder and more confusing than what you have done to date. Don't get hung up on a detail.

Craig

My wife left with my best friend...
     and I miss him!
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #24 on: January 24, 2017, 03:28:41 PM »
Hi, That's true, I'll probably never sort the lua script out by my self, probably in a Year or two with a hard time learning and long nights in front of the computer, but it doesn't feel like it's worth the effort, it's worth it but at the same time it feels like I reinvent the wheel? I know that it will be useful in the future for other projects and such. I know that there is people with knowledge who is glad help :) like you! All the effort you already have put in to this is incredible! :)
 
the basic modbus functions is working and the script is not, I want to learn but have tried many many times, arduino, python and other languages and It feels like I never learn anything? Especially after I got sick.
my brain is totally corrupted.. the unknown disease should be named "Teflon brain" with a hint of failing nervous system and bad memory, haha. And that's a True fact.
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #25 on: January 24, 2017, 05:21:01 PM »
Hi Zuxztah,
I have the same problem with less organic excuse.

The good news tho is that you only need four separate chunks of code each no more that half a dozen lines long. I don't claim to be
good enuf to write them and have them work straight off aside from which you would learn nothing in the process.

With the Program Run Tab on screen with Mach4 disabled, click Edit Screen on the Operator menu.
Click the Spindle CW/Stop button on the right hand side of the page. This should highlight the 'button code' in the screen elements tree on
the upper left and will show either the 'properties' or 'events' of the button at the lower left. With the 'properties' displayed you can change colours,
sizes, texts, enabled states and all that sort of stuff.

What I want you to have a look at tho is the 'events' associated with the button. You will note, assuming the default screen, that the left-up script
is the function 'SpinCW()'. The 'left-up' means the up-click event of the lefthand mouse button whereas the 'left-down' refers to the down-click event.
If you click on that and click on the rightmost extension button an editor window will open with the script for the button.
In this case it's pretty boring, it just the function SpinCW(), but notice the code underneath, all commented out but is in fact a copy of the code which
runs when SpinCW() is called. You may note that all it does is either set the spindle direction signal to off or set it to 1, ie CW. This won't work for you
because your using Modbus to control you spindle. You will have to substitute SpinCW() with code that turns your spindle CW at a given speed.

Just as a matter of interest the LUA editor display window is just a fraction of the LUA SCRIPT. All of the buttons, LEDs, DROs and so on all have their
own little bits of code associated with them. They are all gathered up into one script, the LUA SCRIPT, and it is that conglomerate which runs. You can view
the LUA script on the Oeratrator menu 'Lua Script'. Its quite a sizeable file, about 1000 lines on my machine. In there you will find the Screen load script, Screen
Unload script, Signal script and others besides. Over a period of time as you customise your machine, like your Modbus control, your code will end up
in this file as well. You can view it but you can't run or edit it. If you wish to make alterations you will have to open each button or what have you and edit
its script/code there. Note also that if you have say a button script open in the LUA editor then the conglomerate file can't be bought together because a
piece of it is still open in the editor. If you wish to run the code you need to save any edits and commonly close the editor window before the complete LUA
script can be compiled and run. Don't worry you will forget from time to time and Mach4 will hang as a result. You will have to close Mach4, sometimes
with the help of the 'Task Manager,' and reopen.

Open 'Lua Script' per the above and have a look at lines 136-165. These are the 'event scripts' for the two spindle buttons on screen.

With the left-up script in the Lua Editor rather than delete SpinCW() just comment it out, ie put '--' in front of it. Means that if you wish to unwind what you've
done at a later date its easy to do.

Type in this code (before or after the comments doesn't matter):
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then
      local hregcontrol=mc.mcRegGetHandle(inst,"modbus0/spinCntrl")
      mc.mcRegSetValue(hregcontrol,01)      -- substitute 01 with whatever bit pattern is required to turn the spindle clockwise
      local hregfrequency=mc.mcRegGetHandle(inst,"modbus0/freq")
      mc.mcRegSetValue(hregfrequency,2000)   -- the value 2000 ie 200Hz will as this script grows and gets more sophisticated will be variable but for now....
else
      local hregcontrol=mc.mcRegGetHandle(inst,"modbus0/spinCntrl")
      mc.mcRegSetValue(hregcontrol,,00)   - substitute 00 with whatever bit pattern is required to stop the spindle
end

Please note that I haven't tested this code, without a working 485 link I can't. Note also that some changes could be made to make it better but
try and read it thru and understand what is trying to do.

If sigState=1 (it must have been 0 before), then we want to turn the spindle on, ie update your two Modbus registers to turn the spindle CW and set
a  frequency. If sigState~=1 (it must have been 1 before), then we want to turn the spindle off.

Craig
My wife left with my best friend...
     and I miss him!
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #26 on: January 24, 2017, 05:51:47 PM »
Hi :)

Seems pretty easy when you explain, I understand the part with edit button script and so on, but the code writing is the really hard plart for me, I understand the basics of the code when I read it but typing it from scratch is another problem much like me an English, I understand  the language pretty good but trying to talk or write English is damn hard sometimes, the grammar and so on Is pretty messed up heheh. I'll follow your posted guide here tomorrow after work and see if I get any result :)

By the way I'm running the vx routerset (screen set) if it makes any difference, I know that I followed an old guide to make limit switches to work properly in Mach 4 with ESS (Ethernet Smooth Stepper) the screen load script was different, may be caused of an erlier build/ version of Mach.

For time being it won't listen to "S command"  (S18000 M3)? it's necessary Edit the script for calculating the Spindle rpm from frequency, basically it will listen to S1000-4000 if the script is set to transmit to 8193 function via modbus0/freq

Small steps to success :) ill buy the Mach 4 license tomorrow, didn't know before if it was worth it because of lack of knowledge but now it seems like there is a solution on its way :)

Either way it's worth it because Mach 3 no longer have any updates, feels like it's worth upgrading to get updates/fixes  and reliability :)

Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #27 on: January 24, 2017, 06:11:32 PM »
Hi Zuxztah,
I adopted the approach I did so that I could explain how it works and give you the chance to learn it too.

Glad that you are familiar with the Edit Screen function, you are going to use it a lot while you get this setup.

You are also correct that as I've written it spindle speed is an issue. I did it this way for simplicity... at the beginning...
it will change!

What will evolve is two small button scripts for the two buttons, three m functions; m03, m04 and m05 that take over from
the standard Mach4 functions by the same name and another small piece of code in the PLC script to maintain spindle speed
in step with your Gcode and/or MDI.

Let me know when you've digested and maybe got that previous lot of code working and will make a start on the rest. Good news
is if you understand what I've done then the rest will be easy.

Craig
My wife left with my best friend...
     and I miss him!
Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #28 on: January 26, 2017, 07:55:46 AM »
Hi! I've tried the script now, had to change some small things to get it to compile,  :)

Code: [Select]
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then
      local hregcontrol=mc.mcRegGetHandle(inst,"modbus0/spinCntrl")
      mc.mcRegSetValue(hregcontrol,10)      -- substitute 01 with whatever bit pattern is required to turn the spindle clockwise
      local hregfrequency=mc.mcRegGetHandle(inst,"modbus0/freq")
      mc.mcRegSetValue(hregfrequency,1000)   -- the value 2000 ie 200Hz will as this script grows and gets more sophisticated will be variable but for now....
else
      local hregcontrol=mc.mcRegGetHandle(inst,"modbus0/spinCntrl")
      mc.mcRegSetValue(hregcontrol,01)   -- substitute 00 with whatever bit pattern is required to stop the spindle
end

but when I comment out SpinCW () with (--) it won't trigger the green led bar in Mach anymore, and the script gives no response, note that I edited the button Left Up Script,

tried to change the Reg file to add modbus0/spinCntrl and modbus0/freq

the Operator tab (Lua Script) doesn't seem to implement anything from the button script

Is it really Decimal value the script/mach wants? maybe it's hex?

I'll add some pictures for you to look at if I'm getting it all right, probably not,

https://postimg.org/gallery/1wc50bmou/


Re: Mach 4 Machtric 2.2kw VFD Modbus
« Reply #29 on: January 26, 2017, 10:32:30 AM »
Hi!
Here's a video on the functions I got so far. by editing Regfile values, so that's what we need to link the button scripts to,

https://youtu.be/YzcnwxyAG0Q

Watch out for the Volume in the video, sounds terrible, (runout vibrations/ Unbalanced endmill)