CNC Electronics
and Software
CNC Electronics
CNC Mechanical

CNC Mechanical
CNC Projects

CNC Projects
Speaker Building

Speaker Building
Banjo Building

Banjo Building
Guitar Building

Guitar Building

CNC Electronics

The effects of missed steps on a CNC router

When a CNC router using stepper motor "misses steps" the physical reference to zero on the workpiece moves.  Here are some examples.

Normal CircleCircle Missed Steps

These 2" circles are cut .1" deep by cutting .005" at a time (the bit travels around 20 times to cut this).  The left one has square sides as you would expect.  The right one shows that the CNC router is missing steps -- note the slope on the sides caused by the machine "floating" over a little bit on each pass.

On a real object this can manifest itself by giving really poor results.  Here is a chair back that was done for my neighbor to replace a broken one.  Note that the rungs "X" and "Y" are supposed to be the same width.

Chair back missed steps 

Problem and Fix for the Univelop / TB6560 stepper motor driver missing steps

Photo of Univelop TB6560

I purchased the bipolar stepper drivers for my new CNC machine from because I liked that they have a modular design (each axis with its separate driver board).  I got the electronics put together on the workbench and connected to motors and everything seemed to be fine but after I got the machine together, I noticed that it was missing steps in every axis and this was reproducable with exactly the same error and not speed dependent.  After messing with nearly every setting on Mach3 and the computer parallel port, I suspected the driver board.  I probed the step and direction pins on the TB6560 with my oscilloscope and found the following:

Univelop Step and Direction Pulses

The top trace is the step pulse and the bottom is the direction.  Notice that the direction pulse is changing AFTER the step pulse changes.  This causes the motor to step in the WRONG DIRECTION every time there is a direction change.  This adds up quickly!  I looked at the input to the board and saw the following:

Correct Step/Direction Timing

Notice that on the input to the driver board, the step pulse is after the direction pulse by 16uS which is what should be happening.  I probed the output of the P521 optocoupler and found the following:

Univelop optocoupler rise time issue

The top trace is the output (collector) of the P521 optocoupler and the bottom trace is the input (LED).  Note the VERY significant rise time.  I found that the collector is being pulled high with a 100k ohm (SMT0805 / 104) resistor which is WAY too big for this application.  The parallel port breakout has a 330 ohm (SMT0805 / 331) resistor on its output that is in series with a 100 ohm (SMT0805 / 101) resistor which gives 430 ohms total.  With a 5V source and nominal 1.15V across the LED, we have about 9 milliamps which is a bit low for this part (datasheet recommends 16 to 25mA) but probably ok. 

The real issue is that the step and direction lines go through two different types of optocouplers.  The step pulse goes through a high-speed 6N137 (10Mbps rated) optocoupler and the direction pulse goes through a standard type P521 optopcoupler which is 200KHz in the best case (10V supply / high current).  The direction signal is delayed by the rise/fall time of the slow part (5 to 25 microseconds) and the step signal is delayed by the rise/fall time of the fast part (20 to 100 nanoseconds).

THE FIX: I replaced the
100k ohm (SMT0805 / 104) resistor (labelled R18) with a 220 ohm (SMT0805 / 221) resistor, shorted across the 100 ohm (SMT0805 / 101) resistor (labelled R6 ), and changed Mach3 to use 10uS pulses (the motor tuning says 1-5 but you can enter 10 and it will work).  The board now provides the direction change to the TB6560 IC about 5 to 10 uS before the step pulse which isn't optimal (should be the 16+uS output from the parallel port) but functions correctly without missing steps.

SUMMARY: The board design seems ok except for this issue but the vendor/design takes quite a while to respond (I emailed him about this issue but haven't received a response yet).  If you aren't comfortable soldering SMT components then this board isn't for you since in its off-the-shelf state, it WILL MISS STEPS.

How to set up a touch plate for auto-zero of the Z-axis in Mach3

The idea is to use the cutter itself and a soft conductive plate as a switch that triggers the probe input on Mach3.  The touch plate is connected to a parallel port input pin that is pulled up to +5V with a 10k resistor (see part of schematic below for an example) and the ground is connected to an alligator clip.  The ground is clipped onto the cutter bit and the touch plate is held on the work surface.  Clicking the Auto Tool Zero button runs the Visual Basic code that lowers the cutter until it gets a signal from the probe input, sets the Z-axis readout to the thickness of the touch plate (.060" in my case) then raises the cutter to 1 inch above the surface.

For the touch plate, I used .060" thick PCB material.  This is inexpensive and can be gotten from many sources.  I recommend looking on ebay and searching for copper clad board.

Here is a demonstration of the setup in action.


First we set up the input pin for the probe.  We need to have it configured to the proper pin with an active low input since it is normally pulled up to 5VDC. 

Then we need to add the Visual Basic code to the button.  We go to the Operator menu then click on Edit Button Script.  The configurable buttons will now be flashing and we click on the Auto Tool Zero button.  This will bring up an editor that may have a Not Implemented message in it.  Copy the code below into this editor replacing any existing code.  You will want to modify the .060 value to match the thickness of your touch plate.  Save the file (same name) and exit the editor then restart Mach3.  You should now be able to press the Auto Tool Zero button and have the Z-axis lower until the touch plate connection is made.  I suggest that you try touching the alligator clip and plate together the first few times with the Z-axis nohwere near the table to make sure that this is working.

VB Code for Auto Tool Zero Button
Message( "Auto Zeroing..." )
If IsSuchSignal (22) Then
code "G31 Z-3 F20"
While IsMoving()
Call SetDRO( 2, .060 )
code "G1 Z1"
End If

Additional Electronics Added to my DIY CNC Router

Here is a schematic of the additional circuitry that I added.  This started off by wanting to turn the router and vacuum on and off with Mach3.  I got that part connected but then realized that the computer puts the printer port into an unpredictable state when Mach3 isn't running.  It is quite surprising to have the router and vacuum come on after Mach3 is closed.  I then found that Mach3 could output a square wave when it is running that can be used as a safety.   The charge pump circuit only activates the relay when the square wave signal is present at the output pin and it doesn't matter what state the pin is changed to as long as it doesn't oscillate rapidly.   

Here is the parts list for the above schematic.  If you already have 12VDC available, you can eliminate U1 and C4.  If you have 5VDC, you can eliminate D4 and D5 then connect R2 and R5 to 5VDC.  If you're running a HobbyCNC Pro (like I am), I suggest getting the low-current DC power input from the 24VDC fan connection so you don't risk going over the input voltage range of the 12V regulator.

Parts list for CNC Electronics

Description Digikey PN
IRL510PBF N-Ch Mosfet
.1uF Capacitor 50V  399-4264-ND
.01uF Capacitor 100V 399-4147-ND
.001uF Capacitor 100V  399-4144-ND
10k Resistor 1/4W  10KQBK-ND
1Meg Resistor 1/4W 1.0MQBK-ND
BAT41 Schottky Diode  497-2493-1-ND
12A DPDT Relay 5V coil
SL22 5R012 12A Inrush Current Lim.  570-1053-ND
Terminal Blocks .2" Spacing ED2609-ND
     (These are cheap and fit into .1" perfboard spacing)
Alligator Clip for Touch Plate Gnd   314-1034-ND
Description   MPJA PN
25A @ 480VAC Solid State Relay 17155 RL
E-stop Switch  17054 SW