We are Apogeeweb Semiconductor Electronic


Home  Product Technical Articles   How to Design A4988 Stepper Motor Driver Based on STM32?

How to Design A4988 Stepper Motor Driver Based on STM32?

Author: Iggy Date: 22 Feb 2021  34

Nowadays, production activities are concerned with automation, labor saving and high efficiency. And steppers are widely used in some occasions where flexible control is needed because they can adapt to the requirements of high efficiency and labor saving in production.

In this post, we will introduce how to design a miniature stepper motor controller using STM32F103T8U6 of STM32 series and A4988 as the main modules.

In addition, we will also introduce you how to use this stepper controller in order to achieve the function of closed-loop precise control of the stepping angle of the miniature stepper motor. Further, we will also analyze in depth the working principle of A4988 as well as the micro stepper motor speed control and stepping angle precise control strategy from various aspects.


1 Features and working principle of A4988

1.1 Features of A4988

1.2 Working principle of A4988

1.3 A4988 logic control strategy

2 Controller circuit design

2.1 Hardware circuit design

2.2 Functional design

3 Software design

3.1 Serial communication command design

3.2 Controller control strategy

4 Conclusion

Component Datasheet


1 Features and working principle of A4988

1.1 Features of A4988

A4988 is a complete micro-stepping motor driver with built-in converter for easy operation. This product can operate bipolar stepping motors in full, half, 1/4, 1/8 and 1/16 stepping modes, and the output drive performance can reach 35V and ±2A. The A4988 includes a fixed off-time current regulator that can operate in slow or mixed decay mode. The converter is the key to easy implementation of A4988. Just input a pulse in the "step" input to drive the motor to generate microsteps. No need for phase sequence table, high frequency control line or complicated interface programming. The A4988 interface is very suitable for applications where complex microprocessors are unavailable or overloaded.

During micro-step operation, the chopper control in A4988 can automatically select the current decay mode (slow or mixed). In the mixed decay mode, the device is initially set to decay quickly during part of the fixed downtime, and then slowly decay during the rest of the downtime. The mixed decay current control scheme can reduce audible motor noise, increase step accuracy and reduce power consumption. Provide internal synchronous rectification control circuit to improve power consumption during pulse width modulation (PWM) operation. Internal circuit protection includes: thermal shutdown with hysteresis, under-voltage lockout (UVLO) and cross-current protection, no special power-on sequencing is required.

1.2 Working principle of A4988

To better analyze the working principle of A4988, let us first analyze the internal structure of A4988 in detail. Figure 1 shows the A4988's internal structure diagram and typical external circuit connection diagram.

A4988 internal function modules diagram

Figure 1. A4988 internal function modules diagram

As shown in Figure 1, A4988 has a translator, which is mainly responsible for the information interaction between the microcontroller and the drive circuit.

The DA signal can be generated by the compiler, and the comparator assists the PWM latch to repair the attenuation signal. And, the compiler can generate logic level control logic controllers. Then, the logic controller cooperates with the current regulator and the N-type MOS tube driving voltage to drive the two full-bridge circuits together.

The marked capacitor in the circuit must be strictly the same as that given in the technical document. Rosc mainly changes and repairs the attenuation mode. Connecting to VDD automatically repairs the attenuation, and connecting to GND, the current attenuation is set to increase or decrease the current and repair at the same time.

SENSE1 and SENSE2 detect the drive output voltage, in fact, it detects the output current in real time, and the current regulator adjusts the output current signal to form a closed loop control. Therefore, the resistor connected to the SENSE1 and SENSE2 pins is very critical. Generally, the resistance of this resistor is about a few tenths of an ohm.

1.3 A4988 logic control strategy

The A4988 has simple control logic and is mainly divided into the following control modes: sleep mode, forward and reverse mode, reset mode, enable mode, subdivision mode, etc.

(1) Sleep mode: Set the Sleep pin level to 0, enter the sleep mode, and the driver outputs standby mode; Set the Sleep pin to 1, the driver is in normal working state;

(2) Forward and reverse mode: Set the DIR pin to 0 or 1 in the forward mode and 1 or 0 in the reverse mode;

(3) Reset mode: It is easy to consume energy in the reset mode, and the impact current generated is relatively large. Set the RESET pin directly to 1, and reset the RESET pin to 0 when the system is not affected. Once the driver chip is reset, the system will return to the original A4988 I/O port control state;

