Research on the design of stepping motor drive system controlled by single-chip microcomputer

In order to meet the needs of operation and management of stepping motors in the Internet of things environment, this paper designed the software and hardware of the stepping motor drive system under the control of a single-chip microcomputer based on LabVIEW, which is a graphical programming platform developed by National Instruments Corporation of the United States, and tested and veried the functions of the system. The software part transmitted data between the host computer and the driver terminal based on a service cloud platform called Easy-Control, realizing the network real-time online management operation function. The hardware design made full use of the existing functions of the STM32F407ZGT6 single-chip microcomputer; moreover, the design of circuits was simplied by the special driver chip LV8726TA for stepping motor to increase system stability. The software and hardware of the system were developed on the LabVIEW platform, which had the advantages of high eciency, short development cycle, low cost, and convenient function expansion. This work provides a scheme for the design and implementation of similar systems.


Introduction
Motor is the most commonly used power component in automation systems. As a special motor that can convert pulse signals into linear displacement and angular displacement, the stepping motor has been widely used in various automation systems because of its reliable performance, easy control, simple structure, and low cost [1,2]. With the rapid development of Internet of things technology and automation technology, people have higher and higher requirements for the reliability of automation equipment action and the convenience of management; therefore, it is necessary to study the stepping motor drive control system. In this paper, based on LabVIEW, a graphical programming platform developed by National Instruments Corporation of the United States, a network server-based stepping motor drive system controlled by a single-chip microcomputer was designed. The system supported remote real-time management of multiple stepping motors through an upper computer. A special drive circuit was designed in order to improve the working performance of the stepping motor driver.

Overview Of Stepping Motor
At present, 98.6% of the stepping motors used in the Chinese market are rotary stepping motors.
According to the internal structure, stepping motors can be divided into three main types: reactive stepping motor (also known as variable reluctance (VR) type), permanent magnet stepping motor (also known as PM type), and hybrid stepping motor (also known as HB type) [3].
The stator part of the reactive stepper motor works through the magnetic eld generated by the winding, and the rotor part is composed of soft magnetic material. This kind of stepper motor has a simple structure, low cost, and small step angle (up to 1.2°), but its reliability is di cult to be guaranteed because of its soft characteristic, poor dynamic performance, and low e ciency; thus, it has been eliminated at present. The rotor part of the permanent magnet stepping motor is made of the permanent magnet material. The permanent magnet stepping motor has some improvements compared to the reactive stepping motor, including large output torque, hard characteristic, and good dynamic property.
However, due to the limitation of the permanent magnet material manufacturing process, there is no enough magnetic eld subdivision. This kind of motor has low resolution and large step angle, which is generally 7.5° or 15°; therefore, it can not meet the requirements of the current automation system, and the usage amount of this kind of stepping motor is also decreasing year by year [4,5]. The hybrid stepper motor is a kind of stepper motor developed based on absorbing the advantages of the reactive stepper motor and permanent magnet stepper motor. It has the advantages of large output torque, good dynamic response, and small step angle (up to 0.007° after subdivision). It accounts for 97.3% of the market share of the stepper motor in use at present. The following content is about the structure of the most costeffective two-phase hybrid stepper motor and how it works.
The structure of the two-phase hybrid stepping motor is shown in Fig. 1, which is mainly composed of a stator, a rotor, and a permanent magnet. The permanent magnet is located in the middle of the rotor core, making the rotor core present N-pole characteristics in the axial direction and the other end present S-pole characteristics [6-8]. It is seen from the radial structure diagram in Fig. 2 that some small teeth are evenly distributed on the stator and rotor core. The small teeth on the stator and rotor are staggered by half a pitch. The magnetism of the eight magnetic poles on the stator can change the direction of the magnetic eld of the magnetic poles in the stator by changing the order and direction of power in the Aphase winding and the B-phase winding to drive the stepping motor according to the speci ed direction.
The A-phase winding and B-phase winding of the two-phase hybrid stepping motor are wound on the iron core of 1-3-5-7 and 2-4-6-8, respectively, and the output leads are A, B. Because of the half-pitch difference between the stator winding and the rotor winding, the running state of the motor can be controlled by order of power of phase A and phase B. The rotation angle of the motor each time is inversely proportional to the number of teeth. The common operation modes of the two-phase hybrid stepping motor are single-phase four-beat, two-phase four-beat, and single-phase eight-beat. The speci c control modes are shown in Table 1. Under different beat control modes, the step angle θ N of the stepping motor is different, and the speci c value of the step angle θ N can be calculated as follows: where N is the beat number of the stepping motor control and Z r is the number of teeth of the stepping motor rotor.
For example, if the number of rotor teeth of the stepping motor is 50, the step angle is 1.8 ° when using the four-beat control and 0.9 ° when using the eight-beat control. It can be seen that it is di cult to ensure the control effect only by using beat control in high-precision control occasions; thus, it is necessary to improve the control effect in the electrical drive link. The driving technology of the stepping motor directly affects the performance of the stepping motor. The common driving methods include single voltage driving, double voltage (high and low voltage) driving, frequency and voltage regulating driving, chopper driving, subdivision driving, etc., among which subdivision driving technology has been widely used [9,10].
According to the research results of Li et al., the current owing through the motor winding is loaded in the form of a rectangular step wave according to the sine law, and the input current changes between 0 and the maximum value. Such a kind of segmentally changed current can synthesize continuously changing magnetic eld, and the segmented number of current, i.e., d, will affect the step angle θ d . In this way, the effect of subdivision can be achieved, and the step angle after subdivision is θ d = θ N /d. The operation precision and stability of the stepping motor can be improved by subdivision.

