Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: DamonJones on November 22, 2011, 03:13:08 AM

Title: High Speed Servo as Spindle - My Solution
Post by: DamonJones 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.

Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones 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.

Title: Re: High Speed Servo as Spindle - My Solution
Post by: Hood 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
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones 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.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 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.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: jbrass 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)
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones 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.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 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.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones 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?
Title: Re: High Speed Servo as Spindle - My Solution
Post by: Hood on December 06, 2011, 03:20:01 AM
$300 for the SS? Last time I looked it was $155

Hood
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on December 06, 2011, 06:38:22 AM
Damon, Thanks for the detailed reply. I have done some work with 4th axis with same goals as you are working toward. Obviously you have the knowledge and creativity to make the cat pretty nervous, so I was just curious about how you approached the problem.

It occurred to me in reading your posts that you had no way to run the 4th axis as a spindle and also run the main spindle simultaneously, but now I see that you have that on the list as well. My only comment on your method is to mention that if you are using a servo motor on an axis (S, A, whatever), there is no need for an index pulse to control speed. A single index pulse per rev, in my view, is pretty crude and also problematic in any case.

This is what I ended up doing . . .  again not saying this is *best*, just what I am running at the moment, and how I set up customer systems: Both the S and the A axis are dedicated to the 4th axis and I run the main spindle separately. M3,4, and 5 are editable macros 'out-of-thr-box' so relay on and off is no problem which only leaves speed. In my case, I have had speed under G-code control, and also manual and I much prefer manual, so my solution was an easy one. However, were I inclined to put the spindle speed back under Mach's control, I might spend some time noodling over the possibility of using the C or D axis somehow, but my thinking at this moment is that I would use one of the tiny 'PLC' like Arduino or PIC to generate the speed control for the spindle. Al ll you would need is to read the commanded speed out of Mach and send a command (pulse count would be easy) to the Arduino which in turn would adjust the spindle speed. Arduino/PIC could easily read an index pulse and provide a stable speed.

More comments in next post:
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on December 06, 2011, 07:03:30 AM
Continued from last post . . .

I am prepping an old mill for sale and I am considering options for the head. Those options include: laser cutting head, 3d printing head, or just a more conventional high speed routing/engraving spindle (while maintaining the 4th axis capability), so I was researching VFDs and came across a new Hitachi model that accepts pulse train input, and has a rudimentary positioning capability. Not sure exactly how that all works at the moment, but it is definitely worth a look-see.

Comments on smoothstepper; This device does more than just generate a ver fast and clean pulse stream, it also adds I/O. Adding a 4th axis and second spindle (effectively) gobbles up I/O. I view smoothstepper not unlike a graphics card . . adding processing power for a specifc task, relieving the burden on the CPU. The smoothstepper objects to me using the esc key, it seems. It is annoying, but exiting the error seems graceful and non destructive, so it may just boil down to having to changing my own behavior. Like the old Vaudeville yarn PATIENT: "Doc, it hurts when I do this." DOC: "Then don't do that".
Also, I am using a BOB made by CNC4PC specifically for the smoothstepper. The smoothstepper allows LPT2 to be input or output, the BOB forces LPT2 to be inputs only with no option to change. This limits the usefulness of the board in our application (indexer plus two spindles), so I will be going back to directly plugging cables into the smoothstepper.

Lastly, in my case, the problem with using an AC servo drive for the main spindle is that the power is limited by availability of single phase 220V power. The largest Mistu that runs on single phase 220 is 750W (one HP), and I want considerably more that that amount.  
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on December 06, 2011, 11:44:28 AM
Hood - You're correct on the price - Don't know where I found it for that price. I still like the board but would prefer a solution with more flexibility and something I don't have to rely on support for. Cost for the solution I'm trying will be under $50 so still a savings.

Simpson - The beauty of using the Android was the MODIO capability. I don't have to send a pulse train to the board, I just grab the speed from Mach3 and have MCU calculate the frequency and generate the step pulse. It can also control direction and not eat up any I/O pins in the process. In addition it can compensate for different motors, encoders and gearing. Last was making it turn both all I have to do is add another DDS and rewite some code. Oh and add a few things to Mach3 to handle it. If the first part of this works out I'll do that later.