(4) Enable mode: The enable mode controls whether the system starts to work, ENBALBE pin is set to 0 to start working, and to 1 to stop working;

(5) Subdivision mode: The subdivision coefficient is controlled by MS1, MS2, and MS3. A4988 is subdivided into 1/16 subdivision as the smallest. By calculating the angle value, the minimum subdivision angle can be obtained as 1/16 of the full step angle.

A4988 drive logic control is shown in Table 1.

a4988 logic control

2 Controller circuit design

According to the working principle of the A4988 chip, the controller circuit is mainly divided into the upper computer serial port module, the STM32 minimum system board module and the A4988 micro stepper motor drive module. Receive the control instruction of the upper computer through the STM32F103T8 microcontroller, and execute the stepping motor control operation after identification and analysis. The overall design block diagram of the internal stepping motor drive controller is shown in Figure 2.

Stepper motor drive controller block diagram

Figure 2. Stepper motor drive controller block diagram

2.1 Hardware circuit design

(1) Serial communication module: Mainly responsible for the communication between the upper computer and the lower computer. The upper computer sends corresponding functional instructions to the lower computer through the serial communication module, and the lower computer executes the instructions of the upper computer and controls the A4988 driver module to drive the stepper motor. The hardware circuit design is shown as in Fig. 3.

Serial communication module

Figure 3. Serial communication module

(2) STM32 controller module: the main control module of the micro stepper motor controller, which receives instructions from the upper computer and executes stepper motor control instructions. This module mainly controls stepper motor subdivision operation, speed control, and rotation angle control. The STM32 control module is shown in Figure 4.

STM32 controller module

Figure 4. STM32 controller module

(3) A4988 micro stepping motor driver module: as shown in Figure 5, it mainly controls and drives the micro stepping motor and performs various driving operations of the main controller.

A4988 stepper motor driver

Figure 5. A4988 stepper motor driver

2.2 Functional design

The design requirements of the micro stepper motor controller:

(1) Able to realize stepper motor subdivision control

The subdivision control only needs to control the three pins MS1, MS2 and MS3 to get the corresponding subdivision result. The subdivision angle value is equal to the step angle multiplied by the subdivision coefficient. The subdivision coefficient is obtained by sending a command from the host computer, and the initial subdivision value is 1, which means it runs in full step mode.

(2) Able to realize stepper motor speed control

Through the test, the main factors affecting the speed of the stepper motor are the stepping pulse frequency and the subdivision coefficient. If the stepping pulse frequency is too high, it will cause the stepping motor to lose step. The stepping motor will not lose step after the test is 400Hz, and after the stepping motor rotates after the subdivision, there will be no strong vibration and sound.

When the subdivision factor becomes smaller and smaller, the rotation speed of the stepper motor will also become smaller and smaller. There are two reasons.

One of the reasons is that when the subdivision coefficient is constant, each pulse takes one step, the higher the pulse frequency, the faster the stepper motor rotation speed;

Another reason is that when the input pulse frequency of the stepper motor remains unchanged, the advance angle of the stepper motor per 1/2 subdivision becomes the original 1/2 degree, so the number of pulses doubles, the natural speed It is reduced to 1/2 of the original.

(3) Realize the rotation control of stepper motor at any angle

The arbitrary angle rotation control of the stepper motor is relative to the minimum angle (0.1125 degrees) of the A4988 drive rotation. And A4988 drives the stepping motor by pulse, and the rotation angle value can be obtained by multiplying the number of pulses by the subdivision angle. The number of A4988 input pulses can be obtained by calculating the number of PWM waves through the external interrupt I/O port of the microcontroller.

3 Software design

STM32F103T8U6 is a 32bit microcontroller that can generate independent PWM waves. The PWM pulse width and frequency are adjustable, which is convenient for stepping motor drive and debugging speed.

It can provide an external interrupt to detect the number of PWM output pulses for counting, and provide accurate data for realizing the rotation angle control of the rotating stepper motor, thus forming an angle closed loop control;

It can provide serial communication for information exchange between host computer equipment and microcontroller;

Its I/O port is small and cheap, and it can completely replace 16bit single-chip microcomputer for complex logic operations.

STM32 control method:

(1) Receive the host computer control command and return the receiving command, indicating that the reception is successful, otherwise the reception fails;

(2) Through the received host computer control instructions, they are respectively transformed into control stepping motor instructions to control the stepping motor working mode.

