Abstract: This paper introduces a novel method for controlling a two-dimensional coordinate positioning system via a microcomputer's serial port. This method eliminates the need for an MCU, allowing for easy adjustment of the stepper motor's speed by changing the serial port's baud rate. The direction of movement and the reading of different position information can be controlled via the RS232 serial port's input and output signals of the modem's status. This method uses logic circuits to implement the control functions, which is not only simpler and eliminates the hassle of programming compared to using an MCU, but also improves reliability.
Keywords: serial port; stepper motor; motion control
1. Introduction A stepper motor is an actuator that converts electrical pulses into angular displacement. When a stepper driver receives a pulse signal, it drives the stepper motor to rotate a fixed angle (called the "step angle") in a set direction. Its rotation occurs step by step at fixed angles. The amount of angular displacement can be controlled by controlling the number of pulses, thus achieving accurate positioning; simultaneously, the speed and acceleration of the motor can be controlled by controlling the pulse frequency, thus achieving speed regulation. Stepper motors can be used as special motors for control, utilizing their characteristic of having no accumulated error (100% accuracy), and are widely used in various open-loop control systems. Stepper motors are widely used in automatic or semi-automatic equipment such as CNC machine tools, medical devices, and instruments. The common practice for controlling stepper motors with a computer is to use a stepper control card. This method is not only costly but also inconvenient to operate. Installing a control card in a computer expansion slot requires opening the computer case to operate, and small tablet computers and embedded computers simply do not have the space or expansion slots to install control cards. In recent years, a technology has emerged that utilizes the secondary development of computer serial ports to control stepper motors, replacing the function of control cards. This approach offers advantages such as low cost, ease of operation, and good compatibility. This paper introduces a novel method for controlling a two-dimensional coordinate positioning system via a microcomputer's serial port.
The serial port is a standard configuration of microcomputer systems and is widely used in instrument and meter control systems. The computer serial interface adopts the RS232 standard [1]: the level of logic 1 is specified as -3 to -15V, the level of logic 0 is +3 to +15V, and there are 8 commonly used signals (when the interface is DB9M and DB25M socket, the pin numbers are shown in Table 1). Among them, RXD and TXD are for receiving and transmitting data and can communicate directly with RS232 serial port devices. RTS, DTR, CD, DSR, CTS, and BELL are signals for controlling and detecting the MODEM and play a role in communication and control. The data format has several types of 5, 6, 7, and 8 bits, 1 start bit (logic 0), 1, 1.5, or 2 stop bits (logic 1), and odd parity, even parity, and no parity can be selected. The commonly used baud rates are 2400, 4800, 7200, 9600bps, etc.
Table 1 Pin definitions for standard 9-pin and 25-pin serial ports
The general method for controlling a stepper motor-driven motion system via a serial port is through a microcontroller or other embedded control system. The computer sends control information to the microcontroller system, which then directly controls the motion system, allowing the computer to indirectly control the system's behavior. This method has some drawbacks. For example, it lacks control flexibility, often only moving according to a pre-defined pattern and not allowing arbitrary changes through control software. The microcontroller must simultaneously receive computer commands, send status updates to the computer, and control the motion system, leading to multitasking and complicating programming. Microcontroller programs are prone to crashing, posing a significant threat to system reliability and sometimes requiring manual reset. To overcome these drawbacks, we designed a method for directly controlling the motion system via a serial port in practical applications. This method does not require an MCU and allows for easy adjustment of the stepper motor's speed by changing the serial port's baud rate. The direction of movement and the reading of different position information can be controlled by controlling the modem's status input and output signals through the RS232 serial port. Because it is direct control without an intermediate processor system, it overcomes the above drawbacks and reduces costs. The implementation method of this control system is described below.
2. Control method for two-dimensional motion stepper motor drive
In a stepper motor-driven two-dimensional motion positioning system, each dimension is controlled by a stepper motor driving a lead screw, which then converts the motion into linear motion, as shown in Figure 1. Controlling this system requires not only sending direction control and step pulse signals to the stepper motor but also reading the switch signals for absolute positioning to achieve absolute coordinate control. In the figure, S1 is the limit switch for the coordinate zero point; a high-level output indicates that the motion has reached the absolute zero point. Because the precision of such mechanical or photoelectric switches is limited, the zero-point pulse output by S1 is not highly accurate. To improve the zero-point position accuracy, a switch S0 is also provided, which outputs one pulse for each revolution of the stepper motor. Although the pulse width of S0 is not significantly different from that of S1, the lead screw significantly improves the accuracy of the pulse output by S0 relative to the linear position. Therefore, the method for determining the zero point should be: when moving to the left, first check if S1 outputs a high level. If it does, it indicates that the zero point has been approximately reached, but the accuracy needs further improvement. Then, continue driving the stepper motor to rotate and check if S0 outputs a high level. Only when the output of S0 also reaches a high level does it indicate that the zero point has truly been reached. Switch S2 is a limit switch for the maximum coordinate value; its high-level output indicates that the maximum coordinate value has been reached and further rightward movement is not possible. [align=center] Figure 1 Schematic diagram of stepper motor drive[/align]
Figure 1 only illustrates one-dimensional motion; the control of the other dimension is exactly the same. The specific implementation method will be discussed below.
3. Generation of stepping pulses and velocity calculation
Each pulse sent to the stepper motor driver causes the stepper motor to rotate one step, while the direction is controlled by another voltage level signal. For a given stepper motor, the number of pulses required for one revolution is a fixed constant n. Therefore, the angle the motor rotates with each pulse is also fixed, called the step angle s. The relationship between s and n is: s = 360/n degrees. For example, a four-phase, eight-beat stepper motor requires 400 pulses per revolution, so the step angle s = 0.9 degrees.
The stepping pulse is cleverly generated using the format of computer serial data through appropriate settings. A computer's serial port data frame generally consists of a start bit, data bits, parity bit, and stop bit. Figure 2 shows the transmission of B10010011. Here, the start bit is set to 1 bit, followed by 8 data bits. The parity bit is set to "Mark" (i.e., 1), and the stop bit is 1 bit (logic 1). The stop bit ensures a certain time interval between the completion of one data frame and the start of another when data is continuously transmitted. Thus, a data frame we set has 11 bits. Depending on the data transmitted, we can obtain different numbers and durations of pulses within these 11 data frames. For example, when transmitting the binary number B11110000, the start bit is 0 followed by 4 consecutive 0 bits, then 4 consecutive 1 bits, plus the parity and stop bits, resulting in a single pulse signal consisting of 5 consecutive 0 bits followed by 6 consecutive 1 bits. Different numbers of pulses can be obtained by selecting different data to transmit. For example, sending B10101010 will produce four consecutive pulses. Here, to obtain a uniform duty cycle, the method of sending B11110000 data is always used to generate one pulse per data frame. [align=center]Figure 2. Schematic diagram of transmitting binary number B10010011[/align] The baud rate B of serial communication is defined as the number of bits of data sent per second. A data frame is 11 bits, so the required time T is 11/B. Since each data frame generates only one pulse, the pulse frequency v can be determined as v=B/11. If the number of pulses required by the stepper motor per revolution is n, then the motor speed ω=60B/11n revolutions/minute. For example, if B is 9600 b/s and n is 400, then ω=131 revolutions/minute.
4. Input and output of position and direction signals
In addition to the TxD/RxD signals used for data transmission and reception, the 9-pin standard RS232 serial port of a computer also includes RTS/CTS, DTR/DSR, and DCD signals. These signals are originally defined for controlling the modem; here, we use them to read position signals, output direction signals, and select the dimension. Specifically, we use DTR to output the dimension selection signal. A value of "1" indicates that all outputs and inputs are for movement in the X direction, while "0" selects the Y direction. The RTS signal is used to output the direction of movement, controlling the stepper motor's forward and reverse rotation. The input signals CTS, DSR, and DCD are used to input the limit switch and zero-position switch signals.
In addition, a circuit is needed to convert between RS232 and TTL levels. RS232 is a negative logic level. To achieve the conversion between RS232 and 5V TTL levels, we use the MAX232 dedicated chip. The core of this chip is a "charge pump," requiring only a single 5V power supply. The circuit diagram is shown in Figure 3. The logic of the entire circuit can be implemented using a single programmable logic chip, EPM7064. While implementing the above circuit, we also implemented the pulse distribution logic and protection logic for the stepper motor in the programmable logic chip. After the coordinates reach their maximum and minimum values, the motor is no longer allowed to move right or left.
5. Practical Applications and Programming
The method provided in this paper greatly facilitates the development of computer control software [2]. Taking MSVB6 as an example [3], after placing the serial port control MSCOMM32, the dimensions and directions of motion can be easily controlled by setting the values of DTR and RTS through the program. The motion status can be obtained by reading the values of the control properties CTS, DSR, and DCD. The speed of the stepper motor can be changed by setting different sending baud rates, and the number of steps of the stepper motor can be controlled by placing the number of characters in the sending buffer. We can also easily program in Delphi [4]. On other computing platforms, we can also easily program, for example, on Linux [5]. We can easily control the serial port device by programming the ttyS0 device. The author of this paper has successfully applied the method to the automatic control of the metallurgical microscope stage.
The author's innovative points:
1. Generate stepper motor drive pulses with different frequencies and duty cycles by setting the baud rate, format, and output characters of the serial port.
2. Input and output control signals through the standard serial port to input and output control signals and position signals of the two-dimensional motion system.
References:
1. Microcomputer Interface Technology and Applications, Liu Leshan et al., Huazhong University of Science and Technology Press, 2000.4.
2. "Visual C++/Turbo C Serial Communication Programming Practice", Gong Jianwei, Xiong Guangming, Electronic Industry Press, October 2004.
3. Hu Qingyun, Luo Feilu, Application of Communication Controls in Visual Basic 6.0, Microcomputer Information, 2001 Vol.17 No.2, 40 pages.
4. Zhang Licai, Implementing Serial Communication with MSComm Control in Delphi Programming, Microcomputer Information, 2001 Vol.17 No.3, p.26.
5. Linux Programming: The Definitive Guide, Yu Mingjian et al., Machinery Industry Press, April 2001.