Like I said many ways to do this, this is just my take on it. take on it.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on December 06, 2011, 02:02:16 PM
Simpson - The beauty of using the Android was the MODIO capability. I don't have to send a pulse train to the board, I just grab the speed from Mach3 and have MCU calculate the frequency and generate the step pulse. It can also control direction and not eat up any I/O pins in the process.
I'm a bit confused now. When you say Android, are you referring to the phone or is there also a PLC by the same name?

My suggestion was not to send a pulse train to the Arduino/PIC, but rather a command based on a pulse count. This would allow you to use only two (or perhaps even one) of Machs normal TTL outputs to control the motor speed in discrete steps. i.e. a single pulse could mean 'stop' two pulses could mean run forward, three pulses; run backward, and 4 thru 10 pulses being 200rpm, 300rpm, etc.

Mach also allows you to send a byte to the serial port, so you could have the Arduino/PIC monitor the serial port and easily have 64 separate commands available to send out. Indeed, the Arduino/PIC would generate the pulse stream, variable V signal, relays or whatever was needed to control the VFD.

I have a couple of Arduino boards that do data acquisition on my dynamic balancer. If I get a few minutes play time, I could confirm whether Mach can talk to the Arduino without writing a lot of additional interface code. It's one of those things that *should* be a piece of cake.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on December 06, 2011, 02:38:33 PM
I meant Arduino - hadn't had my coffee yet when I wrote that.  :-[

I already have the Arduino talking to Mach3 via MODIO. Very simple to do. The best part is it doesn't tie up any I/O pins. I have registers that hold the override speed DRO, M3 and M4 for off/on and direction via outputs, signal that holds which axis is in spindle mode, and Estop. Basically anything that is not timing dependent can be sent over the MODIO protocol to the Arduino. 
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on December 06, 2011, 02:49:59 PM
I already have the Arduino talking to Mach3 via MODIO. Very simple to do.

This definitely sound like the hot setup. I have not messed with this technique at all. Would you be willing to post a quick 'MACH/Arduino via MODIO' (for dummies)? Certainly I don't want to reinvent the wheel since you have already done so much of the groundwork on this and have it functioning.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on December 06, 2011, 03:43:52 PM
I can't take credit for the modIO interface but I can make it a bit simpler for you. Here is a link to the library I found.

https://sites.google.com/site/jpmzometa/arduino-mbrt/arduino-modbus-slave

You need the modbus slave library linked at the bottom. It's tar compressed so you will need a program to uncompress it. Drop the folder in your Libraries Folder in your arduino software. Here is all you need to make a sketch that will talk to Mach3. It shows the registers I setup. They are in an array called regs[]. I included a sample if statement to show how to reference them.

#include <ModbusSlave.h>
ModbusSlave mbs;

enum {       
  MB_REGS=6       //Number of Slave Registers
};
int regs[MB_REGS];      //regs[0] = Ignore this register
                        //regs[1] = M3 CW spindle Direction (Active High)
                        //regs[2] = M4 CCW spindle Direction (Active High)
                        //regs[3] = Spindle Speed
                        //regs[4] = Active Spindle 0 = Z Axis, 1 = A Axis
                        //regs[5] = Estop
                       
void setup()         
{
 
    mbs.configure(1,9600,'n',0); //Init ModBus Slave
}

void loop()
{
  mbs.update(regs, MB_REGS); // Update ModBus
  if(regs[5]==0) { // EStop
    digitalWrite(2,LOW); //Set Servo1 to Mach3

  }
}

I'll get a screen shot of the setup for Mach3 and post it shortly.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on December 06, 2011, 04:02:30 PM
Here is the screen shots. Also a brain view of how to address MODIO registers from a brain.

