Configuring Stepper Motor Drivers
A guide to setting up the most commonly available low-cost stepper motor drivers, based on the A4988, DRV8825 or similar micro-stepping motor driver integrated circuits.
Introduction
This guide will describe how to set up the stepper motor driver boards which are supplied with many small CNC machines on the market, such as the CNC 1610 or CNC 3018 models. The driver boards themselves are small PCBs that are designed to plug in to the main controller board, which could be an all-in-one Woodpecker style board or other microcontroller based controller board such as the CNC Shield used as part of the Arduino / CNC Shield Machine Controller project.
Setting up these stepper motor drivers involves two configuration steps, the first being setting up the required micro-stepping and the second being adjusting the motor current limit for the particular motors in use. Neither step is difficult and can be carried out easily with some basic tools and information about the components in your CNC machine. The steps are broadly the same regardless of the driver integrated circuit used, although individual data sheets should be consulted as the calculations and jumper positions do vary between devices. This guide uses two of the most common devices available, the A4988 from Allegro Microsystems and the DRV8825 from Texas Instruments.
Micro-Stepping Configuration
All of the stepper motor driver boards considered here are capable of micro-stepping. This is an electronic technique used to increase the resolution of a stepper motor, allowing a smoother delivery of torque and improved low speed motion. The A4988 driver is capable of up to 1/16 micro-steps and the DRV8825 up to 1/32 micro-steps per full step and the number of micro-steps used is configured via three jumpers located under the stepper motor driver board on the CNC Shield.
Although it might initially seem to be an advantage to increase the resolution of the stepper motor as much as possible, this is not the case in all situations. The full discussion of this is beyond the scope of this guide, suffice it to say that using micro-stepping can result in a loss of torque and might reduce the repeatable accuracy of the machine in some cases, if step pulses are 'lost' for either mechanical or electronic reasons.
The micro-stepping mode can usually be set using three jumpers per stepper driver board. These can be seen highlighted on the photograph of the CNC Shield, noting that the three headers are available for each of the four axes (X, Y, Z and A) that this board supports. Some other controller boards such as the Woodpecker board shown here do not have jumpers to configure the micro-stepping and in this case the micro-stepping is fixed at 1/16 micro-steps by the design of the printed circuit board.
If jumper headers are available then the micro-stepping mode required can be set by placing jumpers in positions M0, M1 or M2. The combination of jumpers required can be determined by looking at the datasheet for the stepper driver being used. For the A4988 stepper motor driver illustrated here, the following table applies:
MS0 | MS1 | MS2 | Microstep Resolution |
---|---|---|---|
L | L | L | Full Step |
H | L | L | 1/2 Step |
L | H | L | 1/4 Step |
H | H | L | 1/8 Step |
H | H | H | 1/16 Step |
Once you have set the jumpers for the micro-stepping mode that you require, you can assemble the stepper driver board into the CNC Shield and then fit the small heatsinks that should have been supplied with your stepper driver board. You can then calculate the number of steps per millimeter for your CNC machine and use this value in the Grbl configuration. If you don't do this, then your machine will not travel the distance that you expect when issued with Gcode commands.
For the CNC 1610 machine used here, the X, Y and Z axis stepper motors have a step angle of 1.8°, the leadscrews used have a lead of 4mm (they are twin start leadscrews with a pitch of 2mm) and the stepper drivers have been set to 1/16 micro-step mode.
$$S_{rev}={360 \over \theta_S}$$ $$S_{rev}={360 \over 1.8}$$ $$S_{rev}=200 \, steps \, rev^{-1}$$where Srev is the number of steps per revolution and θS is the step angle of the stepper motor.
$$S_{mm}={S_{rev} \over {S_{\mu} \times L_{mm}}}$$ $$S_{mm}={200 \over {{1 \over 16} \times 4}}$$ $$S_{mm}=800 \, steps \, mm^{-1}$$where Smm is the number of steps per mm, Sμ is the micro-stepping mode and Lmm is the leadscrew lead in mm.
Setting the Current Limit
Having installed the stepper motor driver boards in the controller board, the current control limit needs to be set to the correct value for the stepper motors that are in use. To do this, you will need to know the current rating per coil (or phase) for the stepper motor that you intend to use. You should be able to find this information from datasheets, on the internet or from the supplier of your stepper motor or CNC machine. The stepper motors used for the CNC 1610 machine used in this guide have a current rating per coil of 1.0A.
The second piece of information that you need in order to set the current control limit is the value of the current sense resistors used on the stepper motor driver board. These resistors vary by the specific driver integrated circuit used and also by the choice of the board's manufacturer, so the best way to know what value is used is to identify the components on your board and read the value printed on them. The current sense resistors are shown on a A4988 stepper motor driver board in the photograph. There will be two such resistors with exactly the same value printed on them.
Current sense resistors have very low values, typically less than 1Ω. On SMD resistors, values less than 1Ω start with the letter 'R', followed by the decimal component of the resistor's value. In this example, 'R100' means the resistor has the value 0.1Ω.
The final piece of information that you need is a formula that relates a reference voltage (Vref) to the current limit (Ilimit) and the current sense resistor (Rsense) for the stepper motor driver integrated circuit that you are using. This can be found in the datasheets for those integrated circuits. For the A4988 driver, the formula is:
$$I_{limit}={V_{ref} \over {8 \times R_{sense}}}$$re-arranging the formula gives:
$$V_{ref}=I_{limit} \times 8 \times R_{sense}$$where Ilimit = 1.0A and Rsense = 0.1Ω,
$$V_{ref}=1.0 \times 8 \times 0.1$$ $$V_{ref}=0.8V$$Note that the calculation for a DRV8825 stepper motor driver is very similar, with the datasheet giving the formula as:
$$I_{limit}={V_{ref} \over {5 \times R_{sense}}}$$re-arranging the formula giving:
$$V_{ref}=I_{limit} \times 5 \times R_{sense}$$Now that we have a value for the reference voltage that will give us the current limit that we require, we can go about setting it on our stepper driver board. To do this, you will need a small screwdriver that will fit into the slot on the variable resistor on your stepper motor board. A slot type screwdriver is recommended as these variable resistors are not designed to be adjusted using a cross-head screwdriver despite their appearance.
It is convenient that the voltage we are trying to measure is actually the one that is on the wiper of the variable resistor, so if we attach the positive lead of the multimeter to the screwdriver it can also be used as a probe. If some mini-hook probes are available for the multimeter then these are ideal, but if not then use whatever you have. The negative lead of the multimeter should be connected to a convenient ground point on the CNC Shield board - many header pins are available for this.
In order to set the reference voltage, ensure that the stepper motor driver boards are plugged in to the CNC Shield but do not connect the stepper motors at this stage. When ready, connect the power supply to your CNC Shield board.
The reference voltage that you previously calculated (in this example 0.8V) can now be carefully set by slowly turning the variable resistor until the correct reading is obtained on the multimeter.
It is important to disconnect the power supply before proceeding as connecting or disconnecting the stepper motors while your driver boards are powered up is very likely to damage them.
The stepper motor drivers have now been fully configured so the stepper motors can now be connected to the CNC Shield (or other) controller board. They can now be tested using some simple Gcode operations on your CNC controller.