Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Newlands on January 22, 2021, 03:23:23 PM

Title: Spindle speed not correct
Post by: Newlands on January 22, 2021, 03:23:23 PM
I’ve failed to get to the bottom of this so far. The setup is a 2.2kW water cooled spindle with a HuanYang vfd, and Mach4 with an Ethernet Smoothstepper and an MB3 breakout board.

Using MBI, if I run M3 S*********x I don’t get the commanded spindle speed. At lower speeds, the spindle runs slightly faster than it should, and at the higher speeds it is slower, eg

6000rpm, 121Hz, gives me 7400

9000rpm, 152Hz, 9000

12,000rpm, 181Hz, 10800

15,000, 214, 12750

18,000, 250, 14,900

21,000, 283Hz, 16,800

24,000, 318 Hz, 19,200

The actual frequency delivered clearly corresponds to the resulting rpm of the spindle, and this is borne out with checks I’ve done so far. I disconnected the analogue output (two wires) from the breakout board and meter to check the analogue output, which shows a perfect proportional output from 0 to 10volts at all speeds ie m3 s6000 gives 2.5v, s12000 gives 5v, etc.

I also connected a benchtop power supply to the vfd analogue input, and again checking with various voltages from 0 to 10v gives the correct frequency and spindle speed, right up to the 400Hz maximum which should be 24,000rpm.

So, the ESS/MB3 is working correctly when tested, and so is the VFD. Mach4 also seems to be delivering the correct information to the ESS. But when it is connected up it doesn’t.

i have the vfd set to 400Hz Max, and 120Hz minimum. I have trawled the Internet for the correct parameters and I’m pretty confident that I have them correct. There are some settings in Mach4 which I’m not altogether sure about - the spindle is set up in the ESS confit as PWM, frequency 50Hz. There is no sensor fitted to it so PID is not relevant. The min and max speeds in the Mach4 config dialog is set to zero and 24,000.

Two possibles that occur to me - first there is a setting somewhere in Mach4 or in the vfd parameters that I’ve missed, or secondly there is some sort of electrical noise that is disrupting the analogue output of the ESS.
Title: Re: Spindle speed not correct
Post by: MN300 on January 22, 2021, 06:11:02 PM
You write that you have tested the Analog output and the VFD input separately. Check the voltage vs speed with the VDF connected. The VFD may be overloading the analog output causing non-linearity.
If your VFD has the option to use 0 to 5 volts analog input that may be a work-around.
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 22, 2021, 11:25:33 PM
Can you connect to the  VFD with modbus? This works well and you can get the spindle load on the screen as a bonus! The low cost drives can be a real challenge to get communication working.
Title: Re: Spindle speed not correct
Post by: Newlands on January 23, 2021, 06:51:05 AM
MN300 - Yes, I tested each separately. I did briefly check the voltage when connected and with the spindle running, and noticed that as soon as the probes made contact I got a slight speed drop. It made me wonder whether the internal resistance of the meter itself was causing the drop, so I stopped in case I damaged the breakout board. So your suggestion that the Vfd May be overloading the output of the BOB seems logical (though why it would cause overspeed at low S settings I don’t know)
So maybe I need to feed the A0 and AG wires through some sort of regulator circuit to ensure there is no voltage drop.

Brian - I have just done a bit of reading about modbus and huanyang vfd’s - it seems Huanyang implement modbus in a non-conventional way which might make things tricky, but I’m tempted to have a go. The only thing I’m not sure about is whether my particular model HY02D223B is fitted with the necessary modbus electronics beyond the RS485 plug socket, as apparently not all models are.
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 23, 2021, 07:36:10 AM
Well option number B for bandaid, make some code in the PMC that will scale the value and make it work at the correct speed. I know it’s not the right thing but sometime it’s the best you can do (other than going to automation direct and getting a new VFD) . If you want to do this I can give you a hand. I think if we got 5 points and did linear interpolation through them we could get this really close.
Title: Re: Spindle speed not correct
Post by: MN300 on January 23, 2021, 08:56:05 AM
I assume you are using a digital multimeter with very high input resistance but even an old fashioned mechanical meter shouldn't load the analog output enough to affect the reading. Something is wrong if connecting a meter changes the speed. Without details of the analog output circuit and the VFD input it's hard to guess what's happening. Unfortunately that much detail is seldom published.

