What could be the reasons for a stepper motor stuttering with an A4988 driver?
Ask QuestionAsked 5 days agoActive todayViewed 179 times21
I am using an A4988 Stepper Motor Driver, which is controlled with an STM32F767ZI on a Nucleo 144 board. The stepper motor takes 12 V with a maximum of 350 mA.
When powered, the motor simply flickers and stutters, but moves at a negligible speed.
Here is a circuit diagram of the setup, with voltage readings taking from a multimeter:

The potentiometer has been set correctly.
The same results occur even with two other A4988 drivers.
For reference, here is the code (though I don’t believe this is a software issue):
main.c
#include "./headers/stm32f767xx.h"
#include <stdint.h>
int main(void)
{
initMotor(0); // initialise the motor
initLed(7); // initialise the led
unsigned long a = 0;
while (1)
{
if (a == 50000)
{
toggleLed(7); // this LED flashes a little quicker than twice per second
stepMotor(0); // output a pulse to the driver to step the motor, attached to PA2
a = 0;
}
a++;
}
}
./drivers/led.c
#include "../headers/stm32f767xx.h"
void initLed(int pin)
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN; // enable the GPIOB clock
GPIOB->MODER |= (0x1 << (pin * 2)); // set to output
GPIOB->OTYPER = 0x00; // push-pull mode
GPIOB->ODR = 0x00; // set output register to 0 across all pins
}
void toggleLed(int pin)
{
GPIOB->ODR ^= (0x1 << pin); // toggle the pin
}
./drivers/motor.c
#include "../headers/stm32f767xx.h"
void initMotor(int step_pin)
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; // enable the GPIOA clock
GPIOA->MODER |= (0x1 << (step_pin * 2)); // set to output
GPIOA->OTYPER = 0x00; // push-pull mode
GPIOA->PUPDR |= (0x2 << (step_pin * 2)); // pull down the pin specified
GPIOA->ODR = 0x00; // set output register to 0 across all pins
}
void stepMotor(int step_pin)
{
GPIOA->ODR |= (1 << step_pin); // output to the pin specified
GPIOA->ODR &= ~(1 << step_pin); // reset the output back to 0
}
With this code, I was expecting the motor to take steady and even steps, rather than the backwards-and-forwards stuttering it does.
I would appreciate any suggestions for the direction I should take from here, or any suggestions as to what the issue could be.
After some discussion, I updated my code a little to slow it down, here it is:
(only included the updated files)
main.c
#include "./headers/stm32f767xx.h"
#include <stdint.h>
int main(void)
{
initMotor(0);
initLed(0);
uint32_t a = 0;
while (1)
{
if (a >= 150000)
{
toggleLed(0);
stepMotor(0);
a = 0;
}
a++;
}
}
./drivers/motor.c
#include "../headers/stm32f767xx.h"
void initMotor(int step_pin)
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOGEN;
GPIOG->MODER &= ~(0b11 << (step_pin * 2));
GPIOG->MODER |= (0b01 << (step_pin * 2));
GPIOG->OTYPER &= ~(0b1 << step_pin);
GPIOG->PUPDR |= (0b10 << (step_pin * 2));
GPIOG->ODR &= ~(0b1 << step_pin);
}
void stepMotor(int step_pin)
{
GPIOG->ODR ^= (0b1 << step_pin);
}
stm32stepper-motorstepper-driverShareCiteEditFollowFlagedited 2 days agoasked Apr 5 at 2:05Starman6166 bronze badges New contributor
- one reason is trying to push her too fast and she can’t handle. – tlfong01 Apr 5 at 2:25
- 1Do you have a datasheet for the stepper? The first thing to check would be that the phases of the stepper motor are correctly connected to the A4988 outputs. – gcr Apr 5 at 2:36
- 1Are you sure ‘stepMotor’ function works to send a ~50% duty cycle PWM? – Ernesto Apr 5 at 5:36
- 1@tlfong01 i have slowed it down, and the result is still the same – Starman Apr 5 at 10:40
- 1@gcr i believe the only wiring concern with the motor is that one coil of the motor is connected to a number pair (1A with 1B, 2A with 2B), as outlined in this image (which is what I have done) – Starman Apr 5 at 10:46
- 1@Ernesto nope, it doesn’t. i was under the impression that any change to a high signal sent to the step pin of the A4988 would step the motor. i’ll give this a go – Starman Apr 5 at 10:50
- I see from your schematic that you are using a bipolar stepper, but It is a bit difficult to follow you code to figure out your stepping sequence. It is not important which driver your are using, A4988, L298, 297, L293 etc. You might like to skim my answer to the following Q&A. Using L293D Motor Driver to Control Bipolar Stepping Motor 28BYJ48 – raspberrypi.stackexchange.com/questions/97975/…. You might also follow the AdaFruit or other newbie friendly tutorial and let me know the stepping schemes you are using. – tlfong01 Apr 5 at 11:35
- You may like to refer to the newbie friendly Components 101 tutorial for a simple full step (no micro step) operation description. A4988 Stepper Motor Driver Module Tutorial – Components 101, 2019aug22 components101.com/modules/a4988-stepper-motor-driver-module. / to continue, … – tlfong01 Apr 5 at 12:34
- It is not clear if you have a 2 coil, 4 coils, 4 wires, 5 wires, or 6 wires stepper. If you have a 6 wire bipolar, and if you wrongly select the wires, you might have strange movements. To make very sure you have selected the correct wires, you see that in my referred answer, I actually spent a couple of hours using a multi-meter and a battery and by hand (and later using a 2 pole 5 throw rotary switch) changed the polarity to actually see the motor stepping small steps of 1.8 degrees. To get a thorough understanding, you might like me, experiment DIY change bipolar to unipolar. configuration. – tlfong01 Apr 5 at 12:47
- Let us continue this discussion in chat. – tlfong01 Apr 5 at 13:02
- 1Are /Reset and /Sleep pulled to logic high somehow? – John Birckhead Apr 5 at 13:35
- 1@JohnBirckhead the sleep pin is pulled up, so both reset and sleep are at logic high (which is intentional) – Starman Apr 5 at 13:58
- 1Ok. We have a pull-up on our design. I couldn’t find reference to an internal pull-up in the data sheet. – John Birckhead Apr 5 at 14:06
- 2@user15278978: Check how long your “step” pulse is. The A4988 requires a minimum of 1 microsecond, with some restrictions on rise and fall time. Get an oscilloscope, and see what your “step” pulse really looks like. – JRE Apr 6 at 14:57
- 1@JRE thanks, i’ll have a look at that. i think my biggest confusion currently is whether the step pin is expecting PWM, or i can just set the output of a GPIO pin to high (i have occasionally seen people mention PWM, but have not seen anything about it in the datasheet)? – Starman Apr 6 at 19:34
- 2@user15278978: All it takes is a pulse. One pulse = one step. The pulse has to meet the minimum requirements, though. – JRE Apr 6 at 19:50
- 1@JRE gave that a go, but still not much luck. however, after taking some more readings with a multimeter and experimented with an LED attached to the same pin, it seems that it might actually be a problem originating from the Nucleo-144 board with the STM32 on it. i’ll look into this further and report any updates on this. – Starman Apr 7 at 0:05
- 1it appears the voltage output by the pin is not changing, and is stuck at around 1.6V both while the program is running and when it is paused, despite this pin being pulled down. and weirdly, it seems to run fairly smoothly but with big stutters at certain intervals when i hold the jumper wire in my hand – Starman Apr 7 at 0:28
2 Answers
After many days, I have finally tracked down the causes of the issues.
- Software
I misunderstood the purpose of Pull Up/Pull Down resistors within the MCU. I thought floating pins (which the STEP pin on the A4988 driver is) had to be pulled up/down. However when changing the output of this pin, there is no need to use Pull Up/Pull Down resistors, simply setting the output is sufficient.
You can see the question and answer posted about my software here.
- Power source
Initially, I decided to use a 12V to 5V DC step down converter. This appeared to work at first (in the sense it was providing the correct voltage to the driver), but when I took readings of the voltage between the output pin on the Nucleo-144 and the GND pin on the driver, it gave fixed readings (there was no evidence of the output of the pin changing, despite the program running). Weirdly though, when taking a voltage reading between the GND pin on the Nucleo-144 board and the output pin instead, the voltage changed in the way it had been written to in the software. So, I connected up the 5V and GND pins on the Nucleo-144 to the driver power pins. When taking the reading between the GND pin on the driver and the output pin of the Nucleo-144, it was clear that this voltage issue had now been fixed.
- Setting the potentiometer
Having done a bit of searching around into motor stuttering, I came across this post on an arduino forum. In short, it mentions how the potentiometer being too high or too low can cause motor stuttering. I adjusted this, with the power running, until the motor was stepping nicely (without taking any backwards steps).ShareCiteEditFollowFlaganswered 18 hours agoStarman6166 bronze badges New contributor
- 2Thank you for the feedback. Glad to hear you got it running, and even better that you explained how you got it going. +1 – JRE 17 hours ago
Question
MCU STM32 with stepper motor driver Allegro A4988 are moving a 2 coil, 4 wire, bipolar stepper motor ridiculously slowly, with flickers and stutters. How to fix?



