1
Mach4 General Discussion / Spindle Speed Lua Script..
« on: February 10, 2022, 03:45:04 PM »
Environment:
Mach4 Version: Hobby (latest version) Licensed
OS: Windows 10 Pro (664 bit).
Controller: Pokeys57CNC
VFD: Huanyang HY01D523B 1.5KW
My inverter, like many others, does not provide a digital stream that can be used to provide a real-time feedback signal that can be fed back to update Mach4's with the spindle's current speed (RPMs). The VFD, instead, provides a 0-10V output that represents 0(0 RPM) up to 10V (maximum spindle RPM).
I talked to Pokeys engineering about two years ago to see if I could find a solution since I was interested in configuring Mach4 to delay motion start until the Spindle had reach 90% of the G-Code programs Speed setting. The solution was to feed this signal back to pin 41 on the controller via a voltage divider network that reduces the voltage range to 0-3.3VDC and write a LUA script to read the voltage and which will get converted to 0->1.0VDC and do a simple calculation to translate to RPM (V-reading * max Speed)=>RPM. Once this is done, I just had to invoke mc.mcSpindleSetSensorRPM(instance,speed).
All this worked when I was using V4300 of Mach4 however with the default milling profile the screens field labled "SPIN RPM" is not updated. However if I run in debug mode All the values are fine, I set the ...SpindleSetSensorRPM then do a val=SpindleGetSensorRPM(instance) and I can see that "set method" did its job and the "get method" returns the same set value.
There script is not complex it just has the main routine that calls a getRegister function to retrieve the value (Pin41) from the Pokeys57CNC controller, and then calls a routine that does the calculation to create the equivalent speed and does the ...SpindleSetSensorRPM function. the main program is also smart enough to throttle back to execute the update process every 10th cycle using a self-created register that is incremented +1 each time the "main" runs. This script should work with any inverter that provides an analog DC voltage that can be read by your converter.
When I initially implemented this code, about 2 years ago, I was unable to have the spindle speed test (90% before moving spindle) work but the actual updating and display of what I was sending to Mach4 (as per above) was working fine. The Mach4 support staff could not figure out how to resolve that issue, so I gave up and just inserted a 6 second delay in every G-Code script I generate.
Has anyone had any experience updating the SpindleSensor via provided "mc" methods?
I've been waiting four days from the support staff on the trouble ticket I wrote this week.
Reuben M. Prichard Jr.
Mach4 Version: Hobby (latest version) Licensed
OS: Windows 10 Pro (664 bit).
Controller: Pokeys57CNC
VFD: Huanyang HY01D523B 1.5KW
My inverter, like many others, does not provide a digital stream that can be used to provide a real-time feedback signal that can be fed back to update Mach4's with the spindle's current speed (RPMs). The VFD, instead, provides a 0-10V output that represents 0(0 RPM) up to 10V (maximum spindle RPM).
I talked to Pokeys engineering about two years ago to see if I could find a solution since I was interested in configuring Mach4 to delay motion start until the Spindle had reach 90% of the G-Code programs Speed setting. The solution was to feed this signal back to pin 41 on the controller via a voltage divider network that reduces the voltage range to 0-3.3VDC and write a LUA script to read the voltage and which will get converted to 0->1.0VDC and do a simple calculation to translate to RPM (V-reading * max Speed)=>RPM. Once this is done, I just had to invoke mc.mcSpindleSetSensorRPM(instance,speed).
All this worked when I was using V4300 of Mach4 however with the default milling profile the screens field labled "SPIN RPM" is not updated. However if I run in debug mode All the values are fine, I set the ...SpindleSetSensorRPM then do a val=SpindleGetSensorRPM(instance) and I can see that "set method" did its job and the "get method" returns the same set value.
There script is not complex it just has the main routine that calls a getRegister function to retrieve the value (Pin41) from the Pokeys57CNC controller, and then calls a routine that does the calculation to create the equivalent speed and does the ...SpindleSetSensorRPM function. the main program is also smart enough to throttle back to execute the update process every 10th cycle using a self-created register that is incremented +1 each time the "main" runs. This script should work with any inverter that provides an analog DC voltage that can be read by your converter.
When I initially implemented this code, about 2 years ago, I was unable to have the spindle speed test (90% before moving spindle) work but the actual updating and display of what I was sending to Mach4 (as per above) was working fine. The Mach4 support staff could not figure out how to resolve that issue, so I gave up and just inserted a 6 second delay in every G-Code script I generate.
Has anyone had any experience updating the SpindleSensor via provided "mc" methods?
I've been waiting four days from the support staff on the trouble ticket I wrote this week.
Reuben M. Prichard Jr.