Fads to Obsessions and Beyond...




Free domain for life, exceptional technical support, website transfer

A4988 Bipolar Stepper Motor Driver

The A4988 microstepping bipolar stepper motor driver is used to control a stepper motor with a PIC18F248 microcontroller. The Pololu breakout board is used as the source of the A4988 (easier/cheaper than using the A4988 directly).

The DIY spectrophotometer project requires a means of precisely controlling the angle of a diffraction grating (made from a DVD/CD) in order to produce monochromatic light. This monochromatic light can then be used within the spectrophotometer to perform chemical analysis (e.g. checking nutrient concentrations in water samples from my growing vegetables hydroponically.

Initially, a SN754410 H-Bridge Driver was used in conjunction with a 0.9o degree bipolar stepper motor. This produced encouraging results, however, smaller step sizes than 0.9o degree were desired, as this would improve the possible resolution of the DIY spectrophotometer.

The most obvious method for decreasing the step angle is to purchase a stepper motor with a smaller step angle. 'Typical' stepper motors (i.e. readily available cheaply on ebay or from salvaged components from disused printers etc) tend to have 1.8o degree steps, and since the smaller the step angle the more motor coils are required, small step angle stepper motors are expensive.

Another option is pulse width modulation of the stepper motor via the H-bridge driver to produce 'microstepping'. These microstepping drivers enable smaller step angles to be produced from a stepper motor than that possible solely due to the physical motor windings (by controlling the magnitude of the supplied currents, not just when the currents are applied).

One disadvantage of microstepping is that the torque available from the stepper motor is decreased. However, since the DIY spectrophotometer only requires the angular positioning of a diffraction grating weighing a few grams, motor torque is not a factor, and the finer resolution steps possible via microstepping are a major advantage.

Additionally, the A4988 has a built-in stepper motor translator that eliminates the need for implementing phase sequence tables and other stepper motor control functions. This means only a single pulse input to a single pin is required to operate the stepper motor. Similarly, motor direction and microstepping mode only require simple high/low logic inputs, eliminating the need for any complex microcontroller interface code. This is an advantage of the A4988 over a solution based around a SN754410 H-Bridge Driver for example, irrespective of the ability to produce microstepping.

Other features of the A4988 from the datasheet:

    • Thermal shutdown circuitry
    • Short-to-ground protection
    • Shorted load protection
    • Automatic current decay mode detection/selection
    • Five selectable step modes: full to sixteenth steps

The schematic for the A4988 Pololu breakout board with connections to the PIC18F248 is given in the Schematics Section below. The ancillary circuitry for the PIC18F248 also includes connection via RS232 to a PC (enables PC control of the A4988).

Power Supply

A typical "wall-wart" power-supply is used (a surplus laptop charger in this case) in conjunction with a voltage regulator (LM317T) to provide the regulated 5V required by the PIC microcontroller.

The Pololu A4988 breakout board also requires a 8-35V supply for the stepper motor. For the purposes of breadboard testing, a 12V supply was obtained from a converted ATX-PSU.

Firmware/Software

The A4988 has built-in stepper motor translator, which means only a single pulse input to a single pin is required to operate the stepper motor. Similarly, motor direction and microstepping mode only require simple high/low logic inputs, eliminating the need for any complex microcontroller interface code.

The Testing/Experimental Results Section details the simple firmware (written in CSS C code) required to enable control of a stepper motor (i.e., step speed, step direction, stop/go).

Note: Image loading can be slow depending on server load.

  • A4988 Basic SchematicA4988 Basic Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    A4988 Basic Schematic

This project did not require a PCB.

The construction was done using prototyping board. See the photographs and schematic diagram sections.

Qty Schematic Part-Reference Value Notes/Datasheet
Resistors
3R110K1/4W, 10% 
Diodes
1D11N4002
Integrated Circuits
1U1PIC18F248PIC microcontroller datasheet
1U27805Linear Voltage Regulator  datasheet
1U3A4988Bipolar Stepper Motor Driver datasheet
1U4MAX232ERS232 Driver/Receiver datasheet
Capacitors
2C1,C222pFceramic disk
1C30.33uFaluminium or tantalum electrolytic
1C40.1uFaluminium or tantalum electrolytic
5C5-C91uFaluminium or tantalum electrolytic
2C1010uFaluminium or tantalum electrolytic
Miscellaneous
1J1CONN-H55-pin connector for ICSP
1P1CONN9-pin connector for RS232
1SW1SW-SPDT 
1X110MHzCrystal Oscillator
1Z1MotorBipolar Stepper Motor
Description Downloads
A4988 - Bill of Materials Text File Download

The first step is testing the basic connections of the A4988 to power supply, the stepper motor and the control signals. There is a 'getting started guide' produced by Pololu to assist with this (1).

The 'calibration' of the A4988 (i.e. setting the current adjust potentiometer for ~0.7*stepper motor coil rating) is important (not just to protect the IC/motor), but for the operation of the microstepping modes. If the current limit is not set low enough, current limiting is not performed by the A4988 and consequently the intermediate current levels to enable microstepping to be performed, will not occur.

For the particular A4988 breakout board used (from a Hongkong Ebay supplier) the current adjust potentiometer had a very limited range (i.e less than a quarter turn from 'full on' to 'full off'). This made current adjustment very difficult (i.e. 'fiddly'). Further, when in A4988 current limiting, the stepper motor being used could be heard buzzing and 'whining'. Instead of the recommended ~0.7*stepper motor coil rating, I decreased the current limit until the motor 'buzzing' stopped.

After this initial testing/setup, connection of the microcontroller is straight forward (refer to the Schematic Diagram and the microcontroller code). The initial code simply enabled stepper motor control via PC (RS232 connection) to stop/start the stepper motor, change motor direction and motor speed. Microstepping mode was selected 'manually' by connecting A4988 pins MS1, MS2 and MS3 to logic high and low (5V and ground respectively) with wire connectors.

The Photographs Section shows how a printed diagram with 0.9o degree markings was used to visually verify the angular movement of the stepper motor in relation to applied number of steps and microstepping mode.

PIC Microcontroller Interface Code

The following code example shows the simple interface required to control the A4988 and connected stepper motor. The code enables control of stepper motor direction and speed via a connected PC (RS232 connection).


#include 
#define A4988_StepPin   PIN_B4
#define A4988_DirPin    PIN_B3
#define A4988_PulseTime 1
// step pulse width in millisec, min Ta=Tb=1us from datasheet

void pulse_A4988_stepPin() {
   output_high(A4988_StepPin);
   delay_ms(A4988_PulseTime); //remain in high state
   output_low(A4988_StepPin);
   delay_ms(A4988_PulseTime); //remain in low state
   //datasheet min Tb=1us, so this last delay_ms probably not needed, as C code
   //overhead giving sufficient time for this before any next function call
}

void main() {
   char recChar;  //recieved character from serial port
   int stepSpeed; 
   int stepperOperate_flag; 

   output_low(A4988_StepPin); //initialise A4988
   output_low(A4988_DirPin); //arbitarily = '[' direction
   stepSpeed = 100;
   stepperOperate_flag = 0;
   
   do {
      if (kbhit()) {
         recChar = getc();
         switch (recChar) {
            case '-' : stepSpeed = stepSpeed + 10; //slower (more time between steps)
                       printf("speed = %u\r\n",stepSpeed);
                       break;
            case '+' : stepSpeed = stepSpeed - 10; //faster (less time between steps)
                       if (stepSpeed<10) {stepSpeed=10;}
                       printf("speed = %u\r\n",stepSpeed);
                       break;
            case 'g' : //toggle stepper motor operation
            case 'G' : if (stepperOperate_flag==1) {
                          stepperOperate_flag = 0;
                       } else {
                          stepperOperate_flag = 1;
                       }
            case '[' : output_low(A4988_DirPin); break;
            case ']' : output_high(A4988_DirPin); break;
            case 's' :
            case 'S' : pulse_A4988_stepPin(); //do a single step
                       break;                  
         }     
      }
      if (stepperOperate_flag==1) {
         delay_ms(stepSpeed);
         pulse_A4988_stepPin();
      }
   } while (TRUE);   
}
			

Downloads

Description Downloads
A4988 header file: CCS C Source Code Download
Example PIC code with PIC18F248/PC serial interface: CCS C Source Code Download
Hex Code Download

The use of the Pololu breakout board for the A4988 makes the use of the component relatively straight forward. The A4988 itself has thermal overload shutdown circuity and short to ground protection, so is relatively 'forgiving' of mistakes. Obviously, double check polarity of power connections etc.

The 'getting started guide' produced by Pololu for the A4988 (1) lists a couple of "gotcha's" which involve checking if the specific breakout board has a A4983 or a A4988 (the A4983 pin MS1 needs a pull-up resistor) and the labelling/connection of stepper motor coils. If you are using a salvaged stepper motor (i.e unknown windings) some information is given at the end of this section to help in identifying motor coil connections.

The couple of other potential "gotcha's" include:

  • The A4988 load supply voltage range (i.e stepper motor supply) is minimum 8V to maximum 35V. Connecting the A4988 motor supply to 5V logic supply will not work.
  • If the A4988 current limit is not set low enough to actually engage current limiting of the stepper motor, microstepping will not be performed by the A4988 (i.e. you need to set the potentiometer on the A4988 breakout board appropriately for the stepper motor being used).

Determining Stepper Motor Type

The following information is copied from National Instruments (2).

Some stepper motors have a motor case ground that can be tied to the ground of the system. It is usually a black wire, and it will add one additional wire to the overall count (4 coil wires + 1 casing ground = 5 wires total).

If there are four coil wires from the stepper motor, using a multimeter:

    • Each of the two phases should have the same resistance when measured with a multimeter. When measuring the resistance across one wire from each of the two phases, the resistance should be infinite because the circuit is open. Locate the two pairs of wires that represent the two phases; both pairs of wires will have similar internal resistance.
    • Connect each phase to the driver and ignore the polarity (+ / -), for now. You have a 50 percent chance of guessing right.
    • Send a command to move the motor. If the motor rotates in the wrong direction, then switch either phase A and A- or B and B- (effectively reversing directions).

If there are six coil wires, then each phase has a center tap wire: The center tap wire should have half the internal resistance of the full phase. The easiest option is to use a multimeter to find the two pairs of wires that have the maximum resistance. Connect each phase to the driver, and ignore the polarity (+ / -) for now. You have a 50 percent chance of guessing right. The motor should rotate, and if it is in the opposite direction, then switch either phase A and A- or B and B- (effectively reversing directions).

If there are eight coil wires, then it is highly recommended you find the exact pinout for the motor. The eight wires represent four pairs of wires, and each pair has the same resistance. It is not easy to find what two pairs represent phase A and phase B without dismantling the motor.

Comments/Questions

No comments yet.

Add Comment/Question

Only Logged-In Members can add comments

"If we could sell our experiences for what they cost us, we'd all be millionaires".

Please donate any amount to help with hosting this web site.

If you subscribe (only $2/annum) you can view the site without advertisements and get emails abouts updates etc.

X

Sorry!

Only logged-in users with correct Membership Level can download.


Membership starts at only $2, so join now!