Hello Guest it is April 24, 2024, 07:58:05 PM

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

0 Members and 1 Guest are viewing this topic.

Re: Modbus control huanyang GT vfd
« Reply #10 on: November 02, 2021, 07:43:46 PM »
Hi,
Writing your own m3 would result in the speed register being updated only at each occasion m3 is called. Quasi continuous updates ocurr with the code in the plc script and is therefore preferred.
Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Modbus control huanyang GT vfd
« Reply #11 on: November 03, 2021, 10:35:46 AM »
A couple of things to check:
Did you add the .lua file to the PMC and enable it through the screen editor?
Are your register names for the modbus exactly the same as it shows in the instruction? The PMC is writing to these specific register paths so it needs to match.

Re: Modbus control huanyang GT vfd
« Reply #12 on: November 04, 2021, 05:48:07 AM »
A couple of things to check:
Did you add the .lua file to the PMC and enable it through the screen editor?
Are your register names for the modbus exactly the same as it shows in the instruction? The PMC is writing to these specific register paths so it needs to match.

Yes i have checked the functions are exact as in the script file.  i added the Lua file to the pmc scripts in screen editor.  I feel like its partly working as it is 'activating' the vfd, it just wont spin!

Re: Modbus control huanyang GT vfd
« Reply #13 on: November 04, 2021, 05:51:17 AM »
Hi,
Writing your own m3 would result in the speed register being updated only at each occasion m3 is called. Quasi continuous updates ocurr with the code in the plc script and is therefore preferred.
Craig

Yes thats what i thought.. i would like this to function as it was - i.e. not need an m3 cmd to update the speed
 
Re: Modbus control huanyang GT vfd
« Reply #14 on: November 04, 2021, 05:53:11 AM »
This is the lua file i'm using here

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

Offline Bill_O

*
  •  563 563
    • View Profile
Re: Modbus control huanyang GT vfd
« Reply #15 on: November 04, 2021, 07:52:41 AM »
I could be very wrong but don't the variables "path" and "value" need to be defined what they are?
Re: Modbus control huanyang GT vfd
« Reply #16 on: November 04, 2021, 08:30:55 AM »
Maybe, i'm not sure too.... i did see that but i dont have the knowledge of Lua to say so
Re: Modbus control huanyang GT vfd
« Reply #17 on: November 04, 2021, 08:31:50 AM »
the modbus resister addresses are present below, so i figured this path was supposed to be there
Re: Modbus control huanyang GT vfd
« Reply #18 on: November 04, 2021, 10:39:34 AM »
Try replacing this line

local spindle_rpm = scr.DroRead(mInst, 27)

with this:

local spindle_rpm = mc.mcSpindleGetCommandRPM(mInst)

I'd edit the lua file with mach closed
Re: Modbus control huanyang GT vfd
« Reply #19 on: November 04, 2021, 01:55:40 PM »
replaced that line of code to no avail....

one thing i have noticed is that when i have the lua script enabled, i cannot write to the speed register using regfile anymore...
As soon as i uncheck the script in screen editor, i can control it again