The OP’s original code (See Appendix A, B, and C below)
Answer
Contents
1. The MCU + Driver _ Motor Schematic V0.1
2. The OP’s STM32 C++ Test Code Analysis
1. The MCU + Driver + Motor Schematic v0.1

2. The OP’s STM32 C++ Test Code Analysis
I skimmed the OP’s three short functions and found them more or less OK, though I did not go step by step in detail to detect any bug.
I think I better test the A4899 driver and motor independently off line, without using any STM32 C++ code, but just use a NE555 timer to simulate the step pulses, and jumper wired by hand for inputting signals.
3. Offline (by hand without STM32 code) testing A4899 and motor, using an NE555 timer to simulate step pulses
3.1 Now I am read the A4988 datasheet, checking out the operation and timing requirement, to make sure the timing of the OP’s code is OK.
(2) A4988: DMOS Microstepping Driver with Translator and Overcurrent Protection – Allegro

4. Specification of the OP’s Stepper Motor

5. A4988 and Bipolar Step Motor Test Setup v0.2
5.1 WARNING: Do not connect or disconnect motor when A4988 power is on. Reason: motor coils are inductive devices. Back EMF when switch off coil current might fry A4988.
5.2 This basic test is for full step mode. Connect MS1, MS2, and MS3 to ground. Do not leave them floating, though datasheet says OK to do so.

