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
Only Logged-In Members can add comments