![]() |
PSMD Triple Axis Stepper Controller |
The gift stimulated me to learn about stepper motors and drivers, as well as ultimately to put together a functional device which makes use of both. While at the beginning I was shying away from 3D printing, in the end I've migrated in that direction given the wealth of information available on the subject. This post is not about a 3D printer, but rather about the motion systems used in a 3D printer, or in any CNC machine for that matter (milling machine, laser engraver, etc).

All stepper motor drivers operate in current limiting mode. This means that they turn off voltage when a maximum current has been reached. The stepper motors that I am using for the x-axis and y-axis positioning are rated for 4V. Yet they are being driven by a computer power supply outputting 12V. If the 12V remains applied for the duration of a step, the motor would get too hot or could have windings burn out. The A4988 and other similar drivers sense the current through a resistor and limit the duty cycle (amount of time) that the voltage is applied to the motor through an H-bridge, effectively limiting the average current seen by the motor. The details are a little more complicated:
"Each full-bridge is controlled by a fixed off-time PWM current control circuit that limits the load current to a desired value, ITRIP . Initially, a diagonal pair of source and sink FET outputs are enabled and current flows through the motor winding and the current sense resistor, Rsense. When the voltage across Rsense equals the DAC output voltage, the current sense comparator resets the PWM latch. The latch then turns off the appropriate source driver and initiates a fixed off time decay mode." See the A4988 datasheet here for more details.

All the stepper drivers which I have are controlled by three digital TTL level pins. One controls whether the stepper is enabled or disabled. The second controls the direction of spin of the stepper. The third is a step pin, which initiates a step when it is pulsed high (or maybe when it drops low again... I'm not sure). A simple function to "step" a stepper has the following form:
void takeSingleStep(int stepPin)
{
digitalWrite(stepPin, LOW);
delayMicroseconds(2);
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
}
When called, this function pulses the step pin low, then high, then low again. I found that the second delay (currently set at 1000 us = 1ms) is important; if that delay is too small then the stepper doesn't have time to execute multiple steps sequentially and it makes weird noises and moves erratically.
A simple function which turns on or off the stepper motors is shown below.
void enableStepperXYZ(int isEnabled, int enablePin)
{
if(isEnabled)
digitalWrite(enablePin, LOW); // enable HIGH = stepper driver OFF
else
digitalWrite(enablePin, HIGH); // enable HIGH = stepper driver OFF
delayMicroseconds(2);
}
Two simple set of functions which change the direction of rotation are shown below. I found that one way did not work for the v3.3 driver; they are labelled appropriately.
The following function worked for only the PSMD and is an absolute function: it sets the direction either clockwise or counterclockwise.
void setCurrentDirection(boolean dir, int dirPin)
{
if(dir == false)
digitalWrite(dirPin, LOW);
else
digitalWrite(dirPin, HIGH);
delayMicroseconds(1);
}
The following two functions worked for both boards and are relative functions: they set the direction to be opposite the previous direction.
boolean currentDirectionZ = true;
void setCurrentDirectionZ(boolean dir, int dirPin)
{
if(dir == false)
digitalWrite(dirPin, LOW);
else
digitalWrite(dirPin, HIGH);
currentDirectionZ = dir;
delayMicroseconds(1);
}
void changeDirectionZ()
{
setCurrentDirectionZ(!currentDirectionZ, dirPin);
}
Besides the step, enable, and direction pins, there are other pins on the A4988 which are important, but the PDMS board takes care of most of them for you. For example, the reset and the sleep pins are both pulled high, effectively making them unusable but so you do not need to worry about them. The board has three mini-switches attached to MS1, MS2, and MS3, which allow you to easily set the stepping mode (full, 1/2, 1/4, 1/8 or 1/16).
![]() |
MakerBot v3.3 Stepper Driver |
.jpg)
I used the v3.3 board with 42BYGHW-811 Wantan stepper motors, which are rated to a higher current of 2.5A. The Rsense resistors are 0.25 Ohm for this board, so with a rated current of Itrip = 2.5A, we can calculate the value of Vref to set for the v3.3 board as 5V. The maximum permissible for the logic of the A3977 circuits is 4V according to the datasheet, so I set Vref = 4.0V.

![]() |
v3.3 Cable Ribbon Pinout |
![]() |
PSMD Cable Ribbon Pinout |