3.1 Serial communication command design

The commands sent by the serial communication host computer are:

(1) Start mode;

(2) Sleep mode;

(3) Reset mode;

(4) Speed setting mode;

(5) Subdivision mode. The sending protocol uses "{" as the start code and "}" as the end code. For example, {+0.1125°C} means forward rotation by 0.1125 degrees. When the lower computer finishes executing the upper computer command, it returns to receive the command, otherwise it does not return. The specific sending method is shown in Table 2.

serial port sending instruction set

3.2 Controller control strategy

The STM32 software is responsible for the main controller of the module.

First, let the startup mode be in the inactive state (DISABLE), and the external interrupt is also in the off state. Once the start mode is turned on, the LED will light up.

Secondly, set the speed, subdivision coefficient and rotation angle. The LED blinks slowly in sleep mode. The specific software design flow chart of the drive controller is shown in Figure 6.

Stepper motor driver software flow chart

Figure 6. Stepper motor driver software flow chart

4 Conclusion

Through system debugging of software and hardware, the controller realizes the setting of stepper motor speed, subdivision coefficient, and arbitrary angle, and achieves the expected set goal.

This controller can be used in relatively fine project control to speed up the project development cycle. The main defect of this module is that the output drive current is not large enough to be used in applications with relatively large torque.

Therefore, through the above analysis of the A4988 module, the A4988 chip can be further improved, and the MOS tube with small on-resistance and large drive current can be replaced to realize the design of the motor driver.

Component Datasheet

A4988 Datasheet


  • How does A4988 work?

The A4988 is a microstepping driver for controlling bipolar stepper motors which has built-in translator for easy operation. This means that we can control the stepper motor with just 2 pins from our controller, or one for controlling the rotation direction and the other for controlling the steps.

  • What is A4988 driver?

The A4988 is a complete Microstepping Motor Driver with built-in translator for easy operation. The driver has a maximum output capacity of 35 V and ± 2 A. It can operate bipolar stepper motors in full-, half-, quarter-, eighth-, and sixteenth-step modes.

  • How do I know if A4988 is working?

disconnect the motors.
connect pin 7 (STEP) and pin 8 (DIR) to pin 9 (GND)
connect a voltage to pin 10 (VDD) of 3 - 5.5v.
ensure pin 9 is connected to Ground. 5 test for voltage between pins 11 and 12 (1A-1B) 6 test for voltage between pins 13 and 14 ( 2A-2B)

Ordering & Quality

Photo Mfr. Part # Company Description Package PDF Qty Pricing
A4988SETTR-T A4988SETTR-T Company:Allegro MicroSystems Remark:IC MTR DRVR BIPOLAR 3-5.5V 28QFN Package:28-VFQFN Exposed Pad
In Stock:7500
1500+: $1.51620

Related Articles

LM393 Comparator: A Detailed Introduction

Irene 18 Jul 2020  887

IntroductionThe LM393 comparator can be regarded as equivalent to the most popular version of the LM358 operational amplifier. Although any operational amplifier can be used as a voltage comparator, t...

Continue reading »

STMicro STM32F7 Series Basic Overview [Video]

Iggy 2 Feb 2021  92

This blog provides you with a basic overview of the STM32F7 Series, including its specifications, datasheet, frequently asked questions, etc., to help you quickly understand what STM32F7 Series are. ...

Continue reading »

ATMEGA168 Microcontroller: Application, Features, Parameters

Iggy 7 Jan 2021  62

Atmega168 is a low-power 8-bit CMOS microcontroller based on an enhanced AVR RISC structure. Due to its advanced instruction set and single clock cycle instruction execution time, Atmega168's data thr...

Continue reading »

CR1220 Lithium Coin Battery Overview [FAQ]

Mia 19 Jan 2021  60

In today's blog, I'll unlock the details of CR1220, the lithium coin battery. CR1220 is a battery cell, also known as a lithium coin battery that comes with a high voltage of around 3V...

Continue reading »

TDA7294 Based Power Amplifier Circuit Design

Mia 14 Sep 2020  920

I. Introduction TDA7294 is a very innovative DMOS high-power integrated amplifier circuit launched by the famous European SGS-THOMSON STMicroelectronics to mainland China in the 1990s. It sweeps away...

Continue reading »

0 comment

Leave a Reply

Your email address will not be published.


# 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z