Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: rcaffin on March 17, 2018, 06:38:23 AM

Title: Step/Dir control of spindle?
Post by: rcaffin on March 17, 2018, 06:38:23 AM
Mach3 gives three relay control options: Relay, PWM or Step/Dir.
However, I have yet to read of anyone actually using the Step/Dir option to control a spindle. Anyone?

The problem, as I see it, comes when you compare what Mach3 does when running an axis motor vs a spindle.
For an axis drive Mach3 will issue a number of step pules to move the axis from A to B. Fine.
But for a spindle, Mach3 would have to be sending out a fast and continuous stream of step pulses with no further limits. And if you are asking for S24000, then Mach3 would have to be issuing 24000 Step pulses per minute. That's 400 Hz. I am not sure it can do this. Or can it?

Cheers
Roger
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 17, 2018, 08:11:59 AM
Hi Roger,
I use Mach4 and my high torque spindle is a 1.8kW servo. It has an 8000 count per rev encoder and rated speed of 3500rpm.
with electronic gearing of 10 the required pulse rate is (3500/60)*8000/10=46.66kHz. My ESS/BoB signals that no trouble
single ended. According to the manualif I used differentia signaling I wouldn't have to use gearing ie a pulse rate of 466.6kHz.

Craig
Title: Re: Step/Dir control of spindle?
Post by: rcaffin on March 17, 2018, 05:25:55 PM
Hi Craig

So your spindle drive can accept Step/Dir? OK, that works. Not that many spindle drivers can do that afaik.

I wonder: is Mach4 actually outputting the pulses at 46 kHz, or is it just telling the ESS to do that?

Cheers
Roger
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 17, 2018, 05:49:00 PM
Hi Roger,
its not a spindle drive its a servo drive and accepts pulse inputs.

Mach4 provides trajectory data, its the ESS that generates the pulses. An ESS can generate pulse streams up to 4MHz, which is academic because my servo drive
can accept up to 500kHz with differential signaling.

As I don't require fine angular resolution on my spindle I elected to use electronic gearing to reduce the pulse rate so I could use a standard BoB and single
ended signaling to the servo drive. Even with the loss of resolution the electronic gearing implies its still capable of 27 arc min resolution, very adequate!

Craig
Title: Re: Step/Dir control of spindle?
Post by: rcaffin on March 17, 2018, 07:12:31 PM
Hi Craig

I am confused. It may be that Mach4 is sufficiently different from Mach3 that the difference is the problem, but I am not convinced about that.

Mach4 provides trajectory data, its the ESS that generates the pulses.
Well, that's fine for an axis drive, but a spindle does not have a trajectory, does it? So I am not understanding how Mach4 can drive a spindle.

Can Mach4+ESS be told to run a spindle at some speed with no destination, but with Step/Dir signals? For hours on end. There is NO destination.

Help!

Cheers
Roger
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 17, 2018, 07:36:53 PM
Hi Roger,
Mach4Hobby allows one out-of-band axis and it is always a spindle. As the attached pic shows it can be driven step/direction.

Given it is an out-of-band axis it is not constrained to motion end points like coordinated axes.

Hobby allows for one OB axis whereas Industrial allows six. At this stage I can't find a means of having Hobby drive my spindle as an indexing axis.
That is to say that the API doesn't apparently allow position commands only speed commands. Exactly how rigid tapping works I don't know.

I can make my spindle index by switching its pulse inputs to the A Axis. Of course the A axis is coordinated but if all I require is an indexed move
I can do so in one move provided there are no other axis moves on the same Gcode line. There might be some overlap due to  CV at the end of the index move.

I consider it a shame that NFS have limited Hobby to one OB axis and also that it has only speed control. I'd love to be able to play with Industrial to see
how those extra OB axes are handled.

Craig
Title: Re: Step/Dir control of spindle?
Post by: ger21 on March 17, 2018, 07:53:04 PM
But for a spindle, Mach3 would have to be sending out a fast and continuous stream of step pulses with no further limits. And if you are asking for S24000, then Mach3 would have to be issuing 24000 Step pulses per minute. That's 400 Hz. I am not sure it can do this. Or can it?


