1016
« on: November 06, 2021, 03:39:58 PM »
Hi,
OK. The PMC module has been around for about three years now, maybe more. Prior to its introduction the only way to have Mach
execute blocks of code repeatedly was to use the PLC, and I must confess its what I am still most familiar with.
The PMC module is a ladder logic module. Its designed to replicate Mach3 Brains and ladder logic is the predominant means of programming
industrial Programmable Logic Controllers. As it is a visual representation it is widely appreciated as the simplest means of programming.
The PMC module in Mach4 takes the visual representation, ie the rung of the ladder, and converts that into chunks of Lua code, and its that
Lua code that simulates the logic implied by the ladder rung. The Lua code blocks are auto generated and are not easy to read or interpret,
really they are seldom ever viewed by human operators, we'd just open the PMC editor and look at the ladder diagram. It comes as no surprise
that you are having difficulty in reading and understanding the Lua code, it was never meant to be human readable.
You have posted screen shots of the Modbus plugin set-up pages, which is useful, but still actually removed from what I asked for.
If you open the Regfile diagnostic you will see a tree diagram of ALL the registers in Machs core, and that is what I would prefer. Having said that
the shots you have posted, and the PM both confirm that the path to the speed register is:
modbus0/wrtvfdspeed
Now the speed command is a little different. In my own VFD if I choose to use Modbus comms I would supply a number related to frequency rather
than speed. For example my VFD goes to 400Hz, and the spindle does its full 24000 rpm at the frequency. The number I have to send is the frequency
IN TENTHS, thus if I send the number 4000 the spindle goes at full speed and if I send a number 2000 the spindle goes at half speed.
Machs core stores the speed as rpm. Thus if I interrogate Mach after issuing an s18000 for instance, Mach will respond with a number 18000.
To convert that into a number my VFD can use I would do the following:
RegisterValue=(MachSpeed / 24000 )*4000
Just to double check:
RegisterValue=(18000/24000)*4000
=3000, which to my VFD means 300Hz which indeed causes the spindle to rotate at 18000rpm.
It would appear that your VFD it somewhat different in that you must issue a number related to percentage of full speed, IN ONE-HUNDREDTHS:
100%=10000 and
50%=5000
Do I have this correct? If so you will need a slightly different mathematic expression to convert the number that Mach reports to the number
that the VFD expects:
RegisterValue=(MachSpeed /12000) *10000 given that 100% speed of your spindle is 12000rpm?
As a sanity check lets say you issue an s9000:
RegisterValue= (9000/12000) *10000
=7500
There are two ways to interrogate Machs core to get the current commanded speed. The way I am most familiar with is:
local speed=mc.mcGetPoundVar(inst, 2132) So this statement gets the value of the pound variable #2132, which is where Mach stores its commanded
speed.
swifty posted this method:
local spindle_rpm = mc.mcSpindleGetCommandRPM(mInst)
This method, which I was previously unaware of, is much better and more elegant and I would suggest you adopt it also.
Thus we should have some draft code:
local registerHandle=mc.mcRegGetHandle(mInst,"modbus0/wrtvfdspeed")
local commandedSpeed=mc.mcSpindleGetCommandRPM(mInst)
local registerValue=(commandedSpeed/12000)*10000
mc.mcRegSetValue(registerHandle,registerValue)
Note here I am asumming that 'mInst' has already been evaluated in the PLC and stored as a local variable. If not you'll have to add a line:
local mInst=mc.mcGetInstance()
Please note that I have not tested this code, my machine is at work, and we are shifting premises and have been for the last two days, in fact
as soon as I finish this post I'm leaving to continue with that. At the moment I cannot even plug my machine in, let alone run it
and test some code.
May I suggest running it in the Lua editor before you put it into the PLC. Faulty code in the PLC can cause you grief. You want/need to de-bug any code
before you put it in there.
Craig