5
« on: February 15, 2022, 09:20:02 PM »
I've included the script (below) and have removed some of the diagnostic code and added several comments. As previously mentioned I have no problem with the operations of the program and can see that the value that is used in the "set..RPM" method is indeed being set (via an immediate call to the "get" method)...It seems as though the source for the "Spin RPM" field may not be getting updated from the object that represents the "actual spindle speed".
The other thing may be how i'm using the script. For example, I modify the file..then compile it..run it in debug mode and runs as expected less updating anything on the Mach4 mill display. Is there something else I need to do to get this linked to the main execution stream??
Writing code is not a stumbling block for me as I've designed and written >2M lines of code prior to retirement.
====================(CODE FOLLOWS)============
--Function to read value from Pokeys57CNC controller analog register (Pin41)
-----------------------------------------------------------------------------
function ReadRegister(i,device, analogPin)
--i = Instance
--device= the name of the PoKeys controller
--pin = the Pokeys pin to read
local hreg = mc.mcRegGetHandle(i, string.format("%s/Analog input %s",
device, analogPin))
local val = mc.mcRegGetValue(hreg)
return val
end
--Function to set active spindle speed
------------------------------------------
function SetSpindleSpeed(i, regValue, maxspeed, tweak)
--i = Instance
--regValue = number between 0-1 representing the
-- voltage read from controller pin41
-- where 0 represents 0 RPM, and 1.0 represents 24000 RPM
--maxspeed = maximum speed of the spindle (24000 RPM)
--tweak = fudge factor to correct RFI generated error on pin 41 reading
----------------------
local speed = regValue * maxspeed * tweak --RegValue 0-1.0V
if(regValue<=0.15) then -- If the register is under .15V then just set
-- the speed to 0 rpm
speed=0
end
local rc = mc.mcSpindleSetSensorRPM(i,speed)
--local rspeed=mc.mcSpindleGetSensorRPM(i) DEBUG to Verify SPINRPM "set"
end
--Main
local device = "PoKeys_*********X" -- The name of my controller
local analogPin = "41" -- Analog input pin number
local MAXSPEED=24000 -- Maximum spindle speed (RPM)
local TWEAK=.985144 -- Adjustment factor to correct for EMI on P41 reading
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, "iRegs0/FireCount") -- Get the handle
local countVal=0 --initialize countVal to 0
if(hreg>0) then
countVal= mc.mcRegGetValue(hreg) -- get the throttle count
local mVal=countVal%10 -- get the modulo remainder
--mVal=0 -- Debug Code to fire every time (remove for operations)
if (mVal==0)then --Execution only runs every 10th execution of main
analogVal = ReadRegister(inst, device, analogPin) --get P41 Value
SetSpindleSpeed(inst, analogVal, MAXSPEED, TWEAK) -- Set SindleSpeed
end
end
countVal=countVal+1 -- pop the counter up 1
mc.mcRegSetValue(hreg,countVal) --Update the "FireCount" register
=======================Code End=====================
Thanks in advance for any guidance!
Reuben