Microcontroller-based stepper motor control systems are characterized by low cost and flexible application, and are widely used in CNC machine tools, robots, quantitative feeding, industrial automation control, and various controllable mechanical tools with positioning requirements. Stepper motors are digitally controlled motors that convert pulse signals into angular displacement. The motor's speed and stopping position depend on the frequency and number of pulse signals, and are unaffected by load changes. Under non-overload conditions, based on the aforementioned linear relationship, and considering that stepper motors only have periodic errors and no cumulative errors, they are suitable for microcontroller control. Stepper motors are controlled by input pulse signals; the total rotation angle of the motor is determined by the total number of input pulses, while the motor speed is determined by the pulse signal frequency. The stepper motor's drive circuit operates based on control signals generated by the microcontroller. Therefore, the microcontroller can control the stepper motor by sending control signals to the stepper motor drive circuit.
1 System Design Principles
The stepper motor control system mainly consists of four modules: a microcontroller, a keyboard with LEDs, a driver/amplifier, and a PC host computer. The PC module is the software control part. The control system can perform the following functions: 1) Start/pause the stepper motor, set its speed, and change its direction via the keyboard; 2) Display the stepper motor's speed and direction using LEDs; 3) Control three-phase or four-phase stepper motors; 4) Control the stepper motor (start/stop, speed, and direction) via the PC host computer. To protect the microcontroller control system hardware circuitry, an overcurrent protection circuit is added between the microcontroller and the stepper motor. Figure 1 shows the block diagram of the stepper motor control system.
2 System Hardware Circuit Design
2.1 Microcontroller Module
The microcontroller module mainly consists of an MSP430FG4618 microcontroller and peripheral circuits for filtering, power management, and crystal oscillator. The MSP430FG4618 microcontroller's internal 8KB RAM and 116KB Flash memory meet the storage requirements of the control system. During stepper motor operation, ports P1 and P2 determine whether to enter an interrupt service routine based on the button status to change the stepper motor's operating state. The USART module enables communication between the microcontroller and the PC, allowing the PC to control the stepper motor. The power management circuit provides stable 3.3V and 5V voltages to power the microcontroller, crystal oscillator circuit, and driver and power amplifier circuits, respectively. The 32kHz crystal oscillator provides the clock for the microcontroller, the 8279 keyboard/display interface device, and the PMM8713 pulse distributor; when using the USART module, an 8MHz crystal oscillator must be enabled to set the communication module. Figure 2 shows the block diagram of the microcontroller module.
2.2 Keyboard/LED Module
To enable human-machine interaction, the system incorporates a 3x4 button matrix keyboard and four 8-segment LED digital tubes, allowing for direct manual operation of the control system. After power-on, the system inputs stepper motor start/stop, step count, speed, and direction via the keyboard, which are dynamically displayed on the LED tubes. The keyboard input and LED output are controlled by an 8279 microcontroller, reducing the workload on the microcontroller. The 8279 is programmed for keyboard scanning input and features debouncing to prevent accidental triggering. Figure 3 shows the block diagram of the keyboard LED module design.
2.3 Driver/Amplification Module
The control system uses the PMM8713 pulse distributor (also known as a logic converter) for stepper motor control. This device is a CMOS integrated circuit with a phase output drive capability (source current or power input) of 20mA. It is suitable for controlling three-phase or four-phase stepper motors and can select the following six excitation modes: three-phase stepper motors: 1 phase, 2 phases, 1-2 phases; four-phase stepper motors: 1 phase, 2 phases, 1-2 phases. Input modes can be selected as single clock (with direction signal) or dual clock (forward or reverse clock). It has functions such as forward/reverse control, initialization reset, origin monitoring, excitation mode monitoring, and input pulse monitoring. The PMM8713 device consists of clock selection, excitation mode control, excitation mode judgment, and a reversible ring counter. All input terminals have Schmitt trigger circuits to improve anti-interference capability. The PMM8713 output needs to be connected to a power drive circuit. The power driver PMM2101 is selected, with a maximum output current of 1.4A, which meets the requirements for driving the stepper motor. The drive/amplifier circuit is shown in Figure 4. The MSP430 microcontroller controls the start, stop, speed, and direction of the stepper motor by adjusting the pulse signals input to ports 1-4 of the PMM8713.
3 System Software Design
3.1 Microcontroller Program
The microcontroller uses the TIMER_A (TA) interrupt of the microcontroller to generate pulse signals. The corresponding interrupt routine accurately counts the steps and revolutions of the stepper motor, and speed control is achieved through PWM. The TA interrupt routine is disabled using the P1.0 port interrupt and pushed onto the stack, stopping the motor. The P1.1 interrupt enables the TA interrupt, pushes the program counter (PC) onto the stack, and starts the motor. A high-level output from the P3.1 port controls the motor's direction of rotation via the PMM8713's U/D port. Ports P3.0 to P3.7 connect to the eight data interfaces of the 8279. When the microcontroller detects a key press on the matrix keypad, the TA is set using the P2 port interrupt, controlling start/stop, speed adjustment, and direction. Simultaneously, the microcontroller feeds back to the 8279 to control the LED display of speed and direction. The program flow is shown in Figure 5.
3.2 PC Host Computer Module
The PC-based host computer module enables PC control of the stepper motor. Communication with the PC is achieved using the USART module of the MSP430 microcontroller. The PC sends control commands to the microcontroller via serial port to control the motor. The microcontroller temporarily stores the received control commands in the RXBUFFER buffer and then compares them with the entry address of the interrupt routine stored in the on-chip Flash memory. If they match, an interrupt is triggered, controlling the stepper motor. Operating this module requires enabling an 8MHz crystal oscillator and setting the baud rate for the USART module (set to 9600). The control software is written in VB6.0 and uses the MSComm control to implement serial communication. The software interface is shown in Figure 6.
4 System Testing
To verify the actual operation of the control system, the maximum static torque of the stepper motor was measured using the energy conversion method under a given PMM2101 output operating current. With an output current interval of 0.2A selected, the static characteristic curve showing the relationship between the maximum static torque of the stepper motor and the current was measured, as shown in Figure 7. This indicates that the control system design is reasonable.
5. Conclusion
This system controls the stepper motor's operation using an MSP430 microcontroller, ensuring high reliability. During motor operation, it allows for easy setting of the stepper motor's start/stop, speed, and direction, improving stepping accuracy. It can control three-phase or four-phase stepper motors, and the PC host computer provides complete control over various stepper motor operating modes. This allows the system to be used in harsh environments, ensuring personnel safety. It has a wide range of applications, a simple circuit, low cost, convenient control, strong portability, and high practical value.