Design Method Of The Driving System
The driver system is designed based on the distributed architecture of the network cloud server to meet the access requirement of the Internet of things and the convenience requirement of system management operation. The system mainly includes two main parts: the stepping motor drive terminal and the upper client. The data between the stepping motor drive terminal and the upper client is transmitted through the Internet cloud server, and the speci c structure is shown in Fig. 3. The stepping motor drive terminal is responsible for receiving the command data and function setting data of motor operation from the server, driving the stepping motor to work according to the control command sent by the upper computer, and feeding back the state data of motor operation to the cloud server. The cloud data server is mainly responsible for data forwarding, transmission, alarm rule setting, authority management, and data storage. The upper computer monitoring system sends the running command of the stepping motor through the graphical interface and monitors its running state simultaneously.
The speci c function design can be summarized into the following two main aspects: one is to use the Embedded Module for ARM Microcontrollers module provided by LabVIEW platform combined with the RealView MDK software produced by Keil company to develop the function of STM32 single-chip microcomputer drive system of the stepping motor drive terminal and drive the motor to run through Hbridge drive circuit; the other is to design the software of the upper computer monitoring system based on the .net and ActiveX calling function of LabVIEW to monitor and manage the running state of different stepping motors [11,12]. STM32F407ZGT6 single-chip microcomputer with 32-bit Cortex-M4 architecture is selected as the controller of the stepping motor drive terminal. The information is exchanged with the corresponding application programming interface (API) of the data server through the ENC28J60 Ethernet controller chip. The server uses the "easy monitoring" cloud service provided by Sanyi electronic studio for data forwarding and other services. The speci c design process is discussed below.

Hardware design of drive system
The hardware diagram of the stepping motor driver designed in this study is shown in Fig. 4. The hardware part of the system mainly includes STM32 single-chip microcomputer control unit, transmission control protocol/internet protocol (TCP/IP) interface unit, optocoupler unit, drive unit, display unit, etc. The single-chip microcomputer can receive the command signal from the server and feedback the operation signal of the stepping motor to the cloud for monitoring and display. The strong current and weak current parts ensure the safety of the system through optocoupler isolation. The drive unit selects the driver module based on the LV8726 chip and drives the motor to operate after power ampli cation by H-bridge.

Hardware design of STM32 control unit
The core controller used in this scheme is the ARM® Cortex®-M4 structure core-based STM32F407ZGT6 chip. The chip has a main frequency of up to 16 MHZ, 1 MB Flash, 192 + 4KB SRAM, a liquid crystal display (LCD) parallel interface convenient for display expansion, and extremely low power consumption.
Moreover, it can supply power for the clock and memory through the voltage of battery (VBAT). It has 140 input/output (I/O) interfaces supporting interrupt function and rich communication interfaces to support most current mainstream communication modes, showing rich hardware resources. In this driver, the function of the STM32 processor is to realize the data communication between the driver and the upper control system, generate the motor drive signal according to the upper computer command code, feedback the operation status of the stepping motor to the upper system, and display the basic operation information locally. In the process of hardware design, referring to the current mainstream learning board design method, except for the I/O ports occupied by the RTC crystal oscillator and COM1 port, the other I/O ports are led out to both sides of the circuit board through two rows of pins for wiring and function expansion.
The following is a detailed description of the circuit design of the Ethernet communication part and LCD module part in the system, and the design of other general auxiliary circuits will not be repeated.
The driver terminal based on the ENC28J60 chip design realizes the network transmission module.
ENC28J60 is an independent Ethernet controller which supports industry-standard serial peripheral interface (SPI) bus communication. It can extend an Ethernet communication port for any micro control unit (MCU) equipped with SPI bus interface. In this system, the command and data interaction between the ENC28J60 module and master controller STM32 is realized by an SPI bus and two interrupt pins. Also, ENC28J60 also reserves two special signal pins for controlling light-emitting diode (LED) lights to indicate the current network activity status. In Fig. 6 STM32 system supports LCD with 8080 or 6800 interface standard, which brings great convenience to the design of display circuit. The display part is directly lead out to the terminal of the display by the FMSC bus provided by the STM32F407ZGT6 chip. The matched touching signals of the LCD are treated by XPT2046 before information exchange with the controller. XPT2046 chip is a typical successive approximation analog-to-digital converter (SARADC), which has functions of sampling/holding, analogto-digital conversion, and serial data output. This design uses the typical circuit to achieve the function. The circuit realization of the LCD part is shown in Fig. 7.

