Copyright (C) 1986-2008 by Daniel H. Hudgins, All Rights Reserved.
No part of "This Web Site" (HTML document), including associated files, may be: distributed, sublicensed, transmitted, copied, archived, mirrored, modified, bundled, embedded, sold, given away, rented, loaned, or shared in any form without express written permission in a formal Vendor agreement contract dated and signed in ink obtained directly from Daniel H. Hudgins by registered postal mail. All agreements for permission to distribute expire after a period no greater than one year from the date of the signing of the agreement by Daniel H. Hudgins. See the current "EULA" for information regarding limited copying and storage for the purpose of "Beta Testing" "This Web Site."
To view or use the current version of this Web page you may need to reload or refresh the display of this page by your browser. Just clicking on the browser's [Reload] or [Refresh] icon may not be enough to insure that all of the page's most current contents have been cached and displayed. Some browsers may have additional commands to help display the page's most current contents such as: holding down the [Shift] key and clicking on the [Reload] icon, holding down the [Control] key and clicking on the [Refresh] icon, holding down the [Control] and [Shift] keys and clicking on the [Refresh] icon, pressing the [Control] and [F5] keys, pressing [Control] and the [R] key, or some other combination of keys or clicks. Check to see which commands your HTML browser uses to load the most current page contents into its cache and then to display them onto the screen.
This Web site is dedicated to the thousands of "users" of my programs, those who have helped test my programs over the last 22 or so years, and especially those who shared their experiences with me.
You must read this notice: This is a licensed Web site (HTML document and associated files). You must read and agree to be legally bound in contract by the Terms of Use and conditions given in the End User License Agreement ("EULA"), Legal Notices, Instructions, Warnings, Disclaimers, and all other text in "SECTION: 0" of "This Web Site" (HTML document and associated files) before reading or using any of the information, software programs, and or files, contained in, linked to, and or associated with, "This Web Site" (HTML document and associated files). Any use or "Beta Testing" of "This Web Site" constitutes your acknowledgment of your full agreement with the current End User License Agreement ("EULA") and your decision to have this current license supersede all prior and contemporaneous agreements and understandings. Information and files in "This Web Site" (HTML document and associated files) have been placed here so that long time users of "The Author's" programs DANCAD3D.COM (tm) , DANCAM.EXE (tm) , or DANPLOT.EXE (tm) could help proofread the text of the documentation files or screens displayed, and also help test data files, example files, and or any software programs that might be made available from time to time, to aid "The Author" in finding mistakes, bugs, and other errors, omissions, defects, mistakes, and faults. Everything in "This Web Site" (HTML document and associated files) is "Beta Test", "Beta Code", Experimental, Preliminary, requires proofreading, or is being evaluated for possible revision, and is NOT warranted to be free of defect. To help "The Author" report any bugs, foul-ups, defects, or mistakes that you find, see "SECTION: 8" for instructions. "This Web Site" (HTML document and associated files) and all other files and programs by Daniel H. Hudgins are made available "AS IS" without warranty of any kind express, expressed, or implied. All offers and specifications are subject to change or discontinuation without notice of any kind. Please read "SECTION: 8" of "This Web Site" (HTML document and associated files) before trying to contact "The Author."
SECTION: 7.10 is for some "general" information about CAM, CNC, or NC type automated machine tools, see also the program files in the current distribution of my programs, the other parts of this HTML documentation, and the current On- Line version of this Web site for information more specifically about my programs. Any comparisons of my programs or methods to some others is only given as a vague generality of my opinion and is not intended as a recommendation or reference to any particular products, always make your own evaluations and comparisons before taking any action.
Between the computer that runs the CAM "motion control" software, and the motors that do the actual moving of the tool or work-piece are some electronic driver circuits. Solid state relay circuits can also be used to amplify the computer's signals to control high power devices like the spindle motor, coolant pump, and such. Some electronic circuits may also be used to amplify, or transmit, signals from switches, or sensors, attached to the machine to tell the motion control software that the machine is in a certain state, e.g. at the home point, or has moved beyond its motion limit.
In a commercial CNC machine the electronic circuits that drive the motors may be enclosed in the case with the proprietary computer system. In such a system the manufacture may have selected components to meet certain sales price points, and to differentiate products at different speed, or performance, levels.
If you are using a personal computer with general purpose CAM motion control software that uses step pulse and direction signals from the parallel port, such as one of my CAM programs, you may be able to select any type of stepper or servo motor driver that works with such signals and will meet your performance needs and budget.
The motors used for motion control are of a special type because the rotation of the motor shaft must be precisely matched to the computer's internal calculations, for the desired motor shaft position, at all time. The stepper, or servo, motors do not simply rotate freely, they are made to all rotate synchronized to one another, in the ratio of the slope of the line of movement, and to start and stop precisely and in a completely controlled manner. Generally three or four motors with their associated drive electronics are used with my programs, but more or less can be used under some special conditions.
TTL, logic level, control signals for turning on the AC spindle motor, and such, can be amplified by using a solid state relay, or a mechanical relay driven by a Darlington transistor amplifier and a small power supply. In the usual Hook-up my programs can operate up to four relays when three motors are used, or two relays if four motors are used, by sending signals directly from the computer's parallel port. Other CAM programs may require a special interface card that has relays on the card, or sends signals to an external box that houses the control relays.
Micro switches, optical switches, or various magnetic switches can be used to sense the home position for the machine, as well as out of range "limit" switch points. A typical three axis machine would have three home switches and six limit switches attached when using my CAM programs. When the machine reaches the limit switches a "fatal" error is generally produced and the tool path must be stopped from moving the motors any longer. If you design your tool path's properly you should never have your machine move so as to trigger the limit switches, they are a safety device.
As pertains to my software and perhaps some other similar CAM programs, the motor control circuitry generally has two parts: 1) a counting circuit that counts up or down, and 2) one or more amplifiers that send electrical current to the motor so that the motor follows the counter.
The "step pulse and direction" signals work this way, first the direction signal is set high or low to tell the counter in the motor control circuits whether to count up or down, then a series of "step" pulses is sent to make the motor rotate a given number of degrees. Whether the counter is counting up or down changes the motor direction from clockwise or CW to counterclockwise or CCW rotation. If a motor has 200 steps per 360 degrees then it will take 400 step pulses to make the motor shaft rotate twice. The speed or frequency of the step pulses determines how fast the motor will rotate, within the abilities of the motor. To make a 200 step per 360 degree motor rotate at 60 RPM (Revolutions Per Minute) would require 200 step pulses per second. With a servo motor the number of steps per 360 degrees is generally four times the number of encoder lines, so to make a servo motor with a 1000 line encoder (4000 counts) rotate at 3600 RPM would require 240000 step pulses per second, or 0.24 MHz.
The counter circuit used with stepper motors is generally called a "translator." The translator translates the destination pulse count from the computer to the "phase" signals that go to the motor coils through the amplifiers. With two or four coil stepper motors operating in "full" step mode the counter just counts up to four and then repeats, or for reverse rotation counts down to 1 and then repeats from four, e.g. counting up is 0, 1, 2, 3, 0, 1, 2, 3, and so on, and counting down is 0, 3, 2, 1, 0, 3, 2, 1, and so on. For half step mode the count for up is 0, 1, 2, 3, 4, 5, 6, 7, 0, and the count for down is 0, 7, 6, 5, 4, 3, 2, 1, 0. For micro step mode the same idea is used but more counts are used before the numbers repeat. The stepper motor needs to physically keep in step with the translator's counter for the tool position to be correct. Because the stepper motor has inertia it is possible to switch the motor coils faster than the motor rotor can rotate, therefore the motor will then be said to have "lost steps". It is important that you do not try to run stepper motors too fast, or the parts you will be making may be ruined because the motors got out of synchronization. Unlike servo motors, stepper motors never "catch up" by themselves once they slip out of synchronization. My CAM programs have some motor tests to check that the stepper motors are going at a safe speed, but stepper motors can lose steps randomly due to resonance, over loading, and other problems. It may be best to run stepper motors slower than you think you can get them to go, and to use larger motors than you think you can get away with, in order to have an adequate safety margin.
The counter circuit used for servo motors might be called a destination "pulse counter" or "register" and keeps track of all of the pulses sent from the computer, counting up for CW rotation and down for CCW, without ever overflowing or under- flowing, and does not repeat. Because the servo counter should not ever lose track of the commanded position, i.e. step pulse count, the counter in the servo driver electronics needs to be large enough for travel along the full length of the machine, e.g. if your machine is 36 inches long, your servo motor has 500 line encoders, your servo circuit multiplies the encoder by 4, you have a 5 tpi lead screw, and your motor is connected to the lead screw through a 3:1 timing belt reduction, the servo circuit counter would have to count up to 1,080,000, i.e. 500*4=2000*3=6000*5=30000*36=1080000. The servo motor destination pulse counter would generally have 24 to 32 binary bits to count with and so can hold such large numbers.
A second counter is used in servo circuits to keep track of the encoder pulses, so that the destination counter and the encoder counter can be compared to produce an "error signal" that will go to the DC motor windings through an amplifier and make the motor rotate to "nul out" the position error. The larger the difference between the destination counter and the encoder counter, the larger the error signal will be, and the greater the voltage applied to the motor to force it to correct the error by having the motor rotate back to the commanded position. When the servo electronics are turned on the destination counter and the encoder counter must be set to the same value, or the motor would begin to rotate to remove the difference error. The starting value, i.e. the initialization count, for the servo counters would generally be half of the maximum count to allow the motor to rotate in either direction.
For two or four coil stepper motors two kinds of power amplifiers are used, Uni-polar, and Bi-polar. Uni-polar amplifiers, generally four of them, simply switch the power to the motor coils, generally four coils, on or off. Some Uni-polar motors have the coils all connected together at one end, e.g. a five lead motor, or have two center tapped coils, e.g. a six lead motor, in which case the common lead generally goes to the positive supply, and each of the four coils other end goes to a NPN transistor's collector, with the transistor's emitter going to the motor supply negative. An eight lead stepper motor would generally have four coils with all of the coils' ends brought out as a lead. When using a Bi- polar amplifier the amplifier can supply either positive or negative power. A Bi-polar amplifier generally takes the form of a "H bridge" amplifier, but a "push-pull" or perhaps some other kind of Bi-polar power amplifier might also be used.
Stepper motors are generally operated at three to ten times their rated holding voltage in order to have them run with useful maximum speeds. In order to operate stepper motors at higher voltages than their holding voltage the stepper motor driver power amplifiers must have "current limiting" so as to achieve "constant current" at all speeds, otherwise the motor will burn up when it stops or runs at less than the maximum speed, since in stepper motors the power to the coils is always on in order to hold and keep the rotor from turning when the motor is stopped. Resistors can be used to limit the motor current when the motor is run with voltages higher than the rated holding voltage, also Bi-level voltages can be used, high for running, low for slow speeds, but many modern stepper motor drivers use a "chopper" circuit since a chopper circuit is generally less expensive for commercial circuits and works well. A chopper drive applies rapidly switching power to the motor all the time, even when the motor has stopped rotating, in order to keep the current from rising as the current would if the power were left on, this self limitation with the high frequency switched power works in part because the motor coil is an inductor rather than just a resistor.
The amplifier for running DC brush type servo motors is almost always Bi-polar, since the motor must be easily reversible. The speed control for a DC servo motor comes from the amount of power, usually with no power supplied when the motor is at the correct position while rotating or stopped, and the maximum power being applied when the position error is large, either because the step pulses are coming in to the destination counter quickly, or some force or weight has moved the motor shaft from its correct position and the motor is "fighting" to pull back to the right place (fighting because the destination counter and encoder counter have different counts, producing and error or "difference" signal.) The amount of power applied to the motor can come from a changing voltage feed to the amplifier as in a "linear" amplifier, or the time the amplifier is switched on versus off can be adjusted in "pulse width modulation." Linear amplifiers for servo motors might make the servo motor run smoother and quieter, but cost more to build and purchase. In a pulse width amplifier full power would be applied for say 1 ms then no power would be applied for 3 ms to give and average power about 25%. If the switching frequency of pulse width amplifiers is above 20 KHz there may be less noticeable difference between the linear and pulse width types, since some of the audio vibrations of the motor coils would be ultrasonic. Sometimes other types of AC or "brushless" motors are used as servo motors but they might need more complicated power amplifier circuits. A variation on the Pulse With Modulation idea is to have the servo motor's power amplifier always switch from positive to negative at high frequency, i.e. 4 KHz to 20 KHz, and use the ratio of the time the signal is positive or negative to control the motor's speed and direction, e.g. 60% positive and 40% negative would make the motor go slowly forward, 5% positive and 95% negative would make the motor move rapidly in reverse, and 50% positive and 50% negative would make the motor just about stand still.
You can purchase IC chip devices for operating stepper motors. Some are a single chip that contain both the translator counter and the coil driver power amplifiers. Such IC chips can operate small stepper motors directly from a personal computer's parallel port using its TTL signal outputs. The stepper motor driver on a single IC chip type UCN-5804B, might cost about $10 each. Three such chips, a few small low cost parts, and a power supply could be used to build your own electronics for a motion control CAM controller.
Medium size machine tools can be operated from smaller size stepper motors if you use a timing belt reduction to the lead screws. Smaller stepper motors can usually run at higher RPMs than larger stepper motors, so the relationship between torque and speed may not be proportional. For example a small stepper motor that might give 30 in-oz when run 240 RPM, after going through a 10:1 set of reduction pulleys might give about 300 in-oz at 24 RPM for rotating the machine's lead screw, whereas a larger stepper motor that gives 300 in-oz might run at speeds up to 72 RPM, so the speed for the machine might be about one third for the small motor, rather than about the one tenth that you might expect. The smaller motor might give ten times better resolution, i.e. a smaller distance moved by the tool for each step pulse, which could give a better surface finish. The cost of the driver circuits and power supply to run the smaller motor might be less than what the larger motor would need. So every time you try to double your maximum feed rate you probably might more than double the total cost of the machine, motors, and circuits. The actual speed differences for different size motors, depend on the maximum voltage the motors will be getting, the model of driver circuit used, and many other factors that may need to be determined by experiment.
The actual feed rates used in cutting are generally slower than the maximum feed rate that the machine can move at. Since only the maximum feed rate used during cutting effects the quality of the part being manufactured, you can ask yourself how much money you want to pay to see your tool zoom around through the air. The ratio of time the machine spends cutting is generally much more than the time spent doing rapid movements through the air going to the next cutting point. So speeding up your machine past the maximum cutting freed rate may only increase the number of parts you can make on that machine each week by a few percent.
It is possible to operate more than one machine simultaneously from a single computer, if you wire the step pulse and direction signals in parallel to the inputs of several motor driver circuits. It is also possible to operate several machines at once by wiring several stepper motors in parallel to the output of the driver stepper motor power amplifier circuits, but when stepper motors are wired in parallel to the output of the driver circuits you may need to reduce the maximum speed since the motors can interact. To avoid overloading the computer's TTL outputs a low cost buffer chip might be used to amplify the signals from the parallel port. Wiring the machines in parallel like this can reduce the total circuitry cost since each machine shares some of the circuitry, and only one computer is needed no matter how many machines are used to make copies of the same part.
The motion control electronics you will use between your personal computer and your motion control motors on your automated CAM machine tool do not need to be large or expensive if you can accept running your machine at some slower speeds. If you need more speed there are a wide range of more expensive options from very many manufactures, but since you might pay ten to a hundred times as much to get a machine that only makes two or three times as many parts per week you might just want to build more cheep machines, i.e. three cheep machines may make more parts than one expensive machine.
Stepper motors are special motors that can be operated by CAM programs such as my DANCAM.EXE (tm) or DANPLOT.EXE (tm) in order to move machine tools, plotters, or robots to automatically make things. Unlike other motors that turn when power is applied, stepper motors remain stationary when power is applied, the so called holding torque. In order to make a stepper motor rotate there are three or more, generally four, holding states. When power is switched to the stepper motor's coils such that the motor is locked into adjacent holding positions the rotor in the stepper motor will rotate in the direction in which the power is switched, for instance if the motor has four coils producing adjacent holding positions numbered one through four, if you switch the power from coil one to coil two the motor will rotate one way and if you switch the power back from coil two to coil one the rotor will turn the other way. Stepper motors are made with different numbers of steps per revolution, with 200 being typical. To get 200 steps from only four coils the stepper motors are made with grooved pole pieces inside, such that 50 poles times 4 coils equals 200 steps per revolution. When the motor has one coil for each holding position it is powered with Uni-Polar signals. Uni-Polar drive can be with just one coil at a time, sometimes called wave drive, or with two coils on at the same time to get more torque at the expense of using twice as much power. Some stepper motors are arranged so that the coils produce two locked positions by reversing the polarity to the drive coils, this is called Bi-Polar drive. If some of the motor's coils are on and some off in a particular pattern is can be possible to half step the motor to get twice as many steps per revolution of the shaft, i.e. a 200 per revolution step motor would produce 400 steps per revolution using half step drive current. Stepper motors can also be powered by gradual changes to the power supplied to its coils rather than just switching the power full on or full off, this is called micro stepping and may allow the motors to turn more smoothly and perhaps a little faster, although the absolute positional accuracy may not be much better because the motor's rotor moves off position about one half of a step under load. Between the computers parallel port and the stepper motor there needs to be some control electronics to amplify and adjust the computer's signals to drive the stepper motor. The voltage used to drive the stepper motor is typically four to six times the motor's rated voltage in order to get the stepper motor to turn faster, but the control electronics must limit the current to stay within the motor's ratings. Stepper motors also come in a linear type that moves in a line rather than rotating. My CAM programs can also operate a special type of motor called a servo motor, but in the servo motor the motor position is locked by the complex drive electronics rather than automatically as in the stepper motor by the position of the motor's coils.
Stepper motors come in different sizes, from small to large, with the larger motors generally being stronger for operating heavier or faster machines. When selecting a stepper motor for a machine you should consult the manufacture's specifications, then do your own testing since the software version, computer type and speed, drive electronics, mechanical loading, lubrication, temperature, power supply used, and other things can effect the motor's performance.
Stepper motors may get hot when operating, and so may need a good flow of cool air around them to keep from burning out. Stepper motors may vibrate when operating and so you should make sure the screws and other fasteners do not come loose and make your machine fall apart.
The large blue motor in the right rear is a 72 RPM synchronous AC motor that can also operate as a stepper motor when the proper drive electronics are used.
The smaller blue motor in front has been opened up so you can see what is inside a stepper motor, see also the close up photos below of the inside of the stepper motor.
There are generally eight coils inside a two or four phase stepper motor, they may be wired to make four pairs of coils. The grooves on the poles of each pair of coils is advanced rotationally the distance of one motor step. See the photo of the grooves on the rotor below.
There are generally fifty grooves on the rotor inside a two or four phase stepper motor, when the tops of the grooves are attracted to the four pairs of poles for the coils as the coils are switched on or off (or north or south) in sequence one at a time the rotor and shaft are advanced rotationally the distance of one motor step. Fifty grooves times four coil pairs, or coil states, gives a total of two hundred steps per revolution for the stepper motor.
You should always check the stepper motor's manufacture's ratings for the holding voltage and current. On some stepper motors the values are marked on a label on the back end of the motor. The voltage tells you that you will need a power supply about six times the value on the motor, but you need to adjust the stepper motor drive electronics so that the current rated on the motor is not exceeded, on average, when the motor is stopped or at any speed the motor is being operated at.
On this label you can also see that the motor is rated at 1.8 degrees per step, or 200 steps per revolution.
For operating small stepper motors you might use a single IC chip combination translator driver amplifier such as the UCN-5804B. A heat sink can be soldered to the two center pins on each side to increase the power the chip can withstand. Three or four chips like this one could be used to operate a small machine tool.
To connect to a DC brush type servo motor you generally need six conductors.
The two heavy wires at the bottom of the photo near the front of the motor connect to the servo motor's brushes and power the motor to rotate, clockwise for positive power, and counterclockwise for negative power. Sometimes the two brush terminals will be at the back of the motor rather than the front as on the motor shown here.
The ribbon cable coming from the incremental optical encoder mounted on the rear shaft of the servo motor generally needs four conductors, e.g. positive five volts for supplying the encoder's electronics, the A and B encoder channel signal outputs, and a common ground wire for the signals and five volt supply. Some encoders require external electronics to make the TTL compatible signals, and so may need different wiring.
Inside the incremental encoder are generally one or two LEDs and two photo transistors. There may also be an comparator or amplifier chip to amplify the signals from the photo transistors so that the A and B channel outputs are compatible with TTL logic chip's inputs.
In the photo you can see the bottoms of the two LEDs wired in series with their current limiting resistor. Just behind the small capacitor above the circuit board you can see the outer edge of the encoder disk that is attached to the servo motor's rear shaft and that rotates at up to more that a thousand RPM when the servo motor is in use. The gap between the encoder's disk and the photo transistors needs to be adjusted carefully since you do not want the encoder disk to rub on the photo transistors, or be too far away so that the signal is poor. The encoder disk needs to be very firmly attached to the servo motor's rear shaft so that is does not become loose from vibration and such.
Some older incremental encoders used on servo motors do not have the signal amplifiers inside the encoder housing on the motor and require an external amplifier, so the wires from the encoder that carry the very weak signals need to be shielded and short, preferably less that a foot long. In some of these older encoders the sensor is a photo voltaic cell rather than a photo transistor, so only the LEDs or in very old encoders "grain of wheat" light bulbs are powered. The signal from the photo cell type encoders might only be 0.05 volt, rather than the 3 to 5 volts or so that the TTL compatible type produce.
This is a top view of an incremental optical encoder on the rear shaft of a servo motor. This encoder uses one LED and two photo cells, the rear of the LED can be seen at the left of the photo above the ruled portion of the encoder disk, the two photo cells are below the disk in the black housing.
This is a side view of an incremental optical encoder on the rear shaft of a servo motor. The encoder disk can be seen on the right side of the bushing that holds it to the motor's shaft as a thin black line.
This is a close up view of an incremental optical encoder disk showing the radial lines that produce the incremental counts. Inside the housing over the photo cells are two similarly ruled stationary grids that make a "flash" every time the disk rotates the distance between two of the lines on the encoder disk. The stationary grids are spaced so that the "flashes" reach their maximum at different locations on the rotation of the encoder disk, such that the A channel disk maximum leads the B channel maximum by one fourth the rotational distance between the spacing of two of the radial lines on the encoder disk, i.e. a 90 degree phase delay of the wave form output when the servo motor is rotating. There is a small adjustment on the housing that holds the photo cells that you can move to adjust the phase relationship between the two photo cells, this would be adjusted while the servo motor rotates at a fast constant speed, and you look at the sum of the two wave forms from the A and B channels on an oscilloscope, i.e. you adjust to get the best spacing of the rise and fall of the signals.
A solenoid might be used in place of a motor for applications where the tool just needs to be in two positions up or down, or on or off. Solenoid controlled valves might be used in applications where the flow of liquid or gas would be turned on or off. In the solenoid shown the black dot between the power terminals is a power rectifier going in reverse of the polarity of the power applied in order to dampen the high voltage spike produced when the power is turned off, for the purpose of protecting the solenoid driver electronics from blowing out. The slug in this solenoid requires an external spring to pull it out when the power is off, some other kinds have a built in spring.
In my CAM program DANPLOT.EXE (tm) the Z axis direction signal might be used to turn a solenoid on or off to lower and raise the tool in plotter like applications. To operate the solenoid off of the parallel port you can use a solid state relay or a Darlington transistor amplifier to increase the power.
A solid state relay can be used to amplify the signals output by the computer and switch on or off high current loads. Solid state relays are available for switching AC or DC loads. Solid state relays like the one in the photo are generally mounted on a metal heat sink to carry away the heat generated when the relay is switched on. You might need to use some heat sink grease compound between the solid state relay and the heat sink.
The spindle motor and coolant pumps might be arranged to be turned on or off by solid state relays at different points in the execution of the tool path file by having the auxiliary relay outputs switched on and off by inserting commands or special codes into the tool path file at selected points. Tool path files for use with my CAM programs can have the auxiliary relays switched on or off by selecting different line colors when the tool path file is drawn, i.e. one color turns the relay on and another color turns the relay off.
A solid state relay might also be used to operate a solenoid or solenoid valve from the Z axis direction signal in order to replace the Z axis motor and motor driver with a solid state relay and solenoid or solenoid valve, i.e. for plotters or other special applications. See the description of the solenoid above.
For operation off of the computer's parallel port you will want a solid state relay that is sensitive enough to work with the feeble output of the parallel port, e.g. 3 volts at about 5 milliamperes. If you need more power you might use a TTL buffer chip to amplify the power from the parallel port in order to give a good drive signal for the solid state relay.
Mechanical relays can also be used to switch things on or off while the tool path file executes. For operation from the computer's parallel port mechanical relays need an amplifier to boost the signal in order to drive the coil in the relay.
You might use a Darlington transistor for the amplifier to operate a mechanical relay from the parallel port, as is shown in this photo. You should probably put a power rectifier "backwards" across the coil of the relay to dampen the high voltage spike produced when the power is switched off, and thereby help protect the amplifier transistor.
In applications where the relay would need to switch on and off frequently a solid state relay might be better than a mechanical relay since the mechanical relay might make lots of noise, ozone, EMI/RFI, and sparks when it opens and closes. The ozone made by the sparks might damage your lungs and such if you do not have enough ventilation.
A micro switch can be used as a home switch as is shown here on an X-Y table. The switch mounting should be firm since you do not want the switch to move more than about 0.0005" in order to have the home position repeatable. If your machine needs to have the home position more accurate than 0.0005" you may need to use one micro switch and an optical switch with a radial shutter blade on the motor's shaft.
You can wire up both home and limit micro switches. With my CAM programs you want the home micro switch to activate before the limit switch activates in order to prevent the machine from stopping before the home switch is reached. In the photo you see the two micro switches stacked, the home switch is twisted a little so that it "clicks" a few motor steps before the limit switch "clicks."
An optical switch can be used in applications that are not too dusty, you would not want the switch to become obscured with dust and goo. The optical switch has two sides, one side has an infrared LED and the other side has a photo transistor. If you are not sure which side is which you might use a camcorder to look at the optical switch in a darkened room when power is applied, since the camcorder may be able to see the infrared light and you can see the LED lighting up through the camcorder's electronic view finder.
Some optical switches have an internal amplifier that has TTL compatible output signals, but many do not, so you may need to use a TTL chip such as the 7414 to amplify the signal from the optical switch before the signal is feed back into the computer as a switch signal. Two current limiting resistors are used with the optical switch, about 22K ohm for the photo transistor, and about 390 to 180 ohm for the LED, when a five volt supply is used.
The shutter blade that passes into the optical switch from the traveling part could be pointed to almost a knife edge like the one shown in the photo so that there is not an indefinite quality about the edge, and there is not a flat edge for dust and stuff to build up on and change the trip point of the optical switch.
A regulated power supply should be used with an optical switch, since any fluctuation of the power could change the brightness of the LED or the bias on the photo transistor, and therefore the point at which the shadow of the shutter blade trips the optical switch.
Here an optical switch has been arranged to operate with a rotary shutter in conjunction with a micro switch with the goal to improve the accuracy of the operation of the home switch. The micro switch is set to trip while the optical switch is blocked by the shutter blade, then after the micro switch trips the optical switch trips. The radius of the rotating shutter blade gives a greater motion per motor step to the shutter, than if the shutter was on the moving part of the machine, and therefore works toward making the trip point for the home switch more definite and repeatable.