Text preview for : an1285 moteur pas à pas sur 11E9.pdf part of MAAS KNT-5000 Stabilized DC Power Supply MAAS KNT-5000



Back to : Maas KNT-5000.pdf | Home

MOTOROLA

Order this document by AN1285/D

SEMICONDUCTOR
APPLICATION NOTE

Stepper Motor Control with an MC68HC11E9 Microcontroller
By Bob King and Edgar Saenz

1 Introduction
This note provides basic implementation details and procedural information to design and assemble a stepper motor system. The controller discussed here is the MC68HC11E9, an 8-bit Motorola microcontroller (MCU). There are many embedded control applications supported by the M68HC11 Family. The note consists of a general description and gives highlights of implementing a basic stepper motor system application. A step-by-step hardware assembly section is included to promote ease of construction should one desire to build a similar system. To simplify the application, the software was generated on the Motorola M68HC11EVM evaluation module (EVM). The program created with the EVM is shown in 6 Listing. The program runs in addresses $C000 through $C1CC. It is meant to be used as a guide and can be modified to support a variety of stepper motor control applications. Some modules will require no changes for use. For convenience, a copy of the code is available through Freeware Data Services. The Freeware BBS can be accessed by modem at (512) 891-3733, or via the World Wide Web at http://freeware.sps.mot.com. The EVM comes with an on-board monitor called EVMbug11 that supports software development. This evaluation system provides easy I/O interfacing to external hardware and offers the user an inexpensive programming solution for devices with OTP, EPROM and EEPROM non-volatile memory. Evaluation of the A0, A1, A8, E0, E1, E9 or 811E2 versions of M68HC11 microcontroller devices is supported when using the EVM. The microcontroller that resides on the EVM for this application is the MC68HC811E1 version.

2 General System Information
Figure 1 shows basic system operation. R1 provides an analog input to the MCU which is converted to a digital value and used to determine the speed at which the motor turns. In this example, the resistance is being varied manually for the A/D input to the MCU. A feedback scheme from the motor back to the A/D input could be implemented to facilitate a closed loop system. To support motor turn direction, one I/O port pin is used to determine clockwise or counter-clockwise rotation. The voltage applied to the pin is sampled each time the program cycles through the software routines. A manual switch controls the state of the I/O pin. Green and yellow LEDs illuminate to indicate the turn direction. A seven-segment display shows the delay between steps when the stepper motor is driven, and indicates motor speed. A parallel port is used to send the appropriate character codes to the seven-segment display. Four LEDs form a second visual speed indicator. These LEDs are turned on in sequence as the respective coils of the stepper motor are activated. The activating pulse originates from an onchip port. The pulse pattern displayed by the LEDs alternates according to the motor shaft turn direction.

© MOTOROLA INC, 1997

5V PORTB[6:0] VRH 7-SEGMENT DISPLAY

A/D INPUT R1

PORTA0

IR DETECTOR/EMITTER

POSITION BAR VRL PORTC[3:0]

S1

IRQ STEPPER MOTOR

S2

PORTD0

SEQUENCE LEDS

CW CCW LEDS

Figure 1 Basic Stepper Motor Operation

3 Hardware Development
3.1 Motor Description The motor coil assemblies operate at voltage levels ranging from +5 to +24 volts. The motor has a single rotor which is connected to a shaft at the center of the assembly. There are multiple coils surrounding the rotor. A total of 100 steps are required for one complete revolution of the shaft. Each step increments by 3.6°. For this application, a wheel is attached to the shaft, but for other applications, the wheel could be replaced by a gear, a pulley, a belt or a timing mechanism.

MOTOROLA 2

AN1285/D

3.2 Components The hardware required to control the stepper motor varies significantly from one application to the next. Below is a list of components used to implement the system interfaced to an EVM: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. One EVM; One stepper motor; One ULN-2075B motor driver IC (optional for enhanced drive); One 25 K potentiometer (A/D input control); Two SPDT switches (power and CW or CCW turn control); One SPDT switch MOM (position control and single-step); One seven-segment display (display stepper motor delay $0­F); One infrared detector and emitter (position control); Seven LEDs (sequence, power and CW or CCW indicators); Two 1-inch square mounting boards for the IR pair; One project assembly board (4-inch x 6-inch); One power terminal strip; Two wirewrap sockets; Four NPN and four PNP transistors (optional for increased motor drive).