Optocoupler circuit
The large power supply noise and current during the operation of the stepping motor are easy to affect the control circuit. The optocoupler isolation circuit must be set to isolate the driving circuit from the circuit of the STM32 single-chip microcomputer to improve the stability of the driving system. The principle of the optocoupler isolation circuit is shown in Fig. 9. In the design scheme, EL817 linear optocoupler produced by Taiwan Everlight company is selected. According to EL817 product manual, the maximum current at the input end of the optocoupler is 60 mA. A 240 Ω resistor is connected in series at the input end to prevent burning the LED at the input end because of excessive current. At the same time, an IN4148 diode is also connected to the circuit for reverse protection, preventing component damages caused by misoperation. All the connections between the STM32 MCU control circuit and the drive circuit are equipped with photoelectric coupling protection, which improves the anti-interference and stability of the system.

Software design of driving system
According to the design scheme of the driving system, the software part mainly includes the following three aspects: the development of the STM32 single-chip microcomputer program of the driving terminal, the interface of the cloud server and its data con guration, and the development and design of the monitoring screen of the upper computer. Considering the uniform style of the system design, the software part of the system uses LabVIEW, a graphical programming platform developed by National It can provide users with a seamless and real-time embedded programming experience. The software architecture is shown in Fig. 10. The tool itself integrates hardware communication interface VI, including common RSR232 serial communication VI, TCP Ethernet communication VI, CAN LAN communication VI, etc. These VI can greatly improve the e ciency of user program development.
The driver terminal and the upper computer exchange data through the data server; therefore, the driver terminal needs to connect to the server to obtain the con guration data after power-on initialization. After data acquisition, the parameter status of LV8726 chip is updated through the local port. If the server connection attempt fails, the cache data of the single-chip microcomputer are used by default to ensure that the system can operate independently. After the drive parameters are con gured, the system control mode is updated, and the control signal is processed according to the mode speci ed by the control mode. After the control signal is processed, the status data in the server and the local display data are updated. The speci c work ow is shown in Fig. 11. In the whole work ow, the monitoring function of server connection processing and status data update is the basic condition to ensure the normal operation of the system.
According to the API provided by the server, the server login and access function, data analysis function, and instruction execution function are designed. The data update timing and display processing program are designed with data processing. Speci c designs of the network access, data sending and receiving, data analysis, and LCD control program of the driver terminal are shown in Figs. 12 and 13.

Data server
In this system, the data server is realized by the third-party data server, the "Easy-Control" service cloud platform provided by Sanyi electronic studio. In the whole system architecture, the service platform is the transfer station of the system, which is mainly responsible for data transfer, processing, and storage, and various alarms of abnormal information. The platform provides a standard API to interact with the collection terminal and the third-party cloud application, providing conditions for the later expansion of the platform function.
The server API rules are as follows: driver command receiving format: ORDER: + command ID + command value; driver data reporting format: DATA: + data ID + data; the command receiving format of upper computer: DATA: + command ID + command value; INIT: + data ID + data; the command sending format of upper computer: ORDER + data ID + data; SETUP + data ID + data.

Software design of upper computer
The upper computer system realizes the human-computer interaction function based on the front panel of LabVIEW 2016, and the background mainly realizes the connection, login, data exchange, data analysis, and exception handling functions with the server through the standard tool palette and network communication tool palette provided by National Instruments Corporation. The connection function is realized by opening TCP connection, reading TCP data, writing TCP data, and closing TCP connection tool in data communication → protocol → TCP palette.
Based on the sequential structure of LabVIEW, the functions of con guration reading, login, data processing, and status display are designed after the upper computer starts. The speci c program is shown in Fig. 14. Data processing and analysis is an important core function of the system. The speci c design procedure is shown in Fig. 15.