(http://damonj.com/pics/MODIO_Mach3.JPG)
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on December 06, 2011, 05:36:28 PM
Just finished drawing up the logic circuit. I'll build this on an Ardunio Proto shield.

Here a link to the PDF

http://damonj.com/pics/Mach3%20Shield%20Logic.pdf

Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on December 07, 2011, 02:05:55 AM
Damon;

This is a slick way of communicating between a tiny PLC and MACH. I have everyting set up and working and the MODIO test reads and writes to the Arduino.

What I cannot get to work is sending data to Arduino using a Macro. I tried a MACH example that was linked on the MODIO library source, but it does not work. I am unclear on your use of Outputs with port 0 that you have (I think) identified with or as MODIO register 1 and 2. My Arduino is on Serial port 5 and the MODIO test talks to it there. How does that relate to MACH I/O ports? Is port 0 the MODIO buss?

Can you post an example of a Macro that will talk to the Ardiono using your setups, please?

Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on December 07, 2011, 02:28:32 AM
Yes port 0 is the MODBUS. The pins of port 0 are the registers.

I haven't used a macro to talk to the modbus yet. I did that with the a brain. So I'm not much help there. My marcos, at this point, just toggle a user defined LED. That LED is tied to the MOSBUS via the brain.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on December 07, 2011, 03:27:41 AM
Damon;

Thanks for the reply. The programmer's reference has little to say about ModBus, but I did get it all figured out and I have everything working now. I think Macros will be more useful as they can be embedded ion the G-code. This will be  8) to play with  . . . sort of Pandora's box, however.
 I love programming, but I tend to get obsessed with it and once I start writing, I do not eat or sleep until the program is finished. Thankfully, G-code and Macros are very short as programs go  :)
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on December 07, 2011, 01:33:48 PM
YA macros have there place for sure. Certain functions like updating the speed and watching EStop are best handled with a brain. My macros will become much more than they are now as they will need to handle homing when coming out of turning mode. I also make sure the spindle if off before the switch and if there is any dwell time required the macro will handle that as well. Glad you got things working.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on December 07, 2011, 03:27:32 PM
Well, I am glad I had some time to poke around on forums (recovering from surgery :'() and came across this thread. I'm going to have a lot of fun with this and maybe even come up with something useful . . .  ;)   Now I have an itch to make up a high speed spindle and drive it with a Mitsu 750W AC servo thru a 6:1 (24,000 RPM) flat belt setup. With spindle load monitoring on-screen, belt change and index mode for hard tapping and on and on . . . all done on the Arduino. How about M600 P25 Q28 R375  (hard tap 1/4-28 .375 deep)

 Just FYI, I do the 4th axis homing via macro, but homing is actually not always needed. Here is a video example of a production part with hard tapping and opposing flats on the barrel. Indexing mode yes, but homing not needed. Thanks for taking the time to explain the Arduino/Modbus interface. Hope the video inspires.

http://www.youtube.com/watch?v=HvjnDQoh-7I (http://www.youtube.com/watch?v=HvjnDQoh-7I)
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on December 07, 2011, 05:39:53 PM
Glad you found the info useful. It's the least I could do considering it's your 4th axis design that started me down this path in the first place.  ;D
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on December 12, 2011, 01:24:27 PM
Quick update:

I have bidirectional communication over Modbus working between Arduino and MACH. Also macros in MACH reading commanded speed and sending that data to the Arduino which in turn generates a PWM signal to create a 0 to 5V ref which is converted to 0 to 10V thru an opto-isolator to provide the follow voltage for speed control using a VFD or equiv. motor control. All sorts of on/off relays can also be controlled via direct command from Mach or semi autonomously thru program logic in the Arduino.

Mach can read the registers in the Arduino, and then apply that data to any normal MACH use (control, DRO, etc). The Arduino can fill the registers based on data from any number of sources (MACH, sensors of all kinds, signals from drives, etc). I looked at the frequency generators mentioned earlier in this thread, but they would only be useful in running a spindle continuously and would not be useful in positioning , so for my purposes (hard tapping capability), that rout is a dead end (unless I am missing something).

During my research on this topic, I finally watched all  of the MACH tutorial videos and also discovered a bunch of new/updated products. I have ordered a new programable digital accelerometer, the new Arduino mega board and a 4 line LCD to play with. I have had the idea for a long time to put a plc between some devices and Mach to supplement the capabilities of the system. An example is to monitor the spindle load and automatically slow the feed rate slightly to prevent a stall (hopefully with an e-stop) or overheating of the spindle motor. Also, since I cut a lot of aluminum and have broken many, many endmills when they clog up, spindle monitoring would save me a lot of money . . . .

