NASA

Technical

Memorandum

NASA TM - 86574

SMALL COMPUTER INTERFACE TO A STEPPER MOTOR

By Fred A. Berry, Jr.

Space Sciences Laboratory

Science and Engineering Directorate

December 1986

(NASA-T_-86574) £_ALL C0_PU_EB I_2ERFACE _fO

A S_E_ _O_C_ (_SA) 13 p CSC£ 09C N87-16_70

Unclas

3/J3 43846

NASA

National Aeronautics and

Space Administration

George C. Marshall Space Flight Center

MSFC- Form 3190 (Rev. May 1983)

TECHNICAL REPORT STANDARD TITLE PAGE

_i. REPORT NO. 31 RECIPIENT'S CATALOG NO.

NASA TM- 86574

4. TITLE AND SUBTITLE

Small Computer

2. GOVERNMENTACCESSIONNO.

Interface to a Stepper Motor

7. AUTHOR(S)

_ Fred A. Berry, Jr.

9. PERFORMING ORGANIZATION NAME AND ADDRESS

35812

12.

Space Science Laboratory

George C. Marshall Space Flight Center

Marshall Space Flight Center, Alabama

SPONSORING AGENCY NAME AND ADDRESS

National Aeronautics and Space Administration

Washington, D.C. 20546

5. REPORT DATE

December 1986

6. PERFORMING ORGANIZATION CODE

ES62

8. PERFORMING ORGANIZATION REPDRF #

10. WORK UNIT NO.

1. CONTRACT OR GRANT NO.

3. TYPE OF REPOR', & PERIOD COVERED

Technical Memorandum

14. SPONSORING AGENCY CODE

15. SUPPLEMENTARY NOTES

Prepared by Science and Engineering Directorate, Space Sciences Laboratory

16. ABSTRACT

A Commodore VIC-20 computer has been interfaced with a stepper motor to provide an

inexpensive stepper motor controller. Only eight transistorsand two integrated circuits

compose the interface. The software controls the parallelinterface of the computer and

provides the four phase drive signalsfor the motor. Optical sensors control the zeroing of the

12-inch turntable positioned by the controller. The computer calculates the position

information and movement of the table and may be programmed in BASIC to execute automatic

sequences.

17. KEY WORDS

Stepper Motor, Controller,

Control, Interface