3.3 Assembly Procedures Use the following sequence to assemble the project. 1. Lay out the positions of the various components that are located on the 4-inch x 6-inch project assembly board. A board of this size provides ample room for all hardware required to assemble this project. 2. Place the power terminal strip at one end of the project board. Connect +5 volts and ground connections from the EVM to the appropriate power terminal strip connection. An optional power supply can be used to provide increased power for driving the motor. 3. Connect the +5 volts from the power terminal strip to one side of the slide switch. Connect the other side of the slide switch to the main +5 volt power bus for distribution to components on the project board. The main ground bus on the project board also needs to be made available for distribution to the components on the project board. 4. Place the two wirewrap sockets at the opposite end of the project board from the power terminal strip. One socket is for the seven-segment display and the other is for the optional motor driver. 5. A 25 K potentiometer is used for the analog input to the A/D converter. Connect one side of the potentiometer to +5 volts and the other side to ground. The center tap of the potentiometer is connected to PORTE bit 0 on the MCU. +5 volts is connected to the high reference voltage (VRH) and ground is used to supply the low reference voltage (VRL) MCU inputs. 6. The base portion of the stepper motor being used is a 1.5-inch cube. Place it securely in the center of the project board with the shaft and turning wheel at the top. Align the infrared (IR) emitter and detector to provide the best transmission and detection of the IR signal. Each IR component is mounted on a 1-inch square mounting board to aid with alignment. 7. Connect the emitter to +5 volts so that it continually emits a signal. Connect the detector to the MCU PORTA0 for sampling. The stepper motor has a narrow position bar located on the wheel. As the wheel turns, the position bar passes through the signal being sent and received by the IR pair. 8. The stepper motor has four coil wires that must be connected to MCU PORTC to promote the desired turning motion. PORTC[3:0] are used for this connection. The order of connecting these wires depends on the motor being used. A wiring diagram of the motor simplifies the connection process. The diagram is usually supplied with the motor. 9. Adding the optional ULN-2075B driver significantly enhances the performance of the system by providing increased drive capability. The ULN-2075B IC contains four individual driver circuits. These must be connected from the MCU to the input of the driver and from the output of the driver to the stepper motor coil connections. Another method of increasing the drive current to the stepper motor is to use a push-pull amplifier between each motor coil and PORTC. The

AN1285/D

MOTOROLA 3

amplifier consists of one NPN and one PNP transistor. One side of the amplifier is connected to the optional +12 volts and the other side goes to ground. 10. The PORTC pins are also connected to four LEDs. As the motor turns, the LEDs indicate the sequence of motor coil activations, turn direction and speed of motor turn. 11. Wire the clockwise/counter clockwise slide switch and the respective LED indicators to the MCU. For this application, the switch is connected to PORTD0. One side of the switch is pulled high and the other side is pulled low. One LED is wired to illuminate when PORTD0 is high and the other LED illuminates when PORTD0 is low. 12. Wire MCU PORTB to the seven-segment display. Figure 2 shows interfacing requirements for the seven-segment display.
A SEGMENT A F B B C D G E F E C G PORTB BIT # 6 5 4 3 2 1 0

D

Figure 2 Seven-Segment Display Interfacing 13. Connect the IRQ line to one side of a momentary switch. Connect the other side to ground. Activation of this switch causes instruction execution to resume after a WAI instruction has been executed. The switch is also used for motor single-stepping.

4 Software Development
All software routines for this application are implemented in assembly language. The EVM supports the software routine implementation. P&E Microsystems IASM11 software was used for code development, assembly, debug, and for programming the EEPROM memory. Program execution occurs in the order shown in Figure 3. To take advantage of modular software techniques, several jump to subroutine (JSR) instructions are used. Each JSR has a corresponding return from subroutine (RTS) instruction. By using this method, the program has a smooth and efficient flow. Debugging software errors is simplified by using the modular approach as well. The following paragraphs describe the subroutines that initialize the system, control the stepper movement, calculate speed, and output digital readouts. Each heading represents an individual stand-alone module.

MOTOROLA 4

AN1285/D

START

INITIALIZE

READ A/D

