Design of a stepper motor control system based on LabVIEW and microcontroller
2026-04-06 06:01:01··#1
Abstract: A measurement and control circuit was constructed using an AT89S52 microcontroller, a DS18B20 single-bus digital temperature sensor, and a stepper motor as the main components. The host computer uses temperature as the main parameter and controls the forward, reverse, acceleration, and deceleration of the stepper motor via a serial port. A C51 program is used to acquire data from the sensor and communicate serially with the host computer. LabVIEW is used to dynamically display the temperature waveform, store data, provide over-limit alarms, and control the motor. In actual operation, the system can effectively control the stepper motor and is suitable for applications requiring timely temperature detection and stepper motor control. Keywords: Microcontroller, LabVIEW, DS18B20, Stepper Motor 1 Introduction LabVIEW is a virtual instrument platform developed by National Instruments. It is a graphical programming language with powerful functions, providing rich data acquisition, analysis, and storage functions, offering advantages over traditional text-based languages. However, virtual instruments developed using LabVIEW typically require expensive data acquisition hardware. While microcontroller-based data acquisition and processing systems have lower hardware costs, their development process is more complex and involves a greater programming workload. Using a microcontroller-based small system as the front-end data acquisition system, and transmitting the acquired data to the host computer via the serial port sub-VI provided by LabVIEW, allows for data processing and analysis within the LabVIEW environment, as well as related control. This approach fully utilizes LabVIEW's powerful capabilities while reducing system development costs, thus expanding the application scope of LabVIEW. This system uses an AT89S52 microcontroller and a DS18B20 single-bus digital temperature sensor to form the front-end data acquisition system, and the same microcontroller and stepper motor drive circuit to form the back-end control system. The microcontroller transmits the acquired temperature data to the host computer via a serial communication circuit. The host computer program, written in LabVIEW, can dynamically display temperature waveforms, store data, and set alarm temperatures. It can also control the microcontroller via the serial port to drive the stepper motor for forward and reverse rotation and acceleration/deceleration based on different alarm temperatures, or directly control the motor's operation manually. The system can be used in applications requiring timely temperature detection and stepper motor control. It can also be expanded to use a host computer as the control center, with multiple front-end data acquisition systems for multi-point temperature measurement and different back-end control systems for different control functions. 2. System Composition The system mainly consists of a microcontroller, temperature acquisition circuit, stepper motor control circuit, and RS-232 interface circuit. Based on this, it expands to include a clock circuit, keyboard input and LCD display circuit, audible and visual alarm circuit, and I²C bus and E²PROM memory. The microcontroller used is the Atmel AT89S52, which has ISP in-system programming capability and 8 kB of FLASH memory. Due to its large program memory space, no external storage unit is needed to complete functions such as LCD character storage. The crystal oscillation frequency is 11.0592 MHz, enabling precise communication with the computer. The system structure block diagram is shown in Figure 1. 3 Hardware Circuit Design 3.1 Temperature Acquisition Circuit Design The temperature sensor is the DS18B20 1-wire digital temperature sensor produced by DALLAS Semiconductor. Its performance characteristics are as follows: (1) It adopts single-bus dedicated technology, which can be used to interface with the microcomputer through serial port or other I/O port lines without the need for other conversion circuits, and directly outputs the measured temperature value (9-bit binary number, including sign bit); (2) The temperature measurement range is -55 to +125 ℃, and the measurement resolution is 0.0625 ℃[1]; (3) It contains a 64-bit laser-corrected read-only memory ROM; (4) It is compatible with various microcontrollers or system machines; (5) Users can set the upper and lower limits of each temperature channel; (6) It contains parasitic power supply. [align=center]Figure 1 System Structure Block Diagram[/align] The interface between the DS18B20 and the microcontroller is simple; just connect the DS18B20's signal lines to a single bidirectional port of the microcontroller.[sup][1][/sup] Its power supply can be either parasitic (VDD and GND are both grounded) or external (VDD is powered by a 3-5.5V supply). In this system, the DS18B20 uses an external power supply. The CPU's access process to the DS18B20 is as follows: first, the DS18B20 is initialized; then, ROM operation commands are executed; finally, read and write operations on the memory are performed. Each operation of the DS18B20 must follow strict timing and communication protocols. For example, when the host controls the DS18B20 to complete the temperature conversion process, according to the DS18B20's communication protocol, three steps are required: The DS18B20 must be reset before each read/write operation; after a successful reset, a ROM instruction is sent; and finally, a RAM instruction is sent. Only in this way can the DS18B20 perform the predetermined operation. 3.2 Clock Circuit DS1302 The DS1302 is a high-performance, low-power real-time clock circuit with RAM, launched by Dallas Semiconductor. It can keep track of year, month, day, day of the week, hour, minute, and second, and has leap year compensation. Its operating voltage is 2.5–5.5 V. It uses a three-wire interface for synchronous communication with the CPU and can transmit multiple bytes of clock signals or RAM data in burst mode. The DS1302 has an internal 31 × 8 RAM register for temporary data storage. The connection between the DS1302 and the microcontroller requires three lines: SCLK, I/O, and RST. The DS1302 adds dual power supply pins for main power and backup power, and also provides the ability to trickle charge the backup power. The backup power can be a battery or a supercapacitor (0.1 F or more). This system has no special time requirements, so a common electrolytic capacitor with low leakage current is used as the backup power; 100μF is sufficient to ensure 1 hour of normal operation. 3.3 Stepper Motor Control Circuit A stepper motor is an actuator that converts electrical pulses into angular displacement. The amount of angular displacement is controlled by controlling the number of pulses, thereby achieving accurate positioning. Due to its characteristic of no accumulated error, it is widely used in various open-loop control systems. The stepper motor in this system is a two-phase bipolar motor with a step angle of 3.75°. The drive section uses Darlington transistors TIP122 and TIP127 to form a bipolar bridge drive circuit. Since the driving methods of the two phases are exactly the same, Figure 2 only shows the driving method of one phase. An optocoupler 4N25 is used for electrical isolation between the microcontroller and the drive circuit to increase system stability. [align=center] Figure 2 Drive circuit of one phase of stepper motor[/align] 3.4 Keyboard, LCD display and sound and light alarm circuit The keyboard of the system has 3 keys, namely the plus key, the minus key and the confirm key, which can set the system time and the alarm temperature of DS18B20. The LCD is of type 12864, with 128 rows and 64 columns. The main contents displayed are: (1) Current time, in the format of year/month/day/weekday/hour/minute/second; (2) Real-time temperature value of sampling; (3) System time setting, alarm time setting and temperature setting interface. The sound and light alarm circuit is mainly composed of light-emitting diodes and small speakers. When the sampled temperature exceeds the alarm temperature, it will automatically alarm. 3.5 I2C bus The I2C (Inter-Integrated Circuit) bus is a two-wire serial bus developed by PHILIPS for connecting microcontrollers and their peripheral devices. The system uses two signal lines: a bidirectional data line (SDA) and a clock line (SCL). The I2C bus supports master/slave bidirectional communication, allowing both master and slave devices to operate in both receive and transmit modes. The maximum transmission rate is 100 kb/s. The system employs an AT24C01 serial E2PROM, which features an I2C bus interface, low power consumption, a wide power supply voltage range (2.5–6.0 V depending on the model), an operating current of approximately 3 mA, and a quiescent current that varies with the power supply voltage, ranging from 30 to 110 μA. It has 128 bytes of storage space, allowing the system to save pre-set alarm temperatures from the DS18B20 even after power failure. The master device in the system is a microcontroller, which generates the serial clock (SCL), controls the bus transmission direction, and sets start and stop conditions. The data state on the SDA line can only change while SCL is low. While SCL is high, changes in the SDA state are used to indicate start and stop conditions. 3.6 RS 232 Interface Circuit Through the RS 232 interface circuit, the system can communicate with the host computer, transmitting the sampled temperature to the host computer and receiving stepper motor control commands from the host computer. Additionally, the system time and alarm temperature can be adjusted via the host computer. 4 Host Computer Program The host computer program is written using LabVIEW 8.2, the graphical programming language from National Instruments (NI). It is divided into functional modules: serial communication module, data display and storage module, parameter setting module, stepper motor control module, etc. Partial operation interfaces are shown in Figure 3. [align=center] Figure 3 Part of the LabVIEW operation interface[/align] 4.1 Serial communication module The serial communication module includes Visa Configure Serail Port VI, Vi2sa Write VI, Visa Read VI and Visa Close VI[sup][4][/sup]. Its functions are: (1) To realize the basic parameter settings of the serial port, such as baud rate, buffer size, parity bit, data bits and whether to include the end bit, etc.; (2) To realize the data transmission between the microcontroller and the host computer. In the program, the baud rate is 9600, 8 data bits, no parity check, 1 stop bit, and the interval between each communication is 1 minute. 4.2 Data display and storage module, parameter setting module The data display module can intuitively display the current time, serial port read and write status, real-time temperature waveform and set alarm temperature waveform. It can also store the measured temperature data as an Excel format document. The parameter setting module can set the first-level low temperature alarm temperature and the second-level high temperature alarm temperature. 4.3 Stepper Motor Control Module Stepper motor control is divided into manual control and automatic control. When set to manual control, the motor can achieve forward and reverse rotation and acceleration and deceleration. The implementation method is to send control characters through the serial port, which are parsed by the microcontroller and the corresponding function is selected. The correspondence between control characters and stepper motor functions is shown in Table 1. For example: sending the character "z" means forward rotation, and "t" means stop. When set to automatic, if the detected temperature value is lower than the low temperature alarm temperature, the motor reverses; if it is higher than the first-level high temperature alarm temperature, it rotates forward at the set lower speed; if it is higher than the second-level high temperature alarm temperature, it rotates forward at the set higher speed. When the detected temperature is within the normal temperature range, the motor stops running. The motor control module can be flexibly applied and the control strategy can be changed according to different control requirements. 5 Conclusion This article introduces a stepper motor control system design method based on LabVIEW and microcontroller, which has the following main features: (1) The front-end data acquisition system is composed of microcontroller and DS18B20, and the data is transmitted to the host computer for analysis and processing through serial communication. The back-end control system is composed of the same microcontroller and stepper motor control circuit. Temperature is the main control parameter, and the host computer controls the stepper motor to realize various actions. (2) The host computer program is written in the graphical programming language LabVIEW to realize the processing of temperature data and the control of the motor. The human-machine interface is user-friendly and easy to operate. (3) The system can be expanded and flexibly applied to various occasions. For example, the DS18B20 networkable sensor can be used to realize multi-point temperature measurement, and different back-end control systems can realize different control functions.