Hello Guest it is July 19, 2019, 01:22:49 PM

Author Topic: High Speed Servo as Spindle - My Solution  (Read 21534 times)

0 Members and 1 Guest are viewing this topic.

High Speed Servo as Spindle - My Solution
« on: November 22, 2011, 03:13:08 AM »
I thought I'd share my solution to some of the issues I've brought up here recently in other threads. This all started with my plan to add a 4th axis to my mill with the intent to be able to run it as a spindle for turning processes as well as index mode. Well if any of you have looked very deep into this Mach3 has a few gotchas and although there has been some success in this area I wasn't really happy with any of the solutions. Now before I get to far into this so far this has been bench tested only so if in the long run it doesn't work out this info can be thought of as learning material.

First lets outline what I wanted. My mill currently has a 5 HP 3 phase motor that is relay controlled for direction and a manual adjustment for speed. Goal: get rid of the 3 phase and get mach to control direction and speed. Second is the addition of a 4th axis that is capable of both indexing and turning functions.

First came the main spindle motor and what to do with it. After some helpful advice on the board here I decided to give an AC servo motor a go for the spindle. Mechanically the switch won't be tough but the control of it soon became an issue. I selected a servo motor 2.5HP 4000RPM and plan to run it 1 to 1 with the main (Z axis) spindle. The motor has an encoder of 8000 steps per revolution. I plan to run the driver with STEP and DIR  signals, for reasons I'll explain later, so here's the first issue. To get full speed out this motor I need to feed it a Step signal at 533Khz. Mach3 parallel ports are only able, at best on my system, to go to 45Khz. Even if I got to the 100Khz max Mach3 allows I'd be well short of my goal. Two solutions came up, one software gear up the driver by multiplying the steps by a factor of 12. Second buy a smoothstepper board. The software gearing my have been OK for the main spindle but not for the A axis the resolution would be unusable. So the smoothstepper solution won out. However they are not exactly cheap and although offer a ton of benefits, in this case all it was really doing was clocking my servos for high speed rotation. In comes the next issue. So far the solutions mentioned did nothing to help with swapping between my main spindle on the Z axis and the future A axis spindle. Mach3 has the swapaxis commands but none of the motor tuning options follow the swap (Mach3 guys this is a huge deal). So if the two servos have any differences (which they will) then a complex set of macros would have to be written to move this information around. In addition the swapaxis command does not undo itself so if it's not reset then the next time you come into Mach3 your axis's will be reversed. So there is the overview.

