Text preview for : 24892B(MSTEP-5).pdf part of Keithley 24892B(MSTEP-5) Keithley Misc 24892B(MSTEP-5).pdf



Back to : 24892B(MSTEP-5).pdf | Home

MSTEP-5
User Guide
User Guide

for the




MSTEP-5

Dual Stepper Motor

Controller Board




Ft6visipn B - April 1991
Copyright Kelthley MetraByte Corp. 1987
Part Number: 24892




KEITHLEY METRABYTE CORPORATION
440 MYLES STANDISH BLVD., Taunton, MA 02780
TEL 508/88&8000, FAX !508/880-0179




..,
- Ill
-
Warranty Information
All products manufactured by Keithley MetraByte are warranted against defective materials
and worksmanship for a period of one year from the date of delivery to the original
purchaser. Any product that is found to be defective within the warranty period will, at the
option of Keithley MetraByte, be repaired or replaced. This warranty does not apply to
products damaged by improper use.



Warning

Keithley MetraByte assumes no liability for damages
consequent to the use of this product. This product is not
designed with components of a level of reliability suitable
for use in life support or critical applications.




Disclaimer
Information furnished by Keithley MetraByte is believed to be accurate and reliable.
However, the Keithley MetraByte Corporation assumes no responsibility for the use of such
information nor for any infringements of patents or other rights of third parties that may
result from its use. No license is granted by implication or otherwise under any patent
rights of Keithley MetraByte Corporation.



Notes
MetraBytem is a trademark of Keithley MetraByte Corporation.

BasiclMis a trademark of Dartmouth College.

IBM@ is a registered trademark of International Business Machines Corporation.

PC, XT, AT, PS/2, and Micro Channel Architecture@ are trademarks of
International Business Machines Corporation.

Microsoft@ is a registered trademark of Microsoft Corporation.

Turbo C* is a registered trademark of Borland International.




-iv-
Contents
CHAPTER 1: INTRODUCTION

1.1 Description ...................................... .1-l
1.2 General Areas Of Application ............................. l-2
1.3 Utility Software .................................................. l-3
1.4 Technical Support. : : : : : : : : : : 1l-4
1.5 Options ......................................... l-4


CHAPTER 2: INSTALLATION

2.1 Backing Up The Disk . . . . . . . . . . . . , . . . . . . . . . . . . . . . . . . . . .2-l
2.2 Hardware Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-l


CHAPTER 3: PROGRAMMING

3.1 General ................................... . . . . . 3-l
3.2 Register Locations & Functions ...................... . . . . . 3-2
3.3 PPMC-101 C Stepper Controller Internal Registers ............ . . . . . 3-5
3.4 Loading The Machine-Language Call Routine MSTEP.BIN . . . . . 3-6
3.5 Structure of The Call Statement . .. ..... ....... : : : : : : : . . . . . 3-8
3.6 Error Codes ................................. . . . . . 3-9
3.7 Stepper Motor Fundamentals . . . . 3-11
3.8 CALLModes.. ....... . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12


CHAPTER 4: MODE CALLS

4.1 MODE 0: Emergency Stop .................... .... .4-l
4.2 MODE 1: Decelerating Stop ................... : : .... : : : : .4-2
4.3 MODE2:JogOrSingleStep. ............................ .4-2
4.4 MODE 3: Step With Acceleration/Deceleration .. .4-4
4.5 MODE 4: Step At Constant Speed. .................. : : : : : : : : : : : : .4-5
4.6 MODE 5: Move To Outer Limit At Constant Speed ................. .4-7
4.7 MODE 6: Move To Limit At High Speed ....................... .4-9
4.8 MODE 7: Move To Base Point At Constant Speed ................. .4-9
4.9 MODE 8: Read Motor Status ............................. 4-l 1
4.10 MODE 9: Read Encoder ............................... 4-14
4.11 MODE 10: Load Divider ............................... 4-16
4.12 MODE 11: Enable/Disable Interrupt ......................... 4-l 7
4.13 MODE 12: Initialization ................................ 4-l 9
4.14 Programmer's Short Summary ............................ 4-24
4.15 Interpreted BASIC (GW, Compaq, IBM, Etc.) .................... 4-25
4.16 QuickBASIC. ..................................... 4-26
4.17 Multiple MSTEP-5s In One System ......................... 4-28


CHAPTER 5 ENCODER CHANNELS

5.1 Optical Incremental Shaft Encoder. ............... .5-l
5.2 MSTEP-5 Encoder Interface ................... : : : : : : : : : : .5-2
5.3 Reading & Resetting The Encoder Counters .5-3
5.4 Connecting Up A Shaft Encoder .. ..................... : : : : : : : : : : : : .5-4




-v-
CHAPTER 6 USING THE SAT-STEP

6.1 STA-STEP Description ................................ 6-1
6.2 Power Drive Circuit .................................. 6-1
6.3 STA-STEP Connections To Stepper Motors ..................... 6-2
6.4 STA-STEP Connections To Encoders ........................ 6-2
6.5 Connection To External Translator .......................... 6-5
6.6 Other Signals On The STA-STEP. .......................... 6-5


CHAPTER 7 STEPPER MOTORS & TRANSLATORS

7.1 How A Stepper Motor Works ............................. 7-l
7.2 Torque Versus Speed ................................. 7-3
7.3 Resonance. ...................................... 7-4
7.4 Full- & Half-Step Operation .............................. 7-4
7.5 Translators & Indexers. ................................ 7-5
7.6 Mechanical Design. .................................. 7-5


CHAPTER 8 TESTING & MAINTENANCE



CHAPTER 9 INSTRUCTIONS FOR PRODUCT RETURN




APPENDIX A PPMC-101 C SPECIFICATIONS & PROGRAMMING

APPENDIX B SOURCES FOR STEPPER MOTORS & ASSEMBLIES
APPENDIX C STEP-MOT1 & STEP-ENCl SPECIFICATIONS

APPENDIX D MSTEP-5 & STA-STEP SPECIFICATIONS