If you have a resistor in the with a value of around 10K see if connecting it changes the voltage. Do this with the VFD disconnected. It will show if loading affects the voltage.

Measure the analog voltage with the VFD connected including speeds below the minimum speed, this might give you more clues. Extending your readings to 0 volts in say the speed would be 4000 RPMs at 0 volts.

The MB3 Owner's Manual mentions using a PWM frequency of 260 Hz. Possibly the wrong frequency could affect the behavior of the PWM to analog circuit.

John
Title: Re: Spindle speed not correct
Post by: Newlands on January 23, 2021, 02:43:26 PM
I think I need to do some more testing, with various parameter settings on the vfd. A quick play this evening seems to indicate that setting different minimum frequencies for the spindle affects the speed obtained throughout the range. So, for example, setting the minimum to be 120hz I managed to obtain a maximum of around 340hz, whereas setting the minimum at 50Hz only gives me a maximum of around 300Hz. It almost seems as though there should be a multiplier parameter setting somewhere!
Title: Re: Spindle speed not correct
Post by: MN300 on January 23, 2021, 03:20:36 PM
The VDF model number or a link to the manual would be helpful if you're looking for advice on the parameter settings, and of course a list of your current settings.
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 23, 2021, 03:24:06 PM
Automation direct / delta VFD and you will be happy :) I know it can be fun to try to make the low cost ones work but they can really make you angry trying to set them up.
Title: Re: Spindle speed not correct
Post by: Newlands on January 24, 2021, 07:46:33 AM
MN300 - the model number is HY02D223B. The parameters settings that I have either changed, or might be relevant are as follows:
PD002   1       (External source of run commands)
PD002   2       (External source of operating frequency)
PD003   400 Hz    (Main frequency)
PD004   400 Hz    (Base frequency)
PD005   400 Hz    (Max operating frequency)
PD006   2.5       (Intermediate frequency of V/F curve)
PD007   2.5       (Min frequency of V/F curve)
PD008   220v      (Max voltage)
PD009   13       (Intermediate voltage of V/F curve)
PD010   6.5      (Min voltage V/F curve)
PD014   10      (accel time)
PD015   10      (accel time)
PDO41   8      (Carrier frequency)
PD044   02      (Forward)
PD055   100%   (VO analogue output gain)
PD070   0      (0-10v analog input)
PD071   10      (Analog filtering constant)
PD072   400Hz   (Higher analog frequency)
PD073   120Hz   (Lower analog frequency)
PD141   220      (Rated motor voltage)
PD142   11.0      (Rated motor current)
PD143   2      (No of poles)
PD144   3000      (Rated motor rpm at 50Hz)

This morning I checked the effect of changing PD073 , the minimum operating frequency, from the MDI window, M3 S12000 and M3 S24000. It clearly affects the speed throughout the range, and I tried different settings from )Hz to 400Hz.
(http://)

Brian - I'm afraid I don't know what is involved with making code for a PMC, or what a PMC is.
I have ordered a USB-RS485 converter and length of shielded cable in case I decide to play with Modbus. And I found myself searching for decent-name VFD's yesterday to see what is available that might replace the HuanYang (which I'm sure would be useful for running one of my manual machine tools). In the meantime, the CNC is still useable - I'll just adjust the speeds for each job to take account of the discrepancy until I decide on a permanent solution to sort it.
Thanks for all the help so far.
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 24, 2021, 08:43:50 AM
Hello, the PMC is the programmable Mach controller ... it is much like a PLC and will update each scan. What we will do to make this work is read the spindle speed and set the value to the analog register. This will allow is some room to play around with the values. We can map what you get for a command to what you need for an output. If you want to do this I will make up the code as I think this is a tool that could help others later on. You tell me what you want to do :) funny enough this is how I made the code for surface mapping and screw mapping. The problem and the users change but the math to solve them stays the same lol. I suspect I could make this code in a few hours or so. Make a deal, if I do this we can post the code here and you tell how to make it work, a white paper is what I would call it. Sound like a plan?
Title: Re: Spindle speed not correct
Post by: MN300 on January 24, 2021, 09:14:44 AM
I have looked over your information. The first two parameter lines have what I assume are typos as the drive does run.