- Troubleshooting Stepping Motor6.1 I have wired up the stepper motor for testing. I checked the resistance and found them around 3R. If I power them with 12V, current would be 4A, and when disconnecting, might create a back EMF of perhaps a couple of time of 12V or around 30V+. I think to play safe, I should monitor the coil current and start with only 6V.

- I found my two stepping motors good. So I moved on to the driver, and found the answer for the OP’s question here.
(13) My experiments with stepper motor – ScientistNobee, 2015mar12
References
(1) A3988: Quad DMOS Full Bridge PWM Motor Driver Datasheet – Allegro
(2) A4988: DMOS Microstepping Driver with Translator and Overcurrent Protection – Allegro
(4) Control of Stepping Motors A Tutorial – Douglas W. Jones, CS Dept, U Iowa 1995
(5) Stepping Motors Fundamentals AN907 – MicroChip 2004
(8) Stepper motor – NEMA-17 size – 200 steps/rev, 12V 350mA PRODUCT ID: 324 – AdaFruit US$14
(9) AdaFruit XY42STH34-0354A Stepper motor datasheet – AdaFruit
(10) TaoBao HY42DJ33 Stepper Motor
(11) Stepper Motors Tutorial – Appin Knowledge Solutions
(12) Stepper motor vibrating and not turning – Asked 8 months ago Active 7 months ago Viewed 315 times
(13) My experiments with stepper motor – ScientistNobee, 2015mar12
/ to continue, …
Appendices
Appendix A – The OP’s Original Code – main.c
#include "./headers/stm32f767xx.h"
#include <stdint.h>
int main(void)
{
initMotor(0); // initialise the motor
initLed(7); // initialise the led
unsigned long a = 0;
while (1)
{
if (a == 50000)
{
toggleLed(7); // this LED flashes a little quicker than twice per second
stepMotor(0); // output a pulse to the driver to step the motor, attached to PA2
a = 0;
}
a++;
}
}
Appenidx B – The OP’s Original Code – ./drivers/led.c
#include "../headers/stm32f767xx.h"
void initLed(int pin)
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN; // enable the GPIOB clock
GPIOB->MODER |= (0x1 << (pin * 2)); // set to output
GPIOB->OTYPER = 0x00; // push-pull mode
GPIOB->ODR = 0x00; // set output register to 0 across all pins
}
void toggleLed(int pin)
{
GPIOB->ODR ^= (0x1 << pin); // toggle the pin
}
---
Appenidx C – The OP’s Original Code – ./drivers/motor.c
---
#include "../headers/stm32f767xx.h"
void initMotor(int step_pin)
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; // enable the GPIOA clock
GPIOA->MODER |= (0x1 << (step_pin * 2)); // set to output
GPIOA->OTYPER = 0x00; // push-pull mode
GPIOA->PUPDR |= (0x2 << (step_pin * 2)); // pull down the pin specified
GPIOA->ODR = 0x00; // set output register to 0 across all pins
}
void stepMotor(int step_pin)
{
GPIOA->ODR |= (1 << step_pin); // output to the pin specified
GPIOA->ODR &= ~(1 << step_pin); // reset the output back to 0
}
Appendix D – Troubleshsooting the OP’s A4899 Test Code v0.1
I skimmed the OP’s three functions and found them in general more or less OK, although I did not go step by step to detect any bug. I think I better test the A4899 driver and motor independently off line, without using any STM32 C++ code, but just use a NE555 timer to simulate the step pulses, and jumper wired by hand for inputting signals.
1. Main Funtion
1.1 Initialize GPIO pins interfacing motor
1.2 Initialize the status LED pin
1.3 Repeatedly (a) Toggle LED pin, (b) Send one step pulse
##############################################################################
# Appendix A - The OP's Original Code - main.c
#include "./headers/stm32f767xx.h"
#include <stdint.h>
int main(void)
{
initMotor(0); // initialise the motor
initLed(7); // initialise the led
unsigned long a = 0;
while (1)
{
if (a == 50000)
{
toggleLed(7); // this LED flashes a little quicker than twice per second
stepMotor(0); // output a pulse to the driver to step the motor, attached to PA2
a = 0;
}
a++;
}
}
##############################################################################
Appenidx B - The OP's Original Code - ./drivers/led.c
#include "../headers/stm32f767xx.h"
void initLed(int pin)
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN; // enable the GPIOB clock
GPIOB->MODER |= (0x1 << (pin * 2)); // set to output
GPIOB->OTYPER = 0x00; // push-pull mode
GPIOB->ODR = 0x00; // set output register to 0 across all pins
}
void toggleLed(int pin)
{
GPIOB->ODR ^= (0x1 << pin); // toggle the pin
}
###############################################################################
# Appenidx C - The OP's Original Code - ./drivers/motor.c
#include "../headers/stm32f767xx.h"
void initMotor(int step_pin)
{
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; // enable the GPIOA clock
GPIOA->MODER |= (0x1 << (step_pin * 2)); // set to output
GPIOA->OTYPER = 0x00; // push-pull mode
GPIOA->PUPDR |= (0x2 << (step_pin * 2)); // pull down the pin specified
GPIOA->ODR = 0x00; // set output register to 0 across all pins
}
void stepMotor(int step_pin)
{
GPIOA->ODR |= (1 << step_pin); // output to the pin specified
GPIOA->ODR &= ~(1 << step_pin); // reset the output back to 0
}
##############################################################################
Appendix D – A4899 Stepper Motor Driver Module
Description
This product is a breakout board for the Allegro A4988 DMOS Microstepping Driver with Translator and Over Current Protection.
This stepper motor driver allows you to operate bipolar stepper motors in full-, half-, quarter-, eight-, And sixteen-step modes, with an output drive capability of up to 35V and 2A.
The translator is the key to the easy implementation of the a4988.
It suffices to insert an impulse on the step input to operate the motor with a microstep.
There are no phase sequence tables, high frequency control lines, or complex interfaces to program.
The A4988 interface is ideal for applications where a complex microprocessor is unavailable or is overloaded.
Characteristics
Simple step and direction control interface
Five different step resolutions: full step, half step, quarter step, eight step and sixteen step
Adjustable current control allows you to adjust the maximum current output with a potentiometer,
That allows you to use voltages above the rated voltage of your stepper motor to achieve higher stepping rates
Intelligent chopping control that automatically selects the correct current decay mode (fast decay or slow decay)
Overheat thermal shutdown, undervoltage lockout and cross current protection
Protection against ground short circuits and short circuits
Warning
Connecting or disconnecting a stepper motor while the driver is powered can destroy the driver. More generally, rewiring something while it is being supplied with power causes problems.
Appendix E – HYU42DJ33 Steppeer Motor Spec

