Abstract: This paper presents a simulation method for controlling a stepper motor from a host computer to a slave device using Proteus. The host computer software is developed in VB, while the slave device is designed and simulated using Proteus. A virtual serial port (VSPD) is used to simulate a serial communication line, enabling serial communication between the host and slave devices. Ultimately, this achieves real-time control of the stepper motor from the host computer (VB) to the slave device (Proteus). This provides an effective and feasible simulation method for the learning, development, and practical application of PC-based stepper motor control.
Keywords: Proteus; stepper motor; serial communication;
1 Introduction
Stepper motors can achieve a fairly high positioning accuracy in a simple open-loop working mode, and can output a large torque when running at low speed, so they are widely used in motion control [1]. PC stepper motor control systems are used in many fields such as CNC machine tools, robots, laser processing equipment and other instruments and equipment. A complete PC stepper motor control system has a master-slave control structure between the lower computer and the PC: the PC is responsible for the management of the human-computer interaction interface, including the management of the keyboard and mouse, the display of system status, and the sending of control commands; the lower computer completes all the details of motion control, including the output of pulse and direction signals, and the processing of automatic acceleration and deceleration. The actual development process of the lower computer is complex, mainly including hardware circuit design and control program design. The control program design process requires three processes: software debugging, hardware debugging and system debugging.
Software debugging is generally easier, but hardware debugging or system debugging, which involves component selection, PCB fabrication, component soldering, and program burning, can easily lead to program distortion if overlooked in any of these stages. By constructing hardware circuits using virtual instruments in Proteus, the control effects of the designed program can be debugged, achieving the purpose of virtual hardware debugging and virtual system debugging. This provides effective theoretical and practical basis for the development of PC stepper motor systems, avoiding program anomalies caused by errors in hardware circuit design or limitations in hardware experimental conditions that could hinder development.
Proteus, developed by Labcenter in the UK, is a circuit analysis and hardware simulation software that combines microcontroller simulation and SPICE circuit simulation. It features simulation capabilities for analog circuits, digital circuits, systems composed of microcontrollers and their peripheral circuits, RS232 dynamic simulation, I2C debugger, SPI debugger, keyboard, LCD, virtual instruments, oscilloscopes, and logic analyzer systems. It supports simulation functions for mainstream microcontroller systems. The hardware simulation system includes full-speed, single-step, and breakpoint setting debugging functions, allowing users to observe the current state of various variables and registers. It supports third-party software compilation and debugging environments, such as Keil uVision2 and MTLAB. Due to Proteus's excellent simulation characteristics, the designed program can complete the simulation process within Proteus, thus essentially proving the accuracy of the designed program. This completes the control program design portion of the system development and provides guidance for the system hardware circuit design.
2 Design Requirements
Taking the construction of a PC-based stepper motor motion control simulation system based on Proteus as an example, the host computer human-machine interface is developed by VB; the lower computer hardware circuit is constructed by various virtual instruments in Proteus; the lower computer control program is developed by Keil uVision2; during this process, a virtual serial port (VSPD) is also used to simulate a serial communication line to realize serial communication between the host computer and the lower computer, and finally realize the real-time control process of the stepper motor in the lower computer (Proteus) by the host computer (VB).
2.1 System Overall Block Diagram
The host computer issues commands to the slave computer via RS232C serial communication. The slave computer's AT89C51 microcontroller generates four-phase control signals (A, B, C, and D) according to a specific timing sequence, implementing single-step, double-step, and single-double-step stepper motor drive modes respectively. In practical applications, signal isolation and amplification integrated circuits are generally required between the microcontroller and the stepper motor. The slave computer also includes a display function, using an LCD1602 to display the stepper motor's motion status in real time. The Proteus simulation circuit may differ somewhat from the actual circuit. Considering the practical verification of the simulation, a control module suitable for actual simulation was designed, as shown in Figure 1.
2.2 Structural Design of the Lower-Level Simulation System
In practical applications, the microcontroller controls the stepper motor and requires an isolation and amplification module. In simulation, this control module can be omitted and the stepper motor can be directly connected to the AT89C51. It can also be used in the simulation circuit. Since the main purpose here is to detect the control effect of the pulse, the isolation and amplification circuit is omitted. Serial communication part [3] In non-simulation control, the host computer level is RS232C level, while the slave computer level is TTL level, so they cannot communicate directly. Therefore, a level conversion chip MAX232 is added.
In actual simulations, since both the upper and lower level machines operate on a PC, a level conversion chip is unnecessary; otherwise, errors will occur. During simulation, bits 2 and 3 of the serial port can be directly connected to the RXD and TXD pins of the AT89C51 microcontroller. For the LCD display circuit, when the microcontroller drives the LCD, signal loss occurs during transmission. Therefore, in practical applications, a signal gain module is often used to drive the LCD. Since there is no signal loss during simulation, the external crystal oscillator circuit and reset circuit can be omitted. In summary, when building a Proteus lower-level machine system, the isolation amplifier module, LCD driver module, external crystal oscillator circuit, and reset circuit are optional, while the RS232 to TTL level conversion module must be omitted.
3 Software Design
3.1 Lower-level software design
The lower-level software was developed using Keil uVision2. The program itself is compatible with both Proteus simulation and actual stepper motor control systems. The lower-level program consists of five parts: an initialization program, a serial interrupt program, a timer T0 interrupt program, an LCD display function (containing several control command sub-functions), and the main program function. The program design flow is shown in Figure 2.
In program design, it is important to set the priority of the serial interrupt to be higher than that of the T0 interrupt, because the default priority of the ET0 interrupt is higher than that of the serial interrupt ES [6]. The statement PT0=0; //low priority, PS=1; //high priority can be used, because only when the serial communication priority is the highest can the real-time control of the lower machine by the upper computer be realized, which is very important. The algorithm for converting character data to ASCII code needs to be applied in the serial interrupt. Because the data sent in MSComm1.Output is character data, and the AT89C51 will convert the received character data into ASCII code. If the upper computer sends a data "0", the lower computer will convert it into "48" after converting it into ASCII code. Obviously, this is not the control instruction agreed with the lower computer in advance. Therefore, it is necessary to perform certain calculations on the received instruction data and then hand it over to the CPU for judgment.
Since the host computer only has seven control command data, the statement if (temp<=57 & temp>=48) temp=temp-0x30; can be used to achieve this. The entire serial interrupt routine is designed as follows: static void com_isr(void)interrupt SIO_VECTOR using 1 { if(RI) //RI=0 Request serial interrupt { temp=SBUF; //Read instruction data from the receive register if(temp<=57 & temp>=48) //Check instruction register data temp=temp-0x30; //Calculate instruction register data RI=0; //RI=0 prepares for the next serial interrupt k=0; //Sets the execution condition for the display function return; } } When designing the T0 interrupt routine, the key elements of the intermediate time (which is determined by the initial value of the timer/counter and the working mode) and the number of interrupts determine the change in the pulse frequency of the drive motor, that is, the stepper motor speed. A reasonable speed needs to be designed to facilitate the recording and acquisition of stepper motor data and observe the motor's motion state under single-beat, double-beat, and single-double-beat drive modes.
Since "MODE:" is always displayed in the LCD display program design, the "MODE:" display of the LCD can be designed during program initialization, and then the corresponding stepper motor motion state can be displayed according to the data instruction. This can save the MCU processing time and improve the real-time control capability of the simulation system. The main program body completes the processing of the final received host computer instruction, and then completes the entire process of the host computer controlling the stepper motor. The corresponding control instruction N corresponds to the state of each device. Each N value means a control instruction. Different N values will have corresponding state contents for the stepper motor, LCD, host computer Text, P1 port pulse [5]. The specific details are shown in Table 1.
3.2 Host Computer Software Design
The host computer software was developed using VB. It utilizes the Microsoft Communications Control ActiveX control for serial communication programming, which encapsulates all necessary API functions, providing an easy way for applications to send and receive data via the serial port. Simply set the Settings property, including parameters such as return baud rate, parity, data bits, stop bits, and the corresponding serial port. Then, design the corresponding event handlers to achieve the desired communication control effect. The program mainly develops the seven commands sent to the lower-level machine and the Text display of the motor status, realizing host computer control.
4. System simulation results and simulation analysis
Figure 3 shows the pulse drive signals acquired by the virtual oscilloscope (OSCILLOSCOPE) for the corresponding single-beat forward rotation, double-beat forward rotation, and single-double-beat forward rotation scenarios. Combined with the P1 port pulses in Table 1, after eliminating normal glitches and jitter, the signals perfectly match the corresponding pulse signals required for actual driving. Figure 4 shows the corresponding movement process of the stepper motor after the lower-level computer receives the single-beat forward rotation command corresponding to Figure 3(a). Here, the virtual step angle of the virtual stepper motor is 90 degrees. In the figure, red represents high level and blue represents low level for phases A, B, C, and D. The information recorded during the simulation process in Figures 3 and 4 perfectly matches the expected operating results of the actual design program control, demonstrating a clearly reliable simulation effect.
As shown in Figure 5, when the lower-level machine is running, the upper-level machine selects Option 1 and clicks the forward rotation button, sending the command "1" to the lower-level machine. The virtual terminal is an auxiliary analysis tool in the Proteus software, recording each serial communication command. The stepper motor will move accordingly based on the pulse pattern of P1, and the LCD in Proteus and the Text display on the upper-level machine correctly show the stepper motor's movement status.
5. Conclusion
A PC-based simulation method for stepper motor motion control based on Proteus is proposed. The constructed simulation system can effectively realize the overall process of synchronous control and status display of the stepper motor by the PC. Through program design and development, it is seamlessly connected with the simulation system, realizing the control process expected by the program. It also provides rich experimental observation interfaces, and the simulation realizes the program hardware debugging and system debugging process.
References
1 Sun Yaojie, Zuo He, Kang Longyun, Cao Binggang, Shi Weixiang. Time-varying repetitive control for suppressing torque ripple in hybrid stepper motors [J]. Proceedings of the CSEE, 2004, 24(11): 183-187
2 Meng Wusheng, Li Liang. Design of stepper motor control system based on AT89C52 microcontroller [J]. Measurement and Control Technology, 2006, 25(12): 46-51.
3 Zhang Junjie, Li Shiqi, Xiong Youjun. Application of robotic arm control technology based on data gloves [J]. Computer Applications Research, 2006(6): 170-175
4 Li Heqing, Hou Zhixiang. Small distributed control system for stepper motor based on serial communication [J]. Computer Engineering, 2007, 33(10): 258-260
5 Jin Jianxin, Zheng Huzi. Research on 16-bit single-chip microcomputer control of hybrid stepper motor [J]. Mechanical Design and Manufacturing, 2007(9): 94-96
6 Li Quanli, Chi Rongqiang. Microcontroller Principles and Interface Technology [M]. Beijing: Higher Education Press, 2004(1).