COMPUTE SPEED

DISPLAY

ALIGN

TURN

Figure 3 Stepper Motor Controller Program Flowchart 4.1 INIT The initialization routine sets the base address for the MCU registers and establishes the constant port values used by the subroutines contained within the main program. In addition, the IRQ interrupt control bit in the CCR (I) is cleared. This allows the control bit to be set when the SWI instruction is executed. A counter for turning the shaft 90°, 180°, or 360° is loaded during initialization. A delay timer to define the number of times each coil is activated is also set up. An alternate method of doing this would be to have a keyboard scan routine that accepts predetermined numbers or letters to control the degree of wheel turn as well as the number of coil activations. 4.2 DIRECTION Following the initialization routine, the main program is entered. The first routine of the main program controls the shaft turning direction. The stepper motor can turn either clockwise or counterclockwise. A yellow LED and a green LED are used to indicate direction of turn. To change direction, a manual switch toggles the state of a single port pin. The state of this pin is stored at ATEMP. The status of the two LEDs is determined by the position of the switch. 4.3 READAD A 25 K potentiometer is used as the analog input to PORT E. The reference high and reference low inputs of the A/D are set at +5 V and 0 V respectively. A value of $90 is written to the A/D OPTION register (OPTION), enabling the A/D power up (ADPU) and the delay (DLY) for crystal stabilization as shown below:

AN1285/D

MOTOROLA 5

OPTION -- System Configuration Options
BIT 7 ADPU RESET: 0 6 CSEL 0 5 IRQE1 0 4 DLY1 0 3 CME 0 2 -- 0 1 CR11 0 BIT 0 CR01 0

$1039

NOTES: 1. Can be written only once in first 64 cycles out of reset in normal modes, or at any time in special modes.

A value of $A0 is written to the A/D control register (ADCTL), enabling the scan mode and setting the conversion complete flag, as shown below. ADCTL -- A/D Control/Status
BIT 7 CCF RESET: I 6 -- 0 5 SCAN I 4 MULT I 3 CD I 2 CC I 1 CB I BIT 0 CA I

$1030