How are you determining that number?
Mach3 at it's lowest kernel speed, 25Khz, can output 25,000 steps/second.
The frequency of steps required depends on what you are doing with them.
Here's board that converts step/dir to 0-10V analog.
https://cnc4pc.com/catalog/product/view/id/7/s/c6-variable-speed-control-board/category/155/

It outputs 10V with a 25Khz pulse stream.


As Craig said, Mach3 (or 4) can output up to 4Mhz pulse streams. 4 million steps/second.




Quote
So I am not understanding how Mach4 can drive a spindle.

Just like in Mach3. Mach tells the ESS what to do, and the ESS generates the required pulses.
Title: Re: Step/Dir control of spindle?
Post by: rcaffin on March 17, 2018, 08:08:22 PM
Hi Craig

OK, I see.

Crawling through Mach3, it seems that this should also be possible. Curious that I have not heard of anyone doing it with Mach3, but then, who would comment if they were doing it that way? And where would they get a suitable low-cost driver anyhow?

Now, I know Greg and Andy at Warp9 are trying to get a PID controller for a spindle encoder into the FPGA they are using, but I suspect they may be having some problems squeezing it into the remaining space. They would be limited to using a PWM output signal which would need to be optically buffered and then DC-filtered.

So I am left to wonder just how hard it would be to set up a small black box between the ESS and the slightly crude DC driver/PS I have on my DC spindle. Basically, it would just need to be a phase-lock loop with an analog output. The Index pulse would still go through to Mach3 for threading sync, but the spindle speed would now be rock-solid.

Hi Gerry

You are right of course. My numbers were for syncing the Index pulse to the Step pulses. But that was written late at night after a very hot day and a lot of work :)
I would want something like 256*24,000 pulses/minute to drive an encoder rather than an Index pulse (as it were) at 24,000 RPM. That's over 100 kHz. I *knew* my figures were far to slow somehow! In my case I cannot get anywhere near that spin: 30 kHz would be enough. A little fast for mach3, but peanuts for an ESS.

The C6 board - Step/Dir to analog, but no option for phase locking on feedback. I want that feedback.

Interesting thoughts.


Cheers
Roger
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 17, 2018, 08:37:08 PM
Hi Roger,
a modern AC servo leaves the ESS PID solution in the dust.

Of course you know that at this time it is limited to one pulse per rev. Andy has expressed interest in extending that to multiple pulses per rev. As you also probably
know many ENTRY level servos are shipping with 17 bit encoders, A Delta servo I've been giving a hand with in the forum has a potential encoder count of
160,000 per rev. Will Andy be able to squeeze that in?

My servo is about 10 years old, Allen Bradley and is equipped with a 8000 count per rev encoder.....very ho hum by todays standards but has proven to really REALLY
spin my wheels! I had to buy the software to program the EMPROM, I would have had it gratis had I bought new, but this is second hand.

Anyway the software has a database of all Allen Bradley servos, mine included and many of the basic parameters are set just by virtue of selecting your servo from
the list. The basic parameters include such things as rated speed, rated current, encoder count etc, all the usual stuff. What may not be apparent is the detail about each
servo, the resistance and inductance of the windings, a table of flux density verses current....yes that's a quasi linear approximation of hysteresis, thermal mass and
temperature rise. In short the database has more information that you could expect to find or measure yourself.

There is the opportunity to adjust the PID parameters if you wish however the database entries have proven to be better than me fiddling with them for hours.
Amongst the facilities of the software is an Oscilloscope where you can plot loop error verses time, just brill....I can see at a glance the damping factor a damn near
0.7071, just what I'd try to achieve if I were fiddling with it...and to have it displayed as a live oscilloscope trace!

In short modern AC servos and their drives with the software support from the manufacturer make old school PID loops look like crap. I bought my servo and drive
including shipping for $800 NZD or about $600 USD. Quite frankly for that sort of money why would you bother with a DC servo?