I interpret PD073 Lower Analog Frequency to be the speed the VFD will run when the analog voltage is zero. When a manual potentiometer is used this would set the minimum speed the operator could select. For your use this should be zero as your analog voltage out starts at zero.

You didn't list your value for PD011 Frequency Lower Limit. This is where the 120 Hz minimum you selected should be.
Title: Re: Spindle speed not correct
Post by: Newlands on January 24, 2021, 10:34:13 AM
Sorry, yes a typo, PD001 is set to 1, PD002 also set to 1. PD011, the frequency lower limit, should have been in there as well, it is set to 120Hz currently though I have tried it at zero with no obvious effect since PD073 is also in play.
I have also tried playing with both the PD011 and PD073 parameters, as they both set the lower operating frequency, but it seems that the PD073 value has the effect of altering the resultant spindle speed over the entire range, whereas PD011 just does what it’s supposed to, ie set a minimum speed.
Re code for the PMC - I’m happy to do whatever I can, though I think I’d need to do some background reading to get an understanding of the topic. The spindle isn’t fitted with any sort of speed sensor, so presumably you would take the speed info from the G code?? As for the PMC, do you mean the Ethernet Smoothstepper controller, or is it a separate bit of hardware?
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 24, 2021, 11:03:09 AM
The PMC is a place where we can run some code on your machine to customize the machine. It is loaded in the screen edit mode.. Anyway that part is easy ! The hard part is to make the code ... I just happen to have made the code this morning for fun :) What can I say I don't get out much LOL
 Here is the code :
Code: [Select]
-- Fit Spindle Speed with linear interpolation

function buildtbl()
rpmtbl = { points = 0,
   addPoint = function (self, commandRPM, trueRPM )
self[tonumber(self.points)] = {}
self[tonumber(self.points)].commandRPM = commandRPM
self[tonumber(self.points)].trueRPM = trueRPM
self.points = self.points + 1
end,
linearInterp = function(self, RPM)
local low = -1
local high = -1
for i=0, self.points-1,1 do-- loop through the points and get the high and the low around the requested RPM
if (self[i].commandRPM <= RPM) then
low = i
end
if (self[i].commandRPM >= RPM) then
high = i
break
end
end
--check to see if the point is on the table, if not simply return what was input
if(high == -1 or low == -1)then
return RPM
end
if(high == low) then
return self[low].trueRPM
end
--y = y1 + ((x – x1) / (x2 – x1)) * (y2 – y1)
--time to figure it out!
local NewRPM = self[low].trueRPM + ( (RPM - self[low].commandRPM) / ( self[high].commandRPM -self[low].commandRPM )) * (self[high].trueRPM  - self[low].trueRPM )
return NewRPM
end,
}

--To add a point call the addPoint function with the Requested PRM, Than the True RPM (this must be done without this function active)
-- Example Command 500 RPM Spindle is teally going 750 
-- The following call would be made rpmtbl:addPoint(500 ,750)
rpmtbl:addPoint(100,10)
rpmtbl:addPoint(200,100)
rpmtbl:addPoint(2000,2500)
rpmtbl:addPoint(3000,5000)
end



function calcRPM(rpm)
-- take the requested RPM and adjust based on the table fitting points
if(rpmtbl == nil) then--build a global table on the first scan
buildtbl()
end
local adjRPM = rpmtbl:linearInterp(101)

end
local SpindleRPM = 2500
local outputRPM = calcRPM(SpindleRPM)

I know this is scary to see the code but all you really need to do is look at the following lines:
   rpmtbl:addPoint(100,10)
   rpmtbl:addPoint(200,100)
   rpmtbl:addPoint(2000,2500)
   rpmtbl:addPoint(3000,5000)

