Stepper motor control system based on 80196 and PBL3717
2026-04-06 06:38:36··#1
Abstract: This paper introduces the control system of a two-phase stepper motor composed of an Intel 80C196KC microcontroller and two PBL3717A motor driver chips. It includes the hardware circuit design of the motor driver based on the PBL3717A chip and the software control program of the stepper motor. The system outputs control pulses through the high-speed output port HSO of the 80C196KC, which occupies very little CPU resources and realizes the rotation, locking, speed control and software microstepping control of the stepper motor. Keywords: PBL3717 80C196KC Stepper motor 1. Introduction Stepper motor is a pure digital control motor. It converts electrical pulse signals into angular displacement. By changing the frequency and number of output pulse signals, speed regulation and position control can be realized. It has good low-speed operation characteristics and a wide speed range. It is simple to control, low in cost, has no cumulative error, and can move and position accurately [1]. The PBL3717A is a dedicated driver chip for single-phase windings of stepper motors manufactured by SGS-THOMSON. Two PBL3717A chips and a few passive circuit components can form a complete control and drive circuit for a two-phase stepper motor. The 80C196KC is a high-performance CHMOS 16-bit microcontroller in the Intel MCS96 series. Using the 80C196KC and PBL3717, the operation, torque subdivision, speed change, and locking control of a two-phase hybrid stepper motor can be well realized. 2. Hardware Design 2.1 Motor Drive Circuit 2.1.1 PBL3717A Motor Driver Chip The PBL3717A stepper motor driver chip used in this system achieves different step pitch control of the stepper motor through the output control signals of the microcontroller. The working principle of the 3717A chip is introduced below. Figure 1 shows the structure of the PBL3717A motor driver chip with a dual in-line package (DIP) of 16 pins [2]. Pins 1 and 15 are the chip current output terminals, which are connected to the two ends of the motor coil, respectively. The internal structure consists of four Darlington transistors and freewheeling diodes forming an H-bridge. Pin 8 is the phase selection terminal, which controls the direction of the current output. When it is high, the current flows from OUTPUTA to OUTPUTB. The built-in Schmitt trigger can effectively eliminate noise interference and commutation current delay. Pins 9 and 7 are the current selection input terminals, which input different logic control signals to select three different voltage comparators in the chip to select different output currents. The reference voltage at the comparator terminal is obtained from the applied voltage through voltage divider resistors. The four on-chip voltage divider resistors from top to bottom are 6kΩ, 223Ω, 223Ω, and 105Ω, with voltage division ratios of 0.084, 0.050, and 0.016. Therefore, under different logic control input signals, the output current is I00 : I10 : I01 = 1 : 0.6 : 0.2. Pin 16 is connected to an external winding current sampling resistor Rs. Pin 11 is the reference voltage input terminal, connected to the three on-chip voltage comparators. Changing the reference voltage allows for fine-grained control of the stepper motor torque. When the phase control terminal Phase is high, thyristors Q2 and Q3 are cut off, Q1 remains on, and Q4 is in a high-frequency switching state, with current flowing from OUTA to OUTB. When Q1 and Q4 are turned on, the current through the motor coil is converted into a sampled voltage signal Urs by the sampling sensing resistor Rs at pin 16. After passing through the RC low-pass filter circuit, a voltage signal Uc proportional to the motor winding current is formed and fed back to pin 10, which is connected to the inverting input of the comparator. When the sampled voltage is greater than the reference voltage of the corresponding on-chip voltage comparator, the comparator is turned on, and a negative level transition occurs at the output, triggering the monostable circuit to output a high level. Thyristor Q4 is turned off, and the motor winding current forms a freewheeling loop through Q1 and D2, the coil discharges, the current decreases, and Vrs decreases accordingly. The current decay time depends on the RT and CT parameters connected to pin 2 (toff=0.69RTCT). When the sampled voltage Vrs is less than the voltage comparator reference voltage, the monostable circuit outputs a low level, Q4 is turned on, and the current increases, and this process repeats. Because the switching frequency is extremely high, the current in the motor winding is approximately a stable DC current, thereby controlling the magnitude of the average current in the motor winding and ensuring a stable output of the winding current. When the reference voltage of the selected comparator is relatively high, the time for Uc to reach the required value is relatively long, so the monostable circuit stays in steady state for a longer time, and the average current of the motor is larger. When the Phase pin is low, the working principle is similar: Q1 and Q4 are cut off, Q2 is continuously conducting, and Q3 is in a high-frequency switching state, except that the current flows from OUTB to OUTA. When the Phase pin level changes, an induced electromotive force is generated due to the inductance of the motor windings during current commutation, generating an induced current that flows through the freewheeling diode, ensuring that the current in the motor windings can quickly drop to zero and commutate. 2.1.2 Motor Drive Circuit and Step Control Figure 2 shows the stepper motor drive circuit, which is a drive circuit for a two-phase stepper motor composed of two 3717 chips. It can realize the full-step, half-step, and 1/4-step operation modes of the stepper motor. The full-step operation mode is a single-phase excitation or a two-phase excitation four-step mode. The half-step operation mode is a single-phase and two-phase alternating excitation eight-step mode. The system uses a 1/4-step operating mode, inserting a 1/4-step state between a full step and a half step. One rotation of the magnetic field is divided into 16 beats, resulting in a small step angle and smooth motor operation. Simultaneously, a step angle subdivision function is added to the system, further reducing the step angle of the stepper motor. The control waveform is shown in Figure 3. 2.2 Microcontroller System Circuit The 80C196KC is a CHMOS 16-bit microcontroller from Intel, offering significantly improved performance compared to the MCS51 series. It can operate at a clock speed of up to 20MHz, with an internal divide-by-2 circuit, resulting in fast instruction execution and low power consumption. The CPU's arithmetic logic unit does not use a conventional accumulator structure but instead employs a register-to-register structure. The CPU directly interacts with 256 bytes of registers, eliminating the bottleneck effect of the accumulator in typical CPU structures and improving operating speed and data throughput. It integrates abundant hardware peripherals and software resources on-chip. It integrates an 8-channel 10-bit A/D converter and a three-channel pulse width modulation output, and has complete HSIO function, which is convenient for implementing complex I/O control. It also adds a peripheral server PTS to handle peripheral interrupt service transactions, which improves the real-time processing capability of interrupt transactions [3]. Based on the above advantages, the 80C196KC microcontroller and PBL3717 can form a complete stepper motor control system. The system circuit of 80C196KC will be described below. 2.2.1 High-speed output port HSO 80C196KC has 6 high-speed output ports, which are used to trigger a certain event according to the time set by the program. The CPU overhead is very small, so the speed is very high. Connect the HSO0~HSO6 of 80C196KC to the I0A, I0B, PHASEA, IB0, IB1, and PHASEB of two PBL3717A chips respectively. Outputting a certain frequency of control word pulses to the HSO port can control the rotation direction and speed of the stepper motor. The system uses timer T2 as the time base for HSO output events, and the system CLKOUT signal is used as the clock source for T2, connected to the T2CLK pin. Utilizing the HSO timer 2 reset command and CAM locking function, the T2 reset time is locked in the CAM, thus generating HSO output events periodically. The period of one rotation of the magnetic field within the stepper motor windings is the reset period of timer T2. By setting the HSO event trigger time to the T2 reset time, the frequency of the control waveform is adjusted, thereby achieving variable speed control of the stepper motor. Clearly, using the HSO function provides precise output pulse waveforms and significantly reduces system overhead. Because the stepper motor may experience displacement due to external interference during actual operation, a certain locking torque is applied to the motor to maintain its fixed position when it stops. At this time, a constant current flows simultaneously through the A and B phase windings of the two-phase stepper motor. The rotor rotates to a position where the two-phase magnetic fields are balanced, thus locking the motor in place. During prolonged locking, the winding output is generally low current to avoid overheating of the motor and chips caused by prolonged energization of the windings. 2.2.2 Interrupt System The upper and lower limit signals of the stepper motor are connected to P1.6 and P1.7 respectively, and then connected to the external interrupt pin P2.2. When the stepper motor rotates to the limit position, the external interrupt source is triggered and the external interrupt service subroutine is performed. In the subroutine, the P1.6 and P1.7 ports are first queried to determine which limit triggers the interrupt signal, and then the corresponding service subroutine is processed. The 80C196KC has four software timers that can work simultaneously. The system uses software timer interrupts for microstepping drive control. Timer 2 is used as the time base, and the output of the microstepping reference voltage is controlled in the interrupt service subroutine. 2.2.4 Microstepping Circuit The step angle microstepping function is added to the system. When the input pulse is switched, only a part of the rated value in the corresponding winding is changed. Each step of the motor rotation is only a part of the step angle. Without changing the motor construction parameters, the stepper motor runs smoothly, improves uniformity, weakens or eliminates oscillation, and improves the control accuracy of the motor [4]. The system uses a D/A conversion circuit to subdivide the reference voltage input of the 3717, up to a maximum of 256 subdivisions. Figure 4 shows the D/A subdivision driver circuit of the four-channel 8-bit digital-to-analog converter TLC7226. The microcontroller selects the digital-to-analog conversion channel through address buses MA1 and MA2, and writes the desired output reference voltage through data buses AD0 to AD8. When the write input selection terminal is low, the selected DA channel input latch is transparent, and the input responds to the activity of the data bus. Data is latched into the addressed D/A latch on the rising edge. When high, the analog output holds a voltage signal corresponding to the data stored in the latch, which is sent to the reference voltage input of the 3717 through a voltage follower. The system address buses MA14 and MA15 and the WR of the 80C196 select the TLC7226D/A chip through logic gates. The microcontroller's address bus 0xC000 to 0xFFFF is occupied by the D/A circuit. 3. Software Design The software design primarily focuses on system initialization, stepper motor forward and reverse rotation, speed control, microstepping control, and motor locking. The initialization program handles the selection and configuration of various microcontroller register windows and the setting of initial system values. The forward and reverse rotation of the motor is controlled by outputting a fixed-frequency control pulse sequence from HSO.0 to HSO.5. Speed control is achieved by changing the reset event time of Timer 2 in HSO_CAM and the trigger time of the corresponding HSO pulse output event. Simultaneously, a software timer interrupt for the 80C19KC is configured, and software microstepping drive control is performed in the interrupt service subroutine to microstep the 3717 reference input voltage, generating a stepped increasing and decreasing reference voltage. A fixed-level signal is configured for HSO to ensure a constant current flows through the A and B phase windings of the motor, thus locking the stepper motor. To achieve precise control of the stepper motor's start and stop operation, the derived exponential operating curve conforming to the stepper motor's torque-frequency characteristics is quantized and stored in an E2PROM. During system operation, the output pulse frequency is controlled by calling the state delay time corresponding to the current speed to ensure the smooth operation of the stepper motor. The main program flowchart, motor rotation control and software subdivision program flowchart of the system are shown in Figure 5. The program of this system is written in C language. The following are the function codes of HSO pulse output: IOC2=0X40; Enable CAM function lock ICO0=0; Enable T2CLK as T2 clock source HSO_COMMAND=0xCE; Lock T2 reset command HSO_TIME=time_reset; Set T2 reset period Delay(8); At least 8 machine cycles are required HSO_COMMAND =0x71; Set HSO.0 timer HSO_TIME= time_up; Set the set time Delay(8); HSO_COMMAND=0x71; Set HSO.0 timer reset HSO_TIME=timer_down; Set the reset time, 4. Conclusion A stable two-phase or multi-phase stepper motor control system can be constructed by using 80C196KC and two or more PBL3717A chips. The high-speed output port of 80C196KC outputs pulse control waveforms with precision and low CPU overhead. Through the software reference voltage subdivision function, the full step, half step and micro step control of the stepper motor can be well realized. This stepper motor control system is low in cost, easy to control, stable in performance and has high practical value. References: [1] Wang Xiaoming. Single-chip control of electric motor [M]. Beijing University of Aeronautics and Astronautics Press, 2002 [2] SGS Company. PBL3717A Stepper Motor Driver [3] Xu Aiqing. Intel 16-bit single-chip microcomputer (revised edition) [M]. Beijing University of Aeronautics and Astronautics Press, 2002 [4] Yang Zhongbao, Lin Haibo, Implementation of stepper motor chopper constant current uniform subdivision circuit based on 80C196MC, Microcomputer Information, 2003, 19(7)