engineering     ...Home of TurboCNC, the best shareware CNC controller around!

Home | Software | Hardware | Articles | Ordering | Neat stuff perpetually in development  | About DAK


Articles: -> CNC lathe FAQ

CONTENTS

1  About this document
1.1  Why write a FAQ?
1.2  Last update
1.3  How to get a copy
1.4  Can I link/post this on my site?
2  CNC in general
2.1  What is CNC?
2.2  What does CNC code look like?
2.3  What do all the G and M calls do?
3  Overview of this conversion project
3.1  Why did you convert this lathe?
3.2  How long did it take?
3.3  How much did it cost?
3.4  Is it finished?
3.5  Can you still use it manually?
4  Machinery
4.1  Is it fast?
4.2  How accurate is it?
4.3  How big of a part can it handle?
4.4  General specifications
4.5  What tooling do you use?
4.6  What about all the backlash?
4.7  How much torque do the motors have?
6  Software
6.1  Did you write your own software?
6.2  What language/platform does it run on?
6.3  How many lines long is it?
6.4  Did it take long to write?
6.5  How do you do linear interpolation?
6.6  How do you do circular interpolation?
6.7  Open loop vs. closed loop control?
6.8  Does it use regular G & M code programs?
          6.9  Can I use your code?
7  Controller
7.1  Did you build the controller/driver too?
7.2  How does it work?
7.3  Can you send me plans to build one?
7.4  What kind of "juice" does it run on?
8  For those who may follow
8.1  Considering a conversion?
8.2  Who are good vendors for servos and stuff?
8.3  Steppers vs Servos?
8.4  Was it worth it?
8.5  Can I have your plans?
8.6  Is it better to buy or build?
8.7  How about converting a mill?


1  About this document

1.1  Why write a FAQ?

     This document was written for the benefit of individuals with specific questions about this lathe conversion.  Also saves me time in replying to email.

1.2  Last update

     Last update was 08/29/2001 at 10:00.  Updates around here happen about once every three months on the average.

1.3  How to get a copy

     If you'd like a copy of this FAQ, please email me at dkowalcz@dakeng.com and I'll send you a current copy.

1.4  Can I link/post this on my site?

     Absolutely, if you want to do so.  Use the URL http://www.dakeng.com/ltfaq.htm  Just don't represent my ideas as your own.


2  CNC in general

2.1  What is CNC?

     CNC is an acronym for "Computer Numerical Control."  It refers specifically to the control system only, but in this day and age has come to be a generic term for all programmable machine tools that use an electronic computer.  Briefly, it is the means whereby the motion of some form of cutting tool is directed by a computer to produce a manufactured product.

     Those that have done work on lathes or similar tools before are aware that making a part frequently involves a series of repetitive motions.  CNC involves reducing those specific motions to codes in a scripting language and then using those to replicate the procedure automatically on command.  The savings in human capital with this process is tremendous, as the operator no longer needs to spend such long hours concentrating and hunched over a machine.  Additionally, most types of curves and other intricate profiles can be produced much more easily when done under computer control.

2.2  What does CNC code look like

     Here's a sample listing of one of my CNC programs.  This is to make a nozzle for a water fountain application with an integral hose fitting.

Click here to download a copy of this program

{program start}
M07
M03
G70
G90 F3.0  ;3 ipm feed
T1
G04 #3
G00 Z-0.030               ;Position for cut
G01 X0.285                ;Face off
G01 X0.060               
G01 Z-0.405               ;Turn to thread shoulder
G01 X0.000  
G00 Z0.050
G01 X0.0805               ;Turn major diameter of thread
G01 Z-0.405 
G01 X0.0175 
G01 Z-0.655 
G01 Z-1.030 X0.140        ;Taper front
G01 Z-1.145               ;Allowance for cutoff tool
G01 X0.000
G00 Z-0.985 
M00                       ;Dwell for drilling op
M05
G04 #4
M04
T2
G00 X0.000
G01 X-0.285               ;cutoff
T1
G00 Z0.000                ;Return Home
G00 X0.000 
M05
M09
G04
M02
{program end}

