Saturday, October 28, 2017

How to use A4988 stepper motor driver module tutorial

A4988 stepper motor driver module

This driver can be used to easily control a bipolar stepper motor or a uni-polar stepper connected in a bipolar mode. Can output up to 2A per phase (with a heatsink) and works with motor voltages from 8 to 35 volts.

  • Simple step and direction control interface
  • Five different step resolutions: full-step, half-step, quarter-step, eighth-step, and sixteenth-step
  • Adjustable current control lets you set the maximum current output with a potentiometer, which lets you use voltages above your stepper motor’s rated voltage to achieve higher step rates
  • Intelligent chopping control that automatically selects the correct current decay mode (fast decay or slow decay)
  • Over-temperature thermal shutdown, under-voltage lockout, and crossover-current protection
  • Short-to-ground and shorted-load protection

A4988 and Nema17



If you want the code for controlling the A4988 module, visit this post - Library for A4988 stepper motor driver using timer interrupt

Connecting A4988 driver to a microcontroller

Minimal wiring diagram for connecting a microcontroller to an A4988 stepper motor driver
Minimal wiring diagram for connecting a microcontroller to an A4988 stepper motor driver (from Pololu website) - Top view

Motor power connection

Starting from top right side on the A4988 driver we have VMOT and GND pins. Here you connect the power supply for the motor from 8V to 35V capable of delivering the necessary current. Between this two connections it is important to add a capacitor of at least 47uF.

Warning: This carrier board uses low-ESR ceramic capacitors, which makes it susceptible to destructive LC voltage spikes, especially when using power leads longer than a few inches. Under the right conditions, these spikes can exceed the 35 V maximum voltage rating for the A4988 and permanently damage the board, even when the motor supply voltage is as low as 12 V. One way to protect the driver from such spikes is to put a large (at least 47 µF) electrolytic capacitor across motor power (VMOT) and ground somewhere close to the board.
Since this driver uses active current control, you can use higher voltages than the motor's rated voltage. Higher voltage allows for higher speed because the current in the windings can increase faster. Also the lower the motor's inductance the faster it can spin.

Motor output connections

The pins 1A, 1B and 2A and 2B are for connecting the two motor phases - one phase on 1A and 1B and the other one on 2A and 2B pins.
Quote from Pololu webpage:
Warning: Connecting or disconnecting a stepper motor while the driver is powered can destroy the driver. (More generally, rewiring anything while it is powered is asking for trouble.)

To find the phases you can use a multimeter to check for continuity or connect two wires and spin the motor by hand; when there is more resistance against your hand when turning that means you have found a phase.

Logic power connection

The driver requires a logic supply voltage (3 – 5.5 V) to be connected across the VDD and GND pins.

A4988 microcontroller interface pin description


STEP - to move the stepper motor one step this pin must be pulsed HIGH and then LOW. Every pulse must be minimum 1us long.

DIR - this pin sets the direction of rotation. It can be LOW for a direction or HIGH for the other one - left or right. The relation between the pin's state and direction of rotation depends on how the motors windings are connected. If you just want rotation in a single direction, you can tie DIR directly to VCC or GND.

Note that the STEP and DIR pins are not pulled to any particular voltage internally, so you should not leave either of these pins floating in your application.

SLEEP - active LOW. To minimize power consumption when the motor is not in use, this input disables much of the internal circuitry including the output FETs, current regulator, and charge pump. When emerging from Sleep mode, in order to allow the charge pump to stabilize, provide a delay of 1 ms before issuing a Step command. Sleep during long delays, wake up time is 1ms. The 1ms delay is added by the library. This pin can be left floating or preferably connected to VCC if not used with the microcontroller.

RESET - active LOW. The RESET input sets the translator to a predefined Home state, and turns off all of the FET outputs. All STEP inputs are ignored until the RESET input is set to high. The RESET pin is floating and if not connected to the microcontroller it must be tied to VCC to enable the board.

ENABLE - active LOW. This input turns on or off all of the FET outputs. The translator inputs STEP, DIR, and MSx, as well as the internal sequencing logic, all remain active, independent of the ENABLE input state. Use this when the load doesn't need the holding torque. By disabling the outputs when the motor is not in use squeaky high pitched sounds that sometimes appear, can be avoided.

MS1, MS2, MS3 - microstepping pins. This pins are used to set the step mode. If left floating, the driver will be in full step mode.
LOW, LOW, LOW - Full Step (1/1)
HIGH, LOW, LOW - Half Step (1/2)
LOW, HIGH, LOW - Quarter Step (1/4)
HIGH, HIGH, LOW - Eighth Step (1/8)
HIGH, HIGH, HIGH - Sixteenth Step (1/16)

Limiting the current

Using a multimeter and a metallic screwdriver connect one probe of the multimeter to the screwdriver and the other one to GND. While turning the potentiometer you should be able to see the reference voltage on the multimeter. Turning clockwise increases the reference voltage and the current, turning counter-clockwise decreases the Vref and current.
With the motor disconnected and the power on measure the reference voltage of the potentiometer on the A4988 board. Turn the potentiometer until the voltage is very low so when you connect the motor you can increase the current slowly at a safe level.
  • First method - using a multimeter to measure the curent:
Turn off the power to the board and connect the multimeter in series with one of the coil. Put the driver into full-step mode and measure the current running through a single motor coil while adjusting the current limit potentiometer. This should be done with the motor holding a fixed position (i.e. without clocking the STEP input); put STEP to GND by hardware or in software.
Quote from Pololu webpage:
Note that the current you are measuring is only 70% of the actual current limit setting, since both coils are always on and limited to this value in full-step mode, so if you later enable microstepping modes, the current through the coils will be able to exceed this measured full-step current by 40% (1/0.7) on certain steps; please take this into account when using this method to set the current limit. Also, note that you will need to perform this adjustment again if you ever change the logic voltage, Vdd, since the reference voltage that sets the current limit is a function of Vdd.
Do not measure the current at the power input because that will be lower since the input voltage is larger. The voltage across the motor coils will be very low but the current will be higher. So always connect the multimeter in series with the A4988 board and one of the motor coil.
Also, if the supply voltage is very high compared to what the motor needs to achieve the set current, the duty cycle will be very low, which also leads to significant differences between average and RMS currents.

  • Second method - measuring the reference voltage of the potentiometer
The formula is:
Vref = I / 2
Example: for 1.2A Vref =  1.2 / 2, Vref = 0.6 volts.
or
Vref = 8 * Imax * Rcs
Imax - is the desired current
Rcs - is the current sense resistor. This can vary depending on the board. Can be 0.050 Ω, 0.068 Ω, 0.1 Ω, etc. To be sure measure the resistance on the board or read the value. It should be two low value resistors.


Tips:

- Disconnecting the stepper motor while power is on, may lead to the A4988 board destruction.

- If you hear squeaky high pitched noises coming from the stepper motor, first check if the motor voltage is not to low in case of using a battery.

- If the motor was working on a certain high speed and now works only on lower speeds, again check the motor voltage if is not low.

2 comments: