DAK's TurboCNC 3.0g+ Documentation      January 09, 2002

This file is best viewed in a fixed width font.
Turn on word wrapping if your text viewer requires it.

0.  Legal notice
1.  Overview
2.  Specifications
3.  Setting up your machine
4.  File Format, G code flavor and quirks
5.  Running parts
6.  How it works
7.  Future improvements
8.  G code primer
9.  Suggested resources
10.  Troubleshooting
11.  Ini file format
12.  Contacting the author

------------------------------------------------------
0.  Legal notice:
------------------------------------------------------

  In summary form:

 1.  It's your own damn fault.
 2.  I don't have any money anyway.
 3.  Piracy is stealing.
 4.  And of course, you agree.

Addendum:

  It's possible, although extremely unlikely, that through a poorly understood process known as "tunneling" this product or parts thereof may spontaneously vanish and reappear anywhere within the known universe.  In such circumstances, continued safe operation cannot be guaranteed.

------------------------------------------------------
1.  Overview:
------------------------------------------------------

This program allows a standard PC computer to act as a CNC controller using the parallel ports for I/O.  I originally wrote it to control my converted 7x10 mini-lathe since commercial software was prohibitively expensive at the time (1997).  Since then I have added features to make it more flexible and easy to use at the request of several interested individuals.  It is my hope that other CNC users find it useful in their endeavors.

TurboCNC is shareware.  With a $10 registration fee, the source code will be emailed to you and you can do anything you want with it except redistribution, building an entire CNC empire if you like.  This also gets you on the "preferred priority" list for support issues, rather than the more easy-going "when I get around to it" stack.  This program has no cripples, as I consider that to be unethical.

I imagine you'll want to change the silly messages that show on the startup screen first after you've registered.  Send payment to admin@dakeng.com through PayPal (www.paypal.com), or put a check in the mail to the address in section 12.  Paypal allows you to pay conveniently with a credit card through a secure escrow service.

If you need more assistance with anything feel free to email me.  Contact info is in the last section.  It is assumed that one is familiar with the basic principles of CNC operation.

The program runs in DOS.  This means a full-blown DOS box, or at least a restart of Windows in DOS mode.  Depending on your system you might be able to get away with multi-tasking it, but I doubt it'll be satisfactory.

------------------------------------------------------
2. Specifications:
------------------------------------------------------

Runs in DOS and uses the parallel ports for I/O
Supports 8 axes simultaneously
28 kHz step rate on a 486-66 PC (single axis move)
Regular ipm/ipr feeds, linear, circular, and helical interpolation
Provides step/dir or phase drive outputs (compatible with Drigotti and MaxNC boards)
External trip, limit, and home switch inputs
Outputs to control coolant pumps, spindles and PLC's
Feed overrides on the fly
Turning, slab milling, and peck drilling cycles
20 tool offsets, incremental/absolute inch or metric modes, and subroutines
Uses canonical EIA-274D G code, works with CAM programs such as DeskEngrave, VectorCAM and others
Reads one line at a time from disk for unlimited file sizes
Old school programming, not "bloatware".  Executable is a mere 130k.

Limitations:

Versions 3.0g and above require an 80386 or better with math coprocessor
M60 and M62 subroutines can be 20 layers deep max.
179 character max line length.
12 bit patterns max per direct step axis.
Accuracy suffers if the distance per step is smaller than about 10^-10 units.
No single move can require more than 2 billion steps on any axis.
Rapid moves can be no faster than 2000 ipm or 30 deg/sec.

Known bugs:

If the part takes longer than 24 hours to machine, the displayed execution time will likely be incorrect.

------------------------------------------------------
3.  Setting up your machine
------------------------------------------------------

TurboCNC supports step/direction or phase outputs to drive stepper motors from the parallel ports.  When you run the program for the first time, go to option (4) Machine Setup.  The onscreen prompts will allow you to set up your machine configuration.

Set the number of axes first.  Common configurations are 2 axes for a lathe, 3 axes for a mill.  If you have extra gadgets, such as a rotary table, power quill or tailstock, robot, or what-have you, then by all means include these in the axis count.  Max number of axes in this version is 8, in any mix of angular and linear.

