Design of a stepper motor driver based on GAL16V8 and ULN2003
2026-04-06 07:39:59··#1
Introduction Microplates are frequently used as measurement carriers in medical testing. To improve the positioning accuracy and operational stability, sequential movement in the Y and X directions is required, making stepper motors a good choice for driving this motion. Introduction to AT89C55 and GAL16V8: The AT89C55 is a low-voltage, high-performance 8-bit microcontroller from Atmel, compatible with the standard MCS-51 instruction set and pin-compatible with the industry-standard 89C51 and 89C52 chips. The AT89C55 has 40 pins, 32 external bidirectional I/O ports, and includes two external interrupt ports, two 16-bit programmable timer/counters, two full-duplex serial communication ports, two read/write lines, and an on-chip clock circuit. The AT89C55 employs two software-controlled static logic idle modes to enter a power-saving sleep mode. It can be woken from sleep mode by RAM, timers/counters, the serial port, and external interrupts to continue operation. In sleep mode, RAM is frozen, and all other functions are stopped until the next external interrupt triggers or a hardware reset. In particular, the rewritable Flash memory effectively reduces development costs. Generic Array Logic (GAL) devices, developed by Lattice Semiconductor, are electrically erasable PLD devices that can be used to construct decoders, priority encoders, multiplexers, comparators, shift registers, counters, bus arbiters, etc. Using GAL16V8 devices to control two-phase and four-phase hybrid stepper motors not only simplifies the system structure and reduces costs but also provides flexible and convenient programming, improves system reliability, and enhances system adaptability. Hardware Design This design uses a GAL16V8 ring pulse distributor and a ULN2003 (domestic model 5G1413) seven-channel Darlington driver array, which is an open-collector (OC) output inverter. The maximum drive current can reach 500mA. In typical applications, one end of the stepper motor load is connected to VDD (12V), and the other end is connected to an output pin, such as pin 16. To prevent the program from entering an infinite loop, an external hardware watchdog timer MAX813L is added. Its internal watchdog timer monitors the operation of UP/UC. If its operation is not detected within 1.6s, the internal timer will set the watchdog output WDO low, and WDO will remain low until UP/UC is detected at WDI. Connecting WR and WDO allows the watchdog to time out and trigger a reset. Two ULN2003 chips are used to drive the stepper motors in the X and Y directions respectively. The specific hardware circuit is shown in Figure 1. Software Design The pulse control of the stepper motor is usually implemented by logic circuits. In computer-controlled systems, the motor's operating mode, direction, and speed can also be determined by programming pulses output from extended I/O ports; however, this method consumes too much CPU time. GAL devices come in various models. Based on design requirements and economic considerations, the GAL16V8 was chosen to control a four-phase hybrid stepper motor. The source code, programmed using the ABEL language, is shown below. module motor title Operation of the simulator on devices with motor DATA I/O Corp. 21 10 2002 FB1 device 'P16V8R'; D1,D2,D3,D4 pin 2,3,4,5; F8 = D1&D2&D3&D4; F7 = D1&D2&D3&!D4; F6 = D1&D2&!D3&D4; F5 = D1&D2&!D3&!D4; F4 = D1&!D2&D3&D4; F3 = D1&!D2&D3&!D4; D1 & !D2 & !D3 & !D4; end motor. Setting a software trap When the program enters the non-program area, by setting an interception measure in the non-program area, the program is forced into a trap, and then forced back to its initial state. For example, if the bytecode corresponding to the CPU's RST instruction is 0FFH, and 0FFH is pre-written into an unused program memory area, then when the program "flies" to that area to execute code due to interference, it is equivalent to executing an RST instruction, thereby achieving the purpose of system reset. The program flow is shown in Figure 2. Figure 2. The assembly source code of the software program flow is as follows: MOV120: MOV R3,#51H MOV121: LCALL MOV124 ;12-line forward program 1 DJNZ R3,MOV121 MOV P1,#0H ;Motor power failure MOV R0,#100 RD08: LCALL DELY DJNZ R0,RD08 MOV80: MOV R3,#13H MOV 2CH,#7 ;8-column forward program 1 MOV81: LCALL MOV84 DJNZ R3,MOV81 MOV P1,#0H ;Motor power failure MOV R0,#10H RD09: LCALL DELY ;Single hole measurement program DJNZ R0,RD09 SETB ET0 ;Start timer 0 LCALL COTP ;Single hole measurement program CLR ET0 ;Turn off timer 0 LCALL QUIT INC 2DH LCALL D10MS; Delay 1ms LCALL D10MS; Delay 1ms MOV85: MOV R4,#0CH; 8-column forward program 2 MOV83: LCALL MOV86 DJNZ R4, MOV83 MOV P1,#0H MOV R0,#10H RD03: LCALL DELY DJNZ R0,RD03 SETB ET0; Turn on timer 0 LCALL COTP; Single-hole measurement program CLR ET0; Turn off timer 0 LCALL QUIT INC 2DH LCALL D10MS; Delay 1ms LCALL D10MS DJNZ 2CH,MOV85; Measure, loop 7 times, CJNE R7,#1,RD02; Determine if measurement is complete POP 07H SETB P3.3; P3.3=1 high voltage = 450V LCALL BK080; Measurement row and column completed, return to initial position program LCALL BK120 LCALL LOCKOFF RD02: LCALL BK080; 8-column backtracking program MOV R0,#250 RD0A: LCALL DELY LCALL DELY DJNZ R0,RD0A RD01: MOV R5,#0BH MOV123: LCALL MOV125; 12-row forward program 2 DJNZ R5,MOV123 MOV P1,#0H; Motor vectoring MOV A,R7 MOV 2DH,#0 INC 2EH DJNZ R7,MOV80; Cycle through several rows Conclusion The stepper motor drive system designed in this way has the advantages of smooth movement, high speed, and high control accuracy, and has been applied to the drive system of a single-photon analyzer counter.