ShareCiteEditDeleteFlagedited 6 hours agoanswered Apr 6 at 5:28tlfong011,68211 gold badge66 silver badges1111 bronze badges
- 8Again, this is not an answer – reposting the contents of the question with other screenshots and quotes from datasheets is in no way helpful. – awjlogan Apr 6 at 8:52
- 8Please, / no continue, … – Transistor Apr 6 at 10:12
- 8@tlfong01: An answer based on the results of a practical test of the problem would be useful. A play by play description as you experiment is not so useful. 1. Do the experiment. 2. Determine the source of the problem. 3. Describe the cause of the problem and how to solve it in your answer. 4. Add a section at the end of your answer that (succinctly) describes how you found the cause and the solution. – JRE Apr 6 at 10:12
- 6@tlfong01, this is not a high quality answer. I don’t know if you’re aware but there is a discussion on meta about how to handle a user who gives long, rambling, blog-style answers with a load of links and material just copied from other sites. I think you should read it. Try writing some direct answers with < 100 words. – Transistor Apr 6 at 10:18
- 8So what exactly is your answer? What is the reason and solution for the motor stuttering? Write that in a short paragraph instead of this load of copy/paste text. – Sohail Apr 7 at 7:29
- 1Not sure if this is answer or thesis. – Mitu Raj 3 mins ago
===========================================================================================================
Chat record
Q: What could be the reasons for a stepper motor stuttering with an A4988 driver?
I am using an A4988 Stepper Motor Driver, which is controlled with an STM32F767ZI on a Nucleo 144 board. The stepper motor takes 12 V with a maximum of 350 mA. When powered, the motor simply flickers and stutters, but moves at a negligible speed. Here is a circuit diagram of the setup, with volta…stm32stepper-motorstepper-drivertlfong01one reason is trying to push her too fast and she can’t handle. user15278978102@tlfong01 i have slowed it down, and the result is still the same@gcr i believe the only wiring concern with the motor is that one coil of the motor is connected to a number pair (1A with 1B, 2A with 2B), as outlined in this image (which is what I have done)@Ernesto nope, it doesn’t. i was under the impression that any change to a high signal sent to the step pin of the A4988 would step the motor. i’ll give this a go tlfong015528I see from your schematic that you are using a bipolar stepper, but It is a bit difficult to follow you code to figure out your stepping sequence. It is not important which driver your are using, A4988, L298, 297, L293 etc. You might like to skim my answer to the following Q&A. Using L293D Motor Driver to Control Bipolar Stepping Motor 28BYJ48 – raspberrypi.stackexchange.com/questions/97975/…. You might also follow the AdaFruit or other newbie friendly tutorial and let me know the stepping schemes you are using.You may like to refer to the newbie friendly Components 101 tutorial for a simple full step (no micro step) operation description. A4988 Stepper Motor Driver Module Tutorial – Components 101, 2019aug22 components101.com/modules/a4988-stepper-motor-driver-module. / to continue, …It is not clear if you have a 2 coil, 4 coils, 4 wires, 5 wires, or 6 wires stepper. If you have a 6 wire bipolar, and if you wrongly select the wires, you might have strange movements. To make very sure you have selected the correct wires, you see that in my referred answer, I actually spent a couple of hours using a multi-meter and a battery and by hand (and later using a 2 pole 5 throw rotary switch) changed the polarity to actually see the motor stepping small steps of 1.8 degrees. To get a thorough understanding, you might like me, experiment DIY change bipolar to unipolar. configuration.The Components 101 Tutorial is good for newbies, because it recommend the full step simple wiring method. It also give references for L293D, ULN2003, L298N DC motor drivers which have the same architecture of 2 full H-bridges. A4988 has built in translator for the stepping and so user don’t need any phase sequence tables, but then you don’t learn the basic principles of stepping motors.I am sorry I am not helping you to debug your program, but only suggest you to use a lower level stepping driver so you can learn the basic things. But if you do have a strong reason to use A4988, you can let us know the link to the tutorial with well documented full code, then more readers can help debugging. Have a nice project. Cheers. user15278978102Mon 21:43@tlfong01 thanks for the very detailed information. firstly i am wondering what you mean by a ‘lower level stepping driver’. does this mean directly programming it from the main MCU? secondly, what is meant by a ‘built in translator’? does that mean i only have to send a PWM high signal to the step pin in order to step the motor?oh and i am using a stepper motor with 4 wires fyi tlfong015528Mon 22:26(1) Ah, if your stepper motor has only 4 wires, then it is difficult to go wrong. Good.(2) I am confused about your MCU STM32xxx. I guess you are NOT using this STM32, but only using jumper wires by hand, for testing. Please confirm.@user15278978 (3) I am also confused about your “step down” box. Is it a “step down voltage regulator”, like those usually based on LM2596 IC?(4) I also got confused about the “potentiometer”. I hope you are not doing the wrong way of using a potentiometer to step down from 12V to 5V. Please confirm.(5) It would be nice if you can give us a photo, showing the step down thing and the potentiometer.(6) Is your 12V battery strong enough to drive the step motor. Do you have a link to the motor. I hope to confirm if the spec of 350mA is correct.No hurry to reply. It is bed time now here. See you tomorrow or day after tomorrow. Good luck and cheers. 6 hours later… user15278978102Tue 4:29@tlfong01 i am using an STM32 on a nucleo 144 board, with jumper wires. here is an imageand this is an image of the dc-dc 12v to 5v step down converterand no, i am not using the potentiometer on the A4988 driver to step down this voltage, i have simply set the current limit to the motor with itrather than a battery, i am using a 12V dc power supply, which provides up to 4A. i have verified the voltage from this using a multimeter, and it does indeed provide 12Vi really do appreciate your guidance, and hope you have a good rest 12 hours later… tlfong01Tue 16:59Thank you for your clarification and confirmation. I also read your code and found it more or less OK. So now I am writing an answer, suggesting an offline test by hand and a 555 timer. Stay tuned. Cheers. 1 day later… tlfong015528Wed 17:02I am going to resume testing. I have wired up athe motor and found its resistances very low, only 3R, meaning 12V power would take 4A, and if accidentally disconnect when power on, might create huge back EMF and fry my A4966. So I would first test the meter to make sure, then A4966.Your motor’s resistance might be too high and take small current, so motor cannot move smoothly. Please confirm your motor resistance and perhaps also check current at 6V or 12V. Also if your logic power is stepped down from motor power, then when motor coils switching on and off, might induced back EMF flying back the A4988 and cause trouble. I might be over worrying. though. 3 days later… tlfong0155289:41I found my motors good, so I moved on the check the driver. I googled and found this article very good.My experiments with stepper motor – ScientistNobee, 2015mar12
scientistnobee.wordpress.com/…. The last message was posted 7 hours ago.
.END
Categories: Uncategorized