Hello Guest it is April 25, 2024, 08:39:42 PM

Author Topic: Modbus control huanyang GT vfd  (Read 3910 times)

0 Members and 1 Guest are viewing this topic.

Re: Modbus control huanyang GT vfd
« Reply #30 on: November 06, 2021, 06:54:15 AM »
Hi,
first please post a screen shot of the Regfile diagnostic, I need to see the register path.
Second, what number do you have to set in the register to cause a given speed?

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Modbus control huanyang GT vfd
« Reply #31 on: November 06, 2021, 10:12:08 AM »
Hi,

Quote
I pasted that code into the lua file for the spindle control, but I had no success with that unfortunately

But it doesn't go in the spindle control file, wherever it is and whatever it is, it goes in the PLC script. The code is not completed,
you have to add some details, you'll not just be able to paste it in as is.

Craig

ok, so i pasted this  code into the Lua file that i posted earlier in this thread, which is called as a PLC script (selected in screen editor). This LUA file is called spindle control - hope this clarifies!

Unfortunately i am not so familiar with coding, scripting and writing macros so forgive my ignorance!
I have attached a screen grab of the regfile and modbus window, and below the code as is at the moment

Code: [Select]
-----------------------------------------------------------------------------
--   Name: PMC Module
--Created: 03/27/2015
-----------------------------------------------------------------------------
-- This is auto-generated code from PmcEditor. Do not edit this file! Go
-- back to the ladder diagram source for changes in the logic

-- U_********* symbols correspond to user-defined names. There is such a symbol
-- for every internal relay, variable, timer, and so on in the ladder
-- program. I_********* symbols are internally generated.

local VFD_Spindle_controller = {}

local hReg, hSig, rc
local mInst = 0

-- Generated function for MachAPI.
local function Read_Register(path)
    hReg, rc = mc.mcRegGetHandle(mInst, path)
    if (rc == mc.MERROR_NOERROR) then
        local value, rc = mc.mcRegGetValue(hReg)
        if (rc == mc.MERROR_NOERROR) then
            return value
        end
    end
    return 0
end

-- Generated function for MachAPI.
local function Write_Register(path, value)
    hReg, rc = mc.mcRegGetHandle(mInst, path)
    if (rc == mc.MERROR_NOERROR) then
        rc = mc.mcRegSetValue(hReg, value)
        if (rc == mc.MERROR_NOERROR) then
            return
        end
    end
    return
end

-- Generated function for MachAPI.
local function Read_Signal(path)
    hSig = 0
    rc = mc.MERROR_NOERROR
    hSig, rc = mc.mcSignalGetHandle(mInst, path)
    if (rc == mc.MERROR_NOERROR) then
        local state = 0;
        state, rc = mc.mcSignalGetState(hSig)
        if (rc == mc.MERROR_NOERROR) then
            return state
        end
    end
    return 0
end

-- Generated function for MachAPI.
local function Write_Signal(path, v)
    hSig = 0
    rc = mc.MERROR_NOERROR
    hSig, rc = mc.mcSignalGetHandle(mInst, path)
    if (rc == mc.MERROR_NOERROR) then
        mc.mcSignalSetState(hSig, v)
    end
end

-- Generated function for signal read.
local function Read_U_b_FSpindle_CW()
    return Read_Signal(1142)
end

-- Generated function for signal read.
local function Read_U_b_FSpindle_CCW()
    return Read_Signal(1143)
end

-- Generated function for signal read.
local function Read_U_b_FSpindle_ON()
    return Read_Signal(1141)
end

-- Call this function to retrieve the PMC cycle time interval
-- that you specified in the PmcEditor.
function VFD_Spindle_controller.GetCycleInterval()
    return 10
end


-- Call this function once per PLC cycle. You are responsible for calling
-- it at the interval that you specified in the MCU configuration when you
-- generated this code. */
function VFD_Spindle_controller.PlcCycle()
    mInst = mc.mcGetInstance()

    if     (Read_U_b_FSpindle_CCW() == 0 and Read_U_b_FSpindle_CW() == 1 and Read_U_b_FSpindle_ON() == 1) then
       Write_Register("modbus0/wrtvfdcmd0", 1)
    elseif (Read_U_b_FSpindle_CCW() == 1 and Read_U_b_FSpindle_CW() == 0 and Read_U_b_FSpindle_ON() == 1) then
       Write_Register("modbus0/wrtvfdcmd0", 2)
    else --if Read_U_b_FSpindle_ON() == 0) then
       Write_Register("modbus0/wrtvfdcmd0", 5)
    end

    local spindle_rpm = scr.DroRead(mInst, 27)
    Write_Register("modbus0/wrtvfdspeed0", spindle_rpm/12000*10000)
