ENGINEERING

Home of TurboCNC, the best open-source CNC control around...

 
web www.dakeng.com
 
  You are here:
  Homepage -> FAQ's -> 7x10 lathe FAQ
Latest release of TurboCNC is v4.01 build 050312
released March 13
 

7x10 CNC lathe conversion FAQ


  Hardware Software  
Articles HOME FAQ's
  Manuals User
Forum
 
About
DAK
Ordering Contact
DAK
  Sitemap Links  

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?
4.8  Can it do threading?
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?

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 11/07/2005 at 07:00.

1.3  How to get a copy

     If you'd like a copy of this FAQ, just use the Save-As option under the file menu of your browser.  Save as a complete html file to preserve the pictures.

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.html  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 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

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 other would have to be the TurboCNC manual), 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.

 


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 mini-lathe, 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 lathe ($$$), 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 200 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!  Much of that was in building the enclosure and getting the machine leveled just right.

3.3  How much did it cost?

    Dollar cost was on the order of $2000 (US), 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.  For comparison, the smallest CNC lathe (a training lathe similar to the Taig) would have been about $8k in 1997.

    CNC hardware is far cheaper now thanks to the Internet and a large number of motivated hobbyists- I expect that this sort of conversion could be done for about $600 now.  

3.4  Is it finished?

     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.  I've added the ability to thread to the lathe, which was something long missing since I removed the original change gears.  Have a look at the threading article here.

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 got a jogging wheel setup that allows me to move the 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 it's kind of a pseudo-manual operation, lacking the "feel" of a true manual machine..

 


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 80ipm 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", 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...  A little editing and measuring 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" 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: 80 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, any possible 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 35 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 M06 pause command in the program.

  The inserts I use are VNMG331 Hti10 in an SVJCR123 holder (these are Mitsubishi part numbers).  Cutoff blade holds a KGT2L U625 insert, which I always seem to have to hand grind since they're never quite sharp enough out of the box.

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.  If you find the explanation above confusing, check out the more detailed article on the anti-backlash mechanism here.

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.

 4.8  Can it do threading?

  Yes.  By adding a 1 pulse per rev encoder to the spindle and appropriate algorithms to the software, the lathe can cut any reasonable pitch of thread, even fractional and multi-start threads.  Refer to the more detailed article on threading for all the nitty-gritty on how it works, and how you can set it up on your machine.

 


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 didn't have that kind of dough wasn't around to spend.  So I "rolled my own", which has evolved into what is now called TurboCNC.  It really didn't take that much time to write originally, but it has become quite a project in recent days.

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 RS-274 standard.

6.3  How many lines long is it?

     About 80 thousand for version 4.01.  A good portion of this is in the menus and interface handling, not to mention comments.  The "meat" of it is about a third of the code.

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.  I've lost track of how much time I've spent on it, certainly over a thousand hours.  Probably about 20 hours is what it took until it could cut very rudimentary X-Z only parts, the really nifty interpolation, feedrates, and RS-274 standard file handling took somewhat longer to devise.

6.5  How do you do linear interpolation?

    This is the way I originally did it.  The current interpolation algorithm is far 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;
     {Divide 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. Here's what is happening above:

  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.  In the current version I've replaced the delay loop with a routine that reads the 8254 motherboard timer, and the linear interpolation is done by varying the timing ratio between the motors, rather than stepping an invisible point along.

  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 dimensional circular interpolation simply involves incorporating a linear move into the routine below.  By the way, another common question is what's the difference between G02 and G03?  G03 is for bullet noses, G02 is for bottlenecks if you're cutting toward the headstock in G18 mode.  Yes, clockwise looks backward because with +Z away from the headstock and +X coming toward you, +Y is down.

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 G06 parabolic interpolation routine!

6.7  Open loop vs. closed loop control?

     This is the only real weakness 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 $60 registration for TurboCNC I'll send out the source code.  But as before, don't represent my ideas as your own.  If you're planning to go commercial, I'd love to hear about it.  Had an email a few years back from a guy that wanted to use my code to run a CNC router that he built out of plumbing fittings.


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 someday for an extra beefy spindle motor someday - as the machine is sitting in the washer/dryer closet with that big 220V plug staring me in the face every time I use it!  It's just too tempting...

 

THAT'S ALL FOR THE FAQ!

 

 

 

 

© 2001-2023 DAK Engineering.  

All rights reserved.

This page last updated on January 11, 2015 . 

Email: admin@dakeng.com