The first number is the RPM you asked for the 2nd one is what you got for an RPM. You can add as many points as you would like. This thing expands every time you add a point. If you ask for an RPM outside of the range it will just return what you sent . You think you can get that data ? I think you had it in your graph ;)


Thanks
Brian
Title: Re: Spindle speed not correct
Post by: MN300 on January 24, 2021, 11:09:17 AM
Setting PD073 to something besides zero changes the offset and the slope of the requested speed to frequency tracking. Are you sure you have tried PD011-120 and PD073=0 ?
Title: Re: Spindle speed not correct
Post by: Newlands on January 24, 2021, 12:42:06 PM
MCN300 - I was pretty sure I tried it, but to be certain I have just checked again, with PD011 set to 120 and PD73 to zero, with the following results:
Requested speed, Measured speed, Hz display on VFD
9000, 7200, 120
12000, 7200, 120
15000, 9000, 150
18000, 12000, 200
21000, 15250, 258
24000, 18800, 312
As you can see, it doesn’t get anywhere near the 400Hz specified elsewhere in the parameters. The only way I can get that is to set PD073 to 400 (which of course is pointless), or to run the vfd manually by disconnecting the analog signal from the BOB and using my benchtop power supply.

Brian - I don’t think anyone gets out much at the moment, not in the U.K. anyway!
I’ve had a very quick scan through the code and, with your comments, can recognise what some of it does even if I wouldn’t be able to write it myself. I’ll have a more detailed look later this evening to see if I really understand it.
To my amateur eye it would seem the approach would be to make a backup of the existing (WX4) screen set, copying and pasting the code into a clean screen set after I’ve put in the rpm data needed and then testing the result. You’d need to point me to the right place to paste the code of course.
If it’s going to be a help to others, then I will gladly write it all up as a possible solution, graphs, photos etc to make it readable.
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 24, 2021, 03:44:37 PM
If we put it in the PMC it will be very portable :) I can show you how that is done. Very easy!
Title: Re: Spindle speed not correct
Post by: Newlands on January 26, 2021, 06:53:26 AM
I've had a look at the code. But i wonder if there will be a problem actually implementing it. At the moment it seems that the top speed is limited to 312Hz or around 18,800 rpm. That is presumably because the analog voltage is being limited to around 7.5volts. While it will be possible to substitute actual speeds for commanded speeds with the code, I don't see how that will enable any speeds over 18,800 to be obtained, since whatever anomaly is limiting the analog voltage to 7.5 volts is still going to be present.
This makes me wonder if the best options are to investigate modbus control or to replace the inverter. The modbus option is attractive as the hardware only costs a few bucks, in contrast to a decent name-brand vfd. Against the modbus option is that Huanyang vfds apparently don't conform to normal standards so the Mach4 modbus plug-in may well not work.
Title: Re: Spindle speed not correct
Post by: MN300 on January 26, 2021, 07:40:45 AM
Your VFD might be usable if you are willing to give up the protection of having the minimum speed set in the VFD and are careful not to command too low a speed from MACH4.
If your analog output is limited to 7.5 volts the VFD has a 0 to 5V option.

