Share this

Microcontroller control of stepper motors

2026-04-06 07:38:35 · · #1
Abstract: This design uses the Sunplus 16-bit microcontroller SPCE061A to control a stepper motor. A timed square wave output from the I/O port serves as the control signal for the stepper motor, which is then driven by the L298N chip. Simultaneously, a 4x4 keyboard controls the motor's status, and a digital tube displays the motor's speed. A 74LS164 is used as the driver for the 4-digit digital tube display, receiving signals from the microcontroller. The Sunplus microcontroller's voice function is used to announce the motor's speed. Keywords: Stepper motor, microcontroller , digital tube I. Scheme Demonstration and Comparison 1. The focus of this design is the control and drive of the stepper motor. The controlled motor in this design is a four-phase six-wire stepper motor (internal resistance 33 ohms, step size 1.8 degrees, rated voltage 12V). Scheme 1: Using multiple power amplification devices to drive the motor. By using different amplification circuits and devices with different parameters, different amplification requirements can be achieved, resulting in higher power output. However, since a four-phase stepper motor is used, the four signals need to be amplified separately. Because it's difficult to make the amplification circuits completely identical, the motor will be unstable when the power is high, and the circuit construction is also relatively complex. Solution Two: Using the L298N chip to drive the motor. The L298N chip can drive two two-phase motors (as shown in Figure 1-1) or one four-phase motor, with a maximum output voltage of 50V. The output voltage can be directly adjusted via the power supply; signals can be directly provided using the microcontroller's I/O ports; and the circuit is simple and easy to use. [align=center] Figure 1-1 [/align] Through comparison, using the L298N chip fully utilizes its functions, can stably drive the stepper motor, and is inexpensive, so the L298N is chosen to drive the motor. When using the L298N, the L297 can be used to provide timing signals, saving the use of microcontroller I/O ports; alternatively, the timing signals can be directly simulated by the microcontroller. Since the control is not complex, the latter is chosen. 2. Design Scheme 1 for Digital Tube Display Circuit: Serial Connection. This design requires displaying 4 digits, using a 74LS164 as the display driver. The serial connection saves I/O port resources, but requires SIO for easier data transmission control. Scheme 2: Parallel Connection. Using the parallel connection requires individual I/O input for each digital tube, consuming more resources. Since the design uses a single microcontroller for control, resources are limited, so Scheme 1 was chosen. Additionally, using a latch also saves resources. II. Stepper Motor Control Principle Stepper motors are digitally controlled motors that convert pulse signals into angular displacement. A single pulse signal causes the stepper motor to rotate by one angle, making it very suitable for microcontroller control. Stepper motors can be divided into reactive stepper motors (VR), permanent magnet stepper motors (PM), and hybrid stepper motors (HB). The biggest difference between stepper motors and other controlled motors is that they are controlled by input pulse signals. The total rotation angle of the motor is determined by the number of input pulses, while the motor speed is determined by the pulse signal frequency. The stepper motor drive circuit works according to the control signal, which is generated by the microcontroller. Its basic principle and function are as follows: (1) Controlling the commutation sequence The process of commutation is called pulse distribution. For example, in the three-phase stepper motor, the commutation sequence of each phase is ABC-D. The commutation control pulse must strictly control the on/off of phases A, B, C, and D respectively according to this sequence. (2) Controlling the direction of the stepper motor If the given working mode is commutated in the forward sequence, the stepper motor rotates forward. If the commutation is commutated in the reverse sequence, the motor rotates in the reverse direction. (3) Controlling the speed of the stepper motor If a control pulse is sent to the stepper motor, it will rotate one step. If another pulse is sent, it will rotate one more step. The shorter the interval between the two pulses, the faster the stepper motor rotates. By adjusting the pulse frequency sent by the microcontroller, the speed of the stepper motor can be adjusted. III. Theoretical Design Based on the above selected schemes, the overall process is shown in Figure 3-2. [align=center] Figure 3-1 [/align] 1. Stepper Motor Drive Circuit: The stepper motor drive circuit is constructed using L298N, and the circuit diagram is shown in Figure 3-2. Square wave pulse signals are sent to the IN1-IN4 ports and ENA and ENB ports of L298N through IOB8-IOB13 of the SPCE061A microcontroller, and the timing diagram is shown in Figure 3-3. [align=center] Figure 3-2[/align][align=center] Figure 3-3[/align] 2. Digital Tube Display Circuit Design: The digital tube display driver uses 74LS164, and data is sent to DATA and CLK through IOB0 and IOB1 ports of SPCE061A. [align=center] Figure 3-4[/align] 3. 4x4 Keyboard Circuit: A standard 4x4 keyboard is used in the design, and its circuit diagram is shown in Figure 3-5. The lower 8 bits of the microcontroller's A port are the keyboard interface. Although the design requirements only require four keys to control the stepper motor's state, a 4x4 keyboard was used to expand the control functionality. [align=center]Figure 3-5[/align] IV. Program Design The program design mainly consists of five parts: dual-machine communication, voice counting, digital display, stepper motor drive, and keyboard. The implementation of dual-machine communication and voice counting are particularly noteworthy, and their flowcharts are briefly described below. The other parts are shown in the attached program. 1. Dual-Machine Communication [align=center]Figure 4-1[/align] In implementing dual-machine communication, we used a "three-way handshake," a common data communication confirmation protocol in Internet. Its flowchart is shown in Figure 4-1. 2. Voice Counting The voice counting program uses SACM-A2000. Considering the program's simplicity, an automatic counting mode was initially used. However, continuous counting was not possible, so a non-automatic mode was used. The flowchart is shown in Figure 4-2. [align=center]Figure 4-2[/align] V. Results Analysis and Summary It should be said that this course design basically met the design requirements, but there were still some unresolved problems. Due to the high resource consumption during the execution of the voice program, the output of the stepper motor drive signal was interrupted during voice number reporting, causing the motor to stop. Therefore, we modified the solution, using two microcontrollers to transmit signals through dual-machine communication. Unfortunately, the problem was still not solved. In this comprehensive stepper motor experiment, we learned how to use stepper motors, digital tubes, 4x4 keyboards, voice number reporting, and dual-machine communication. More importantly, we learned how to debug programs when problems occur and developed the habit of debugging. We also learned the basic methods for solving program problems. References: [1] Xie Zimei, Electronic Circuit Design, Experiment and Testing (Second Edition) [M], Wuhan: Huazhong University of Science and Technology Press, 2000. [2] Xue Junyi, Zhang Yanbin, Fan Bo et al., Sunplus 16-bit Microcontroller Principles and Applications [M], Beijing: Beijing University of Aeronautics and Astronautics Press, 2003. [EB/01] http://www.sunplus.com. [EB/02] http://www.21ic.com
Read next

CATDOLL Milana Soft Silicone Head

You can choose the skin tone, eye color, and wig, or upgrade to implanted hair. Soft silicone heads come with a functio...

Articles 2026-02-22