19. SECURITY CLASSIF. (of this repoet_

Unclassified

MSFC - Form 3292 (May 1969)

Computer

18. DISTRIBUTION STATEMENT

Unclassi fied--Unl imited

SECURITY CLASSIF. (of this page) [2,.NO. OF PAGES [22. PRICE

Uncl a ss i fi ed [ z3 [ NTIS

For sale by National Technical Information Service, Springfield, Virginia 221 51
• • _ i[
TABLE OF CONTENTS

T •

II.

II[.

Introduction

Description

Ae

B.

C.

Application

Page

1

1

1

1

2

2

LIST OF ILLUSTRATIONS

Figure

1. Octal buffer

2, Stepper

3. Sensor

Title

interface

motor interface

interface ..................................

eDoeto,oeoooeooo*le,eoooeoo•

o'oeee,oooaoeooe,Dioeooeooo

Page

3

4

5

LIST OF TABLES

Table

i.

2.

Program Li st ing

Program Listing

Comp u t e r s

Ti tle

for VIC-20 Computer

for Commodore 64 and

oeoooooomteeeoo

128 ..........

Page

6

8

iii

TECHNICAL MEMORANDUM

SMALL COMPUTERINTERFACETO A STEPPERMOTOR

I. INTRODUCTION

In the past, stepper motors have been controlled by expensive dedicated electronics with

littleor no programmability or flexibility.A Commodore VIC-20 computer was interfaced with

a controller to provide an inexpensive programmable stepper motor controller(see Table 1). A

Commodore 64 version of the program isavailable and may be run on either a C-64 or a C-128

computer operated in C-64 mode (see Table 2). The computer program iswritten in BASIC and

may be adapted to any small computer with a parallelinterface. This controller allows the user

to both interact with the stepper motor and program in a special sequence of steps for the

motor to perform.

The drive circuitsof the motor controller,originallydesigned by Guy N. Brown, serve to

control current to the motor and provide level shiftingfor the computer interface. An

interface integrated circuit(IC)provides isolationand line driving capabilitiesto the circuit.

The computer provides both the four phase drive signals for the motor and maintains the

position information of the table. The computer may be separated from the motor controllerby

a distance of twenty or more meters without resorting to special line driver electronics.

The parallelport of the computer isisolated from the line by an identical interface IC.

This IC provides the line driving and receiving functions for the VIC-20 parallelport. Two sets

of infrared positionsensors, coarse and fine,are used by the computer to detect the zero

setting of the stepper motor. The coarse sensor detects the zero position of the table while the

fine sensor defines the zero positionof the drive motor shaft. Two comparator circuitsare used

to condition the optical sensor outputs for the computer.

II. DESCRIPTION

A. Motor Interface

The computer controls the octal buffer interface and line drivers (see Figure 1). Cables

coanect the computer interface to the controllercontaining the other 74LS244 octal buffer IC

(see Figure 2). The 2N2222 switching transistorsare controlled by tlleoctal buffer. The

2N2222 transistorscontrol the high current motor switching transistorsto buffer the motor

from the TTL electronics. The fieldcoilsof the stepper motor, in turn, are switched directly by

2N6191 high current capacity transistors.Other output transistorsmay be required to interface

to the particularstepping motor used. The 2N6191's may be used safely to switch the phase

current for up to 2 amperes.

B. Sensor Interface

The sensors used for this project are infrared emitter LED's and photo-transistors

packaged together (see Figure 3). The outputs of the photo-transistorsare fed into LM111

comparators. These comparators detect a threshold when a sensor iseither blocked or

activated. Then the comparator outputs a logic pulse to the buffer which is then sent to the

parallelport of the computer for use in the program.
OF POOR QUALITY

C. Computer Program

The computer program iswritten in BASIC on a Commodore VIC-20 computer. This

computer was chosen for itscompact size and low cost. A slightmodification to the address for

the parallelport will allow the program to function on a Commodore C-64 or C-128 computer.

Other modifications would be necessary for use with other brands of computers.

Statements 1-3 (see listing)of the program contain the port assignments with P being the

port address value and D being the Data Direction Register. Statement 10 refers to the

subprogram in statements 800-890, the operating instructionsubroutine. This subprogram

contains allthe necessary operating instructionsand allows the user to use the program without

referring to any manual or instructionsheet.

Statements 11-30 form the main program loop. In statements 11-15, the information

about direction and distance of rotation of the table isinputted. This iswhere any custom

programming or subroutines might be placed to take advantage of the computer's

programmability. Statements 16 and 25-29 take care of steps less than one fullrevolution of

the motor. Statements 22-23 take care of fullrevolution travel.

Statements 40-90 are the counter-clockwise movement of the stepper motor for lessthan

one fullrevolution; i.e.,they set which bits are on and off for each step. Statements 140-190 do

the same thing for the clockwise motion. Statements 331-390 form the subroutine that controls

fullrevolution movement of the motor in the counter-clockwise direction. Statements 391-500

do the same in the clockwise direction.

Each routine determines the sequence of bits to turn the different fieldsof the stepper

motor on and off and the pattern of movement of the motor. Statements 377 and 437 provide

for the intervention of the operator to stop a movement inprogress. Statements 375 and 475

provide an odometer readout of the number of steps taken. Note that alldisplays and inputs are

in degrees and the number of steps is 1/100 of a degree. This isbecause the gear ratio of the

turntable moved by the stepper motor is 180:1. Other gear ratios and other applicationsof the

controller might use other numbers.

Statements 600-740 are a zeroing subroutine for tileturntable. A best direction query in

line 600 sets the program to the most efficientdirection of returning to zero. This method was

chosen over the method where the program keeps up with the best direction because the system

might be shut down with the table of zero and get confused on powerup. The subroutine looks

for the coarse zero being detected in lines 630 or 710. Lines 632-635 or 715-725 search for the

fine zero. Line 640 or 740 returns to the main loop.

III.APPLICATION

The controllerisnow being used to command a 12-inch turntable. By controllingthe

stepper motor to within one step, a positionalaccuracy of +_0.01,has been achieved. This is

consistent with the accuracy of the turntable being controlled. Further modifications of the

program would allow the user to move the stepper motor in half-steps and increase the accuracy

of the positioner. Also, the motor isturned off after each operation to conserve power and

allow for cooling. If itisnecessary to hold something in position,a holding current could be

implemented simply by omitting statements 85, 185,385, and 450. One may modify the

program to include linear and other positionalvariations. Various sequences might be as easily

programmed in so that the motor would carry out a listof instructions. Further enhancements

could include an acceleration/deceleration routine,programmed sequences, and motor feedback

to the computer.
C PB0

_

f

D PB1

>>

E PB2 F PB3

>>

G PB4

>>

H PB5

>>

2 +5VDC

>>

1,A8

•/

R,

N/GND _>>

/

74LS244 I

12I b18 I

16 A_14 III

f8 b.1218 i I I 9 ,, 11 16 i I

17_ 13132

II I 10,1 '1 L .... _1__9__ JI N

BIT

iVALUE

I11 PiN

12 2> J4 3> I

4..

5>

6>

8

CABLE>

/

8

/

E] N

Figure i. Octal Buffer Interface.

tJ
+5 VDC P/S

BIT 1/8 74LS244

(9

2N2222

BIT 1/8 74LS244

(_) 1K

2N2222

ON 74LS244

PIN

20 +5

10,1,15 GND

1K

33O

lw

3o_.

33o

lw

lk

2N6191 2N6191

2N6191

WH

I+5 VDC

P/S

330

lw

1N4001

330

lw _191

2N2222

1K

2N2222

1K

74LS244

14 (_)

[]

®

Fig. 2. Stepper Motor Interface.
+5

I

+5 VDC

I

OPTICAL +5 VDC

RED SENSOR WHITE /

+5 8 <_ 74LS244

GREEN 3 . ": '

_G _>E .o

+5 VDC

8 1K

.o,_

ORANGE WHITE

._50k

74LS244

11 _9

D

CABLE FOR SENSORS

CONN PIN CABLE COLOR

A WHITE/BLUE

B ORANGE/WHITE

C BLUE/WHITE

D WHITE/ORANGE

E ORANGE/WHITE

F WHITE/ORANGE

G BLUE/WHITE

H WHITE/BLUE

SENSOR COLOR

GREEN

WHITE

BLUE

ORANGE

GREEN

WHITE

BLACK

RED

Fig. 3. Sensor Interface
TABLE i. PROGRAM LISTING _OR VIC-20 COMPUTER

I P=37136:D=3'7138:PA=I:Q=IS: PO%=0

2 POKED, 15

3 POKEP, 0

I0 GOSUB 8O0

ii INPUT"WHICH DIR";DIS

12 IFD[$="ZERO"THENPO%=0:GOTO600

13 IFDI $="E"THENI000

14 PRINT"ROTATION IS IN DECIMAL DEGREES 'XXX.XX'"

15 INPUT"# OF DEGREES";W:T=INT(W*I00) :Z=T/4-1

16 IFT<4TH_N25

22 1PDI $ =" CW"THENGOS U8391

23 1 _'0 [$ ="CCW"THENGOS UB 331

25 C=(T/4-1NT(T/4))*4

26 IPT>4AND C=0THENC=4

2 8 1 _'D[ S="CCW"THENPO%=PO%-C :ONCGOS UB70,60,50,40 :XO=PO% :PRINT

"TABLE AT";XO/100;"DEG"

29 IFDI S="CW"THENPO%=PO%+C :ONCGOSUBI70,160, 150,140 :XO=PO% :PRINT

"TABLE AT";XO/100;"DEG"

30 GOTOI 1

31 RE_

40 POKEP, QA_D5

50 POKBP, QAND6

60 POKEP, QANDI0

70 POKEP, QAND9

85 POKEP, 0

90 RETURN

140 POKEP, QAND9

150 POKED, QANDI 0

160 POKEP, _AND6

170 POKEP, QAND5

1195 POKEP, 0

190 RETURN

331 REM

335 PORX=ITOZ

340 POKEP, QAND5

350 POKE P, QAND6

360 POKEP, QANDI 0

370 POKE P, QAND9

3 75 PO%=PO%-4 :XO=PO% : PRINTXO/I 00 ; "DEGREES"

377 IF(PEEK(198) )>0THENX=Z

380 NEXT

381 REM

385 POK_]P,0

390 PRINT""

437 IF(PEEK(198))>0THENX=Z

440 N_XT

450 POKEP, 0

500 PRINT" {CLR}EMD" :RETURN

600 INPUT"BEST D[R";DIS

610 [ _"DI ,q=" CW" THEN 700

ORIGL_)_L

OF POOR QUALITY
ORIGINAl,,PAGE. 13

OF POO_ QUALITY

'FABLE 1 (concluded)

620 DI $=" CCW"

625 REMPRINT(PEEK(P)AND32)

630. [F(PEEK(P)AND32)<>0THENGOSUB40:GOTO625

632 IF (PEEK (P)AND16 )=0THENGOSU840

635 [F(PEEK(P)ANDI6)=0THEN632

640 GOTOI 1

700 REMPRINT(PEEK(P)AND32)

710 IF(PEEK(P)AND32)<>0THENGO_UBI40:GOTO700

715 IF (PEEK (P)AND16 )=0THENGOSUBI40

725 IF(PEEK(P)A'NDI6)=0THEN715

740 GOTOI 1

800 PRIN'F."{CLR}INSTRUCTfONS FOR USE OF VIC 20 STEPI?ER r4OTOR

INT E R_AC E "

8i0 PRINT" IN PUT 'CW' TO MOVE THE TARLE CLOCKWISE"

820 PRINT"INPUT 'CCW' TO MOVE THE TAF{LE COUNTERCLOCKWISE"

830 PRINT"INPUT 'ZERO' TO MOVE THE ".PASLE TO IT'S INITIAL

POS IT ION"

835 PRI_T"A PREFERRED DIRECTION SHOULD RE INP_ITTED TO AID THE

ZEROING ROUTINE"

840 PRINT"INPUT 'E' TO END THE PROGRAM

850 PRINT

890 RETURN

i000 END

[010 OPEN15,8,15,"S0:OS"

1015 C LO.SEI 5

1020 SAVE"OS",8

10.%0 OPEN15,8, 15,"S0:ODOSTEPPER"

1035 SAVE"ODOSTEPPER",8

1060 CLOSE15

1080 END
TABLE 2. PROGRAMLISTING FOR COMMODORE64 AND 128 COMPUTERS

1 P=56577 : D=56579 : PA=I :_=I 5:PO%=0

2 POKED,15

3 POKEP,0

I0 GOSUB800

Ii INPUT"WHICH D[R";DI$

12 [ P_DI$ =" ZERO"THENPO%=0: GOTO600

13 IFDI $="E"THENI000

14 PRINT" ROTATION IS IN DECIMAL DEGREES'XXX.XX'"

15 INPUT"# OF DEGREES";W:T=INT(W*I00) :Z=T/4-1

16 I_T<4THEN25

22 IPDI$ =" CW"THENGOSUB391

23 1_D[ $="CCW"THENGOSUB331

25 C=(T/4-INT(T/4))*4

26 IFT>4AND C=OTHENC=4

28 IPDI$="CCW"THENPO%=PO%-C:ONCGOSUB70,60,50,40:XO=PO%:PRINT

"TABLE AT";XO/100;"DEG"

29 IPDI$="CW"THENPO%=PO%+C:ONCGOSUBI7O, 160, 150, 140:XO=PO%:PRINT

"TABLE AT";XO/100;"DEG"

30 GOTOI1

31 REM

40 POKEP,QAND5

50 POKEP,QAND6

60 POKEP,QANDI0

70 POKEP, QA_,_U9

85 POKEP,0

90 RETURN

140 POKEP, QAND9

150 POKEP, QANDI 0

[60 POKEP, QAND6

170 POKEP, QAND5

[,%5 POKEP, 0

190 RETURN

331 REM

335 PORX=ITOZ

340 POKEP, QAND 5

350 POKE P, QAND6

360 POKEP, QANDI0

370 POKE P, QAND9

375 PO%=PO%-4:XO=PO%:PRINTXO/100;"DEGREES"

377 IP(PEEK(198))>0THENX=Z

380 NEXT

381 REM

385 POKEP,0

390 PRINT""

437 I_'(PEEK(198))>0THENX=Z

440 NEXT

450 POKEP, 0

500 PRINT" _] " {CLR} ,NO :RETURN

600 INPUT"BEST DIR";DI$

610 lffDIS="CW"THEN700

620 DI S:"CCW"
OF PO0_ QUALU'¥

TABLE 2 (concluded)

625 REMPRINT(PE_K(P)AND32)

630 IF(PEEK(P)AND32)<>0THENGOSUB40:GOTO625

632 IF(PEEK(P)ANDI6)=0THENGO._UB40

6.35 IF (PEEK (P)AND16 )=0THEN632

64 0 GO']?O 1 .l

700 REMPRINT(PEEK(P)AND32)

710 IF(PEEK(P)AND32)<>0THENGOSUBI40:GOTO700

715 IF(PEEK(P)ANDI6)=0THENGOSUBI40

725 IF (PEEK (P)AND16 )=0THEN715

740 GOTOI 1

800 PRINT"{CLR}INS'FRUCTIONS FOR USE OF VIC 20 sr._JPPER' E MOTOR

INTERFACE"

810 PRfNT"INPUT 'CW' TO MOVE THE TABLE CLOCKWISE"

820 PRINT" INPUT 'CCW' TO MOVE THE TABLE COUNTERCLOCKWISE"

830 PRINT" INPUT 'ZERO' TO MOVE THE TABLE TO IT'S INITIAL

POS IT ION"

835 PRINT"A PREPERRED DIRECTION SHOULD BE INPUT'fED TO AID THE

ZEROING ROUTINE"

840 PRINT"INPUT 'E' TO END THE PROGRAM

850 PRINT

890 RETURN

i000 END

[010 OPEN15,8, 15, " S0: OS"

1015 C LO._E 15

[020 SAVE"OS",8

1030 OPEN15,8, 15,"S0:ODOSTEPPER"

1035 SAVE"ODOSTEPPER",8

1060 C LO.q E 15

1080 END

9
APPROVAL

SMALL COMPUTER INTERFACE TO A STEPPER MOTOR

By Fred A. Berry, Jr.

The information in this report has been reviewed for technical content. Review of

any information concerning Department of Defense or nuclear energy activitiesor

programs has been made by the MSFC Security ClassificationOfficer. This report, in its

entirety,has been determined to be unclassified.

)/

E. A. TANDBERG-HANSSEN

Deputy Director, Space Science Laboratory

10 _U.S. GOVERNMENT PRINTING OFFICE 1987 730-067/40051