It just occurred to me that the symptoms might be explained if you have connected the analog signal to the current input instead of the voltage input. The correct terminals are ACM and VI
Title: Re: Spindle speed not correct
Post by: Newlands on January 26, 2021, 10:00:48 AM
It’s definitely connected to VI and ACM, and parameters set for 0-10 volts.
I think you had it right in one of your earlier replies - the VFD is probably asking the breakout board for a bit more current than it can supply, so the voltage drops.
I’ve got a usb-RS485 converter ordered, so I will have a play with it to see if the Huanwang understands Mach4 modbus and if that doesn’t work it will be relegated to running an old bandsaw in the workshop, and replaced with something better.
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 26, 2021, 10:42:00 AM
I have been able to get the modbus to work with tons of VFD's. It may take some messing about but I am sure we can make it work. If you would like I can remote in and look at it with you... All I need to see is the manual !
Title: Re: Spindle speed not correct
Post by: Newlands on January 26, 2021, 11:01:24 AM
Thanks Brian. I’ve just sorted out some twisted pair cable, and I’m waiting for the rs485 adaptor to arrive, hopefully this week sometime. I found this https://caldwellfam.net/bill/wp-content/uploads/2019/04/Connecting-a-VFD-to-Mach4-through-the-Modbus-v5.pdf#page21 (https://caldwellfam.net/bill/wp-content/uploads/2019/04/Connecting-a-VFD-to-Mach4-through-the-Modbus-v5.pdf#page21) which looks useful.
Title: Re: Spindle speed not correct
Post by: Newlands on January 27, 2021, 11:02:54 AM
Just spent some time attempting to get modbus setup, and unsurprisingly failed, at least so far. The modbus diagnostics show there is no communication. The parameters I’ve set on the Huanyang are pd01 and 02 both set to 2, pd163 = 01, pd164=1 (9600 baud rate, though have also tried 19200), and pd165=3 (8N1).
The link in my last post referred to register addresses, and for his particular model (GT series Huanyang) they are Command register address 4096 decimal, Status register address 4097 decimal, and Speed register 8192 decimal.
I can’t find the correct addresses for my vid model (HY02D223B) though I did try some alternative values (8193, 8203 and 8192) which didn’t work.
Oh well, for the total sum of £4 it was worth a try.
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 27, 2021, 11:09:26 AM
swap the send and receive lines . Most people so them backward the first time. 
Title: Re: Spindle speed not correct
Post by: Newlands on January 27, 2021, 11:18:37 AM
Already tried!
As far as I can tell I don’t think anyone has managed to get this particular series of HY inverters running via modbus successfully with Mach4, although quite a few have done so with LinuxCNC.
There was a plug-in available for Mach3, but of course that’s no use for Mach4. Although I did wonder whether there is anything in the plug-in that might give a clue about some of the values needed, maybe?
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 27, 2021, 12:30:36 PM
The modbus in Mach4 will run way more devices ... I have not had anything that could not be run :)

You want me to remote in at some point and have a look ?
Title: Re: Spindle speed not correct
Post by: MN300 on January 27, 2021, 12:34:20 PM
Are you using RS-, RS+ and DCM at the VFD?

https://store.chipkin.com/articles/rs485-rs485-cables-why-you-need-3-wires-for-2-two-wire-rs485
Title: Re: Spindle speed not correct
Post by: Newlands on January 27, 2021, 01:14:01 PM
MN300 - Just two wires and a shield which I've grounded to the chassis of the enclosure holding all the control gear. Only two terminals on the usb/rs485 converter so nowhere for a DCM connection to go at the computer end.

Brian - I don't have an internet connection at the workshop unfortunately. Would it be useful to grab some screenshots?
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 27, 2021, 01:18:51 PM
Not really... The issue is sometimes you have to be 1 register off (base zero base one issue) Subtract the table location from the value (sometimes, depends on the manual).  It's just not that much fun! I am ordering one and I will beat that thing into submission ! Can you give me a link that will show me the correct VFD ?
Title: Re: Spindle speed not correct
Post by: Newlands on January 27, 2021, 01:38:06 PM
This is the one as far as I can tell https://www.ebay.com/itm/3HP-10A-2-2KW-220V-Variable-Frequency-Drive-Inverter-VFD-VSD-Single-To-3-Phase/274338564112?hash=item3fdfda4810:g:cCkAAOSwel9emA~7 (https://www.ebay.com/itm/3HP-10A-2-2KW-220V-Variable-Frequency-Drive-Inverter-VFD-VSD-Single-To-3-Phase/274338564112?hash=item3fdfda4810:g:cCkAAOSwel9emA~7) - it's a 220v input 2.2kW model. Serial number HY02D223B. If its anything like the UK there are a number of sellers.
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 27, 2021, 02:09:10 PM
ordered! Please allow some shipping time and I can tell you that I will make it work :) I don't care what it takes! if I have to point at it and wag my finger aggressively at it I will do it ;) I suspect next week I should see it .

