ST EPPER MOTOR CONTRO L USIN G 89C51 MICROCONTRO LLER
Active In SP
Joined: Feb 2011
17-02-2011, 04:14 PM
Here’s a stepper motor controllerbased on 89C51 microcontroller tocontrol the rotation of a DC steppermotor in clockwise and anti-clockwisedirections. The controller is simple andeasy-to-construct, and can be used in manyapplications including machine control androbotics for controlling the axial rotation inXY plane. A similar circuit can be added tocontrol the rotation of the motor in eitherXZ or YZ plane.Fig. 1 shows the block diagram of thestepper motor control system. The powersupply section (in Fig. 2) consists of a stepdowntransformer (7.5V AC, 1A), bridgerectifier (comprising diodes D1 throughD4), filter capacitors (C1 and C2) andregulator IC 7805.We have used here an Atmel makelow-power, high-performance, 8-bit CMOSmicrocontroller AT89C51 with 4 kB of Flashprogrammable and erasable read-onlymemory (PEROM). It has a 128x8-bit internalRAM, 32 programmable input/output(I/O) lines and two 16-bit timer/counters.The on-chip Flash allows the programmemory to be reprogrammed in-systemor by a conventional non-volatile memoryprogrammer. By combining a versatile 8-bit CPUwith Flash on a monolithic chip, AtmelAT89C51 is a powerful, highly flexible andcost-effective solution to many embeddedcontrol applications. From traffic controlequipment to input devices, computernetworking products and stepper motorcontrollers, 89C51 microcontrollers delivera high performance with a choice of configurationsand options matched to thespecific needs of each application.IC AT89C51 features:1. 8-bit CPU with math registers Aand B2. 16-bit program counter (PC) anddata pointer (DPTR)3. 8-bit program status word (PSW)4. 8-bit stack pointer (SP)The control switches for the motor areconnected to Reset and Port P0.7 pins of themicrocontroller.
When powersupply switch S1 is closed, LED1 glowsto indicate the presence of power in thecircuit. Capacitor C3 connected to pin 9(RST) provides the power-on reset to themicrocontroller.The stepper motoris connected to portpins P2.4 throughP2.7 of the microcontroller(IC2) throughthe motor -dr ivercircuit consisting offour Darlington pairscomprising transistorsBC548 and SL100(T1-T2, T3-T4, T5-T6and T7-T8). Coils1 through 4 are the stepper motor coils.When transistors conduct, 5V (Vcc) isapplied to the coils and the currents flowingthrough them create magnetic fieldsand the motor starts rotating. The magneticfield energy thus created is stored in thecoils.When transistors stop conducting,power to the coils is cut off, the magneticfield collapses and a reverse voltage (calledinductive kickback or back emf) is generatedin the coils. The back emf can bemore than 100 volts. The diodes connectedacross the coils absorb the reverse voltagespike. This voltage, if not absorbed by thediodes, may produce opposite torque andcause improper rotation of the motor andalso damage the transistors. You can usevirtually any type of rectifier or switchingdiodes of appropriate current and reversevoltage breakdown rating.Clock and reset circuit. Two 33pFcapacitors (C4 and C5) are connected topins 18 and 19 of the microcontroller,respectively, with an 11.059MHz piezoelectriccrystal (XTAL1) across them. The clock frequency of the microcontrollerdepends on the frequency of the crystaloscillator used. Typically, the maximumand minimum frequencies are 1 MHz and16 MHz, respectively, so we should use apiezoelectric crystal with a frequency inthis range. The speed of the stepper motoris proportional to the frequency of the inputpulses or it is inversely proportional tothe time delay between pulses, which canbe achieved through software by makinguse of instruction execution time.The time taken by any instruction toget executed can be computed as follows:where ‘C’ is the number of cycles an instructiontakes to execute and ‘F’ is thecrystal frequency.The crystal frequency in this circuitis 11.059 MHz, so the time taken toexecute, say, ADD A, R1 (single-cycleinstruction), is about one microsecond(μs). Use of a 6MHz crystal will bringdown the instruction execution speed toto 2 μs.When power is applied, the reset inputmust first go high and then low. A resistorcapacitorcombination (R1-C3) is used toachieve this until the capacitor begins tocharge. At a threshold of about 2.5V, thereset input reaches a low level and the microcontrollerbegins to function normally.Reset switch (S2) allows you to reset theprogram without having to interrupt thepower.One major feature of 89C51 microcontrolleris the versatility built into the I/Ocircuits that connect the microcontroller tothe outside world. Ports P0 through P3 ofthe microcontroller are not capable of drivingloads that require tens of milliamperes(mA). Logic level current, voltage andpower requirement for different versions ofmicrocontrollers are given in Table I.Driver circuit design. The microcontrolleroutputs a current of 1.7 mA. Todrive the coil of a stepper motor requiringa torque of 7 kg-cm, 12V DC and 2amp/phase, we have to use a driver circuitthat amplifies the current from 1.7 mA to3 amp.As mentioned earlier, we have usedBC548 and SL100 as the driver transistorsfor driving a low-power rated steppermotor such as the one used in earlier14cm (5.5-inch) floppy drives. But for a7 kg-cm stepper motor, a driver circuit usingtransistors SL100 and 2N3055 wouldbe needed to amplify the current to 2.72amp. Typically, SL100 and 2N3055 each has a gain (hfe) of 40, but 2N3055 canhandle larger current since it belongsto the family of power transistors. So aheat-sink is required to dissipate the heatgenerated.The output gain of the Darlington pairof SL100 and 2N3055 transistors is:AVo = AV1 × AV2= 40×40= 1600AVo = Io/Iin = 1600where Io is the output current and Iin isthe input current of the Darlington pair.Io = 1600×1.7 mA Since the stepper motor has four coils,we need to use four Darlington pairs.
The program is written in Assembly languageand compiled using ASM51 crossassembler.The listing file is given at theend of this article. 89C51 microcontrolleris programmed using Atmel’s Flash programmer.One-step rotation of the stepper motorused in this project and implimentation equals 1.8o. When youprogram the motor for 200 steps, the motormakes one complete revolution, i.e. 360o.In the program, the line ‘MOV R7, #0CAH defines the rotation by 202 steps. Thehex number ‘0CAH’ equals the decimalnumber ‘202.’ However, one can changethe number of steps in the program as perone’s requirement.The step sequence is defined by theline ‘MOV A, #033H.’ Table II shows thestep sequence for 100 steps to energise thewindings of the stepper motor in clockwiseand anti-clockwise directions. The rotor ofthe stepper motor is in a position of minimumreluctance and maximum flux. Thusby energising the windings (representedby A1, A2, B1 and B2), the rotor takesthe position accordingly. In the program,the instructions ‘RR A’ and ‘RL A’ areused for clockwise and anti-clockwise,
download full report