Experimental Results
After the design of hardware and software, the function of the system were tested. The main hardware equipment list is shown below:

System function test
First, a service account was created on the "Easy-Control" service cloud platform, and the upper computer parameters and the hardware access con guration parameters of the terminal driver system were con gured according to the access information provided by the platform. In the sensor data column of the upper computer, the project of receiving the motor working state data was con gured. In the switch control column, the hardware control command data were con gured. The step driver setting parameters were directly sent to the driver terminal by the upper computer according to the API provided by the platform. The driver terminal directly analyzed the data and performed the corresponding operation.
After the driver control board program was con gured, the process of compiling and downloading is as After downloading the program, the system function was nally con rmed and tested through online debugging. After debugging, the terminal drive system could log in and access the system normally, receive the command code normally, and feedback the state data of motor operation to the server. The working state of the driver terminal is shown in Fig. 16.
The main functions of the server are as follows: managing and con guring the device access of the terminal drive system, managing user login and operation authority, and storing, forwarding, and alarming data. After testing, the server could normally manage the working state of the driver controller hardware, record the online time, manage the access time of the upper computer client, and forward and receive the driver status data. The server function execution interface is shown in Fig. 17.
The upper computer set up several functional areas, such as the log control area, command sending area, status display area, and data receiving area. The login control area could freely change the server access address and user information and has the function of login status indication. The windows below the landing area were the driver control information sending window and the user-de ned command sending window; the user could send the command code according to the API rules provided by the server, which had strong exibility. The status display area could graphically display and control the common functions of the driver terminal, such as providing the shortcut operation of the stop function to facilitate the user's operation. The data receiving area could display all the data information issued by the server, and the data analysis area on the right could analyze and display the important data, which was convenient for users to understand and use. After testing, the upper computer could set and operate the driver terminal through the server, and the interface of the upper computer is shown in Fig. 18.

Motor winding current waveform test
As the circuit model of the stepping motor is a series model of resistance and inductance, if oscilloscope was directly used for the test, the waveform would not re ect the actual waveform of winding current; therefore, in the process of testing, a sampling resistor with the same resistance (accurate to 0.001 Ω) was connected in series with two windings to collect the measurement signal, and the actual current waveform of the motor winding was obtained by adjusting the magni cation through the waveform transformation of the oscilloscope. In order to analyze the actual driving effect of the chip, the upper computer set the driver to work in 2-subdivision, 16-subdivision, and 128-subdivision working states, respectively, and monitored the actual current value of the stepping motor winding and the chip input signal, and the waveform signals were obtained, as shown in Figs. 19-21.

Discussion
Through the test, the software and hardware of the system cooperate well, can work according to the design requirements, and achieve the design goal. The following is a further discussion on the problems in the testing process.
The data exchange between the upper computer and the hardware of the stepping motor drive system is carried out through the server, which relies heavily on the real-time performance of the network and the data processing ability of the server. When the system is running on a large scale, it is necessary to fully test the performance of the server and the load capacity of the network before it can be formally deployed. The operation instruction code of the upper computer system is sent according to the API standard, which has high professional requirements for the operators and is prone to misoperation. Therefore, the menu operation can be further developed in the later use process to reduce the possibility of misoperation. The driver terminal is equipped with a display screen to display the running status of the device. In the later use process, the local touch operation function can be further developed to enrich the function of the driver terminal and enhance the interaction of the system.
It is found from the monitoring waveform of the motor winding current that with the increase of driving subdivision, the current waveform in the motor winding becomes smoother, closer to the sine wave, and the motor runs more smoothly. However, in the process of testing, we found that the driving frequency of the stepping motor must be kept within some range to ensure accurate operation. If the frequency exceeds, abnormal phenomena will happen to the stepping motor, such as losing steps, skipping steps, and locking rotor. The speci c performance mainly depends on the performance of the terminal driver chip; therefore, the input signal of the driver can be monitored by software to ensure the normal operation of the system.

Conclusion
The experiment shows that the single-chip microcomputer-based stepping motor drive system can drive the stepping motor accurately according to the design requirements, and the system supports multiterminal real-time online management. The terminal stepping motor driver access system is convenient and exible to con gure and modify and can give full play to the performance of the stepping motor driver chip. With the help of the LabVIEW graphical development platform, the system has high development e ciency, short development cycle, low implementation cost, and convenient function expansion, which provides a typical technical scheme for the design and implementation of similar systems.
Declarations Figure 1 The axial structure of a two-phase hybrid stepping motor Figure 2 The radial structure of the two-phrase hybrid stepping motor Page 14/27 Figure 3 The structure of the stepping motor drive system Figure 4 The system hardware diagram 128-subdivision current waveform