Thanks
Brian
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 29, 2021, 08:11:03 AM
looks like I will have my VFD on the 4th if the shipping lie is correct.
Title: Re: Spindle speed not correct
Post by: Newlands on January 29, 2021, 01:09:08 PM
Lets hope it comes prepared to have a finger wagged at it!
Title: Re: Spindle speed not correct
Post by: Brian Barker on January 29, 2021, 01:48:39 PM
I got a spindle to test it with... MAN that was fast! I will have wires in the spindle waiting for a dump electrons from the VFD ! This thing is small for 2.2kw, 3HP of pure fun!
I have a Germo usb to 422/485 converter somewhere here that I will use in my test as well.

Waiting like a kid for Xmas
Title: Re: Spindle speed not correct
Post by: Brian Barker on February 09, 2021, 12:21:35 AM
The VFD is in and we are starting to setup the test. I am using the opportunity to teach but will also give the settings here. I did get a cheaper 485 converter as an alternative so we can have a budget friendly option.

Trying not to forget anything here.
Title: Re: Spindle speed not correct
Post by: Newlands on February 09, 2021, 05:22:31 AM
I’m looking forward to seeing how you get on - I still haven’t managed to get modbus talking to the vfd, and haven’t found any more info on the address registers.
Title: Re: Spindle speed not correct
Post by: Brian Barker on February 09, 2021, 07:07:47 AM
The manual for the drive is not great but I will crack it ;)
Title: Re: Spindle speed not correct
Post by: Brian Barker on February 09, 2021, 02:30:30 PM
Well that is nonstandard Modbus... I am not impressed! I am looking into what we need to change to be able to talk to the drive. More later :)
Title: Re: Spindle speed not correct
Post by: Brian Barker on February 09, 2021, 04:10:07 PM
Well after digging on the web we have found the docs for the VFD. We are going to make a new plugin for the drive because everyone seems to be using this drive! They are not great but they seem good enough LOL.

I hope we can test this in the week to come.
More when I know more ;)
Title: Re: Spindle speed not correct
Post by: joeaverage on February 10, 2021, 02:54:23 AM
Hi,
HuanYang are famous for having non-Modbus compliant comms, that's the reason for the special plugin in Mach3
for these VFDs.

The manufacturers must have taken a lot of heat over the non standard comms because they have released later models
which are compliant.....just they are more expnsive....so people still buy the el-cheap ones with this result.

I'll try to find the model identifier, its something like HuanYang nnnn.GM, with the GM, or some other accronym signaling
compliance with the Modbus standard.

Craig
Title: Re: Spindle speed not correct
Post by: Newlands on February 10, 2021, 05:49:36 AM
Some links which might give some clues (not to me though, as I’m way out of my depth).
https://gist.github.com/Bouni/803492ed0aab3f944066 (https://gist.github.com/Bouni/803492ed0aab3f944066)
Also a thread on cnczone:
https://www.cnczone.com/forums/phase-converters/91847-software.html (https://www.cnczone.com/forums/phase-converters/91847-software.html)

I know that a few have managed to get Linux apps to talk to the HY vfds, and that someone wrote a plug-in for Mach3 to do the same. Maybe those endeavours would provide a clue on how to do the same with Mach4, as far as identifying register addresses go at any rate.
Title: Re: Spindle speed not correct
Post by: Brian Barker on February 10, 2021, 07:06:37 AM
We figured it out. They used the wrong function codes! The frames of how they constructed the data is correct... so it’s modbus done wrong lol. We can get it to talk to Mach4... I almost did it in Lua just for fun but we wanted to make it a plugin as that will be a bit simpler to install.
Title: Re: Spindle speed not correct
Post by: Newlands on February 11, 2021, 04:04:16 AM
A quote from one of the posts I linked to above said something like ‘I think the Huanyang developers were off having a coffee break when the Modbus protocols were handed out’.
Title: Re: Spindle speed not correct
Post by: Brian Barker on February 11, 2021, 06:40:30 AM
It is the function numbers, they have 3 and 5 swapped. That is the biggest issue. They have the read and write swapped in other words :) if that was correct we may be able to make it work.  Check sum is a bit odd too. Basically it is not modbus lol