* * * * *




- vi-
CHAPTER
1
INTRODUCTION
1.l DESCRIPTION
MetraByte's MSTEP-5 is a plug-in 2-axis stepper motor and incremental shaft-encoder motion-control
board for the IBM PC/XT/AT and compatible computers. The board is 12 inches long and requires a
full-length expansion slot. All connections are made through the rear plate using a standard 50-pin
insulation-displacement (mass-termination) connector. MetraByte also offers (as options) a screw
connector, a stepper-motor-driver accessory (STA-STEP), a popular type of stepper motor (STEP-
MOTl), and an incremental shaft encoder (STEP-ENCl; see Section 1.5). Figure l-l is a block diagram
of the MSTEP-5.

Each independent stepper channel consists of a Sil-Walker PPMC-1OlC intelligent controller chip that
can execute a variety of motion control commands. The PPMC-101C is one of the most popular
Japanese robotics chips and has been designed to provide essential features with simplicity of use.
MetraByte's driver software further enhances the ease of stepper motor control by personal computer.

Once a command has been loaded into the PPMC-1OlC controller chip, the host computer is no longer
burdened by the execution of the particular motion, but may monitor its status as needed. The
associated stepper motor may be moved any number of steps up to 24 bits of resolution (+/-16777,216
steps) either with a controlled acceleration/deceleration profile or constant stepping rate. Associated
with each motor are 5 limit switch inputs as well as a motor enabled input. The limit switches provide
normal and emergency stop limits at both ends of travel, plus a home or reference point at any
intermediate point. A normal stop is defined as a normal deceleration to rest without loss of the step
count due to inertial effects, an emergency stop is a sudden stop that may lead to run on of the motor
and hence loss of location from the step count and would normally require recalibration by return to
the reference or home point. The emergency stop amounts to an immediate cessation of step pulses
regardIess of what the motor is doing at the time. In addition to controlling the number of steps
travelled by the motor (normal motion), the PPMC-1OlC controller executes the following commands
described below:


Initialization Controls number of phases driven (3,4 or 51, logic levels of
phase excitation, (normal, inverted), internal/external step clock select
and switching excitation on/off at standstill. In addition this command
sets the start up, acceleration/deceleration and high speed run rates.
The components of this comman d that relate to the motor configuration
cannot be altered by a further initialization command without resetting
the PPMC-1OlC controller.


Move Normal Moves the motor the desired number of steps with a controlled
rate and acceleration/deceleration.


Move Constant Rotates motor at constant speed for a specified number of steps.


Find Limit Rotates motor to an outer limit switch.


Find High-Speed Limit Rotates motor to a high-speed or inner-limit switch.

1-l
MSTEP-5 USER GUIDE


Find Base Point Rotates motor to home or reference-limit switch.


Read status Read PPMC-1OlC controller status.


Decelerating Stop Stops motor normally.


Emergency Stop Instantly stops motor by removing drive pulses (may lead to loss of true
location from step count).


Single Step Single step or "jog" command.



Each stepper channel provides two different types of outputs. One is a counter-clockwise/clockwise
(CCW/CW) signal plus a pulsetrain output corresponding to the number of steps to be moved. This
is suitable for driving a wide variety of standard stepper-motor translators available from most
stepper-motor manufacturers. The other set of signals consists of 5-phase outputs used to drive power
transistors to switch the stepper motor windings directly. The number of outputs enabled and the
stepping sequence is controlled by the initialization command and can be matched to 3,4-, or 5-phase
motors. MetraByte's STA-STEP accessory is an L/R type of driver including power mosfets driven by
the phase outputs and can drive small motors directly. When the motor is at standstill and the
winding excitation current is at a maximum causing the greatest heating, you can select a mode in the
initialization that switches the phase outputs at 2.2KHz and about 30% duty cycle. This action takes
place automatically about 100 milliseconds after standstill and reduces motor heating without much
affecting holding torque. Also the logic polarity of all the phase drive outputs can be selected true or
inverted.

The step rate is controlled by the clock frequency. The PPMC-1OlC chip has an internal clock of
12.5KHz plus a programma ble divider that can divide by any number in the range 20-255 giving
corresponding step rates between 49 to 625pps (pulses per second). This is usually adequate, but you
also have the option of selecting an external clock. There are two external clock sources on the
MSTEP-5, a 1OOKHzcrystal, on-board clock with an 8-bit programmable divider, or an external user
input. The additional 8-bit divider works in conjunction with the PPMC-1OlC internal divider to give
step rates ranging from 1.54 to 5,OOOpps and further allows you to vary the step rate during operation
or execution of a co mmand. This lets you produce variable speeds with any motion command that is
not directly possible with the internal PPMC-1OlC clock. The user input can provide even more
flexibility. Selection of the clock source is software controlled.

In addition to the stepper-motor channels, there are two independent incremental shaft encoder
channels. These may be ignored in open-loop stepper-motor control or used for closed-loop control or
setting manual reference positions. The encoder channels are not in any way linked to the stepper-
motor channels, so it is up to the host computer to intervene in any type of control utilizing the
encoder inputs. Each encoder channel is TI'L-compatible and consists of a 24-bit up/down counter for
counting single edges with Channel A/Channel B quadratureoutput type incremental encoders. The
encoder counters may be cleared and read by the computer. The MSTEP-5 encoder inputs include a 2-
stage shift-register digital filter to reject transient noise, this limits the encoder input pulse rate to
25KHz (about 1500 rpm with a 1000 line/rev. encoder). Cascade outputs are provided from the
encoder counters to allow use of additional external counters if needed.

All communications with the MSTEP-5 is via I/O ports (no memory address space is used); eight
contiguous addresses are used in I/O space. The Base Address is selected on a DIP switch and can be
anywhere in the range 0 - 3F8 hex; lOO-3F8 or 200-3F'S is the usual usable range in an IBM PC/AT/XT.
More than one MSTEP-5 may be installed in a PC for multiple-axis control. The number is limited

l-2
CHAPTER 1: INTRODUCTION

only by available expansion slots.

The PPMC-1OlC stepper controller chips can also generate interrupts on completion of commands and
certain other conditions. This is supported in the MSTEP-5 hardware, interrupts may be jumper
selected to any of the IBM PC Interrupt Levels 2-7 and in conjunction with the PPMC-1OlC Status
Registers makes interrupt handshaking a simple procedure and allows the programmer to perform
background control.




1.2 GENERAL AREAS OF APPLICATION
Many manufacturers produce stepper motors, stepper motor assemblies such as X-Y tables, shaft
encoders, etc. A short summary of sources appears in Appendix B. MetraByte can provide from stock
a standard 5V, lA, 2OO&ep/revolution motor (STEP-MOT11 and l,OOO-line/revolution optical shaft
encoder (STEP-ENCl), see Appendix C for specifications. These devices are representative only of
typical hardware that can be used with the MSTEP-5.

Generally, stepper motors are suited to applications requiring variable torque, low speeds (not
exceeding 500 rpm) and maximum position retention. They also offer the simplicity of open-loop
position control simply by counting the number of steps. If your needs dictate higher speeds, fast
acceleration and deceleration, and the ability to return to a set position regardless of load
perturbations, a closed-loop DC servo drive may be more suitable. MetraByte also offers this type of
motion control board for the IBM PC (see our Model MSERVO-2 and accessories). This type of drive
is generally more complex and costly than a stepper drive but has characteristics that may be essential
in certain applications.

The MSTEP-5 may be combined with other MetraByte measurement and control boards to implement
complex "move and measure" type of instrumentation. It has obvious applications in robotics, optics
and lasers, mechanical assemblies, remote control, etc.




1.3 UTILITY SOFTWARE
It is possible to program the MSTEP-5 directly using normal I/O port commands (IN' and OUT etc.).
This is explained in Section 3 and Appendix A, but for the programmer who wants fast results, our
accompanying utility software (MSTEP.BIN) will simplify the use of the MSTEP-5 and save a lot of
programming time. The utility software is provided on a single-sided PC-DOS 1.10 format 5-l/4"
floppy disk (upward compatible with DOS 2.0 and higher revisions):

1. A Microsoft Basic callable driver (MSTEP.BIN) is provided for control of the basic stepper and
encoder functions. The fully commented assembly source for this driver (MSTEPASM) is also
provided. The object module, MSTEP.OBJ, is also on the disk for linking when using compiled
BASICs (for example, IBM BASIC Compiler, Microsoft QuickBASIC, etc.).
2. Examples and demonstration programs. A comprehensive demonstration program (DEMO.BAS,
DEMO.EXE) is provided. This is excellent both as a programming example and a way of getting
the "feel" of the PPMC motion commands and driver software features. It will also be useful in
your system setup and test. For further details see Chapters 3 and 7.
3. Instructions for ASSEMBLY LANGUAGE, C, Pascal and Fortran programmers are included in
Appendix E.




1-3
MSTEP-5 USER GUIDE


1.4 TECHNICAL SUPPORT
If you have a problem, need information or advice, give us a call [617-880-30001 and ask for
applications engineering. We will do our best to assist you because our philosophy of doing business
is to provide a solution to your problem, not just sell a piece of hardware. If for any reason you are
dissatisfied with any MetraByte product or find it is unsuited to your requirements, you are welcome
to ietum it within the first 30 days of purchase for a full refund. Please call us first for an R.M.A.
(Return Material Authorization) number before sending back any hardware. The MSTEP-5 and
accessories are warranted against defects in manufacture and material for 1 year from the date of
original purchase.




1.5 OPTIONS
Several optional accessories to facilitate the use of the MSTEP-5 are available from MetraByte. These
include:

1. STA-STEP: As an an aid to using the MSTEP-5, this combination screw terminal and
power driver board accessory can be connected directly to the 50-pin
rear connector of the MSTEPS using MetraByte's CACC-2ooO cable.
The STA-STEP accessory board performs two functions. All of the input
and output co~ections of the MSTEP-5 (with the exception of the motor-
phase drives) are brought out to miniature screw terminal connectors.
The phase drives are optically isolated and drive ten Motorola MTPN-08
6Ov2SA 0.08 ohm power mosfet transistors (5 transistors for each of the
2 axes). Inductive clamping circuitry and provision for current limiting
resistors are also provided on the board. For 3,4 or 5 phase stepper
motors up to about 24V 5A rating, all that is required is an external DC
power source of appropriate voltage for the motors. Because of the opt*
isolation, all of the motor power drive circuitry is isolated from the
computer ground and MSTEP-5 outputs. This provides additional
safety and convenience in application. See Chapter 5 for more details.


2. STEP-MOTl: MetraByte can provide (as a stock item) a Superior Electric stepper
motor, type MO61-LS02 (or other manufacturer's equivalent). This has
200 steps per revolution (1.8 deg. step angle), 5v 1A excitation and 35
oz-in torque with an output shaft diameter of 0.25 inch. Specifications of
this motor are provided in Appendix C . Other motor types should
should be ordered direct from the manufacturer, a partial list of sources
is in Appendix B.


3. STEP-ENCl: MetraByte can provide (as a stock item) an optical shaft encoder. This is
5v powered and outputs 1000 pulses/revolution. Additional
specifications are provided in Appendix C.


If you wish to use a stepper motor translator card manufactured by another company, the MSTEP-5
pulse and CCW/CW outputs can be used to drive the translator. In this case, you can either make up
your own cable, avoiding the use of the STA-STEP, or use the STA-STEP and simply pick up the
desired co~ections on the miniature screw terminal connectors.




l-4
CHAPTER 1: INTRODUCTION




m




a
W
t
i


c m




l-5
MSTEP-5 USER GUIDE




* * * * *




l-6
CHAPTER
2
INSTALLATION
2.1 BACKING UP THE DISK
The Disk back-up utility software supplied with MSTEP-5 is in DOS 1.10 format and is compatible
with DOS 2.0 and higher revisions. You are urged to make a back-up copy before using the software.
For a direct back up, use the DOS DISKCOPY utility or alternatively COPY *.* to a pre-formatted disk.
For a hard disk, simply use COPY *.* to transfer to a directory of your choice, the MSTEP-5 software is
not copy protected. If for any reason you should misplace or destroy your MSTEP-5 utility software
disk, please contact MetraByte for a free replacement.




2.2 HARDWARE INSTALLATION
MSTEP-5 utilizes 8 consecutive address locations in I/O space. Some I/O addresses will already be
used by internal I/O and your other peripheral cards. To avoid conflict with these devices, MSTEP-5's
I/O address can be set by the BASE ADDRESS DIP Switch to be on an 8-bit boundary anywhere in the
IBM PC decoded I/O space. The IBM PC-XT I/O address space extends from decimal 512-1023 (Hex
200-3FF) and the IBM PC-AT I/O address space extends from decimal 256 to 1023 (Hex 100-3FF). In
either case this is much larger than is ever likely to be fully occupied. Such a large space also allows
use of more than one MSTEP-5 in a single computer. For your convenience, the reserved I/O
addresses for standard IBM devices are detailed on the next page. You must avoid setting the MSTEP-
5 to the same address as any other peripheral adapter card, but only if that other adapter card is
already installed in your machine. A conflict of addresses will not cause physical damage but may
cause malfunction of the MSTEP-5 and the conflicting adapter and in some circumstances, power on
self test (POST) diagnostic messages. If you experience any of these problems, remove the MSTEP-5
and set it to another base address.

HEX RANGE USAGE HEX RANGE USAGE

OootolFF InternalSystem 387 to 37F LpTl:
200 to 20F Game 380 to 38C SDLC comm.
210 to 217 Expansionunit 380 to 389 Binary comm. 2
220 to 24F ReSelWd 3A0 to 3A9 Binary comm. 1
278 to 27F Re&XWXl 3B0 to 3BF Mono dsp/LPTl:
2F0 to 2F7 LPT2 3co to 3CF Reserved
2F8to2FF COM2: 3D0 to 3DF Color graphics
300 to 31F Prototypecard 3E0 to 3E7 Reserved
320 to 32F Harddisk . 3F0 to 3F7 Floppy disk
3F8 to 3FF COMl:

The above list covers the standard IBM I/O options (most compatibles are identical), but if you have
other I/O peripherals (special hard disk drives, special graphics boards, prototype cards etc.), they
may be making use of I/O addresses not listed in the table above. Memory addressing is separate
from I/O addressing so there is no possible conflict with any add-on memory that may be in your
computer.

Usually, a good choices is to put the MS'IEP-5 at Base Address Hex &H300 or &I-I310 (Decimal 768 or
784). (Note if you are using an IBM prototype board, it uses the Hex 30031F address space and would


2-l
MSTEP-5 USER GUIDE

conflict, &I-I330 or &H340 would be a good alternative in this case). As an aid to setting the base
address DIP switch, a graphical switch position display program INSTALL.EXE can be from the
prompt. To the installation program, type A > INSTALL

When you the Desired base prompt, type your choice decimal or
&H- format press < >. program will your address the nearest
boundary, check possible conflicts standard IBM devices (and you if and draw
picture of correct positions the seven on the Address DIP For additional
on Base switch settings, Figure 2.0.

next step to remove MSTEP-5 board its protective packaging and the
Base switch, located to the left of gold edge It is good precaution
discharge any charge you have accumulated touching the frame of
computer before the board the computer.

only other setting is choice of Level. Most you will initially be
use of interrupt capabilities the MSTEP-5 can park "IRQ LEVEL"
level) selector block in "X" inactive If your will use from
the MSTEP-5, then select the Hardware Interrupt Level 2 thru 7 that you intend to use. Take care to
avoid selecting a level that is used by another adapter card (for example, Level 6 is always used by the
floppy disk controller, Level 4 by COMl:, Level 3 by COM2: etc.). For more information on interrupt
programming, see MODE 11, Section 3.8.12

To install the board, TURN OFF THE POWER on your computer and remove the case (See the IBM
"Guide to Operations" manual if you are not already expert at this maneuver). Remove a vacant back
plate by undoing the screw at the top and plug the MSTEP-5 in and secure the backplate. MSTEP-5
will fit in any of the regular full depth slots of the IBM PC-XT or Portable computer. On the PC-AT, it
can be plugged into any socket but it will not make use of the extended AT bus interface connector.
Due to the length of the 50-pin rear connector, it is advisable to set the retainer latches on this
connector out straight, pass the connector through the rear slot and pivot the board down into the
edge connector. The board is 1 inch shorter than the slot length to allow for this maneuver.
Installation is now complete. You may plug any of the MSTEP-5 accessories or your own cable into
the 50-pin connector on the rear.

Remember, TURN OFF THE POWER whenever installing or removing any peripheral board
including the MSTEP-5. Never try to install or remove any peripheral board with the power on as it
can cause costly damage to the electronics of your computer and/or the MSTEP-5 board.

If for any reason you later remove the MSTEP-5 board, MetraByte recommends that you retain the
special electrostaticalIy shielded packaging and use it for storage.

EASE ADDRESS INTERRUPT
IRO LEUEL
LEVEL . - 2 3 4 5 6 7 :<
E:ASE ADDRESS S"(GLIN ,_________-_-_-----_________(




hASE +
: i ;
ADOFESS : ;r3 9
: : . . . . .. . . . .._____.__....... A.q 16 i
PLACE ;lJMPER BLOCK ON DESIRED LEVEL
: .._..........._...._........... As 3'
,.,.. . . . . . . . . . . . . . . A6 "x" IS INACTIVE PARKING POSITION
6-1
. A7 SEE SECTIOti 3.8.12 FOR CHOICES
128
fj8 256
. . .. . . . . . . . . . . . .. . . . . A4 51.2

St.1 I TCHE5 HA'JE `.`kLIJE 5 A3 ABOVE I PI THE "OFF" "OS I T I Grl
IN THE "Ghl" PGSITION. DECI?IAL UALUE IS -/ERG


Figure 2.0. Base Address Switch & Interrupt Settings.


2-2
CHAPTER
3
PROGRAMMING

3.1 GENERAL
At the lowest level, the Stepper Motor Controller is programmed using I/O input and output
instructions. In BASIC, these are the lNP(X) and OUT X,Y functions. In Assembly Language, they are
IN AL,DX & OUT DX,AL. Most other high level languages have equivalent instructions. Use of these
functions usually involves formatting data and dealing with absolute I/O addresses. Although not
demanding, this require many of code necessitates an of the data
format, architecture of MSTEP-5. To program generation, special I/O
routine "MSTEP.BlN" included in MSTEP-5 software This may accessed from
by a line CALL The CALL will perform used sequences
instructions. An is Mode which performs normal stop. routine to this
operation BASIC using and OUT's require many of code would be
slow and tedious to

A sequence BASIC lNPs OUT's to the Stop to PPMC A would as
follows:

xl0 cNR% = INP (BASADR% + 0) `read current control register
x20 cNR% = ((CNRB AND &HFC) OR hH05) 'select A, AORSEL=l
x30 OUTBASADR+O,CNR% `write control register
x40 STAT% = INP (BASADR% + 1) 'fetch PPMC status
x50 IF (STAT% AND hH04) = 0 THEN GOT0 xx150 'motor stopped?
x60 IF (STAT% AND &H02) 00 THEN GOT0 xx140 'input buffer full?
x70 cMD% = &HO1 + &HlO `stop Motor, disable interrupt
x80 CNR% = CNR% AND hHFE 'set AORSEL = 0
x90 OUT BASADR% + 0, CNR% `write control register
xl00 OUT BASADR% + 1, C24D% 'write PPMC command
xl10 CNR% = CNR% OR &HO1 'set AORSEL = 1
x120 OUT BASADRB + 0, CNR%
x130 STAT% = INP(BASADR% +l) 'fetch PPMC Status
x140 IF (STAT% AND &H04) <> 0 THEN GOT0 xxx130
x150 STOP 'finished



All this code can be circumvented by using the driver:

x10 MD%=1 'command - decelerating stop
~20 D%(O) = 1 'select channel A
x30 CALL MSTEP (MD%, D%(O), STP#, FLAG%)



Obviously, the MSTBP.BlN driver greatly reduces programming time and effort. Both methods of
programming are described (see Appendix A for programming the PPMC-1OlC directly) and you are
free to choose either. Usually the BASIC programmer will find the CALL routine method very much
simpler to implement. The MSTEP.BlN driver also provides an example interrupt service routine. It
is not possible to program interrupt routines directly in BASIC and the driver is the only way of
utilizing interrupts from the MSTEP-5 hardware.

3-1
MSTEP-5 USER GUIDE

3.2 REGISTER LOCATIONS & FUNCTIONS
The I/O address map of the MSTEP-5 is structured as follows:

ADDRESS READ WRITE

Base Address + 0 Control Register (read/write
register)
+I PPMC Registers A/B (read/write registers)
+2 - Clear Encoder A
+3 Encoder Low Byte Clear SMC A
4 Encoder Middle Byte Clear SMC B
+5 Encoder High Byte Clear Encoder B
+6 Clock Divider A
+7 Clock Divider B]




Base Address +0: Control Register (Read/Write)
Access to each of the PPMC stepper controllers is through the I/O port at Base Address +l. The
Control Register, at Base Address +0, acts as an indirect address or pointer register for the other
devices on the board; it controls the following:

l Which of the PPMC stepper channels is accessed.
l Which of the internal registers (there are four in each controller) is selected.
l Which of the two encoder channels is read at Base Address +3, +4, or +5.
l Generation of interrupts.
l Choice of internal/external stepper-clock sources.


Bit functions in the control register are as follows:

II I I I I I I I 11
BIT: D7 D6 D5 D4 D3 D2 Dl DO
I I I I I ! I I
Ii I I I I I I I 1
XCB XCA EINTB EINTA ECTRAB CSB CSA AORSEL
II I I I I I I I u



Bit functions:

XCB Selects External Step Clock (XCB = 1) on Pin 42 or lOOKI& + Divider on-board clock
(XCB = 0) for stepper channel B. This applies only if the PPMC initialization command
has specified external clock otherwise the 12.5KHz PPMC internal clock will be used.
XCA Selects external step clock (XCA = 1) on pin 41 or 1OOKI-I.z divider on board clock (XCA
+
= 0) for stepper channel A. This only applies if the PPMC initialization command has
specified external clock otherwise the 12.5KHz PPMC internal clock will be used.
EINTB Enables hardware interrupt from PPMC Stepper Channel B (EINTB = 1). Interrupt is
disabled if EINTB = 0.
EINTA Enables hardware interrupt from PPMC Stepper Channel A (EINTA = 1). Interrupt is
disabled if EINTA = 0. If both ElNTB and ElNTB are enabled, interrupts from the 2
controllers are ORed together. In this case, the Interrupt Service Routine must poll each
controller to determine the source of the interrupt.

3-2
CHAPTER 3: PROGRAMMING
ECTRAB Selects which of the Encoder Counter channels can be read at Base Address +3, +4, +5.
ECTRAB = 0: Encoder Channel A
ECTRAB = 1: Encoder Channel B


CSB, CSA, AORSEL select PPMC registers as follows:
CSB CSA AORSEL READ(R) WRITE(W)

1 0 0 PPMC Channel A Data Register (R/W)
1 0 1 A Status Register A CommandRegister

0 1 0 PPMC Channel B Data Register (R/W)
0 1 1 B Status Register B CommandRegister

0 0 0 Illegal Write both data registers
0 0 1 ,, Write both commandregisters

1 1 X Unselected both channels


Programming of the PPMC-101C controllers is covered in Section 3.3 and Appendix A.




Base Address +3, +4, +5: Encoder Counter Registers (Read Only)
Each Encoder Counter consists of three &bit sections that are read only. Channel A or Channel B is
selected by the ECI'RAB bit in the Control Register. The 24-bit Encoder Counter data is then read
from Base Address +3, +4, and +5 as follows:

Base Address +3: Low byte (Read Only)
Base Address +4: Middle Byte (Read Only)
Base Address +5: High Byte (Read Only)

To clear Encoder Counter A, write to Base Address +2.

To clear Encoder Counter B, write to Base Address +5.


Note that the encoder data is not latched (the counter is read directly. To avoid erroneous data, the
encoder data is best read when the encoder is stationary. Reading the counter with the encoder
moving may give rise to errors in the data due to the delays between reading each byte, this depends
to some extent on the speed of rotation of the encoder bee MODE 9, Section 3.8.10, and Section 4.3).


A typical encoder-read sequence in BASIC might be as follows:

x10 cNR% = INP(BASADR%) 'Fetch current control register
x20 cNR% = ((CNR% AND LHF7) OR CH08) I= encoder A, &HOO=B
x30 OUT BASADR%, CNR% 'set ECTRAB bit
x40 RDcL% = INP (BASADR% + 3) 'read low byte
x50 FiDcM% = INP (BASADR% + 4) 'read middle byte
x60 RDCH% = INP (BASADR% + 5) 'read high byte
x70 POSN# = RDCL% + (256*RDCM%) + (65536*(RDCH% and &H7F))
x80 IF ((RDCH% AND CH80) <> 0) THEN POSN# = -POSN#
'Position is CCW of initial point

3-3
MSTEP-5 USER GUIDE

This example illustrates a few important details. First the encoder channel to be read is selected with
the ECTRAB bit in the Control Register. Since the data returned is 24-bit, it would ideally be suited to
reading into a long (double-word) integer. Many languages (C, Fortran, etc.) provide long integers,
but BASIC is an exception that forces you to use a floating point variable, instead. Note this needs to
be a double-precision variable in BASIC to provide 24-bit resolution. Use a single precision variable
and you lose counts at high values (to prove this, try X=17111113:PRINT USING "########";X). If
we clear the encoder channel at the reference or "home" point of the system, the most significant bit of
the up/down encoder counter can be treated asa sign bit and will indicate the rotation direction from
the home point.




Base Address +2, +3, +4, +5: CLEAR Commands (Write Only)
Four Clear addresses have been provided. They are

1. A write to Base Address +2 clears Encoder Counter A.
2. A write Base Address +5 clears Encoder Counter B.
to
3. A write to Base Address +3 resets PPMC A stepper controller.
4. A write to Base Address +4 resets PPMC B stepper controller.


A write to these registers at any time is similar to a hardware reset. The data written to these I/O
addresses is irrelevant and is lost; it is the act of writing to the port that provides the Clem function.
The PPMC-1OlC stepper controllers are specialized microprocessors that are automatically reset on
power-up of the computer. Afterwards, these controllers can also be hardware-reset by a write to
Base Address +3 or +4. After resetting a PPMC controller, allow at least 100 micro-seconds to elapse
before performing an initialize command. This lets the specialized processor perform its own
internal start-up initialization before responding to commands. In interpreted BASIC, allowing for
this delay is not a concern, but in other languages, be sure to wait. An example of clearing all four
registers in BASIC is as follows:

x10 OUT BASADR%+P, 0 'Clear Encoder A
x20 OUT BAsADR%+S, 0 'Clear Encoder B
x30 OUT BASADR%+3, 0 'Clear PPMC A
x40 OUT BASADR%+4, 0 'Clear PPMC B



Base Address +6, +7: Clock Dividers (Write Only)
There are three different stepperclock sources usable by the PPMC. PPMC internal 12.5KHz clock,
Stepper Motor Controller Board external 1OOKHzclock, or an external user-supplied clock source. To
use either of the clock sources external to the PPMC stepper controller chip(s), the PPMC initialization
command must specify external clock input. Alternatively, the initialization comman d can also
specify use of a 125KHz clock generated internal to the PPMC chip (internal clock), which is usually
adequate for most applications. If the external clock option is selected on initialization, you have the
further choice between external hardware inputs (Pins 41 and 42) or an on-board 1OOKHzcrystal with
programmable divider source. The external clock selection is controlled by the XCA and XCB bits of
the Control Register.

If you elect to use the the Stepper Motor Controller Board external 1OOKHzClock, you can select the
pulse rate by loading the appropriate clock divider register. This register is Read/Write and may be
programmed to select a pulse rate between 1.54 and 1,000 pulses per second (I%). In addition, this
register works in conjunction with the internal PPMC I&Aregister to give an effective divider range of


3-4
CHAPTER 3: PROGRAMMING
20 to 65535.

The pulse frequency may be calculated using the formula:

PPS = 100,000 / ((FD+l) ' RA)

where

FD = Frequency Divider (1 - 255)
RA = PPMC Divider (20 - 255)


If the PPMC Internal Clock and RA Divider are selected at initialization time, the pulse rate may be
between 625 pps (RA = 20) and 49 pps (RA = 255). The formula to calcuIate this is

PPS=12.5/RA

where

RA = 20 - 255


If XCA or XCB = 1, a square-wave TTL-level clock may be provided on the external clock pins (Pins 41
and 42) as appropriate. To use this clock, the PPMC must be initialized for external clock. This clock
source is divided by the internal PPMC RA register which is also set up at initialization time. The
external input option allows user to synchronize the two stepper motor controllers with the same
clock or change its rate during motion commands.

The pulse rate may be determined by the following formula:

PPS = (External Clock Rate (Hz)) / RA

where

RA = 20 - 2551


The following BASIC code is an example of programming the MSTEP-5 board clock dividers (an
identical function is performed by MODE 10 of the driver):

xxx10 cNR% = INP(BASADR% + 0) 'read current control register
xxx20 cNR% = CNR% AND LH3F 'turn off XCA 6 XCB - select lOOKliz
xxx30 OUT BASADR%+O, CNR% `write control register
xxx40 OUT BAsADR%+C, DIVA% 'write Divider A
xxx50 OUT BASADR%+7, DIVB% 'write Divider B




3.3 PPMC-101C STEPPER CONTROLLER INTERNAL REGISTERS
Bach PPMC-1OlC Stepper Controller is a specialized microprocessor. The MSTEP-5 Control Register
selects the PPMC channel (A or B) through the CSA and CSB bits, and any of the four internal PPMC
registers by the AORSEL bit:




3-5
MSTEP-5 USER GUIDE

AORSEL READ WRITE

0 DATA DATA

1 STATUS COMMAND




Motion commands are issued to the PPMC controller by writing a command code to the Command
Register (with AORSEL = 1). Since the PPMC may be busy executing a command, you must always
read the STATUS register to determine whether the PPMC is ready to receive the command. After a
command is issued, it may require or produce a variable number of data bytes (depending on the
command) which are written or read from the Data Registers (with AORSEL = 0). Apart from
controlling access to the Command Register, the Status register also provides additional information
on the operation of the PPMC controller.

There are eight motion-control comman ds as well as the INITIALIZATION command that set the
operating conditions of the controller. The functions of the Command and Status Registers are as
follows:

INITIALIZATION Selects the motor type, method of excitation acceleration/deceleration
rate, internal/ external step clock, phase output logic type and start up
and high speed pulse rate. Once the initialization command has been
sent, it may not be overwritten by a further initialization command. The
PPMC controller must be reset either by turning the computer power off
and on or more conveniently by issuing a hardware clear command Gee
Sections 3.2.4 and 3.8.13 - mode 12).
OPERATION This is the user interface mode in which COMMAND selects any of eight
motioncontrol commands. The length of the data to follow depends on
the specific command.
STATUS Before/after the completion of an operation command, the status register
provides data on the limit switches, motor in motion or at standstill and
input/output data buffer full or valid. It also enables you to read the
number of steps remaining to be travelled etc.


Direct progr amming of the PPMC-101C controllers and their full specification is more fully covered in
Appendix A.




3.4 LOADING THE MACHINE-LANGUAGE CALL ROUTINE MSTEP.BIN
In order to make use of the CALL routine MSTEP.BIN, it must first be loaded into memory. You must
avoid loading it over any part of memory that is being used by the main body of your program, DOS,
or programs such as RAM disks that use high memory. If you do collide with another program, your
computer will usually hang up although sometimes the results can be more peculiar. Often you will
need to turn the power off and restore it to reboot the machine, the usual Ctrl-Ah-Delete reset may
fail to restore DOS. This may sound ominous, but apart from the frustration, no damage will ever
result!

MSTBP.BIN uses about 3 Kbytes of memory and is best loaded outside BASIC's workspace. A typical
loading sequence is as follows:




3-6
CHAPTER 3: PROGRAMMING

xx100 DEE' SEG = &IX3000 'segment of memory to load link
(choose an empty area e.g. @@ 192K)
xx110 BLOAD "MSTEP.BIN",O 'load driver . . Continue program


The above initializing steps will be the same for any interpreted BASIC program. A more
comprehensive example is provided on the disk in DEMO.BAS. Note that the DEF SEG = &H3000
statement in line 100 specifies the load location for the MSTEP.BIN driver. All subsequent CALL's will
occur to the last DEF SEG address, so if you add other DEF SEG's in your program, remember to
precede your CALL's to MSTEF-5 with the same DEF SEG = &H3000 that you used to load the link
(see CALL and DEF SEG in your BASIC reference manual).

Finding a place to load MSTEl'.BIN is seldom much of a problem now that most PC's are equipped
with at least 256K of memory. The following explanation provides some insight into the process of
choosing a memory location for the driver and what to do if memory is in short supply.

DOS occupies the bottom of memory, the amount of memory required being dependent on the
version (it grows as each new revision adds extra features!). The simplified memory map below shows
what happens after booting up BASICA.

DOS 1.1 DOS 2.1 DOS 3.0

Bonom: OK --__-- OK ------- OK ------

DOS
19K --mm--

DOS
DOS
47K ---__-

BASIC 63K _---_-

BASIC
BASIC
98K ------

Free
memory 126K ------

Free 140K --m-v
memory
Free
memory



hdSTEP.BlN should be loaded somewhere in the free memory area so that it does not interfere with
either BASIC or DOS. This would be above 98K (&H1880) for DOS l.l,126K (&HlF80) for DOS 2.1 or
140K f&H23001 for DOS 3.0. If you have 256K &H4000) or more of memory, then loading the link at
DEF SEG = &I-I2800 or &H3000 is a good solution for all versions of DOS. One further small detail is
that if you are using a PC compatible which does not have BASIC in ROM like the IBM PC, then
BASIC (e.g. GWBASIC) is usually loaded as an .EXE file from the top of memory down. This is likely
to fill up to 64K of the top segment of memory. Some virtual disks or print spoolers will do the same.
Also if you are accustomed to using DOS resident programs such as Borland's Sidekick etc. be aware
that these will push the loading floor of BASIC up and require a compensating increase in the location
of MSTEI'.BlN.

3-7
MSTEP-5 USER GUIDE

If you are memory limited, or you have so much resident stuff that there is no longer 64K left for
BASIC to load in, then BASIC will attempt to make the most of what it can find. Instead of getting the
message when BASIC has loaded:

The IBM Personal Computer Basic
Version A2.0 Copyright IBM Corp. 1981, 1982, 1983
60865 Bytes free
OK

You may get only 49345 bytes free (or something less than 60000 bytes) for example. In this case make
a note of what space BASIC has found. You can then contract this space further using the CLEAR
function and load the link at the end of BASIC. This is more complicated, but just as effective.

Let's suppose we get the message 52ooObytes free. MSTEP.BIN will use 3K bytes, so to be on the safe
side let's force BASIC to use 48K. Our initializing code would now be:

xx100 CLEAR, 48000 'contracts BASIC workspace



Next we need to find out where BASIC has loaded in memory, add 48ooO to it and load MSTEP.BIN
just after the end of BASIC workspace. Memory locations &H510 and &H511 always contain BASIC's
load segment:

xx110 DEE' SEG = 0 'set up to read &HSlO and &H511
x120 LS = 256*PEEK(&H5ll)+PEEK(&H510) 'load segment
x130 SG = LS + 48000/16 `rpmpmhpr segment addresses are on
16-byte (paragraph) boundaries
xl40 DEF SEG = SG 'set up to load link
x150 BLOAD "MSTEP.BIN",O 'load link
. .
Proceed with your program as before




3.5 STRUCTURE OF THE CALL STATEMENT
If you are new to using CALL statements, this explanation may assist you in understanding how the
CALL transfers execution to the machine language (binary) driver routine (also see CALL in your
Basic Reference Manual). Prior to entering the CALL, the DEF SEG = SG statement sets the segment
address at which the CALL subroutine is located. The CALL statement for the MSTEP.BIN driver
must be of the form

xxxx CALL MSTBP (MD%, D%(O), STP#, FL&G%)


Let us examine the parameters after CALL one by one:

MSTEP In interpreted BASIC this is a variable that specifies the offset of the start of our routine
from the segment defined in the last DEF SEG statement. In our case its value is always
set to zero (MSTEP = 0). In compiled BASIC (and most other compiled languages)
MST'EP has a different significance - it is the name of the external routine that the linker
will look for. Note: We would have liked to use the name STEP instead - it's a better
mnemonic than MSTEB, but be warned that STEP is a reserved word (as in FOR I=0 TO 6
STEP 2) and CALL STEP would produce a syntax error.



3-8
CHAPTER 3: PROGRAMMING

MD% This is an integer variable that specifies the operation that we wish the driver to perform
e.g. MD%=0 performs an emergency stop, MD% = 12 initializes a channel etc. In the
case of this driver, valid mode numbers range from 0 to 12.
D%(9) This is a IO-element integer array that passes data to and from the driver. The
signifigance of particular data items varies according to the mode (MD%) selected. Not
all elements of D%(+) are used in all modes.
STIW This is a double precision variable that specifies the direction and number of steps to
travel or returns optical shaft encoder counts. The sign indicates the direction, +
clockwise, - counter-clockwise. Not all modes utilize the STP# data , however it must
always be included in the call parameter list.
FLAG% Returns an error code if any of the specifying D%P) or MD% are out of range or if the
motor is busy or at standstill in certain commands. In the case of no error, FLAG% is
returned zero.


The four variables within brackets are known as the CALL parameters. On executing the CALL, the
addresses of the variables (pointers) are passed in the sequence written to BASIC's stack. The CALL
routine unloads these pointers from the stack and uses them to locate the variables in BASIC's data
space so data can be exchanged with them. Three important format requirements must be met, as
follows:

1. The CALL parameters are positional. The subroutine knows nothing of the names of the
variables, just their locations from the order of their pointers on the stack. If you write:
- CALL MSTEP (D%(O), FLAG%, MD%, STP#)

you will mix up the CALL routine, since it will interpret D%(O) as the mode data, and FLAG% as
the D%(O) data variable etc. The parameters must always be written in the correct order, as
follows: mode #, data, step count, errors
2. The CALL routine expects ik parameters to be of correct type and will write and read to the
variables on this assumption: integer, integer array, double precision, integer
If you slip up and use the wrong variable types in the CALL parameters, the routine will not
function correctly and may hang up the program.


3. You cannot perform any arithmetic functions within the parameter list brackets of the CALL
statement. There can only be a list of variables. Also you are not allowed to replace variables by
constants.
Apart from these restrictions, you can name the variables what you want, the names in the examples
are just convenient mnemonics. You should always declare the variables before executing the CALL
so that BASIC has reserved memory locations for them before entering the CALL. In the case of the
integer array, the first element D%(O) should be specified in the CALL parameter list as the data
variable so that the CALL routine can locate all of the other remaining data items in the array
correctly.




3.6 ERROR CODES
Some value checking is performed on entry data and any errors discovered are returned in FLAG%.
This is primarily to prevent you setting up the CALL with obviously incorrect data such as interrupt
level 9, mode number -6, base address 2000, byte output data 299 etc. and is intended to help avoid a
bad setup of the hardware which could hang the computer. Also certain commands, such as an


3-9
MSTEP-5 USER GUIDE
emergency or decelerating stop are redundant if the motor is already at standstill (FLAG% = 7) and
the PPMC controller may not be receptive to further commands if it is already busy executing a
command @`LAG% = 1). If a non-zero error code is returned in any mode, execution of that mode will
have been abandoned without action since error checking precedes any I/O to the hardware.

ERROR CODE # PROBLEM

0 No error, OK
1 Motor busy
2 Driver not initializedon Channel A
3 Driver not initializedon Channel B
4 Mode numberCOor > 12
5 Hardwareerror
6 Step count out of range +/-16,777,215
7 Motor already at standstill
8 - (not used)
9
10 Error in range of D%(O)
11 Error in range of D%( 1)
12 Error in range of D%(2)
13 Error in range of D%(3)
14 Error in range of D%(4)
15 Error in range of D%(5)
16 Error in range of D%(6)
17 Error in range of D%(7)
18 Error in range of D%(8)
19 Error in range of D%(9)


Checking for errors is easily performed after each CALL and is recommended if not as a permanent
feature then at least while debugging your program

xxx00 CALL &STEP (MD%, D%(O), STP#, FLAG%)
xx10 IF FLAG%<>0 THEN PRINT "Error number ";FLAG%:STOP



Certain error codes are useful in performing cha