end

return VFD_Spindle_controller
Re: Modbus control huanyang GT vfd
« Reply #32 on: November 06, 2021, 10:15:27 AM »
Hi,
first please post a screen shot of the Regfile diagnostic, I need to see the register path.
Second, what number do you have to set in the register to cause a given speed?

Craig
Re: Modbus control huanyang GT vfd
« Reply #33 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:

Code: [Select]
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
« Last Edit: November 06, 2021, 03:42:24 PM by joeaverage »
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Modbus control huanyang GT vfd
« Reply #34 on: November 06, 2021, 05:32:45 PM »
should i bin the rest of the code or append this into it?

Re: Modbus control huanyang GT vfd
« Reply #35 on: November 06, 2021, 11:48:45 PM »
Hi,
I would guess at least a part of the code that you have installed is working, ie the VFD turns on and off and you can select FWD or REV,
so to bin it would be to 'throw the baby out with the bath water'.

What I would suggest is to put the proposed code in a macro so that you can run it in the editor.  Once you have established that it works
to your satisfaction and you understand it thoroughly then and only then install it in the PLC script.

The reason I suggest this is because a macro executes just once, if there is a problem with it you can stop it, and/or single step through the code
until you understand what's going on. If you put it directly in the PLC script it will run every few milliseconds, and if it does something strange you may have
to crash Mach to get it to stop, not ideal.

For no particular reason lets call the macro m666:

Code: [Select]
function m666()
     local mInst=mc.mcGetInstance()
     local registerHandle=mc.mcRegGetHandle(mInst,"modbus0/wrtvfdspeed")
     local commandedSpeed=mc.mcSpindleGetCommandRPM(mInst)
     local registerValue=(commandedSpeed/12000)*10000
     mc.mcRegSetValue(registerHandle,registerValue)
end
if(mc.mcInEditor()==1)then
     m666()
end

Try installing that in the macros folder of your current profile. You need to single step through it using the debug functions of the editor.
Using single step is the sure-fire best way to understand how your code works, and even more importantly when it does  not work!

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Modbus control huanyang GT vfd
« Reply #36 on: November 06, 2021, 11:51:08 PM »
Hi,
I have just got back from work, been shifting stuff all day and I'm buggered again! I'm beginning to think that going to Church on a Sunday
may not be such a bad idea after all.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Modbus control huanyang GT vfd
« Reply #37 on: November 07, 2021, 07:22:27 AM »
Hi,
I would guess at least a part of the code that you have installed is working, ie the VFD turns on and off and you can select FWD or REV,
so to bin it would be to 'throw the baby out with the bath water'.

What I would suggest is to put the proposed code in a macro so that you can run it in the editor.  Once you have established that it works
to your satisfaction and you understand it thoroughly then and only then install it in the PLC script.

The reason I suggest this is because a macro executes just once, if there is a problem with it you can stop it, and/or single step through the code
until you understand what's going on. If you put it directly in the PLC script it will run every few milliseconds, and if it does something strange you may have
to crash Mach to get it to stop, not ideal.

For no particular reason lets call the macro m666:

Code: [Select]
function m666()
     local mInst=mc.mcGetInstance()
     local registerHandle=mc.mcRegGetHandle(mInst,"modbus0/wrtvfdspeed")
     local commandedSpeed=mc.mcSpindleGetCommandRPM(mInst)
     local registerValue=(commandedSpeed/12000)*10000
     mc.mcRegSetValue(registerHandle,registerValue)
end
if(mc.mcInEditor()==1)then
     m666()
end

Try installing that in the macros folder of your current profile. You need to single step through it using the debug functions of the editor.
Using single step is the sure-fire best way to understand how your code works, and even more importantly when it does  not work!

Craig

So i have done as you suggested, i have saved the macro into the macro folder as m666 an if i go to the mdi, enter m3 s2000, i have the same result - power but no rotation.
then i enter m666 to call the macro (screen dro displays 2000 rpm) nothing happens so no better  :(
Re: Modbus control huanyang GT vfd
« Reply #38 on: November 07, 2021, 07:23:02 AM »
Hi,
I have just got back from work, been shifting stuff all day and I'm buggered again! I'm beginning to think that going to Church on a Sunday
may not be such a bad idea after all.

Craig
wow must be bad lol
Re: Modbus control huanyang GT vfd
« Reply #39 on: November 07, 2021, 09:49:05 AM »
I can confirm it is still the speed register not working/updating