To simplify the design, keyboard inputs can be used to provide the necessary value directly to the A/D converter rather than using a potentiometer. 4.4 COMSPD This routine reads A/D result register 1 (ADR1) to determine the speed value being input by the potentiometer. ADR1 is an 8-bit register that contains one of 256 possible values. The value in the register is complemented so that the highest value (F) represents the longest delay or slowest turning speed. To obtain the highest resolution of result register content, four consecutive LSRA instructions are executed. Following these four shifts, a value in the range 0 to F remains in the lower nibble of accumulator A. The value is stored in ATEMP2 for later use. To insure that the latest converted value is represented, the ADCTL register is set up so that the result register is continuously being scanned during program execution. 4.5 DISPLAY The A/D conversion value is retrieved from location ATEMP2. DISPLAY calls the COMPDIS subroutine, which determines the number to be displayed. When the polling routine finds the appropriate match, the data to turn on the segments for that particular number is stored in PORT B. The information from PORT B is routed to the seven-segment display for visual monitoring. 4.6 ALIGN The ALIGN routine controls the actual alignment of the motor wheel to a known starting point, as shown in Figure 4. This configuration illustrates an easy method of controlling wheel alignment. An infrared (IR) emitter and detector are used to establish proper alignment of the wheel. The motor wheel has an extension connected to its topside. As the wheel turns, the extension breaks the invisible IR beam between the emitter and detector. When this occurs during the very first revolution, the interrupt flag (I) is set, the wheel stops turning and the letter `S' for STOP is displayed on the seven-segment display. The wheel is now aligned to a known starting point, and the program is waiting for the interrupt to be serviced by the appropriate routine. When the program continues to cycle through the main subroutines, the ALIGN routine is bypassed.

MOTOROLA 6

AN1285/D

MOTOR WHEEL 5V 5V

IR DETECTOR IR STATUS TO MCU

IR EMITTER

Figure 4 IR Emitter and Detector Stepper Motor Wheel Alignment 4.7 TURN Now that the wheel is perfectly aligned to a known starting point, the TURN subroutine can be executed. To initiate the turn sequence, the interrupt from the ALIGN routine must be serviced. This is accomplished with a momentary switch S1 connected to the IRQ line. The value from ATEMP is used to control whether to use the clockwise or counterclockwise subroutine. After the direction has been determined, the corresponding routine is entered and the coils energize in the proper sequence to cause the motor to turn. Figure 5 shows the interface between the MCU and the stepper motor coils.
STEPPER MOTOR ROTOR

STATOR COILS A THRU D

FROM MCU PORT

OPTIONAL DRIVER CIRCUITS

A B C D

Figure 5 MCU Interface to Stepper Motor Coils Table 1 shows the pattern used to energize the coils of the stepper motor for clockwise and counterclockwise rotation. Only four port pins are needed to control the pulses going to the motor. The letters A through D represent the inputs to the coils.

AN1285/D

MOTOROLA 7

Table 1 Stepper Motor Coil Energizing Pattern for CW and CCW Rotation
CW Rotation D 0 0 0 0 0 1 1 1 C 0 0 0 1 1 1 0 0 B 0 1 1 1 0 0 0 0 A 1 1 0 0 0 0 0 1 D 0 1 1 1 0 0 0 0 CCW Rotation C 0 0 0 1 1 1 0 0 B 0 0 0 0 0 1 1 1 A 1 1 0 0 0 0 0 1

Four PORT C pins are used to drive the inputs to the stepper motor coils. Direct connection from the MCU to the motor is fine for applications that require minimal drive. But for applications that require increased current drive capabilities, enhanced circuits are necessary. One way to increase drive current is to use a motor controller IC designed specifically for that purpose. An example of this device is the ULN2075B driver IC. Each IC contains four individual high-current Darlington switch and driver circuits. One IC satisfies the MCU to the stepper motor interfacing requirements. Another approach is to use discrete components to form a push/pull amplifier. Each amplifier consists of an NPN and a PNP transistor. The amplifier is arranged to generate a 12 volt output pulse to one input of the motor in response to a +5 volt pulse coming from PORT C. Figure 6 shows the amplifier configuration for one motor coil.
12V

0­5V PULSE FROM MCU

0­12V PULSE TO MOTOR COIL

Figure 6 Amplifier Configuration for a Stepper Motor Coil As the motor turns, the A/D input from the potentiometer is being scanned. When the value varies, the seven-segment display changes accordingly as does the speed of the motor. The momentary switch connected to the IRQ line has an additional function. It is the input for the manual/single step control feature of this application. When the switch is engaged, the motor halts. When the switch is released, the motor resumes normal operation. Many applications can take advantage of the single step feature to monitor elapsed time or observe the status of activities that may be linked to the motor.

MOTOROLA 8

AN1285/D

The IR emitter and detector have numerous potential uses in this and similar applications. A visual display can be used for each revolution of the wheel. This application displays a 'P' each time the IR emission path is broken. For enhanced applications, this same principal can be used to increment a counter each time there is a missing IR signal received by the MCU. After the RTS instruction is executed at the end of the TURN subroutine, the program is directed with a BRA instruction to go to the label NEXT and sample the A/D input. From here, the program continues to cycle until the routine is forced to stop or until a predetermined count or time period has elapsed.

5 Conclusion and Summary
There are numerous stepper motor applications that can take advantage of the power, features and flexibility of the M68HC11 single-chip MCU. Applications would include robotics controllers, turning machine tools and other precise shaft positioning control environments. This example is a general solution that demonstrates the ease with which an MCU can be designed into a stepper motor control application. Due to the types of applications supported, stepper motors operate at relatively low rotating speeds. The actual speed is controlled by varying the delay between coil activations. With this system application, the stepper motor converts binary input pulses coming from the MCU to rotary shaft movement on the stepper motor. The direction of turn is a function of the sequence in which the binary pulses are applied to the stepper motor. In addition, the requirement for a digital-to-analog converter is eliminated when using stepper motors versus dc or ac motors in dc systems. Ac and dc motors provide continuous shaft rotation. However, stepper motors produce shaft rotation in precise steps or increments as the result of the applied binary pulses. This can be in the form of either half or full steps (step-angular sensitivity) depending on the sequence of coil activations. It is noteworthy to mention that most stepper motors are used in applications with relatively small loads. An overload condition could result in a shaft slip. This undesirable condition could induce an error that might not be recognized and affect operating precision. To minimize the possibility of this occurring, buffer type amplifiers should be placed between the MCU and the stepper motor. In terms of reliability, MCUs can operate problem-free in stepper motor applications for years if used within their specified limits.

AN1285/D

MOTOROLA 9

6 Listing
0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0001 0002 0003 0004 0005 0006 0007 C000 C000 C003 C006 C009 C00C C00F C012 C015 BDC017 BDC034 BDC03D BDC04E BDC058 BDC0D2 BDC0EF 20EC 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ADCTL PORTA PORTB PORTCDR PORTC PORTDDR PORTD RESREG ADON ATEMP ATEMP2 ATEMP3 ATEMP4 ATEMP5 TIMER COUNTER FLGIRQ EQU EQU EQU EQU EQU EQU EQU EQU EQU RMB RMB RMB RMB RMB RMB RMB RMB ORG START NEXT $30 $0 $4 $7 $3 $9 $8 $31 $39 1 1 1 1 1 1 1 1 $C000 ;INITALIZE ROUTINE ;DIRECTION ROUTINE ;READ A/D ROUTINE ;COMPUTE SPEED ROUTINE ;7-SEGMENT DISPLAY ROUTINE ;POSITION CONTROL ROUTINE ;STEPPER MOTOR TURN ROUTINE

JSR INIT JSR DIRECTION JSR READAD JSR COMSPD JSR DISPLAY JSR ALIGN JSR TURN BRA NEXT

C017 C01A C01C C01E C020 C022 C024 C026 C028 C02A C02C C02E C030 C032 C033

CE1000 86FF A707 8600 A709 C605 D705 8610 9706 8600 A700 9704 9707 0E 39

INIT

;INITALIZE ROUTINE LDX #$1000 LDAA #$FF ;SET PORTC FOR OUTPUT STAA PORTCDR,X ;TO TURN MOTOR LDAA #$00 ;SET PORTD FOR INPUT STAA PORTDDR,X ;TO CONTROL MOTOR TURN ;DIRECTION LDAB #5 ;SET TIMER FOR # OF TIMES TO STAB TIMER ;ACTIVATE EACH COIL LDAA #10 ;SET COUNTER FOR # OF STEPS STAA COUNTER ;20 = 1 REVOLUTION LDAA #$00 ;SET PORTA FOR STAA PORTA,X ;IR EMITTER DETECTOR STAA ATEMP5 STAA FLGIRQ CLI RTS

C034 C036 C038 C03A C03C

A608 8401 A708 9700 39

;DIRECTION ROUTINE - CLOCKWISE OR COUNTER CLOCKWISE DIRECTION LDAA PORTD,X ;READ BIT 0 OF PORTD ANDA #$01 ;MASK PORTD BITS 1-7 STAA PORTD,X ;WRITE TO PORTD BIT 0 FOR CW OR CCW STAA ATEMP ;STORE DIRECTION AT ATEMP RTS ;SET UP A/DCTL REGISTER (READ VARIABLE RESISTOR ;THROUGH PORT E) READAD LDAA #$90 STAA ADON,X LDAA #$A0 STAA ADCTL,X LDY #$26 DEY BNE DELAY RTS ;OPTION REG SET A/D PWR ON & DELY ;ENABLED FOR XTAL STABLIZATION ($1039) ;SET A/D CONTROL WORD FOR SCAN MODE ;& CONVERSION COMPLETE FLAG SET ($1030)

C03D C03F C041 C043 C045 C049 C04B C04D

8690 A739 86A0 A730 18CE0026 1809 26FC 39

DELAY

MOTOROLA 10

AN1285/D

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117

;READ CONTENTS OF THE RESULT ;REGISTER TO COMPUTE TURN SPEED COMSPD LDAA RESREG,X COMA LSRA LSRA LSRA LSRA STAA ATEMP2 RTS ;DISPLAY SPEED ON 7-SEGMENT READOUT LDAA ATEMP2 ;READ ATEMP2 # TO BE DISPLAYED JSR COMPDIS ;JUMP TO ROUTINE TO COMPUTE DISPLAY STAA PORTB,X ;DISPLAY 0-F THROUGH PORTB (7-SEG) RTS CMPA #$00 BEQ DOWN0 CMPA #$01 BEQ DOWN1 CMPA #$02 BEQ DOWN2 CMPA #$03 BEQ DOWN3 CMPA #$04 BEQ DOWN4 CMPA #$05 BEQ DOWN5 CMPA #$06 BEQ DOWN6 CMPA #$07 BEQ DOWN7 CMPA #$08 BEQ DOWN8 CMPA #$09 BEQ DOWN9 CMPA #$0A BEQ DOWNA CMPA #$0B BEQ DOWNB CMPA #$0C BEQ DOWNC CMPA #$0D BEQ DOWND CMPA #$0E BEQ DOWNE CMPA #$0F BEQ DOWNF BRA COMPDIS LDAA #$C0 ;COMPARE A = 0 ;COMPARE A = 01 ;COMPARE A = 02 ;COMPARE A = 03 ;COMPARE A = 04 ;COMPARE A = 05 ;COMPARE A = 06 ;COMPARE A = 07 ;COMPARE A = 08 ;COMPARE A = 09 ;COMPARE A = 0A ;COMPARE A = 0B ;COMPARE A = 0C ;COMPARE A = 0D ;COMPARE A = 0E ;COMPARE A = 0F ;END OF POLL ROUTINE ;DISPLAY VALUE ON 7-SEG DISPLAY IF ;VALUE = 0 ;READ RESULT REGISTER ($1031) ;COMP SO HIGH # = LONGEST DELAY ;SHIFT 'A' 4 TIMES FOR 0 - F COUNT ;SHIFT ;SHIFT ;SHIFT ;STORE SHIFTED # AS FINAL SPEED CONTROL

C04E C050 C051 C052 C053 C054 C055

A631 43 44 44 44 44 9701

C057 39

C058 C05A C05D C05F C060 C062 C064 C066 C068 C06A C06C C06E C070 C072 C074 C076 C078 C07A C07C C07E C080 C082 C084 C086 C088 C08A C08C C08E C090 C092 C094 C096 C098 C09A C09C C09E C0A0

9601 BDC060 A704 39 8100 273E 8101 273D 8102 273C 8103 273B 8104 273A 8105 2739 8106 2738 8107 2737 8108 2736 8109 2735 810A 2734 810B 2733 810C 2732 810D 2731 810E 2730 810F 272F 20BE

DISPLAY

COMPDIS

C0A2 86C0 MATCH C0A4 C0A5 C0A7 C0A8 C0AA C0AB C0AD C0AE C0B0 39 86CF 39 8692 39 8686 39 868D 39

DOWN0

118 119 120 121 122 123 124 125 126

DOWN1 DOWN2 DOWN3 DOWN4

RTS LDAA RTS LDAA RTS LDAA RTS LDAA RTS

#$CF #$92 #$86 #$8D

;VALUE = 1 ;VALUE = 2 ;VALUE = 3 ;VALUE = 4

AN1285/D

MOTOROLA 11

C0B1 C0B3 C0B4 C0B6 C0B7 C0B9 C0BA C0BC C0BD C0BF C0C0 C0C2 C0C3 C0C5 C0C6 C0C8 C0C9 C0CB C0CC C0CE C0CF C0D1

86A4 39 86A1 39 86CE 39 8680 39 868C 39 8688 39 8680 39 86F0 39 8683 39 86B0 39 86B8 39

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191

DOWN5 DOWN6 DOWN7 DOWN8 DOWN9 DOWNA DOWNB DOWNC DOWND DOWNE DOWNF

LDAA RTS LDAA RTS LDAA RTS LDAA RTS LDAA RTS LDAA RTS LDAA RTS LDAA RTS LDAA RTS LDAA RTS LDAA RTS

#$A4 #$A1 #$CE #$80 #$8C #$88 #$80 #$F0 #$83 #$B0 #$B8

;VALUE = 5 ;VALUE = 6 ;VALUE = 7 ;VALUE = 8 ;VALUE = 9 ;VALUE = A ;VALUE = B ;VALUE = C ;VALUE = D ;VALUE = E ;VALUE = F

;ALIGN WHEEL FOR POSITION CONTROL BETWEEN THE ;R EMITTER AND DETECTOR ALIGN LDAA PORTA,X ANDA #$01 CMPA #$00 BEQ NEX1 BNE TURN LDAA FLGIRQ CMPA #$00 BEQ WAIT BNE TURN LDAA #$A4 STAA PORTB,X LDAA #10 STAA COUNTER CLI WAI RTS

C0D2 C0D4 C0D6 C0D8 C0DA C0DC C0DE C0E0 C0E2 C0E4 C0E6 C0E8 C0EA C0EC C0ED C0EE

A600 8401 8100 2702 2613 9607 8100 2702 260B 86A4 A704 8610 9706 0E 3E 39

NEX1

;CHECK IRQ FLAG ;IF = 0 GOTO WAIT ;IF NOT = 0 BRANCH TO TURN ;DISPLAY 'S' FOR STOP ;AT PORTB AND WAIT FOR

WAIT

;INTERRUPT TO BE SERVICED

C0EF C0F2 C0F4 C0F6 C0F8 C0FA C0FC C0FE C100

7A0006 9606 8100 2702 2607 8610 9706 2001 39

TURN

BB

;STEPPER MOTOR TURN ROUTINE DEC COUNTER LDAA COUNTER CMPA #00 BEQ BB BNE BBB LDAA #10 STAA COUNTER BRA BBB RTS LDAA ATEMP BNE CCW BEQ CW ;GET STORED DIRECTION ;IF NOT =, TURN CCW ;ELSE TURN CW

C101 9600 C103 2653 C105 2700

BBB

C107 C109 C10B C10E C10F C111 C113

D605 8601 BDC1A9 5A 26F8 D605 8603

CW CW1

CW3

;CLOCKWISE TURN ROUTINE LDAB TIMER LDAA #$01 ;COIL VALUE FOR POSITION 1 JSR DELAY1 DECB BNE CW1 LDAB TIMER LDAA #$03 ;COIL VALUE FOR POSITION 2

MOTOROLA 12

AN1285/D

C115 C118 C119 C11B C11D C11F C122 C123 C125 C127 C129 C12C C12D C12F C131 C133 C136 C137 C139 C13B C13D C140 C141 C143 C145 C147 C14A C14B C14D C14F C151 C154 C155 C157

BDC1A9 5A 26F8 D605 8602 BDC1A9 5A 26F8 D605 8606 BDC1A9 5A 26F8 D605 8604 BDC1A9 5A 26F8 D605 860C BDC1A9 5A 26F8 D605 8608 BDC1A9 5A 26F8 D605 8609 BDC1A9 5A 26F8 39

C158 C15A C15C C15F C160 C162 C164 C166 C169 C16A C16C C16E C170 C173 C174 C176 C178 C17A C17D C17E C180 C182 C184 C187 C188 C18A C18C C18E C191 C192

D605 8601 BDC1A9 5A 26F8 D605 8609 BDC1A9 5A 26F8 D605 8608 BDC1A9 5A 26F8 D605 860C BDC1A9 5A 26F8 D605 8604 BDC1A9 5A 26F8 D605 8606 BDC1A9 5A 26F8

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257

CW2

CW6

CW4

CWC

CW8

CW9

JSR DELAY1 DECB BNE CW3 LDAB TIMER LDAA #$02 JSR DELAY1 DECB BNE CW2 LDAB TIMER LDAA #$06 JSR DELAY1 DECB BNE CW6 LDAB TIMER LDAA #$04 JSR DELAY1 DECB BNE CW4 LDAB TIMER LDAA #$0C JSR DELAY1 DECB BNE CWC LDAB TIMER LDAA #$08 JSR DELAY1 DECB BNE CW8 LDAB TIMER LDAA #$09 JSR DELAY1 DECB BNE CW9 RTS

;COIL VALUE FOR POSITION 3

;COIL VALUE FOR POSITION 4

;COIL VALUE FOR POSITION 5

;COIL VALUE FOR POSITION 6

;COIL VALUE FOR POSITION 7

;COIL VALUE FOR POSITION 8

CCW CCW1

CCW9

CCW8

CCWC

CCW4

CCW6

;COUNTER CLOCKWISE ROUTINE LDAB TIMER LDAA #$01 ;COIL JSR DELAY1 DECB BNE CCW1 LDAB TIMER LDAA #$09 ;COIL JSR DELAY1 DECB BNE CCW9 LDAB TIMER LDAA #$08 ;COIL JSR DELAY1 DECB BNE CCW8 LDAB TIMER LDAA #$0C ;COIL JSR DELAY1 DECB BNE CCWC LDAB TIMER LDAA #$04 ;COIL JSR DELAY1 DECB BNE CCW4 LDAB TIMER LDAA #$06 ;COIL JSR DELAY1 DECB BNE CCW6

VALUE FOR POSITION 9

VALUE FOR POSITION 8

VALUE FOR POSITION 7

VALUE FOR POSITION 6

VALUE FOR POSITION 5

VALUE FOR POSITION 4

AN1285/D

MOTOROLA 13

C194 C196 C198 C19B C19C C19E C1A0 C1A2 C1A5 C1A6 C1A8

D605 8602 BDC1A9 5A 26F8 D605 8603 BDC1A9 5A 26F8 39

C1A9 C1AB C1AD C1AF C1B2 C1B4 C1B6 C1B8 C1BA C1BC C1BE C1C0 C1C2 C1C4 C1C8 C1CA C1CC

A703 9601 9702 18DE02 1809 26FC A600 8401 8101 270E 2600 8698 A704 18CE0FFF 1809 26FC 39

FFF2 FFF2 FFF4 FFF4 7C0007 FFF7 3B

258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299

CCW2

CCW3

LDAB TIMER LDAA #$02 JSR DELAY1 DECB BNE CCW2 LDAB TIMER LDAA #$03 JSR DELAY1 DECB BNE CCW3 RTS ;DELAY ROUTINE STAA PORTC,X LDAA ATEMP2 STAA ATEMP3 LDY ATEMP3 DEY BNE COUNT LDAA PORTA,X ANDA #$01 CMPA #$01 BEQ NOSEG BNE SEG LDAA #$98 STAA PORTB,X LDY #$FFF DEY BNE ZZ RTS

;COIL VALUE FOR POSITION 3

;COIL VALUE FOR POSITION 2

DELAY1

COUNT

;DELAY PER LOADED VALUES

;COMPARE VALUE TO OUTPUT TO DISPLAY

SEG

;DISPLAY 'P' FOR POSITION

ZZ NOSEG

;INTERRUPT ROUTINE FOR POSITION CONTROL ORG $FFF2 ;VECTOR FOR IRQ FDB IRQHND IRQHND INC FLGIRQ RTI

MOTOROLA 14

AN1285/D

AN1285/D

MOTOROLA 15

Motorola reserves the right to make changes without further notice to any products herein. Motorola makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpose, nor does Motorola assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. "Typical" parameters which may be provided in Motorola data sheets and/or specifications can and do vary in different applications. All operating parameters, including "Typicals" must be validated for each customer application by customer's technical experts. Motorola does not convey any license under its patent rights nor the rights of others. Motorola products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the Motorola product could create a situation where personal injury or death may occur. Should Buyer purchase or use Motorola products for any such unintended or unauthorized application, Buyer shall indemnify and hold Motorola and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that Motorola was negligent regarding the design or manufacture of the part. MCUinit, MCUasm, MCUdebug, and RTEK are trademarks of Motorola, Inc. M O T O R O L A and ! are registered trademarks of Motorola, Inc. Motorola, Inc. is an Equal Opportunity/Affirmative Action Employer.

How to reach us:
USA/EUROPE/Locations Not Listed: Motorola Literature Distribution; P.O. Box 5405, Denver Colorado 80217. 1-800-441-2447, (303) 675-2140 MfaxTM: [email protected] - TOUCHTONE (602) 244-6609, U.S. and Canada Only 1-800-774-1848 INTERNET: http://Design-NET.com JAPAN: Nippon Motorola Ltd.; Tatsumi-SPD-JLDC, 6F Seibu-Butsuryu-Center, 3-14-2 Tatsumi Koto-Ku, Tokyo 135, Japan. 81-3-3521-8315 ASIA PACIFIC: Motorola Semiconductors H.K. Ltd.; 8B Tai Ping Industrial Park, 51 Ting Kok Road, Tai Po, N.T., Hong Kong. 852-26629298 Mfax is a trademark of Motorola, Inc.

AN1285/D