Craig
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 17, 2018, 09:03:37 PM
Hi Roger,
sorry about my rant, as you can tell I'm enthusiastic about AC servos, you might say I've had my eyes opened.

Quote
Basically, it would just need to be a phase-lock loop with an analog output. The Index pulse would still go through to Mach3 for threading sync, but the spindle speed would now be rock-solid.

I think that would work. Essentially the step pulse from an ESS is proportional to required speed as reflected by the encoder. If you feed the step pulse and the
encoder feedback into a frequency discrimination circuit you would end up with an error term which could be applied to your drive.

I personally would approach the problem slightly differently. I would have the step/dir pulses cause an accumulator count up/down to reflect position.
An identical accumulator would count up/down with encoder position and the difference between the two accumulators would be the required error term.
Obviously I am anticipating doing this on a micro. As a result of another project I bought a development board of Texas Instruments with a TMS320F28069
32 bit microcontroller with on board everything, single cycle 32 bit floating point.....and the list goes on. $47NZD +15%GST free shipping. It might be like
using a sledgehammer to crack an egg but POWER to burn!

Given my new found enthusiasm for AC servos and the realization that servo manufacturers are very VERY good at getting the best from their products
all the effort involved in making my own feedback loop would be undertaken for interests sake/bragging rights only.

Craig
Title: Re: Step/Dir control of spindle?
Post by: rcaffin on March 17, 2018, 10:19:47 PM
Hi Craig

I understand about your enthusiasm for AC servos - no worries. Sounds well-supported.

But I have a rather large Baldor industrial DC motor already mounted on my CNC. 180 V nominal, 3 A nominal, although it has run at 6-8 A briefly (an oops moment). I don't want to replace this motor right now as it runs so well, and has so much guts.

Yes, one could go with the up/down counter approach as well. It's the feedback around the counter or the phase-lock loop that manages the PID bit. Or you could program the TI chip with PID software, working in the s-plane. All the same thing in some ways.
So my Q is what is the least effort to get to where I want to be - precision spindle speed and STABLE threading, with my hardware. With a background thought that i wonder how many others would be interested in such a small black box?

Thinking ...

Cheers
Roger
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 18, 2018, 12:03:15 AM
Hi Roger,
yes those Baldor servos are the very best quality, you certainly want to keep using it, whats the bet it outlasts us both.

Is it fitted with an encoder or a resolver? I know a lot were fitted with resolvers. I have a big kick-arse servo  fitted with a resolver and I'm making a Field Oriented
Control for it. The TI micro does a very nice job of producing sinusoidal excitation and synchronous detection. It could be done analogue, in fact I did make an
analogue exciter while I was experimenting but it becomes very time consuming. In fact, except for very simple stuff, high quality analogue is more time consuming
than digital.

If I were designing/making something that might find some modest market appeal I would go digital because of the flexibility it confers. Rather than change a resistor
or capacitor for adjustment of a PID loop for instance a simple parameter change with a digital solution. If I were making for myself I would be more inclined to an
analogue solution, I still get a blast out of designing my own analogue circuits. Under those circumstances I would be doing it as a hobby and any time I spend is
for fun.

How close or tight do you want the control to be? I would guess that a load/no-load regulation of a few percent would suffice for lathe threading...would you agree?
Either digital or analogue would achieve that easily. Beyond that level of control analogue becomes increasingly difficult, any drift or leakage current or noise.....
and control accuracy goes out the window.