Then under the axis setup option, set the parameters for the parallel port configuration.  Any letter may be used as an axis designator except for the following (M,F,G,I,J,K,#,N,T,R,S).  Standard designations for CNC equipment are X,Y,Z,U,V,W for linear axes; A,B,C for angular.

Step increment is the distance in INCHES or DEGREES that the axis will move with each step.  If Metric mode is set, you can enter the step distance in mm as well.

If you need help figuring the step increment, take the lead of the screw and divide by the steps /rev of your motors.  For example, a typical motor might have 400 steps/rev in half-step mode.  If the leadscrew pitch is 0.0625" (16 TPI), then the step increment is .0625/400 or 0.00015625".  Simple, right?

Select a port to control the axis.  All the step/direction or winding outputs for one axis must be on the same physical port.  LPT1 is usually $0378, although configurations vary.  TurboCNC reports the installed ports and their addresses at startup.  It's a pretty safe bet that on a machine with only one printer port, the address will be $0378.

When entering the winding code information (option 6 under axis setup if option 5 is set to direct windings), enter it so that the axis is travelling in the positive direction as you go down the list.  Up to 12 patterns can be input from the setup screen, 16 if you edit the ini file directly (see section 11 for details).  A sample winding sequence:

1.  1000XXXXXXXX
2.  0100XXXXXXXX
3.  0010XXXXXXXX
4.  0001XXXXXXXX

That would be for a 4 phase unipolar motor running full step on pins 2-5 of the selected port.  At each pattern, a 1 will set a pin HIGH on the port, 0 will pull it LOW, and an X will not affect the state.  With care, H-bridge and other custom home-brew concoctions may be driven by this scheme directly as well.  The pin order goes like this (corresponding to the first pattern in the example above):

Pin state: 1 0 0 0 X X X X X X  X  X
Pin ID:    2 3 4 5 6 7 8 9 1 14 16 17

Pins 1,14,16,17 are driven separately from the other 8 since the computer can only change one byte at a time on the port.  Therefore, keep all the phases for one motor on pins 2-9 or on pins 1,14,16 and 17.  However, step and direction drives can use the pins in any combination.

Motion parameters set the movement envelope for each motor.  Start speed is the fastest step rate that can be applied to your motors "cold" without locking the rotor.  Max speed is the maximum step rate, and acceleration is in "counts per second", per second.  For a typical NEMA 34 double-stack stepper good initial values are:

Min: 500 CPS
Max: 4000 CPS
Accel: 2500 CPS/S

  Keep them all as high as you can for good performance.  The Max speed will never be exceeded, ever.  The Start speed also decides the speed the motor will decelerate to at the end of a move.

  Backlash comp uses a non-accumulating algorithm and is applied at the beginning of a move, not the end.  Here's an example commanding moves from position 1 to 2 and back and what's happening exactly on the machine.

;Axis X starts at 0

G00 X1  ;Preload
G00 X2  ;Start at 1 and move to 2
G00 X1  ;Back to 1

Preload:    ---| * |---
by move to 1:	---|*  |---
Move to 2:			  ---|*  |---
Backlash comp:	      ---|  *|---
Back to 1:    ---|  *|---

Backlash is taken up at inflection points of arcs and circles as well, and on angular axes, if selected.  Units of backlash are inches or degrees as appropriate, and the rate of compensation is the start speed rate for the axis being compensated.  

An option is available on the Manual Machining menu to turn on an indicator for the backlash preload.  An up arrow means the last move was toward the positive direction, down arrow means the last move was toward the negative direction.  A small infinity symbol will be displayed for an axis that does not have backlash set, or has not moved since power-up (indeterminate preload).

The pulse width parameter changes the duration of the step pulse on step/dir axis.  The parameter is set directly in 1 uS increments*.  Setting this too high costs you speed, and setting it too low can make the drive response erratic.  Sorry, but you just have to experiment here since every system is different.  Some equipment combinations are fairly tolerant in this respect, whereas others are not.  On my 486-66, using an IB-104 commercial stepper driver, I can get by with leaving the pulse width at 0.  Using the same computer with the PIC unipolar driver requires a pulse width of 30 uS.

* (Actually, this is a multiple of the motherboard timer, which outputs a 1.11931799704 MHz clock tick that is the basis for the step timing in TurboCNC.  It's close, but not exactly equal to one microsecond.)

Optoelectronic buffers take a lot of time to register a step pulse.  For these, I would start at about 50 to 150 uS.

The usual setting for a step/dir configuration on the step pin is ACTIVE LOW (pulled low for a few uS each step).  Very rarely will the configuration be the opposite, although I have it on good authority that drives based on the UNC5804B IC's require an active high pulse.

The auxiliary I/O functions are optional.  If you enable one of them, you have to specify the port and pin that services that function.  This is mainly for configuring relays and such for coolant and spindle, plasma cutting torches, filament heaters for foam cutters, etc....  Also good for the 'ol "Big Red" panic button, which I strongly recommend that you have.  

This is positive logic, so ground a pin to make it LOW; HIGH is 5V.  I usually just ground the inputs since they tend to float high by themselves.  If you're not sure what runs where, run FKEYBIT.EXE, which is included.  Be sure to use this version only, as it has been re-compiled to read the port the same way that the CNC program does.  Note that Fkeybit is limited to driving 8 outputs (pins 2-9) and reading 8 inputs (pins 10-17) for now.

Note that homing switches are now available, thanks to the programming efforts of Nigel Christianson.  The setup is self-explanatory for the most part.  An axis that is at its home position (eg, switch is closed) displays an asterisk (*) next to the axis designator in the STATUS window.

There is no "babysitter" code that checks that you haven't assigned the same pin to different functions, or named two axes with the same letter, etc...  This allows some fairly creative things to be done, but do be careful.

If the changes are ones that you want to keep, save the ini file with option 8.  Reloading the ini file (option 7) will wipe out any changes you've made in favor of the infomation on disk.  Most changes won't take effect until you save the ini file and reset the ports.

If you have multiple machines or configurations, you can start TurboCNC with a command line parameter that specifies the name of the ini file to be used.  For example, typing:

turbocnc myfile.ini

from the prompt will cause the program to read myfile instead of turbocnc.ini at startup and use it throughout the session for machine configuration editing.  The file can have any name, as long as it has an ini extension and respects DOS's limitation of eight characters in a filename.

 All the pertinent machine configuration info is in the .ini file.  If you really get fouled up, you can delete it entirely and start over.

When you get the machine set up the way you want it (and have saved the ini file), get back to the main menu screen by hitting <ESC> and then press 3, then 1.  This gets you to the jogging panel, where you can try moving things around to see how the perfomance is.  Typically it takes a few tries to get the motion parameters right.

Metric users:  If you set the units to millimeters and save the ini file, the next time you load the program you'll default to metric.

If you've got a good setup going, please send your .ini file to me.  I'm looking to distribute some "stock" setup files for the more common PC controlled mills and lathes out there, such as MAXNC, Drigotti, and some of the Camtronics drives with future versions.  Thanks.

Note that with version 3.0g and up the ini file is "man-readable", meaning that you can conveniently inspect and edit the file with any text editor.  Information pertaining to the ini file format is in section 11 of this manual.

------------------------------------------------------
4.  File Format, G code flavor, and quirks.
------------------------------------------------------

The format of a file for this control is as follows;


{dakcnc3.0}

- put random notes here

{program start}
G/M codes           ;comments
...
M02     ;last program line

Everything between the "{program start}" and the last line is executed by the interpreter.  Above and below this you can enter your own comments.  Comments can also be placed on each line after a semicolon as shown.  The "{dakcnc3.0}" header must be present as the first line of the file.  This guards against cnc files from other controller versions being used indiscriminately, as this flavor of Gcode is different in a few placs.  See the included file SAMPLE.CNC for a demonstration.

Typically I use Notepad or MS-DOS EDIT to write my programs using the shell command from TurboCNC.  With some minor tweaking (generally just adding the special header), output from ACEconverter, VectorCAM, and DeskEngrave is known to work just fine.

NOTES:

- Use only ONE G or M word per line.  

- N codes are not necessary except when using subroutines.  When using subs, put a line number (eg, N010) on both the calling line and the target line.

- Jumping to or from a sub loses the modal Gcode, but not the feeds or anything else.

- G codes and feeds (F words) are modal.  

- Circular and helical interpolations are called using either I and J, or R notation, for any combination of axes (see primer).

- Set off comments with a semicolon, eg:

N010 G00 X0.000   ;comment here  

  Putting a semicolon at the beginning of a line negates the line.

- All moves involving more than one axis are interpolated, even in rapid.  On some mill controls, the Z axis will always retract first before moving X and Y.  On others, a rapid move uses a sort of "loosey-goosey" interpolation.  Not so here!

- There is no "plane" selector, nor a limitation on the number of quadrants in circular or helical interpolation including a full circle.  Eventually, I'll be adding G17, G18, and G19 to the program, but for now the planes are either fixed (for G81-G83) or implicit (for G02, G03).  See the primer section.

- Sometimes a little "rounding error" will be present at the end of a helical or circular interpolation.  If you are off in calculating I and J for the move, the problem is exacerbated.  (Note, in rev 3.00d this was pretty bad, it's better now!  If you have a program that develops a motion error of this type, please let me know.)

- Angular axes are always driven in degrees modulo 360.  For example, if a table is at 10deg and you command it to 350deg, it will go around "the long way".  If you commanded it to -10deg instead, it will zip over to -10deg "the short way" and then report the current position as 350deg.  Commanding a +720deg incremental move will index the table around two full revs, but the coordinate will remain unchanged since it is always set to somewhere between 0 and 360 only.

- No spindle encoder option is available yet, as this is still in development (Yes..., still!).  If you use IPR feeds through a G95 call, use the S word to set the spindle speed in RPM from which the feedrate will be calculated first.

- Metric distances, feeds, etc, are in mm and mm/min or mm/rev as appropriate.

- Dwells are programmed in integer seconds, from one second (G04 #1) on up to hours.

  Exception:  The dwells for G82, G78, and G83 are in milliseconds.

- The feedrate in an interpolated move is based on the actual distance covered by each of the linear axes involved.  If there are none, then the first angular axis on the list is assigned the feedrate (degrees/sec).

- If you hit a limit switch, the machine won't move again until you either disable it, or use Jog mode to back away from the switch.  These are for preventing "going off the rails" only - use the home switches for calibrating the machine.

------------------------------------------------------
5.  Running parts
------------------------------------------------------

Under the manual and auto machining menus there are a variety of options to actually cut metal.  After loading a CNC file (1, 1 from the main menu), use Manual Mode to set the tool position(s) and get everything set up.  Here's how you might use the tool offsets to make a part using multiple tools on a mill:

  Put your first tool in the machine, eg, the one you calibrate the stock position with.  Some machinists I work with use a short starter drill, others a "calibrated" R8 shank with a tapered point on it or an edge finder.  Whatever is comfortable for you.

  Be sure that "TOOL 0" is showing on the status window (second line from the bottom).  Use the R & T keys to change this until it is.

  Now move it down to a reference point on your work, say, the corner of the workpiece or vise using the jogging screen.  Zero the tool at this position by pressing "0" for each axis, or use the "Z" function to zero them all.  Now the master tool is set.  You can make a part using only that one tool, in principle.  Many people do.

  For the second tool, hit "T" to switch to the next tool offset.  It should now show "TOOL 1" in the status window.  You are now in a new coordinate system for tool #1.  Jog around, slap your next tool in the spindle and zero it to the same corner of the vise as the first.  The coordinate offsets of this tool are automatically stored in relation to the master tool - ergo, the "zero" for the master is not lost.  Play with the R and T keys in jog mode and move around to convince yourself of this.

  Now, say you had a starter drill for the master and a regular 3/8" drill for the #1 tool in this example.  Here's how you'd use that in pseudo-code:

...
M06 T0
... move to position and drill starter hole
...
... retract
M06 T1 ; Pause to allow human to change tool
... move to same position and drill thru.
... etc

  This is powerful, because you don't have to worry that one tool is 3" longer than the other when you write the program.

  Once you get all the tools set up, I recommend that you save the offsets using the option under the file menu since it takes a little time at first to get them all in there.  Typically, on a mill you'll only be adjusting the Z coordinate from tool to tool, but on a lathe you need to worry about both Z and X.  Hence, the tool offsets work in every axis for flexibility.

Note: Never put the tool word on a line by itself, as the modal Gcode is still active from the previous line when the offset changes.  Use M00 T1, or M06 T1, or something similar for safety.

You can also manually run G/M codes from the MDI screen.  The input is shadowed to a file MDI.CNC with a timestamp for your convenience.  All the codes are supported in MDI except subroutines.

Now move over to the Automatic Machining option from the main menu.

One-step is for when you're testing out a new program for "sticking points".  You can exit at any time using <ESC>, and keep hitting <ENTER> or <SPACE> to execute the lines one at a time.

Operator moderated production is the usual setting for chucking operations where the operating sequence is one of "load, run, stop, unload, load" by a human operator.  A running count of cycles executed is kept, and can be set at any number to keep track of how many parts you've made, up to 2 billion.  Why so high?  Well for starters, you can set the number to some arbitrary value to begin with, and use it as the serial number for each part as you make it.

Automatic production runs the CNC file continuously for some number of cycles that you specify.  This is great if you've got pallet changing, bar pulling, PLCs, or other robotic hardware to do the loading and unloading for you.  The G codes to run the robots as other axes must be included in the same program with the code to machine the part.  This is the reason why I've included so many axes of motion.

Panic stop and limit switches are wired to the parallel ports as logical inputs.  This is to get around the keyboard buffer in case of an emergency, and also allows for fast polling of the input states.  You have the option, after a panic event, of continuing where you left off or aborting completely.  The former option is good for fixing simple things, like a incompletely tightened tool or something that you noticed just before the "rubber met the road", so to speak.

You can also use <ESC> as a panic stop key, and activate feedrate overrides on the fly using the greater than/less than (<,>) symbols.  Try to hit this on single axis moves only, as you'll cause an interpolation problem if an axis ends up commanded to go faster than its maximum speed on a multi-axis move.

The status window at the left of the screen shows the axis positions, status of coolant and spindle, the current tool and motion modes, feed override, and so on.  Generally, anything important is displayed in white, whereas unimportant or default stuff goes to brown to keep the information manageable.  The position of each axis is updated at the end of a move, "In motion..." will be displayed while things are still moving.  In previous versions you were allowed to have the position updated each step, but I found this costs too much CPU time to keep up with.

------------------------------------------------------
6.  How it works.
------------------------------------------------------

At the software level, motion control can be fairly simple yet tantalizingly complex if one is to do it well.  I invite you to look at the source code if you're interested in nuts and bolts (registered folks only).  It is written in Turbo Pascal 7 and 80386/FPU assembly.

What you'll see is essentially 80% menus, help screens, and handshaking code, and about 20% actual hard-core motion control.  

Moving a single axis is easy.  Once it can be established how many steps you're going and how quickly you want to take each one, then take your first step.  Take the next step a little faster, and the third faster yet according to an acceleration algorithm that allows a linearly increasing velocity with time (the trapezoidal move).  While you're at it, keep track of how many steps it'll take to get back down to the initial speed, and start slowing down when there are exactly that many steps left.  Simple right?

The big boondoggle with performing even that simple trick was getting a precision timer set up to resolve down to microseconds without a lot of overhead.  As does all the competing software, TurboCNC uses the system motherboard timer's 1.1193180 MHz timer tick to pace out the step pulses.  I won't name any names, but I've found my package to output smoother pulse trains than many of the competing programs out there - primarily because this motion algorithm has been heavily optimized in assembly.

Linear interpolation is just several of the single axis moves stacked together, with the accelerations calculated such that each axis stops and starts in sync with the others.  This implementation is quite general, and can support asynchronous moves on any number of axes at the same time.  It would be possible, if fed the right data, to simultaneously cut arcs in two different planes at different feedrates with this motion control unit (MCU), and have each end at a different time.

For now, my circular and helical interpolation algorithm is basically a cop-out from doing any real programming.  A imaginary point is swept through space by a constantly updated vector.  Whenever the tool position is more than one increment away from that point in any axis, it is moved closer by one increment (or step).  The resolution of the sweep is based on the resolution of the axes involved so that little computational overhead is invoked.  Soon, the arcs will be a series short line segments fed into the constant velocity engine with a "sag" parameter for defining the accuracy instead.

The interpreter is simple also.  It parses a line into "chunks" based on the spaces it finds in the line, and then checks the first byte of each chunk.  If it's a recognized letter, then the rest of the chunk should be a number and is assigned to a variable accordingly.  A procedure is called based on the value of the G or M variable.  In rev 3.00f, I've added some preprocessing steps to accept output from CAM programs that scrunch all the letters together or introduce odd spacing by adjusting the line format before it hits the parser.

------------------------------------------------------
7.  Future improvements.
------------------------------------------------------

No project of mine is ever done!  Here is a list of some improvements I'd like to make in rev 4 of this program.  Many of them are user suggestions.

- Spindle encoder support
- Constant lead threading (closed loop to spindle)
- Mouse pull-down menus (especially for files)
- Integrated code editor
- Conversational machining / G code builder
- Toolpath visualization
- Radius compensation
- Jogging wheel encoder input
- Improved hyperlink based help system
- Parabolic and function based f(x) curve generator
- Parameters and looping codes
- Multiple input file flavors (TurboCNC, Fanuc, CNCpro, HPGL, etc..)
- Letter engraving macros or font reading capability
- Anti-crash watchdog
- Machine hours/job logging function
- Command line batch programming
- PET "PLC Emulator Thingy"
- Overtemperature trip
- "Top Five" most recent files/macro commands
- Drive disable outputs
- Look-ahead ramping
- The tool position is stored upon exit and restored when the program is run again.
- Dry-lock verify
- More than three lines visible?
- Limit switch +/- inputs rather than "bang, you're dead" inputs

  One thing I'd like to do is step away from building a Gcode interpreter based on the usual logic (if x then...) and build an AI inference engine to handle the file input.  This would be "trained" against a wide collection of file formats and have some scoring function to develop a reasonable interpretation of the input, even if the specific file format has never been seen before.  An interesting idea....

------------------------------------------------------
8.  G code primer
------------------------------------------------------

A list of the supported G, M, and additional codes and their meanings:

************
G00  Rapid move
************
  Moves to the coordinates specified as fast as possible using interpolation.
Usage: 

G01 X1.2 Y0.3      ;Moves to coordinate (1.2,0.3) at full speed.

************
G01  Interpolated feedrate move
************
  Moves to the coordinates specified using the programmed feedrate (as modified by the override)
Usage: 

G01 X1.2 Y0.3 F3.0   ;Moves to coordinate (1.2,0.3) at 3 units/minute

************
G02  CW circular interpolation
************
  Moves in a CW circular arc with its center set by signed I and J coordinates, to the destination given.
Usage: 

G02 X1.0 Y1.0 I0.0 J0.0 F2.0  ;Arc to (1,1) with center at origin

  That will move from the current point to (1,1) in an arc with its center at (0,0) at 2 units/minute.  I is the center point for the first axis on the line (X in this case) and J is the center point for the second (Y in this case).  If the destination is the same as the origin, a full circle will be described by the tool motion.  I and J are absolute in absolute mode, and are incremental in incremental mode.

  An alternate syntax is to define the radius of the arc and the endpoints only, as follows:

G02 X1.0 Y1.0 R0.25  ;Radius defined arc to (1,1)

  This heads to (1,1) from the current point with an arc of .25 radius.  Using a negative radius chooses the arc greater than 180 degrees that crosses both points, a positive radius takes the arc that is 180 degrees or less.  The program will stop with a warning if you have a radius that is impossible.

  Although you can cut a full circle by specifying the endpoint to be the same as the start point, I don't recommend this since rounding of the values can cause the control to cut the infinitesimally short arc instead.  Program both halves of a full circle.

************
G03  CCW circular interpolation
************
  Similar to G02, but counterclockwise.

************
G04  Dwell
************
  Pauses execution for an integer number of seconds.
Usage: 

G04 #6           ;pauses for 6 seconds

  !!Safety tip:  Don't use G04 and your hands as a tool-changer.  It takes longer than you think...  Use M00 or M06 instead.

************
G53  Change to master coordinates
************
  Puts the machine in the master coordinate system.  This has the same effect as calling T0.

  TurboCNC defaults to the master coordinate system at startup.  Once a system of offsets is created in jog/setup mode, it may be saved using the file menu for later retrieval.

************
G54-G59  Change to coordinate offset 1-6
************
  This is an alias for T1, T2, T3, etc... (G54 is T1).  The coordinates of each axis are reset to align with the origin point in the new offset.  For example, in jog mode:

- Get into T0 (use R and T keys)
- Move to some special point on your machine, and zero all the axes.  This is the master origin.
- Press T to go to tool 1
- Jog to some other point, and zero the axes again.  This is the 1st offset origin. (G54 or T1)
- If you press R to get to master/machine coordinates (T0 or G53), the coordinates in the STATUS window will change to reflect your position relative to the first point again.

  The most common uses for this are tool length adjustment and multiple fixturing on the same table.

************
G70  Inch mode
************
  Sets distance unit to inches.  

************
G71  Millimeter mode
************
  Sets distance unit to mm.

************
G72  CW helical interpolation
************
  Like G02, but allows a third axis to travel linearly as well.
Usage: 

G72 X1.0 Y1.0 Z.125 I0.0 J0.0 F2.0  ; Helical move

  This line moves from the current point to (1,1) in an arc with its center at (0,0) at 2 units/minute.  Meanwhile, Z will move linearly to 0.125.

  The radius form of definition using the R word may be used here as well, just like G02.

************
G73  CCW helical interpolation
************
  Similar to G72, but counterclockwise.

************
G77 Turning/Boring/Milling Cycle
************
  Cuts with multiple passes, infeeding by an amount set by the I word.
Usage: 

G77 Z-1.250 X0.250 I0.050 F5.0  ; Diameter turning cycle

  That cuts to an X coordinate of 0.250, back and forth in Z from current position to -1.250, feeding in 0.050 each pass and cutting at 5 units/min.  The sign of I is important!  If you're turning, I should be +, use a - I for boring (same as change on infeed axis).  Infeed is applied to the second axis on the line - so this code can be used for flycutting/slabmilling or cutting deep blind slots on mills or trimming the edges of stock.  Here's the actual motion sequence for on the above, assuming the tool started at 0,0:

X0.050 slowly
Z-1.250 slowly
X-0.025 slowly
Z0 rapidly
X0.100 slowly
Z-1.250 slowly
... etc

NOTE:  After each pass, the control "backs off" by 1 1/2 times the infeed.  So if you're boring, make sure you have enough clearance for the bar.

Also, if the infeed doesn't divide into an even number of passes, don't worry.  The program's smart enough take a small finishing pass.

The order of the operands defines the motion.  The back-and-forth action will occur from the current position of the first axis on the line to the position specified.  The second axis called out will eventually reach the position specified by feeding in increments of I each pass.

************
G78 Peck Drilling Cycle
************
  Feeds to a position on an axis, incrementally in "pecks" with a full rapid retract.
Usage: 

G78 Z-2.000 I-0.100 F2.0 

  That drills from the current position to Z-2.000 at 2 units/min 0.100 units at 
a time (retracts to original Z each time) .  Sign of I must be the same as the direction of cutting.  If you put in a dwell parameter with the # operator, a dwell in milliseconds will be taken at the "bottom of the hole".  So:

G78 Z-2.000 I-0.100 F2.0 #100

  does the same as the above, with a tenth of a second dwell at the bottom of the hole.  This helps the tool life considerably in some cases.  After each peck and retract, the drill will rapid to 10% of the peck increment before the bottom of the hole before feeding in again.

  Note that this code can be used for "peck turning" plastic on a lathe to keep the chips short.

************
G80  Cancel drill cycle
************
  It's good practice, although not strictly necessary, to put this code after a series of the G81, G82, or G83 drill cycles.  It clears the canned cycle variables from memory.

Usage:

G80 ;Clears canned cycles

  Some CAM programs automatically generate this code after every series of drilled holes.

************
G81  Drill cycle
************
  This is the canonical RS-274D drill cycle.  Drills a hole at a specific XY position, to a depth Z at the current feedrate, and retracts to a release plane "R".  If the release plane is further away from the work than the drill at the start, the control will rapid to the release plane first for maximum clearance.

Usage:

G81 X1 Y1 Z-0.75 F2.0 R0.25

  This line will cause the control to perform the following actions:

- Rapid to R plane if Z is less than 0.25 absolute
- Move the table to the XY position (1,1) specified, holding Z at the point it was before.
- Feed the Z axis to -0.75 at 10ipm.
- Rapid the Z axis to 0.25 (the release plane)

  To drill another hole just like the first, just input the XY position on the next line:

G81 X1.5 Y1.25

  This second hole will be done the exact same way was the first, but at the new position of X=1.5 and Y=1.25.

  If the R plane is between the current Z position and the bottom of the hole, the control will rapid to the R plane after moving XY and before drilling.  If the R plane is "above" where the drill is in Z at the start of G81, the control will rapid to the R plane first before moving XY.  This affords maximum safety without overly compromising speed.

  Note that R is always absolute!  All the other parameters are incremental if incremental mode is set.

  All of the coordinates (XYZR) need to be called out on the first G81.  These will "stay in effect" thereafter until G80 is called.  So, if you have a series of holes that are all to the same depth, you can use this:

G81 X1 Y1 Z-0.75 F2.0 R0.25  ;First hole
G81 X2 Y2
G81 X3 Y2
X2.5
G80  ;Four holes were drilled at (1,1) (2,2) (3,2) and (2.5,2)

  Note that there is presently no plane selector for these cycles - they must be carried out conventionally in XYZ as shown.

************
G82  Drill + Dwell cycle
************
  Similar to G81, but requires a # parameter for the dwell at the bottom of the hole in milliseconds.

Usage:

G82 X0 Y0.5 Z-1 F10 R0.25 #250

  Drills at coord (0,0.5) to a depth of Z=-1 at 10 ipm.  Dwells for a quarter second, and then retracts to Z=0.25.

************
G83  Peck drill cycle
************
  Similar to G81/82, but requires an I parameter for the peck increment when drilling.

Usage:

G82 X0 Y0.5 Z-1 F10 R0.25 I-0.100 #250

  Same as the G82 example above, but the drill will descend at the 10 ipm feedrate in 0.100 inch pecks with a rapid retract to the original Z.  The drill rapids down to 10% of the peck distance above the bottom of the hole before feeding again to minimize "air time".

  The dwell parameter (#) is optional with G83 as well.  The above exampe will dwell a quarter second at the end of each peck.

************
G90  Absolute coordinates
************
  Set coordinates to absolute mode (default).

************
G91  Incremental coordinates
************
  Set coordinates to incremental mode (offsets from current position)

************
G92  Preload of registers/Set machine coordinates
************
  This code sets the position of any or all axes to a specific value.  Use this to reset the position inside a program.  No motion will occur.

Usage:

G92 X0  ;Zeroes X axis

G92 X0 Y0 Z0  ;Zeroes all priniciple axes on a mill

G92 Z1.234  ;Z is now set to 1.234

  You must be in the master coordinate system to use this code.  All of the other offsets (1-20_ follow the master.  Ergo, if the origin in offset 1 is set to be exactly 3" away from the master  origin (in G53 mode), then that relationship is maintained as the master origin moves.

  Use jog mode to setup the coordinate offsets (tool offsets) and save them through the file menu.

************
G94  IPM feedrate
************
  Set feedrate unit to units/min

************
G95  IPR feedrate
************
  Set feedrate unit to units/rev.  Be sure to have set the "S" parameter when calling this function!

G95 S1000 F0.002  ;feed is .002/rev at 1000 rpm
.
.
G01 F0.001 ;Finish pass at .001/rev

************
G97  Program spindle RPM
************
  Set spindle RPM using S word.

Usage:

G97 S1000   ;1000 rpm

  This function is a "placeholder" in the source code.  Registered users can use it as a starting point to program their own spindle control routines into TurboCNC.  Note that if you use inches/rev feedrates by calling G95, you must call G97 or otherwise set the S parameter beforehand with the spindle speed.
 
************
M00  Automatic halt
************
  Halts program until operator presses a key.

************
M01  Optional halt
************
  Same as M00, but can be disabled by the operator. (Option available under machining menu)

************
M02  End of program
************
  Stops execution and cycles.  This must be the last line of the program.

************
M03  Spindle on CW (usual for a lathe or mill)
************
  Turns on spindle.

************
M04  Spindle on CCW
************
  Similar to M03.

************
M05  Spindle off
************
  Turns spindle off to coast to a stop.

************
M06  Tool change
************
  Essentially the same as M00, but with a prompt to tell the user which tool is being requested.  Registered users may program their own, more sophisticated routines for automated tool changes here.

Usage:

M06 T1  ;Prompts for change to tool #1 and changes to tool 1 coord offset.

************
M07  Coolant A on (flood)
************
  Switches on relay A.

************
M08  Coolant B on (mist)
************
  Switches on relay B.

************
M09  Coolants off
************
  Switches off both relay A & B.

************
M13  Spindle CW and coolant A on
************
  Turns the spindle on in the CW direction and activate the "A" coolant.

************
M14  Spindle CCW and coolant A on
************
  Similar to M14.

************
M30  End of program & rewind
************
  Functionally identical to M02.  Hard disks don't need to be "rewound" of course, but paper tapes used to be!  Some CAM programs generate this code instead of M02 at the end of a program, so it's here for compatibility.

************
M48  Restore feed override
************
  After an M49, this brings the feed override back to whatever it was just before the M49 call.

************
M49  Cancel feed override
************
  This resets the feed override to 100% "from the inside".  Use it before entering a critical section of your program that requires an exact feedrate.

************
M60  Jump to subroutine
************
  Jump to line number given and save return address.
Usage: 

N020 M60 #10     ;Jumps to line 10.  Use an N code when calling subs.

************
M62  Return from subroutine
************
  Back to most recent M60 call.
Usage: 

M62  ;Will jump back to line N020 and execute next line in the above example.

See sample.cnc for a simple subroutine example

************
M70  Set PLC handshake output to inactive
************
  Two PLC handshaking lines can be configured in TurboCNC.  These are for telling external logic, such as an automatic toolchanger or what-have-you to do some work.  M70 sets the output handshake line to the inactive state.  This can also be used to control extra solenoids or relays.

************
M71  Set PLC handshake output to active
************
  Similar to M70, M71 sets the output handshake line to the active state.

************
M72  Wait for PLC handshake input to go inactive
************
  When this code is called, the program stops running and waits for the PLC input line (separate from the output line) to go to the inactive state.  This is intended to be used to synchronize the program with external logic that might be loading more stock, or performing some other function.

************
M73  Wait for PLC handshake input to go active
************
  Similar to M72, this pauses until the PLC line goes to the active state.  With either of these two codes, the user can press <ESC> to bypass the paused condition.

************
Code letters:
************

N Line number
F Feedrate
I Interpolation parameter, 1st axis; or infeed parameter
J Interpolation parameter, 2nd axis
K Thread lead parameter (not yet implemented)
T Tool offset
R Arc radius; or release plane
S Spindle speed parameter
D,L,H,Q Future Use
# Timer or subroutine parameter


See sample.cnc for examples of the codes in action.

------------------------------------------------------
9.  Suggested resources
------------------------------------------------------

Resources on CNC abound.  A few of my favorites:

Machinery's Handbook - Industrial Press.  A must-have handbook covering many aspects of machining, CNC, and metallurgy.  A copy of the pertinent info from the RS-274D Gcode standard is in here.

http://groups.yahoo.com/group/CAD_CAM_EDM_DRO   A hobby oriented list group devoted to CNC machines.

alt.machines.cnc   Usenet newsgroup on CNC equipment.  Commercial bent.

http://www.geckodrive.com   Source for stepper and servo drives

http://www.rutex.com  More stepper and servo drives

http://www.seanet.com/~dmauch  Plug and play CNC drives with motors, very well priced.

http://microsystemsgeorgia.com/cnc.htm   Glossary of CNC terms

http://www.cnckits.com  Information on how to setup a hobby CNC system

------------------------------------------------------
10.  Troubleshooting
------------------------------------------------------

If the program does nothing when you try to move, check these things:

- Are the ports set up properly?
- Is the command syntax correct?
- Are you jumping to a sub that does not exist?

If your steppers are losing steps, back off on the max speed and acceleration parameters.  If they vibrate badly or start in reverse sometimes, bump up the start speed until you get clear of the resonance band.  Also check to see if the winding activation sequence is correct, and play with the pulse width parameter.

"Sticky Stepping" is normally caused by a pulsewidth that is too short on a step and direction drive, or noise in the electrical system.  Check the grounds, and shield the logic cables if they are at all lengthy.  Be aware that not all printer connectors have pins 18-25 are ground - some will have pin 18 only or similar.

Also, be sure that you aren't running under Windows, or that a hard-disk caching program isn't running in the background.  EMM386.exe is known to cause some trouble with timing under DOS as well.

If programs refuse to run, check to be sure that you have {dakcnc3.0} as the first line of the file and {program start} just before the first line of Gcode.  Check the program minimal.cnc for an example.  Programs can be written in Notepad or MS-DOS EDIT.

Weird stuff?  RT-errors?  Circle looks non-circular?  If they can be duplicated (eg: every time I load this file and press this, then this, it screws up the same way), then send in your ini file and your tear-filled tale of woe to me at admin@dakeng.com.  I'll do what I can...  Some of you have been quite good at finding problems, and for that I thank you.

------------------------------------------------------
11.  TurboCNC.INI file format
------------------------------------------------------

If you look at the TurboCNC.ini file, you'll see that it has a format not unlike that of a standard Windows ini file.  There are several sections that define each component of the machine by category, and comments are set off with a semicolon.  

Each parameter has a default if it is not read - so the ini file only contains the information necessary to uniquely define your machine.  If you only have three axes, then you'll only see definitions for three axes in the file, not all eight.

The first section is titled [General] and contains the number of axes on the machine, and whether Metric mode will be the default as startup.

[GENERAL]
NumberOfAxes=3   ;Number of axes on machine
Metric=FALSE     ;Will not default to Metric mode on startup

Next each axis is defined in one of two ways, depending on whether it's a step/direction controlled axis or a phase drive axis:

[AXIS1]
Designator=X
StepIncrement= 1.0000000000E-03
IsLinear=TRUE
IsStep/Dir=TRUE
PortAddress=$0378
StepPin=2
IsActiveLow=TRUE
Pulsewidth=50
DirPin=3
LowIsPositive=TRUE
Acceleration= 2.5000000000E+03
StartSpeed= 2.0000000000E+02
MaxSpeed= 1.2000000000E+03
Backlash= 3.0000000000E-03
HomePosition= 0.0000000000E+00
HomeInPositiveDir=TRUE

Most of the above is self-explanatory.  For a phase-drive axis, the step and direction pin information is not written, and IsStep/Dir is set to False.  Here's an example from my own machine:

[AXIS2]
Designator=X
StepIncrement= 5.0000000000E-05
IsLinear=TRUE
IsStep/Dir=FALSE
Phases=8
Phase1=1001XXXXXXXX
Phase2=0001XXXXXXXX
Phase3=0011XXXXXXXX
Phase4=0010XXXXXXXX
Phase5=0110XXXXXXXX
Phase6=0100XXXXXXXX
Phase7=1100XXXXXXXX
Phase8=1000XXXXXXXX
Phase9=XXXXXXXXXXXX
Phase10=XXXXXXXXXXXX
Phase11=XXXXXXXXXXXX
Phase12=XXXXXXXXXXXX
Phase13=XXXXXXXXXXXX
Phase14=XXXXXXXXXXXX
Phase15=XXXXXXXXXXXX
Phase16=XXXXXXXXXXXX
PortAddress=$0378
Acceleration= 2.2500000000E+03
StartSpeed= 9.0000000000E+02
MaxSpeed= 4.0000000000E+03
HomeInPositiveDir=TRUE

Note that all 16 phase patterns are written, even if they are not all used.  This is not strictly necessary, but it makes the computer happier as the file access takes longer if the phase is not found.  Once again, the pin order is from left to right: 2-9, 1, 14, 16, 17.  A 0 is low, 1 is high, and X is "no state change".

Each of the accessory I/O functions is written the same way.  Following are two examples:

[SPINDLE_ON_(OUTPUT)]
Enabled=TRUE
Pin=17
PortAddress=$0378
ActiveHigh=TRUE

[HomeSwitch1]
Enabled=TRUE
Pin=10
PortAddress=$0378
ActiveHigh=TRUE

This should be pretty self-explanatory also.  There are 13 I/O functions in TurboCNC, and each of the headers is spelled as follows:

[SPINDLE_ON_(OUTPUT)]
[SPINDLE_FWD_(OUTPUT)]
[COOLANT_A_ON_(OUTPUT)]
[COOLANT_B_ON_(OUTPUT)]
[PLC_HANDSHAKE_ACTIVE_(OUTPUT)]
[DRIVE_ENABLE_1_(OUTPUT)]
[DRIVE_ENABLE_2_(OUTPUT)]
[DRIVE_ENABLE_3_(OUTPUT)]
[PANIC_STOP_(INPUT)]
[LIMIT_SWITCH_1_(INPUT)]
[LIMIT_SWITCH_2_(INPUT)]
[LIMIT_SWITCH_3_(INPUT)]
[PLC_HANDSHAKE_ACTIVE_(INPUT)]

So to define one of the functions, write the header as above on one line, followed by Enabled=TRUE and the pin/port/state as appropriate.  Remember that pins 2-9 are always output, pins 10,11,12,13,15 are always input, and pins 1,14,16,17 can be either input or output on the parallel port.

I'd have to recommend that the setup be done from within TurboCNC, as the error checking is more robust within the program.  However, those that can't resist tinkering here can have at it!

This format ensures upward compatibility with new versions of the program as they are released.

------------------------------------------------------
12.  Contacting the author
------------------------------------------------------

I try to respond to email pretty quickly on most days.  My email address is dkowalcz@dakeng.com.

Or if you prefer the snail mail route:

Dave Kowalczyk
4904 Glenwood Ave
Everett WA 98203 USA

Registration payments ($10) can be sent via Paypal to admin@dakeng.com, or by check to the address above.

Hope you enjoy using the software!  If there are features you want to see in a future version of this program, don't hesitate to let me know about it.  So far, I think I've put in just about everything people have asked for.