2.3  What do all the G and M calls do?

     Although there are other resources on the Internet and otherwise that do a good job of explaining what all the individual codes do (My favorite is the Machinery's Handbook from Industrial Press), the following is a brief overview of what is going on:

M00 - Automatic halt until keypress

M01 - Optional halt until keypress

M02 - End of program

M03 - Spindle on, CW (usual direction for a lathe)

M04 - Spindle on, CCW

M05 - Spindle off

M07 - Coolant pump on

M09 - Coolant pump off

M19 - Oriented spindle stop

M10 - Move spindle to angular position and clamp

M11 - Unclamp spindle

M60 - Goto subroutine

M62 - Return from subroutine

G00 - Rapid movement

G01 - Linear interpolation

G02 - Circular interpolation CW

G03 - Circular interpolation CCW

G04 - Dwell (certain number of seconds)

G06 - Parabolic interpolation

G33 - Constant lead thread

G70 - Set units to inches

G71 - Set units to millimeters

G90 - Set absolute positions

G91 - Set incremental positions

G94 - Set feedrate to units/min

G95 - Set feedrate to units/rev

     The letters and codes afterward specify coordinates of the table, feedrates, numbers of seconds to dwell, and so on.  Not too different from most programming languages really.  My interpreter doesn't require the use of line numbers except for subroutine calls.  If you leave the line numbers in, that's fine.


3  Overview of this conversion project

3.1  Why did you convert this lathe?

     The primary motivation, I'd have to say, was frustration.  The lathe, a Harbor Freight 7x10 minilathe, just doesn't have the horsepower nor the ergonomics to be a production machine right out of the box.  At the time I was involved in running a small business out of my basement, and the hassle of having to stand around all day and turn boring cranks and get dirty was enormous!  So the choice came down to, get a real CNC ($$$), or convert this one.  Pictures of the converted lathe may be seen at the CNC lathe conversion page.

3.2  How long did it take?

     Not very long, actually.  In terms of man-hours, about 550 or so all told including the programming, which took place in dribs and drabs long after the fact to add all the bells and whistles.  In terms of turn around, it was about four weeks after I said "enough is enough I'm converting this thing" that I was able to make parts under computer control.  Mechanical side was about 70 man hours or so to hook together; there's really not much to it!

3.3  How much did it cost

    Dollar cost was on the order of $2000, not including the initial cost of the lathe itself.  About half of that is accounted for by tooling, the rest by electronics, enclosures, and motors/controls.  Surplus would have been cheaper - I bought most of it new.

3.4  Is it finished?

     (laughs!)  No project of mine can ever truly be considered "finished."  Seriously, a laundry list of improvements is in the queue for this machine, most importantly an automatic collet chuck and bar puller for unattended production.  But as far as major features go, I consider this a done deal.

3.5  Can you still use it manually?

     No.  Now that it's computerized and enclosed, only the computer can use it effectively.  I've been working on a jogging wheel setup that would allow me to move cross-slide pseudo-manually (imagine a machine-by-wire arrangement and you've got the idea) for ease in setup and for "quickie" projects.  But for now, I have a slewing command in software that works for setup positioning and tool wear compensation, and a manual data input feature that lets me enter G codes one at a time.  Kind of pseudo-manual operation.


4  Machinery

4.1  Is it fast?

     For its size, yes, it's fairly fast.  A typical part takes around 2 minutes to finish and load the next; maybe 4-5 if I want a really nice finish or if a lot of hogging is involved.  The axes move at around 20ipm in rapid, which for those used to the industrial machines probably seems pretty pokey.  The production rate is at least triple what it used to be when I did it manually on this same machine, and that's on the days when I was really cutting hot!  When you consider that it doesn't take breaks or make much scrap, it's around a factor of ten for the whole day.

4.2  How accurate is it?

     Lots of folks have asked me about accuracy/repeatability, so I mic'd up 20 typical parts that I made just to be sure.  For a 0.485" to 0.495" diameter callout, the machine was holding 0.491" within 0.001" in production with plain turning tools (no grinding).  Here's the histogram and statistical breakdown courtesy of MiniTab;

                   

     The standard deviation is 0.0006" according to MiniTab, which means that about 65% of the parts were +/- 0.0005" from the setpoint (0.491"). In theory then, 95.4% of the parts will then be within two standard deviations or +/-0.0012", and  99.7% will be within three (+/- 0.0018).  Sounds about right.  Resolution in software is 0.000050" per half step, in case you were wondering.

     Although repeatability is excellent, as evidenced by the above, accuracy is only fair. I think the third-world leadscrews are to blame with this - there's enough wobble in the threads to eat up 0.002" across the entire travel. That's 0.004" on the diameter when turning! So sometimes I have to "overtravel" a bit on a cut because I know the screw isn't exactly 0.062500" on every rev. Kind of a fun game that way...  Tool compensation generally keeps everything right where I want it to be after a trial cut or two.  

  Some days it's quite impressive.  For example, 30 parts I made a few weeks back had all the diameters consistent from part to part within 0.0003" (as close as the "good" Mitutoyo mic can measure!).  I think temperature is a big variable here, it gets better the longer the machine runs.

4.3  How big of a part can it handle?

     The work envelope is specified below in the general specs, but the tooling and such can end up using a fair bit of this.  Without making changes from its current arrangement, it can comfortably handle 1" diameter stock about 6" long.  Most of the parts I make are 3/4" diameter and less than 3" long.

4.4  General specifications

Swing: 3"
Capacity: 10" between centers
Spindle: 50 - 2200 RPM 1/2 hp
Max bar size thru headstock: 3/4"
Max feedrate: 20 ipm
Accuracy: +/- 0.001" (90% confidence)
Typical cycle time: 2-3 min
Typical part finish: 32-40 micro

4.5  What tooling do you use?

     You know, I never really seemed to get a good finish on the parts until I switched to regular coated carbide indexable inserts.  The ones I use are supposedly optimized for use with aluminum making light finishing cuts (from an industrial perspective, all the cuts on this lathe are "finishing cuts"), and at that they work admirably well.  They're not razor sharp though, the edges are honed just slightly to promote longer tool life.  Thus there's a small horsepower penalty invoked with using them, but generally the results have been excellent.  With a 30 degree diamond on the front and a cutoff/grooving tool on the back it handles most common parts that require a couple of journals and some chamfers.  Using the quick change toolpost I switch to other tools as needed during the cycle with an M00 pause command in the program.

4.6  What about all the backlash?

     Since there always seems to be backlash in any acme thread type arrangement, I skirted this issue by preloading the slide rather than replacing the screw.  By attaching a cable to the cross slide and running it to a couple of 1 gallon paint cans over a pulley I managed to make the results of the turning quite satisfactory - especially during profiling cuts which require the tool to move forward and back in X without lost motion.  When I got tired of tripping over the cable I built this little gem, which accomplishes the same thing with a tension spring and sits under the way cover.  Sorry if you have to crane your neck to figure it out - unusual camera angle eh?

     On the Z axis it isn't so critical unless cutting to a shoulder, and for this I make it a point to always feed toward the headstock to keep things consistent.  This lathe doesn't seem to have much slop in Z anyway, so I haven't done much about it yet.

4.7  How much torque do the motors have?

     Tough question to answer, since steppers do not produce constant torque over their entire range.  The static torque for the Z axis stepper is 370 oz-in, and the X is 150 oz-in.  These are geared 3:1 and 2.5:1 to the leadscrews respectively, so there's quite a bit of torque capability there at low speeds.  If you're thinking of building your own system, these are probably pretty good numbers to start with.  I keep the gibs pretty tight, so there's a bit of drag in there to contend with.


6  Software

6.1  Did you write your own software?

     Absolutely.  I had some offers from firms that were in the business of providing CNC software, and it was great stuff, but it started at $4000!  At the time I was in community college, and that kind of dough wasn't around to spend - besides I was uncertain of the venture's success and didn't want any stranded cost.  So I "rolled my own."

6.2  What language/platform does it run on?

     Borland's Turbo Pascal 7.0 is the language I used.  Nice, easy to use, and pretty fast since it compiles a tight stand-alone exe.  It runs under DOS on a dedicated 486-66 machine for the purpose - used to be a 286-10 but I needed more speed when I upgraded the drive electronics to handle it.  The G code is all EIA standard.

6.3  How many lines long is it?

     2500. Most of this is in the menus and interface handling, not to mention comments.  The "meat" of it is about 20% of that. 

6.4  Did it take long to write?

     Well, it's easy to lose track of time when you're on a computer, so "long" is somewhat relative.  My estimates are around 550 hours of time invested coding, learning, debugging, and so forth until I got to the point it is today.  Probably about 20 hours is what it took until it could cut very rudimentary X-Z only parts, the really nifty interpolation, feedrates, and EIA standard file handling took somewhat longer to devise.

6.5  How do you do linear interpolation?

     The following is part of the larger program that handles everything; as the "meat" of the algorithm.  By the way, if you're using servos and not steppers to drive your machine, than I guess very little of what follows applies to you!  The current version is a bit more sophisticated, but this is the basic idea...

CONST  outvalueX: ARRAY[1..6] of integer =
                 (5, 4, 6, 2, 3, 1);
       outvalueZ: ARRAY[1..8] of integer =
                 (3, 6, 7, 13, 15, 10, 11, 1);

     These next two procedures, halfstepZ and X, are to index the stepper motors. When the interpolating procedure is doing it's work it calls on these two to pop each axis in 0.000050" increments and update variables accordingly. "Outvalue" is just an array that converts an arbitrary "Currentstep" # from 1 through 8 (or however many sequences) to a string of bits to actually turn windings on and off.

PROCEDURE HalfStepX;
   BEGIN
     currentstepX:= currentstepX+directionX;
     X:= X + (directionX * 0.000050);
       CASE currentstepX OF
         0 : currentstepX:= 6;
         7 : currentstepX:= 1;
       END;
     Portbyte:= Portbyte AND $F8 OR (OutvalueX[currentstepX]);  {AND to clear bits, OR to set}
     port[$0378]:= Portbyte;
   END;

PROCEDURE HalfStepZ;
   BEGIN
     currentstepZ:= currentstepZ+directionZ;
     Z:= Z + (directionZ * 0.000050);
       CASE currentstepZ OF
         0 : currentstepZ:= 8;
         9 : currentstepZ:= 1;
       END;
     PortbyteB:= PortbyteB AND $F0 OR OutvalueZ[currentstepZ];  {AND to clear bits, OR to set}
     port[$0278]:= PortbyteB;
   END;

Note that the X axis is driven by a three phase variable-reluctance stepper, hence only 6 energizing sequences. The Z axis is more conventional, an off-the-shelf bipolar type.

This is a one-dimensional move algorithm (X-axis):

PROCEDURE Xmove (Xdest: real ; Feed: integer);
  BEGIN
    steptime:= 45; {45 Milliseconds per step to begin}
    IF Xdest - X > 0 THEN directionX:= 1
                     ELSE directionX:= -1;

     WHILE abs (Xdest - X) > 0.000001 DO
       BEGIN
          HalfStepX;
          ShowStatus;
          IF Keypressed THEN BEGIN
                              ch1:=Readkey;
                              IF (ch1= #27) OR (ch1= ' ') THEN PanicStop;
                              IF Abort= True THEN Exit;
                              Steptime:=45;
                              END;
          delay(steptime);
          IF abs (X-Xdest) >= 0.0030 THEN steptime:= steptime-2 {This is the acceleration per half step}
                                     ELSE steptime:= steptime+2;
          IF steptime < Feed THEN steptime:= Feed;
          IF steptime > 45 THEN steptime:= 45;
       END; {While}

    WriteLn ('Done Xmove to: ', Xdest:7:5);
  END;

Pretty simple, eh? The steptime (delay between winding changes) starts at 45ms and keeps getting smaller arithmetically, until it reaches a lower limit (Feedrate) while the motor is stepped by calling the HalfStep procedure. When the linear position is within .003 of it's final destination, the steptime increases again with each step. Nice and simple trapezoidal acceleration! Maybe when I get some free time I'll program in a sine-curve acceleration profile - but the idea insofar as code goes is basically the same.

Ok, here's how to do X-Z: Same basic thing, just a little more going on... This is adaptable to an infinite number of axes of simultaneous motion:

PROCEDURE MoveTable (Zdest: real ; Xdest: real ; Feed: integer);

  VAR TrueDistance, Zincrement, Xincrement, Divfactor: real;
      Ziterate, Xiterate: Real ;

  BEGIN
     TrueDistance:= SQRT(SQR(Zdest - Z) + SQR(Xdest - X));    {Apply Pythagorean theroem}
     Divfactor:= TrueDistance / 0.000050;                 {Divde the distance by 50 millionths}
     Zincrement:= (Zdest - Z) / Divfactor;
     Xincrement:= (Xdest - X) / Divfactor;                       {Determine how far each axis will advance per iteration}
     Ziterate:= Z;                                             {Create temporary axis values for calculation}
     Xiterate:= X;
     IF Xdest - X > 0 THEN directionX:= 1                      {Determine axis directions for the motor controls}
                      ELSE directionX:= -1;
     IF Zdest - Z > 0 THEN directionZ:= 1
                      ELSE directionZ:= -1;
    StepTime:= 45; {45 milliseconds per step to begin}

    WHILE (ABS(Zdest - Z) < 0.000001) AND (ABS(Xdest - X) < 0.000001)  DO   {Begin iteration procedure}
     BEGIN
       Ziterate:= Ziterate + Zincrement;                      {Increment temp axis values}
       Yiterate:= Xiterate + Xincrement;
       IF ABS(Ziterate - Z)>= 0.000050 THEN HalfStepZ;        {Update axis positions when necessary}
       IF ABS(Xiterate - X)>= 0.000050 THEN HalfStepX;
       IF (abs(Z - Zdest) >= 0.003) OR (ABS(X - Xdest) >= 0.003) THEN steptime:= steptime-2
                                                                 ELSE steptime:= steptime+2;
       IF steptime < Feed THEN steptime:= Feed;
       IF steptime > 45 THEN steptime:= 45;
      ShowStatus;
      IF Keypressed THEN BEGIN
                              ch1:=Readkey;
                              IF (ch1= #27) OR (ch1= ' ') THEN PanicStop;
                              IF Abort=True THEN Exit;
                              Steptime:= 45;
                              END;
      delay(steptime);
      END;    {While}
     WriteLn('Done MoveTable to', Zdest:8:6, Xdest:8:6);
  END;

Hmmm, I guess it would be easiest if I tried to explain this in words. What is happening above goes like this:

The procedure begins. The X and Z of the table are defined from the last move, and the X and Z final positions for the move about to take place are supplied by the part file when the procedure is called.

The first thing the program does is compute the true distance from (X1, Z1) to (X2, Z2) and determine the quadrant that the move is in.

Then it divides that true distance into a number of discrete divisions (each of them 0.000050" long). The reason I chose that number is because that's what half-a-step translates to on my machine.

For every 50 millionths of interpolated travel, each axis will move some corresponding, and smaller, amount. For instance, a move from (0,0) to (1,1) means that every unit of motion on the 45 degree "angle" translates to 0.707 of those units on X and Z. No trig here, just plain 'ol division to get the slopes of the angles. The program resolves this into two variables, Xincrement and Yincrement.

In the looping part of the procedure the program is delightfully simple! All it does is keep adding Xincrement to a dummy "X", and when the dummy "X" and the real axis of the table are finally .000050" apart it pulses the motor one blip forward.

Acceleration is just as simple as before - the steptime keeps decreasing to a lower limit until both X AND Z are within .003 of their destinations. And then it increases again.

To make circles and arcs you can either feed a bunch of straight lines through this procedure (the cheap way, but everyone does it!), or see the section below on circular interpolation.

6.6  How do you do circular interpolation?

     Of all the cans of worms in motion control, this is one of the wormiest!!!  Instead of taking the multiple straight line "almost looks like a circle, but isn't" approach, I wrote the following, which works to the resolution of whatever machine it's on.  It functions in much the same manner as the linear interpolation algorithm above in that it involves sequencing an "imaginary" point through space along an arc, and "blips" the axes forward when they need to be to keep up with this point.  This is a two-dimension only routine.  Three or four dimensional circular interpolation is something I'll probably never achieve until retirement.  By the way, another common question is what's the difference between G02 and G03?  G02 is for bullet noses, G03 is for bottlenecks if you're cutting toward the headstock.

PROCEDURE G02; {Clockwise circular interpolation}
VAR AngStart, AngFinish, AngIterate, Xiterate, Ziterate : double;
    Xoffset, Zoffset, Radius, TotalAngle : double;
    DeltaAngle : extended;

BEGIN
{Convert all incremental inputs to absolute and metric to inches}
Fcode:=Round(Fcode);
IF Fcode=0 THEN Fcode:=1;
IF (Zcode=999) OR (Xcode=999) OR (Icode=999) OR (Jcode=999) THEN Exit;

IF Metric=True THEN BEGIN Xcode:=Round((Xcode/25.4)*10000)/10000;
                          Zcode:=Round((Xcode/25.4)*10000)/10000;
                          Icode:=Round((Xcode/25.4)*10000)/10000;
                          Jcode:=Round((Xcode/25.4)*10000)/10000;
                      END;

IF IncrementalMode=True  THEN BEGIN
                              Xcode:=(X+Xcode);
                              Zcode:=(Z+Zcode);
                              Icode:=(X+Icode);
                              Jcode:=(Z+Jcode);
                              END;
{Evaluate angular postions for endpoints of arc relative to center}

{Startpoint of arc}
Zoffset:=(Z-Icode);
Xoffset:=(X-Jcode);
IF (Zoffset>0) AND (Xoffset>=0) THEN Angstart:=(Arctan(Xoffset/Zoffset));     {Quadrant I}
IF (Zoffset>0) AND (Xoffset<0) THEN Angstart:=(Arctan(Xoffset/Zoffset)+2*PI); {Quadrant IV}
IF (Zoffset<0) AND (Xoffset<=0) THEN Angstart:=(Arctan(Xoffset/Zoffset)+PI);  {Quadrant III}
IF (Zoffset<0) AND (Xoffset>0) THEN Angstart:=(Arctan(Xoffset/Zoffset)+PI);   {Quadrant II}
IF (Zoffset=0) AND (Xoffset>0) THEN Angstart:=PI/2;                           {-90, 90 Arctan is undefined}
IF (Zoffset=0) AND (Xoffset<0) THEN Angstart:=-PI/2;

{Endpoint of arc}
Zoffset:=(Zcode-Icode);
Xoffset:=(Xcode-Jcode);
IF (Zoffset>0) AND (Xoffset>=0) THEN Angfinish:=(Arctan(Xoffset/Zoffset));     {Quadrant I}
IF (Zoffset>0) AND (Xoffset<0) THEN Angfinish:=(Arctan(Xoffset/Zoffset)+2*PI); {Quadrant IV}
IF (Zoffset<0) AND (Xoffset<=0) THEN Angfinish:=(Arctan(Xoffset/Zoffset)+PI);  {Quadrant III}
IF (Zoffset<0) AND (Xoffset>0) THEN Angfinish:=(Arctan(Xoffset/Zoffset)+PI);   {Quadrant II}
IF (Zoffset=0) AND (Xoffset>0) THEN Angfinish:=PI/2;                           {-90, 90 Arctan is undefined}
IF (Zoffset=0) AND (Xoffset<0) THEN Angfinish:=-PI/2;

IF AngFinish>AngStart THEN AngStart:=AngStart+(2*PI);

{Radius of arc}
Radius:=ABS(SQRT((SQR(Xoffset)+SQR(Zoffset))));

{Evaluate total circumferential displacement; divide by machine's resolution to resolve "DeltaAngle"}
TotalAngle:=AngStart-AngFinish;
IF TotalAngle<0 THEN TotalAngle:=TotalAngle+(2*PI);
DeltaAngle:=TotalAngle/((2*PI*Radius*(TotalAngle/(2*PI)))/0.000050);


{Interpolate the arc}
AngIterate:=AngStart; Xiterate:=X; Ziterate:=Z; Steptime:=45;

WHILE Angiterate>(AngFinish-DeltaAngle) DO                 {Main loop begins...}
 BEGIN
  Ziterate:= (Radius*Cos(AngIterate))+Icode;                   {Resolve z,x}
  Xiterate:= (Radius*Sin(AngIterate))+Jcode;
  IF Xiterate - X > 0 THEN directionX:= 1                      {Determine axis directions for the motor controls}
                      ELSE directionX:= -1;
  IF Ziterate - Z > 0 THEN directionZ:= 1
                      ELSE directionZ:= -1;

       IF ABS(Ziterate - Z)>= 0.000050 THEN HalfStepZ;        {Update axis positions when necessary}
       IF ABS(Xiterate - X)>= 0.000050 THEN HalfStepX;

  ShowStatus;                                                 {Update screen display}
  IF (ReadDI AND $80)=$80 THEN BEGIN                          {Panic button check}
                              PanicStop;
                              IF Abort= True THEN Exit;
                              Steptime:=45;
                            END;

     AngIterate:=AngIterate-DeltaAngle;
   delay(steptime);
   IF (abs(Z - Zcode) >= 0.001) OR (ABS(X - Xcode) >= 0.001) THEN steptime:= steptime-2
                                                             ELSE steptime:= steptime+2;
       IF steptime < Fcode THEN steptime:= Fcode;
       IF steptime > 45 THEN steptime:= 45;
 END; {While}

 {closure of circle -> rounding error correction}
 IF Xcode - X > 0 THEN directionX:= 1                      {Determine axis directions for the motor controls}
                  ELSE directionX:= -1;
 IF Zcode - Z > 0 THEN directionZ:= 1
                  ELSE directionZ:= -1;

       IF ABS(Zcode - Z)>= 0.000050 THEN HalfStepZ;        {Update axis positions when necessary}
       IF ABS(Xcode - X)>= 0.000050 THEN HalfStepX;

  ShowStatus;                                              {Update screen display}
           IF (ReadDI AND $80)=$80 THEN BEGIN
                              PanicStop;
                              IF Abort= True THEN Exit;
                              Steptime:=45;
                            END;
  Write('Completed CW circular inter to Z ',Z:7:5,' X ', X:7:5);
  delay(30);
END;

     When I get around to it I'll post a few parts made with the above routines.  They're really quite beautiful, a sort of mathematical expression of their own.  Wait until I come up with an excuse to fill in the parabolic interpolation routine!

6.7  Open loop vs. closed loop control?

     This is the only real flaw with my machine as I designed it.  The steppers run in an "open loop" mode, which means that the computer just sends pulses downstream without really knowing whether the motors are really turning.  Works well despite it's obvious shortcomings, but about once every few weeks or so it'll screw up and the results are always comical - if I catch it in time that is!  Someday I'll upgrade to servos, which are closed loop by definition, and this problem will go away.

     Another important point with open loop control is that the computer is actually directing the position of the handwheels as opposed to the actual position of the axis proper.  With decent leadscrews and limited backlash this isn't much of a problem, but I can imagine with some systems this would be a real headache.  Bottom line: open loop is good enough for what I do with this machine, and that actually says a lot..

6.8  Does it use regular G & M code programs?

     Absolutely.  See the general section on CNC above for an example of the actual code that the lathe uses.  Conventions vary from machine to machine, but in general all of the codes and formats are interchangeable throughout.

6.9  Can I use your code?

     Sure, if you cough up the $10 registration for TurboCNC I'll send out the source code.  But as before, try to avoid representing my ideas as your own.  If you're planning to go commercial, I'd love to hear about it.  Had an email about a year or two ago from a guy that wanted to use my code to run a CNC router that he built out of plumbing fittings.  Click here to download the control software


7  Controller

7.1  Did you build the controller/driver too?

     Absolutely - these were almost as expensive off the shelf five years ago as the control software!  It's really nothing too complicated to construct, but takes some attention to detail.  A photo of the inside of the controller is on the lathe page.

7.2  How does it work?

     Sorry if this is an unusually terse section of the FAQ, but there really isn't much to say here in between "a handful of relays and MOSFETs connected to the printer port" and giving a complete discourse on the theory of modern electronics.  What is being done through the controller, in essence, is an amplification of the low level signals from the PC's printer ports (:LPT1 and :LPT2) through such devices as relays and transistors to drive more macroscopic components, like motors.  Not much difference really, in principle, between this and a stereo amplifier although the requirements of each are altogether quite different.  

     If you need some background in electronics I'd suggest the series from Radio Shack by Forrest Mims III, which is good for those who don't want the intense theoretical background that accompanies most college texts.  Quite a few websites deal with the electronics behind stepper motor drivers, which are a study in their own right.  The software just sends 1's and 0's that become, in essence, bigger 1's and 0's that switch the motor windings.

7.3  Can you send me plans to build one?

  Here are the schematics for the electrical side, with a bill of materials as well:  cncsche.zip (15k).

7.4  What kind of "juice" does it run on?

     120V single phase AC.  All the transformers to get 90VDC and 12VDC for the various systems of the machine are internal to the controller.  It's probable that a 220V AC connection will be added for an extra beefy spindle motor someday - as the machine is sitting in the washer/dryer closet with that big 'ol 220 plug staring me in the face every time I use it!  It's just too tempting...


8 For those who may follow

8.1  Considering a conversion?

    If you're thinking of converting your tired lathe or mill to CNC, I recommend you do so as it can be a fun and intensely rewarding project.  Before you do, it's probably a good idea to consider what you typically use it for and whether a CNC conversion will help you do it better/faster.  Generally the further along the spectrum you are toward the production side, the better off you are converting.  For one-off hobbying around or oddball maintenance I wouldn't recommend it, as it tends to get in the way of getting anything done that requires "feel" on the part of the operator.  Check out the backlash and the generally serviceability of the machine beforehand, as CNC's tend to get run pretty hard under unforgiving conditions.

8.2  Who are good vendors for servos and stuff?

     There are more of these every time I look, but I would start with Intelligent Motion Systems and Superior Electric, as well as Baldor Electric.  They sell what are called "motion controllers" and servos, which are minicomputers that drive anywhere from two to eight axes depending on how much you spend. The motors and drivers hook up to these, and then your computer tells the controller where to go and how fast. Usually these come with software, although it is usually of a fairly crude sort. This is the middle of the road option, and probably the best one if you want something to work without a lot of tinkering. These are usually around 1k for the controller and a few hundred for motors and such.

     Full retrofit kits are around, Anilam makes them for regular Bridgeports I believe and OmniTurn has a good lathe retrofit that basically bolts a new set of axes on top of the old ones. Haven't checked in awhile, but these are $$$. Good for professional shops.  See http://www.cnckits.com/ for a good listing of resources, as well as www.mendonet.com/cnclinks.  Dan Mauch has a pretty solid selection of hobbyist-type kits at his site.

8.3  Steppers vs Servos?

     Servos are the best thing to have for CNC. "Servo" is Latin for slave, which is exactly what the motors do. In a nutshell, they're regular DC synchronous motors that are optimized for low inertia, high acceleration, and continuously variable speed through their range and have an integral encoder. Generally these take a lot of computing horsepower to direct accurately since they have to be monitored and controlled continuously, usually using a PID filter or other dedicated driver.

     Steppers are more open-loop and don't burden the computer much, but when they skip steps - grrr!!  They're not as powerful either.  I went with steppers only because they're cheap and easy to control in an open loop arrangement.

8.4  Was it worth it?

     You betcha!  Although it has it's own peculiar frustrations, at the end of the day I can have 200 parts complete, exactly alike and to spec, and take care of my reading and mail in the meantime; whereas previously I'd only be able to knock out 50-60, and be pooped by the time I was through.  Some of the other payoffs involve the people I meet that are curious to see it go and watch what it can do - always a perennial interest there especially among professional machinists.  The learning that took place going from A to B was phenomenal as well.  Looking back, I'd say the do-it-yourself approach was as beneficial on the human capital side as the utility one.

8.5  Can I have your plans?

     Sorry, but I don't think I'll be posting these.  Plans are available for the electrical side, but as for the hardware, there are just too many variations of this little lathe for such a thing to be useful.

8.6  Is it better to buy or build?

     There always seems to be an inverse time-money spectrum that people stand on; no time but some money or the reverse, plenty of time but no cash.  It depends on your goals really, whether to focus on learning and personal enjoyment or on the output side of production.  It's about equally expensive to build a conversion as to buy if you already have the "iron".  If you don't have a lathe at all and want a CNC, you can buy one for 6-50k depending on your ambition.  For any serious work, I'd recommend getting "real McCoy" motors and drive electronics, as the printer motor scrounged types don't seem to cut the mustard.  Even on this small lathe I had to upgrade from those...

     As far as controls and drivers go you'd be dollars and headaches ahead to buy a conversion kit or commercial stepper driver and control boards to connect to your PC. Sticker shock, but it costs as much and more to do it yourself since getting performance out of a stepper takes a bit of doing. The boards are matched to the steppers for maximum torque, etc, and this is worth it in my opinion - if the learning by doing part isn't an important part of the project.

8.7  How about converting a mill?

     I must say I'm not really qualified to speak much on this topic, but I do know that it's more common to retrofit mills for CNC than lathes - and I'm sure standard kits to do this are available for the more common Bridgeport type machines.  For those doing it themselves, it really isn't any harder than converting a lathe really, just one more axis to fit with a motor and away you go.  Some of the import bench type mills may be hard to convert in this respect because the Z (quill) is not really easy to connect to a servo motor in a satisfactory way, so watch out.

THAT'S ALL FOR THE FAQ!


Send email: admin@dakeng.com   |  Last updated 08/29/2001 - 10:00