Stepper Motor Control Using Microcontroller
Stepper Motor Control Using Microcontroller
i ocnt i o n
89C51 MICROCONTROLLER
Mandeep Singh Walia By combining a versatile 8-bit CPU Parts List
with Flash on a monolithic chip, Atmel
H
Semiconductors:
ere’s a stepper motor controller AT89C51 is a powerful, highly flexible and IC1 - 7805 5V regulator
based on 89C51 microcontroller to cost-effective solution to many embedded IC2 - AT89C51 microcontroller
control the rotation of a DC step- control applications. From traffic control T1, T3, T5, T7 - BC548 npn transistors
per motor in clockwise and anti-clockwise equipment to input devices, computer T2, T4, T6, T8 - SL100 npn transistors
directions. The controller is simple and networking products and stepper motor D1-D8 - 1N4001 rectifier diodes
easy-to-construct, and can be used in many controllers, 89C51 microcontrollers deliver LED1 - Red LED (5mm dia.)
applications including machine control and a high performance with a choice of con- Resistors (all ¼-watt, ±5% carbon):
robotics for controlling the axial rotation in figurations and options matched to the R1 - 100-ohm
XY plane. A similar circuit can be added to specific needs of each application. R2 - 10-kilo-ohm
control the rotation of the motor in either IC AT89C51 features: R3, R5, R7, R9 - 1-kilo-ohm
XZ or YZ plane. 1. 8-bit CPU with math registers A R4, R6, R8, R10 - 470-ohm
Fig. 1 shows the block diagram of the and B Capacitors:
stepper motor control system. The power 2. 16-bit program counter (PC) and C1 - 220µF, 25V electrolytic
supply section (in Fig. 2) consists of a step- data pointer (DPTR) C2 - 100µF, 16V electrolytic
down transformer (7.5V AC, 1A), bridge 3. 8-bit program status word (PSW) C3 - 10µF, 16V electrolytic
rectifier (comprising diodes D1 through 4. 8-bit stack pointer (SP) C4, C5 - 33pF ceramic disk
D4), filter capacitors (C1 and C2) and The control switches for the motor are C6 - 100µF, 16V electrolytic
regulator IC 7805. connected to Reset and Port P0.7 pins of the Miscellaneous:
We have used here an Atmel make microcontroller. X1 - 230VAC primary to 0-7.5V,
low-power, high-performance, 8-bit CMOS 1A secondary step-down
microcontroller AT89C51 with 4 kB of Flash transformer
Circuit description - 5V DC stepper motor
programmable and erasable read-only
memory (PEROM). It has a 128x8-bit inter- Fig. 2 shows the complete circuit of the
nal RAM, 32 programmable input/output stepper motor controller. When power stepper motor coils.
(I/O) lines and two 16-bit timer/counters. supply switch S1 is closed, LED1 glows When transistors conduct, 5V (Vcc) is
The on-chip Flash allows the program to indicate the presence of power in the applied to the coils and the currents flow-
memory to be reprogrammed in-system circuit. Capacitor C3 connected to pin 9 ing through them create magnetic fields
or by a conventional non-volatile memory (RST) provides the power-on reset to the and the motor starts rotating. The magnetic
programmer. microcontroller. field energy thus created is stored in the
The stepper motor coils.
is connected to port When transistors stop conducting,
pins P2.4 through power to the coils is cut off, the magnetic
P2.7 of the microcon- field collapses and a reverse voltage (called
troller (IC2) through inductive kickback or back emf) is gener-
t h e m o t o r - d r i ve r ated in the coils. The back emf can be
circuit consisting of more than 100 volts. The diodes connected
four Darlington pairs across the coils absorb the reverse voltage
comprising transis- spike. This voltage, if not absorbed by the
tors BC548 and SL100 diodes, may produce opposite torque and
(T1-T2, T3-T4, T5-T6 cause improper rotation of the motor and
Fig. 1: Block diagram of the stepper motor control system and T7-T8). Coils also damage the transistors. You can use
1 through 4 are the virtually any type of rectifier or switching
diodes of appropriate current and reverse
Table I voltage breakdown rating.
Power Consumption of Microcontrollers Clock and reset circuit. Two 33pF
IC Voh Ioh Voi Ioi Vil Iil Vih Iih Pt capacitors (C4 and C5) are connected to
pins 18 and 19 of the microcontroller,
CMOS 2.4V –60 µA 0.45V 1.7 mA 0.9V 10 µA 1.9V 10 µA 50 mW respectively, with an 11.059MHz piezo-
NMOS 2.4V –80 µA 0.45V 1.7 mA 0.8V –800 mA 2.0V 10 µA 800 mW electric crystal (XTAL1) across them. The
Table II
Clockwise Step Sequence of the Motor
A1 A2 B1 B2 A1 A2 B1 B2 Hex value
0 0 1 1 0 0 1 1 =33h
0 1 1 0 0 1 1 0 =66h
1 1 0 0 1 1 0 0 =CCh
1 0 0 1 1 0 0 1 =99h
0 0 1 1 0 0 1 1 =33h
1 0 0 1 1 0 0 1 =99h
1 1 0 0 1 1 0 0 =CCh
0 1 1 0 0 1 1 0 =66h
Fig. 4: Actual-size, single-side pcb for stepper motor control Fig. 5: Component layout for the PCB
system using 89C51 microcontroller
STPB1.LST
1 $MOD51 13 0023 758D01 25 MOV TH1, #1D
0000 2 ORG 0000H 0010 7FCA 14 P12: MOV R7, #0CAH; 0026 D28E 26 SETB TR1
0000 E580 3 MOV A, P0 0012 7433 15 MOV A, #033H; 0028 308FFD 27 BACK: JNB TF1, BACK
0002 33 4 RLC A 0014 F5A0 16 P11: MOV P2, A; 28
0003 500B 5 JNC P12 0016 03 17 RR A; 002B C28E 29 CLR TR1
6 0017 111B 18 ACALL DELAY 002D C28F 30 CLR TF1
0005 7FCA 7 MOV R7, #0CAH; 0019 DFF9 19 DJNZ R7, P11 002F DBEF 31 DJNZ R3, Z
0007 7433 8 MOV A, #033H; 20 0031 22 32 RET
0009 F5A0 9 P13: MOV P2, A; 21 33 END
000B 23 10 RL A; 001B 758910 22 DELAY: MOV TMOD, #10H
000C 111B 11 ACALL DELAY 001E 7B05 23 MOV R3, #05 VERSION 1.2k ASSEMBLY COMPLETE, 0 ERRORS
000E DFF9 12 DJNZ R7, P13 0020 758B08 24 Z: MOV TL1, #8D FOUND q