Now for my solution. So I need a way to clock two different high speed servos using STEP and DIR signals, Also be able to index with at least the A axis (actually I can do both using C axis to index on the Z spindle, I'm sure this will come in handy some day), Lastly I need to control this all from Mach3 and not have the software get "confused" about the config it's in. What came to mind was a microcontroller. In particular an Arduino Uno. First it's cheap $30, second it has built in timers for clocking, it has a built in USB port for talking to Mach3, and it's programmable. So as things change or issues come up I can reprogram on the fly. It is well supported and I don't have to eat up a bunch of my parallel port pins run logic.

So into the junk draw I go and out comes the arduino and my proto boards. Here was the progression of events that I've gone through the past week.

First issue: Make the Arduino board talk to Mach3. Here is the beauty part of a well used open source microcontroller. Someone wrote a MODIO slave library already. It is very basic and all it does is write output holding registers to the arduino from Mach3. Took a little playing as I'd never worked with MODIO before but soon had Mach3 writing 4 registers to the arduino. Registers 1 and 2 I mapped to Outputs 8 an 9 in Mach3 with I tied to spindle relays control for CW(M3) and CCW (M4). Sweet I now have spindle direction, along with Off and On control in my Arduino. Next came speed. I wrote a quick one command brain that maps the Override speed DRO to ModIO register 4. Again success I now have the speed I need to turn my servo in my arduino. Last for the registers in number 5 which is tied via the brain to an OEM LED I put on all my screens. I added a button that calls two custom macros (M900 and M901) which turn this lLED off and on. So I have button control and well as gcode control of the LED. This is going to show the current spindle. LED off the main spindle is active and the A axis is in indexing mode. LED on and the reverse is true. (Yes it will index the main spindle too). Sweet I have control of everything I need.

Second issue: First before we get to much farther I should let anyone know that does't that MODIO is not suitable to run STEP (timing) signals for axis movement directly. There is lag time in the USB that prohibits this. That's a complete topic of it's own. Just know it doesn't work. Also what doesn't work is using the Arduino board to intercept the parallel ports pin signals and do logic control of them and spit them back out on another port. Again the response and log time just don't allow for it. But wait I need to change the STEP and DIR source for my Servos to either my external clock signal (next issue) or the STEP and DIR pins from the parallel port. The only option is to us TTL logic chips to do the swapping and control them from the arduino. A couple of AND, OR and NOT 7400 series chips later and I have a matrix to swap the control signals for the two servos. I'll probably add the INDEX pin as well for speed feedback to mach. I won't bore you all with the details of the logic just know what it does.

Third issue: So I now have all the control signals from Mach3 I need and a way to swap the controls signals between my two servo motors. All controlled by a program in the arduino. Testing on all this goes great. Now for the big issue. How do I drive the servo at the speed I need. This turned into quite a big deal. When I looked at the datasheet for the arduino MPU it mentioned that one of it's three timers has a 16bit resolution of the system clock. The system clock is 16Mhz and 16 bit (65000+ options) seemed plenty. Well not so fast. The details of how the clock works is quite involved. Basically it is a divider network of the system clock that as higher frequencies are output the gap between them gets log-rhythmically larger. After hours of trial and error and allot of math I'd forgot how to do I came up with a timer program that is reasonable for the range I needed. Using the servo motors I mentioned The worst case is about 132 RPMS variance at 4000 RPM. It gets more accurate the lower the speed. The control program also gives configurable ramp up and ramp down, as well as different encoder counts which will come into play when I gear down the A Axis. Each servo has it's own profile so they can be  totally different and the program will compensate and send the appropriate frequency to the motor based on the speed asked for in Mach3.

So it works on the bench and I'm waiting on parts to build the real deal. I'm sure there will be a ton of tweeking to make the motors spin up and down smoothly. My test setup just has a small stepper I had laying around as a test motor. A far cry from the full sized servos that will be used for real. I did bind an encoder to the stepper and grabbed the index pulse and fed it back to mach3. Test so far of the limited speed of the stepper are 100% accurate.

I'll keep you all posted on the build as it progresses. Eventually I'll post he arduino code but I'll wait for it to be tested and working. I haven't written in C for about 15 years and I had a bunch of cobwebs to clear. Bit register sets and clear, floating point variable, Arrays and pointers, just to mention a few of the problem areas.

For those interested here is some of the math involved in this project. Just FYI stuff.

Frequency of STEP signal for given RPM is figured as follow: Frequency=(RPM/60) * Encoder Count for 1 Revolution. (Note this could be different from your encoder resolution on the motor based on the gearing from the motor to the spindle.

Mach3 motor tuning for STEPS rotational axis: Mach3 wants the steps for 1 degree of rotation or unit. So a 1:1 geared servo to axis with an 8000 count encoder would be 22.222222 steps. 2:1 gearing would be 44.4444444 and so on.

« Last Edit: November 22, 2011, 03:29:20 AM by DamonJones »
Re: High Speed Servo as Spindle - My Solution
« Reply #1 on: November 22, 2011, 06:46:56 PM »
I added a couple of things today to the project. First was an additional register to MODIO for Estop. I added a control line to the brain to control it. Then I modified the Arduino code to disable everything in Estop.

I also changed the logic so I can control both sources (mach3 and the Ardu Timer) independently for each servo. This allows me more programming options and eliminated my 74HC04 Inverter chip that I was only using to invert the control signal for the source signals. Before it was one or the other (Mach3 or Ardu) at a hardware level. Now I can do either, both or none. Basically this allow me to index both motors at the same time. You can never spin both of them at the same time however. The Ardu only has one timer  capable of the frequencies required. One timer source only allows for one spindle at a time. Some day I'll build in another timer but for now this works.  I know this probably makes no sense without the schematics. I do plan to draw them up soon.

The next challenge is homing the index axis when switch modes. I also need to inhibit Axis indexing while in spindle mode. Although the gcode should override any issues this would bring. That is as long as the axis is re-homed properly.

Offline Hood

*
  •  25,849 25,849
  • Carnoustie, Scotland
    • View Profile
Re: High Speed Servo as Spindle - My Solution
« Reply #2 on: November 23, 2011, 07:39:33 AM »
Sounds like its going to work very well. A lot of work but it should be worth it in the end.

Hood
Re: High Speed Servo as Spindle - My Solution
« Reply #3 on: November 30, 2011, 09:00:46 PM »
Quick update - I have come up with a better solution than using the internal timer in the Arduino. I found a cool add-on module called a DDS. ($12 on ebay) It is a serial programmable frequency generator that will produce a square wave from 0 to 1M hz. Perfect for the servo motor controllers. In theory a 1Mhz signal will drive an 8000 count encoder servo motor to 7500 rpm. Plenty for my needs of around 4000 rpm. The benefit is that it will produce the exact frequency needed for the requested RPM unlike the Arduino timer that could be off by as much as 3%. I've created a library to run the DDS boards that allow for multiple board control. If in the future I want run more that one spindle at the same time the library would handle it. Mach3 has no provisions for this so for now the main program will just run either of two motors as the spindle. I've tested the DDS module and it seems to be very fast between frequencies which will make ramping the servos work well.

I've also changed the messy logic control circuit from a bunch of AND, OR  gates to us some tri-state drivers instead. Simplifies the hookup and reduces the number of components required. They handle the switching between Mach3 using the motor as an axis and the Arduino driving it as a spindle. This will also give me the option to swap the index and the home signals to mach3. Basically when running the servo as a spindle the signal from the sensor will be fed to Mach3's index pin. When using as an axis it will feed as to Mach3's home input. This was another issue that the swapaxis function in Mach3 could not handle.

The MODIO part of the Arduino remains the same and has been working very reliable throughout testing.

More to come soon.
« Last Edit: November 30, 2011, 09:03:09 PM by DamonJones »

Offline simpson36

*
  •  1,374 1,374
    • View Profile
Re: High Speed Servo as Spindle - My Solution
« Reply #4 on: December 01, 2011, 06:31:08 PM »
What is the advantage of arranging a 'complete' swap axis to accommodate different A vs Spindle parameters over dedicating both MACH's A and spindle to 4th axis operation and running the mill spindle by another method?

You are going thru a lot of work to accomplish this so there must be some compelling reason. Just curious.
Re: High Speed Servo as Spindle - My Solution
« Reply #5 on: December 02, 2011, 11:41:50 AM »
Why didn't you simply use a frequency multiplier, wich will multiply the MAch3 output from 45khz to 450khz (x10 example)
Re: High Speed Servo as Spindle - My Solution
« Reply #6 on: December 03, 2011, 01:06:22 AM »
Let me explain. Mach3 can, on my system, run a maximum clock of 45 khz. Some systems would allow up to 100 Khz but this would require a serious motherboard and parallel port to work if at all. A 45Khz signal has a max possible speed on a servo motor with an 8000 count encoder of (45000/8000) * 60 which equals 337 RPM. A far cry from the possible 4000 RPM of the motor. And that's at 1:1 gearing. I plan to run my 4th axis at least 2:1. So spindle speed would be half of 337 or like 168 rpm. Now to get the 45 Khz signal up to full speed you would have to multiple it my a factor of 12. This can be done with the driver with a function called software gearing but you'd be stuck with it for the indexing mode as well. The resolution would stink at best. The other option would be to have an intermediate controller to switch in and out of multiplication. Well that is no more difficult then my solution. Add in that now that I have an intelligent and programmable solution I'm not locked into any one solution. Giving me things like being able to swap the index and home signals or change the ramping of the motors, ect.

I hope that answered the questions, if not let me know I'd be happy to expand.

Offline simpson36

*
  •  1,374 1,374
    • View Profile
Re: High Speed Servo as Spindle - My Solution
« Reply #7 on: December 03, 2011, 06:14:52 AM »
A couple of comments on the speed issue:

Some industrial AC servo drives allow you to have more than one multiplier and switch back and forth on command. This would resolve the multiple speed range issue. My Mitsubishi drives have that feature. Other industrial brands (Yaskawa, AB, etc) *probably* also have that feature as well.

A consideration on 'consumer' level drives is that not all behave well with software gearing active, and some only have a few preset ratios while others have separate numerator and denominator params which allow literally any ratio, and run smoothly with multipliers active.

One general FWIW:
Smoothstepper recently released new drivers and a new plug-in and now supports swapaxis. I have tested the new softwares and they seem to function to spec and are stable (so far). As a result, I have just completed switching over to the smoothstepper on my new (4 axis) mill. I am still using my hardware swapaxis board, but over time, if the smoothstepper performs in every other area, I will start experimenting more with the software swapaxis. Also note that Mach has functions where you can change many of the config params via macro. Before I get into trouble, let me just state that I am not pointing to any particular 'best' solution, only that there are a lot of ways to skin this cat.

And my original question:

What is the advantage of arranging a 'complete' swap axis to accommodate different A vs Spindle parameters over dedicating both MACH's A and spindle to 4th axis operation and running the mill spindle by another method?

You are going thru a lot of work to accomplish this so there must be some compelling reason. Just curious. I have some other questions to ask, but these are the fundamental ones.
Re: High Speed Servo as Spindle - My Solution
« Reply #8 on: December 05, 2011, 08:10:40 PM »
You are right there are many ways to do this. I briefly went over some of them in the beginning. A lot of this project is just to see if it can be done and be done cheaply. The smooth stepper is a great option but at close to $300 bucks it seemed like a lot of money to just get over the clocking limit in Mach3.

As far as the reason for the project let me expand. First was the goal of a cheap system and one that was not fixed. Meaning I can change it at will and I'm not tied into support from anyone. If it works great if not then I'll go away with much more knowledge of what I really need.

Next was to overcome the short comings of the parallel port and Mach3. I don't really need to index the main spindle on the Z axis but it's the same technology that I need to setup the 4th axis the way I want. Meaning having it capable of turning as a spindle. My mill has manual speed control of a 3phase motor and needed to change. So it just seemed natural to make it function just as the 4th axis is going to. The first big problem with Mach3 is that my spindle is setup on relays that control forward and reverse. The swapaxis command does not disable them. I actually designed a brain to overcome the issue but it seemed a bit hokey. So the next plan was to replace the motor with a servo motor that would eliminate the relay issue. That's when the frequency limit came into play. Now PWM was an option but it occurred that I was going to have the same issues with my 4th axis. So I quickly dismissed the PWM option because it would not index and went for a solution using STEP and DIR signals. So back to the issue with frequency in Mach3. Mach3 just won't drive STEP and DIR fast enough to use as as spindle.

So the issues with swapaxis that came up are; first that none of the tuning information follows the motor. Any encoder differences that come from either different motors or gearing would not follow the motor. It simply switches the pin outs. So you would have to macro change those params on the fly. Again a bit hokey and prone to problems. Especially if the software lost track of what mode it was in for what ever reason. Then came the Index input issue. Mach3 only has one so there needed to be a way to switch it from spindle to spindle so you can get speed feed back from the appropriate motor. The sensor will also be used to home the axis when in indexing mode so needs to switch from one pin to another.  Again all this probably could have been done via macros and brains but the hardware solution just seemed cleaner.

So in a nutshell it's an inexpensive way of doing it myself without a bunch of customizing to Mach3. I get to learn a bunch of new things along the way to.

The long term goal of the system will be to have the 4th axis setup to index as the (A) axis and be able to turn as a spindle on the fly. To have the main spindle on the (Z) axis be able to index as the (C) and work as the main spindle. Last will be to run both as spindles at the same time but that's a long term goal.

I liked the multiple gearing option you mentioned. My driver has the option to run both STEP/DIR and switch to +-10V mode. I tossed that around but then I'd be locked into a particular drive. Also another reason I didn't like the software gearing option. STEP/DIR is everywhere and I have a ton of drive options when using that. It also is capable of running both modes of operation. Just seemed like the best way to go. One technology covering everything I wanted to do.

To sum it up here's a list of benefits:

1. Eliminate the need for 3phase by replacing the current main spindle motor with an AC servo motor.
2. Give the machine software control over spindle speed and direction. Currently manual speed change.
3. Use STEP/DIR protocol as the one and only protocol for flexibility and simplicity.
4. Control both the A axis and the main Z axis motors as spindles or as index axis's.  
5. Minimize customization to Mach3. (I'll have one very simple brain, 2 simple macros and one OEMLED only).
6. Minimize cost.
7. Maximize customization.
8. Minimize outside support requirements.
9. Control of the Index input.
10. Control of the Home sensor (use one sensor for both functions, home and Index)

Did that answer what you were asking?

Offline Hood

*
  •  25,849 25,849
  • Carnoustie, Scotland
    • View Profile
Re: High Speed Servo as Spindle - My Solution
« Reply #9 on: December 06, 2011, 03:20:01 AM »
$300 for the SS? Last time I looked it was $155

Hood