My AC servo, within its torque limit (rated 6Nm, O'Load 18Nm) is good to (20/8000)=0.0025 or 0.25%. You can see why I like these AC servos ....1/4%... straight out
of the box!

Craig
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 18, 2018, 12:23:12 AM
Hi Roger,
when I was programming my controller for the servo I required only a PI loop. I did it using delays, I guess you'd say a Z plane approach, very similar
to the s plane approach. I found that how you managed integrator wind-up rather more important or at least as important than the PI gain constants.

Craig
Title: Re: Step/Dir control of spindle?
Post by: rcaffin on March 18, 2018, 12:38:27 AM
Hi Craig

Yes, it's very robust. And I have it. :-) Plus some spares by EEG I think.

It is fitted with an encoder - 256 line or 512 line, A+B+I. Old HP (or subsequent) unit, same as on axis servos. Reliable.

Either analog or digital control. If I went for a phase-lock loop, it would of course be 'analog'. I have built those before for some very strange things, and they work very well. Some delicate design needed to get the start-up right, to avoid massive hunting at the start. Most of my designs in the past have had a known centre frequency: this would be different.

If I go digital with an up/down counter, it would be an s-plane servo control using a microP.

In either case I would expect the ESS to be outputting the Step pulses at the required rate of spin*encoder. In this case I would expect overall spin accuracy of well under 0.01% at most speeds. That is good enough for some very fine threading. Stability - not so sure, but with a 512 line encoder I would be expecting fairly fast and effective response to any transients. The spindle drive PS is a KBWT-26 MOSFET switcher. Very gutsy with huge overload capacity, albeit also with incredible RF noise possibilities. I had to deal with that to keep the CNC positions stable.

To my mind, the difficulties in either case would be handling the transients at start-up and what happens when you accidentally stick a threading tool into the stock a bit too far. So I am wondering whether anyone else has already done this and is willing to share info. Much easier if someone else has banged their knuckles first.

S-plane vs z-plane: well, we tend to use the phrase s-plane even though we are working in digital space. But yes. As for wind-up on the integrator - one can do all sorts of good tricks there in the digital space, like limiting the size of any term in the equation. One can also do some very nice things like introducing 'anti-dither' at the digital level, to prevent servo grumbling. I WISH the Gecko servos had this.

Cheers
Roger

Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 18, 2018, 02:07:08 AM
Hi Roger,
I've always battled with phaselock loops, I've had some good successes but they can be very hard fought.

I made a fairly simple estimation of my servo accuracy, 20/8000=0.25%  That number comes from the Following Error window, 20 is its default.
Thus if the commanded position gets any more than 20 encoder counts away from the actual encoder position the drive faults 'Following Error'
The 'Zero Error' window is by default 4 encoder counts, thus if the error is less than 4 counts then the drive doesn't bother to try to reduce the error
further, you might say its ultimate position error is 4/8000=0.01%

Really these sorts of numbers are not truly reflective of the performance of the machine for lathe threading purposes. As you point out its ability to recover
from sudden changes in load like a tool digging into the start of a thread. My servo drive will fault if the commanded position lags by more than 0.9 degree
but whether it will fault is all about its torque reserve and the time it takes for the drive to apply the extra current. The control loop in my Allen Bradley
servo drive is 16kHz and in my own home grown one 20kHz. If I assume 10 control cycles is sufficient to have the drive increase current to match a sudden
increase in load I would expect a lag of 500-600us.

If of course the applied load exceeds the torque available from the servo it will fault no matter what happens. I can stall my Allen Bradley spindle by crashing
it into a job but it makes a hell of a bang....you may have heard it after all your only 2000nm away!

Craig
Title: Re: Step/Dir control of spindle?
Post by: rcaffin on March 18, 2018, 02:46:08 AM
All sounds good to me.

Very low frequency PLLs can be a pain, but the real situation is not that bad. Assume 512 lines and 60 RPM: that's 512 Hz for the PLL. Manageable. Below that - digital perhaps.

Yes, a tool digging in would require a solid response, but it is rarely that bad. Assume a 2 mm pitch at 100 RPM with the tool seriously digging in: it is going to take the job 1/2 rev for the load to get up high, and it will start from zero. That's 5 mS. I imaging your servo loop could handle that fine? And I tend to be a coward and always run very lightly anyhow.

I am going to have to ask Andy at Warp9 some Qs about just what data the ESS can get from Mach3. Could the ESS get the commanded spin from Mach3 and generate its own Step rate from that and from knowing the encoder count? That way Mach3 would only have to worry about the Index pulse and nothing else.  There is a place in this world for external hardware engines!

Cheers
Roger
Title: Re: Step/Dir control of spindle?
Post by: ger21 on March 18, 2018, 07:39:32 AM
Quote
So my Q is what is the least effort to get to where I want to be - precision spindle speed and STABLE threading,

I've never done any threading, but I've read tens of thousands of Mach3 forum posts over the years. My understanding is that threading in Mach3 is fundamentally flawed, and best results require constant spindle speed. Meaning the more powerful the spindle, the better the results will be.
Title: Re: Step/Dir control of spindle?
Post by: rcaffin on March 18, 2018, 05:23:31 PM
Hi Gerry

I have to fundamentally disagree with you. Threading in Mach3 works very well on small diameters of aluminium and plastic. I have done a lot of such threading and sold the results.

I would not talk in terms of 'best results', rather I would say that constant spindle speed is essential if the Z axis movement is to be solely dependent on the Index pulse. The problem comes when the part is large diameter and steel: most lathes do not have the huge amount of torque needed to keep the spindle speed constant using only the Index pulse. Geared lathes don't care of course if the spindle slows down a bit.

The alternative would be to have an encoder on the spindle and to use the encoder signals to control the Z axis. This would be analogous to mechanical gearing. Mach was not designed this way unfortunately, but then, not all lathes can do threading either.

I don't know how Mach4 implements threading: does it too rely solely on the Index pulse? A good question.

Cheers
Roger
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 18, 2018, 05:27:57 PM
Hi,
Mach4 doesn't handle threading per se, the motion controller handles it. The only one I'm familiar with is the ESS
and it not not capable of threading currently but the preliminary code is written and it looks like one pulse per
revolution at this at stage.

Craig
Title: Re: Step/Dir control of spindle?
Post by: rcaffin on March 18, 2018, 05:45:07 PM
However, a group of us are hassling Andy & Greg to put a PID servo into the ESS to stabilise the spindle speed using encoder feedback. The index pulse would still be returned to Mach for thread-start sync. It has become a priority item at Warp9, but whether there is enough room in the FPGA is an open question.

Cheers
Roger
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 18, 2018, 06:11:17 PM
Hi Roger,
I thought PID was already there but not multipulse PID.

Craig
Title: Re: Step/Dir control of spindle?
Post by: rcaffin on March 18, 2018, 06:53:05 PM
Not to the best of my knowledge, at least for Mach3.

Cheers
Roger
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 18, 2018, 07:40:42 PM
Hi Roger,
the recent Mach4 builds have PID control, index pulse only at this stage to my knowledge.
I haven't tried it out so I cant comment how well it works or even if it works. I was lead to believe that
it was an important stepping stone to lathe threading in Mach4.

Craig
Title: Re: Step/Dir control of spindle?
Post by: rcaffin on March 18, 2018, 07:45:20 PM
PID on the index pulse is interesting, but useless really. By the time the next Index pulse has turned up late, the thread is trashed.
And yes, Andy knows this.
However, having got the PID stuff in there is a big hurdle passed. You could say they are now half-way around the loop.

Cheers
Roger
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 18, 2018, 07:51:42 PM
Hi,
Mach of whatever flavour requires a spindle of significant rotational inertia and reserve torque to accomplish
lathe threading. Not even the most superb PID control will ever overcome inadequacies in the spindle having
said that a good PID controller will make the most of whatever spindle you have.

Craig
Title: Re: Step/Dir control of spindle?
Post by: joeaverage on March 18, 2018, 07:55:45 PM
Hi Roger,
as I recall all the lathe threading code is in place already but had a bug in the sychronisation part. Apparently Greg and
Andy have decided on a different approach (multipulse?) which has required some significant rework.

Part of that rework was to make the lathe threading code compatible with the planned API.

Craig
Title: Re: Step/Dir control of spindle?
Post by: rcaffin on March 18, 2018, 08:26:48 PM
Well, it does help if it is compatible with the rest of the world!
We await.

Cheers
Roger