I will need to do some testing to determine how fast a square wave the Arduino can generate . .  unless someone has already done this and will post the info . .  :-*
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on December 12, 2011, 02:33:47 PM
I'll answer a couple of your questions together. Arduino by itself will produce a square wave up to a max of 1/3 the clock speed of 16Mhz. The problem is that the increments for the clock speed get larger the higher the frequency goes. See my notes before and the formulas for frequency. This is why I went to the DDS module. It will create any frequency up to 1 Mhz. as a square wave. Also this technology would not and could not be used to index. The USB bus talking to the arduino does not have a consistent update timing sequence. This is why I build the circuit to switch from the DDS frequency for turning mode to the parallel port STEP and DIR pins for indexing mode. The only way to make the Arduino work to index would to make it become a full motion controller and give it control of all the axis's and just feed it movement instructions. Basically what the Smooth stepper does. This is also why the Arduino should not be used directly to home inputs can be delayed at different intervals depending on what is going on in the Arduino and on the PC.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on December 12, 2011, 03:40:54 PM
I was not intending to use the Arduino for indexing. I was just wondering if it could generate a pulse stream fast enough to spin the 4th axis in turning mode. The reason being that acceleration and deceleration are major considerations with the 4th axis in 'lathe mode'. And as you might imagine, the profiles vary greatly with and without a chuck installed and also with the mass of the workpiece.

The Arduino, if it were monitoring the motor load, could adjust the acceleration in real time based on the load. Assuming the Arduino was controlling a dedicated frequency generator,  it may be possible to accomplish the same thing, albeit with some amount of lag time, which may or may not be a significant problem. So again we have more than one way to skin the cat.

I am mulling over a number of arrangements, but one that seems to make sense is to dedicate MACH's "S" axis  and "C" axis to the mill spindle and the "C" axis plus the Arduino to the 4th axis, with the Arduino handling the 'lathe mode' operation in some manner.

There are a bunch of different frequency generators on ebay ranging up to 40mhz. Do you have a link to the one that you chose?
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on December 12, 2011, 04:40:52 PM
This is the one I used:

http://www.ebay.com/itm/190570439517?ssPageName=STRK:MEWAX:IT&_trksid=p3984.m1423.l2649

Note that even though they say 70Mhz they will only produce a square wave up to 1 Mhz. This is a limit of the build in comparator that it being used to generate the square wave from the sine wave produced. Pulse width is also set in two ways. either by an onboard pot or an external voltage reference. So far my testing shows that this will not need to vary and I can set it and forget it via the pot. Most drives will signal on either the up edge or the down edge of a square wave and don't care about the width of the pulse as long as it's long enough to trigger.

Acceleration and Decel profiles could be programmed into Arduino. Currently I have a fixed program to ramp up and down the final frequency. You bring up a great point of being able to change them on the fly based on the load on the spindle. Either via a feedback loop or via a user defined setup. You could add a DRO to Mach and pass it to Arduino that would then select a profile for different ramping requirements. Just thinking out loud. Will cros that road when the time comes.

One other thought: you mentioned you are passing the speed to Arduino via a macro. Is this the override speed? I did mine via a brain instead so no matter how the override speed gets changed it will always be correct in Arduino. Just a thought for you.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on December 12, 2011, 05:56:34 PM
One other thought: you mentioned you are passing the speed to Arduino via a macro. Is this the override speed? I did mine via a brain instead so no matter how the override speed gets changed it will always be correct in Arduino. Just a thought for you.

My 4th axis (axii?) are used on a variety of systems, so I try to avoid using capabilities that are specific to only one software. Brains have an advantage in speed, but they are unique to Mach, so far as I am aware.

I do 'swapaxis' in hardware for the same reason.


Do you have the signal generator working with a drive?
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on December 12, 2011, 06:12:31 PM
So far the signal generator (DDS) is just driving a stepper. I have the AC servo on the bench but need to build some cables for the motor and just don't have time right now. I'll let you know when I get things tested.

Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on December 13, 2011, 10:51:09 AM
Another quick update: FWIW, if dedicated to the task, the Arduino can generate a max frequency of 100khz square wave (wide enough to be recognized by a typical drive). I think 25khz would be adequate, so the board can do the job, but I have a lot of other stuff in mind for the board to be thinking about, so testing and retesting the signal speed after each code addition would be a real time gobbler. Therefor I am going to acquire a separate signal generator and just have the Arduino command the desired frequency.

This method will actually dovetail nicely into one of the features I had in mind; that being to automatically vary the spindle speed to maintain a given SFM during profiling or facing operations. This will significantly improve surface finish as well as reduce production time.

Another feature bouncing around in my head is to have the PLC monitor imbalance thru an accelerometer installed in the 4th axis in order to provide an operator warning or perhaps to restrict spindle speed in the event of a significant imbalance before a serious and potentially dangerous problem arises.

The list goes on, but I wonder if any readers have some ideas for cool features that could be added to either the 4th axis or the mill spindle.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on January 08, 2012, 10:20:27 AM
Quick Update: After numerous simulations, the Alpha software (1,800 lines of C code) is running live tests on the 4th axis. The test programs run all night and so far are stable.
Working features (so far) are:
 *Communicating with MACH thru serial Modbus, one MACH Brain and a series of macros.
 *'Wait states' implemented. PLC genrates a 'Speed Reached' signal used to make MACH wait until accell/decel events are completed before MACH continues.
 *Interrupt driven E-stop forces immediate signal to MACH regardles of what the PLC was doing at the time.
 *Accell/Decel is autonomous and completely independent of MACH. Controlled by two parameters configurable 'on the fly' via macro.
     example: Speed set to 450 RPM (spindle RPM) M3 to M4 causes automatic smooth Decel to a stop, dir change, accel back to set speed.
 *RPM max limit is configurable 'on the fly' via macro. User enters spindle RPM (or SFM in AutoSpeed) and back gear is calculated automatically.
      commanded RPM that exceeds  RPM max is held at RPM max and a warning indicator (or LCD message) informs operator of overspeed.
      no error or E-stop need to be generated and when RPM drops back, indicators go off and operation continues without interruption.

*'AutoSpeed Mode': user supplies desired SFM and speed is automatically controlled via position of the Z or Y axis
                      Speedmatch feature allows switching 'on the fly' into or out of AutoSpeed and the spindle will accel/decell to the set speed of the new mode.
                      Z or Y axis coords are fed to the PLC and the PLC feeds back current RPM via MACH Brain. This is another 'machining center' capability brought to the benchtop.
                         One step further =  G95 feedrate results in automatic feedrate changes based on PLC reported RPM.

*'Manual Mode':  full manual control 'uncoupled from Mach via control panel. Accel/Decel, max speed, E-stop fully functional even in manual mode.  There is lots more, but this is the basics so far.


(http://www.thecubestudio.com/4thAxisMotorContol/PLCandLCDandPanelWEB.jpg)
(http://www.thecubestudio.com/4thAxisMotorContol/PLCandLCDcloseWEB.jpg)

Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on January 08, 2012, 10:24:06 AM
Some notes on Smoothstepper use with 4th axis motor controller:

CNC4PC has a custom BOB for the SS and it is convienient to use, but for some reason they decided to lock port 2 permanently as inputs.

The only solution is to cut the traces on the board and put jumpers between the pins. See photos below. If anyone knows of another custom BOB for SS< please post it.

THanks

(http://www.thecubestudio.com/4thAxisMotorContol/SSbobBackWEB.jpg)
(http://www.thecubestudio.com/4thAxisMotorContol/SSbobFrontWEB.jpg)
Title: Re: High Speed Servo as Spindle - My Solution
Post by: simpson36 on January 18, 2012, 03:54:32 AM
Last post to this thread. Project completed and software is in beta and ready for customer testing. If I have time I will add a video to my YouTube account that follows this project. Here is the final control box and screen mods:

(http://www.thecubestudio.com/4thAxisMotorContol/ControlBoxFinal01WEB.jpg)

(http://www.thecubestudio.com/4thAxisMotorContol/MachScreenMod01WEB.jpg)
Title: Re: High Speed Servo as Spindle - My Solution
Post by: DamonJones on January 18, 2012, 01:24:14 PM
Very nicely done. I haven't had time to work on any of this project for ever now. Been off on other things. Glad to see things worked out so well for you however.
Title: Re: High Speed Servo as Spindle - My Solution
Post by: Len-Tikular on October 10, 2012, 05:03:30 PM
Post moved to correct area.

Appologies