Text preview for : 24413A(PCF-M5).pdf part of Keithley 24413A(PCF-M5) Keithley Misc 24413A(PCF-M5).pdf



Back to : 24413A(PCF-M5).pdf | Home

PCF-MS




Keithley MetraByte Corporation
* * * * *
User Guide

for the



PCF-M5

Language Drivers




R&vision A - April 1991
Copyright Keithley MetraByte Corp. 1991
Part Number: 24413




KEITHLEY METRABYTE CORPORATION
440 MYLES STANDISH BLVD., Taunton, MA 02780
TEL. 508/880-3000, FAX 508/880-0179



...
- /I/ -
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 Keith@ 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
Keithley MetraByte/Asyst/DAC is also referred to here-in as Keith@ MetroByte.

BasicTMis a trademark of Dartmouth College.

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

PC, XT, AT, PS/2, and Micro Channel Architecture@ (MCA) 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 Overview ........................................ l-l
1.2 Implementation .................................... .1,-l


CHAPTER 2 INTERFACE DRIVERS

2.1 Microsoft C & QuickC .................................. .2-l
Small Model ..................................... .2-l
Medium Model .................................... .2-2
Large Model ..................................... .2-3
Microsoft C Example. ............................... .2-4
2.2 Borland Turbo ...................................... .2-6
Small Model ..................................... .2-
Medium Model .................................... .2-7
Large Model., ................................... .2-7
Turbo C Example. ................................. .2-8
2.3 Microsoft PASCAL. ................................... 2-l 1
Medium Model .................................... 2-l 1
Microsoft PASCAL Example. ........................... 2-12
2.4 Borland Turbo PASCAL. ............................... 2-13
Compact Model.. ................................. 2-13
Large Model ..................................... 2-l 4
Turbo PASCAL Example. ............................. 2-15
2.5 Microsoft FORTRAN. ................................. 2-17
Large Model ..................................... 2-l 7
Integer (Default) Function Or Subroutine. .................... 2-18
Microsoft FORTRAN Example. .......................... 2-18
2.6 MSTEP.LIB General Purpose Library. ........................ 2-20

CHAPTER 3 BASIC INTERFACE DRIVERS

3.1 Interpreted BASIC (GW, Compaq, IBM, etc.) .................... .3-l
3.2 QuickBASIC. ..................................... .3-2




-v-
* * * * *




- vi -
CHAPTER
1
INTRODUCTION

1.I OVERVIEW
MetraByte's PCF-M5 is for Pascal, C, and Fortran programmers writing data acquisition and control
routines for the MSTEP-5 Board. The PCF-MS supports all memory models for the following
languages;

l Microsoft C fV4.0 - 6.0)
l Microsoft QuickC (Vl .O- 2.0)
l Borland Turbo C (Vl .O- 2.0)
l Microsoft PASCAL W3.0 - 4.0)
l Borland Turbo PASCAL (V3.0 - 5.0)
l Microsoft FORTRAN (V4.0 - 4.1)


The PCF-M5 consists of several assembly language drivers for the various supported languages along
with example programs for each language. This manual is structured to illustrate memory model
usage for each of the above languages and to include a brief example program at the end of each
language section. Full source listings are included on the supplied disk.


This manual is not an introduction or operating guide to the supported MSTEPS boards. You should
be familiar with the boards' various operating MODES, PARAMETERS, and ERROR codes before
attempting PCF-MS implementation. Refer to the main sections of this manual supplied with your
MSTEP-5 MetraByte board for a complete discussion of hardware and related functionality.


PCF-M5 Distribution Software is furnished on a 5.25" floppy diskette. A 3.5" diskette version is
available as an option.




Al .2 IMPLEMENTATION
Before working with this interface package, you are urged to become familiar with MSTEP-5 board
functions and specifications. Example programs herein do not assume any knowledge of these boards
since the programs are general in nature and do not actually implement features of any specific board.
They are limited to the actual language interface for the various languages supported.


In the following chapter, each interface driver (implemented via a CALL statement) consists of three
position-dependent parameters. These are MODE, ARGUMENT (or PARAM), STPNUM, and FLAG,
as follows:




l-l
PCF-M5 USER GUIDE


MODE Type of function to be executed by the MSTEP-5.


PARAM Function-dependent arguments required for execution.


STl'NUM Step Number, which is a long integer that specifies the direction and
number of steps to travel, or it returns optical shaft encoder counts. The
sign indicates direction (+ = clockwise, - = counter-clockwise). Not all
MODES use StpNum data, but it must always be included in the CALL
parameter list.


FLAG Error number, if any, corresponding to selected MODE




* * * * *




1-2
CHAPTER
2
INTERFACE
DRIVERS
2.1 MICROSOFT C (V4.0 - 6.0) & QUICKC (Vi .O - 2.0)

Small Model
Model: Small ("/AS") switch on command line
Passes: word size pointers (offset, no DS register)
Sequence: Arguments Passed Right to Left
Default Calling
Convention: Arguments Passed by Value (Passing pointers to a subroutine is
considered pass-by-value convention)



Example:
`c' Call: mscs-mstep &Mode, Param, &StpNum, &Flag);
`c' Declaration: extern void mscs-mstepfint*,unsigned long *, int*l;



.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:

-mscs-mstep proc near
push bp ; save base pointer
mw~ W,sp ; save stack pointer
; [bpt4] holds offset of Mode
; [bpt6] holds offset of Param
; [bpt8] holds offset of StpNum
; [bptlo] holds offset of Flag
; Program execution here
I


. ;
POP bp *restore
I bp & sp prior to exit
ret ; return
-xnscs-mstep endp



Other:
This information is provided for those wishing to create their own drivers:

. -mscs-mstep is declared "PUBLIC" in the .ASM file
l mscs-mstep is declared "extern" in the "C" file


2-1
PCF-MS USER GUIDE

l The .ASM file contains the ".model small" directive (MASM & TASM only)
l Add leading underscore "-`I to all mscs-mstep occurrences in .ASM file
l mscs-mstep is a near call
l mscs-mstep must be in a segment fname-TEXT (where fname is the name of the file where
mscs-mstep resides) if .ASM file contains mixed model procedures.



Medium Model
Model: Medium ("/AM") switch on command line
Passes: Word-size pointers (offset, no DS register)
Sequence: Arguments Passed Right to Left
Default Calling
Convention: Arguments Passed by Value



Example
`c' Call: mscm-mstep f&Mode, Param, &StpNum, &Flag);
`c' Declaration: extern void mscm-mstep(int*,unsigned long*,int*l;



.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:

-mscm_mstep proc far ; far CALL (dword return address)
push bp ; save base pointer
mew bptw ; save stack pointer
. ; [bp+C] holds offset of Mode
. ; [bpt8] holds offset of Param
. ; [bptlO] holds offset of StpNum
; [bpt12] holds offset of Flag
; Program execution here
. I




POP bp ;restore bp & sp prior to exit
ret ;return
-mscm_mstep endp



Other:
This information is provided for those wishing to create their own drivers:

. -mscm-mstep is declared "PUBLIC" in the .ASM file
l mscm-mstep is declared "extem" in the "c" file
l The .ASM file contains the ".model medium" directive (MASM & TASM only)
l Add leading underscore "-" to all mscm-mstep occurrences in .ASM file
l mscm-mstep is a far call


2-2
CHAPTER 2: INTERFACE DRIVERS

l mscm_mstep must be in a segment fname_TEXT (where fname is the name of the file where
mscm-mstep resides), else Linker returns an error.



Large Model
Model: Large ("/AL") switch on command line
Passes: dword size pointers (offset and DS register)
Sequence: Arguments Passed Right to Left

Default Calling
Convention: Arguments Passed by Value



Example
`c' Call: mscl-mstep (&Mode, Param, &StpNum, &Flag);
`c' Declaration: extem void mscl-mstep(int*, unsigned long*, int?;



.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:

-mscl-mstep proc far ; far CALL (dword return address)
push bp ; save base pointer
mov bprsp ; save stack pointer
; [bpt6] holds offset of Mode
. ; [bptlO] holds offset of Param
. ; [bptll] holds offset of StpNum
. ; [bpt18] holds offset of Flag
. ; Program execution here
;
. ;
POP bp *restore bp & sp prior to exit
,
ret ;return
-mscl-mstep endp


Other:
This information is provided for those wishing to create their own drivers:

-mscl-mstep is declared "PUBLIC" in the .ASM file
mscl-mstep is declared "extern" in the "c" file
The .ASM file contains the ".model large" directive (MASM & TASM only)
Add leading underscore "-" to all mscl-mstep occurrences in .ASM file
Both code and data use dword (segment/offset) pointers
mscl-mstep must be in a segment fname_TEXT (where fname is the name of the file where
mscl-mstep resides), else Linker returns an error.




2-3
PCF-M5 USER GUIDE


Microsoft `C' Example
/* */
/* Demonstration Program for WSTEP-5 */
/* Keithley Metrabyte Corporation f/
/* */
/* Language: Microsoft "C" */
/* File: MSCSDEM0.C */
/* */

#include
#include

#&fine Beep printf("%s","\7") /* make a beep sound */

#define TRYAGAIN 1
#define REV-VIDEO 7
#define DEF-VIDEO 0
#define READY 1
#define ON 1
#define OFF 0

/************************************************************************/
/* */
/* The Following are the function Calls for different models: */
/* */
/* mscs-mstep(&Mode,Param,&StpNum,&Flag) : Microsoft C mall Model. */
/* mscm-mstep(&Mode,Param,&StpNum, &Flag) : Microsoft C medium Model.*/
/* mscl~mstep(&Mode,Param,&StpNum,&Flag) : Microsoft C large Model. */
/* */
/* This Program Uses the Small Model Function Call */
/* */
/*********************~******k****k******~***~***********~***********/
/* DECLARE CALL structure */
extern mscs-mstep(int *,unsigned *,long *,int *);

/************************************************************************/
int modeO(void); /*mode0 */
int mo&l(void); /* mode 1 */
int mode2(void); /* mode 2 */
int mode3(void); /* mode 3 */
int mode4(void); /* mode 4 */
int modeS(void); /* mode 5 */
int mode6(void); /* mode 6 */
int mode7(void); /* mode 7 */
int modee(void); /* mode 8 */
int modeg(void); /* mode 9 */
int modelO(void); /* mode 10 */
int mo&ll(void); /* mode 11 */
int model2(void); /* mode 12 */
int setchannel(void); /* select channel */
int ErrWandler(int); /* error handler */
int MenuHandler(void); /* menu handler */
int GetLongInp(int,int,char *,long *); /* input get long integer */
void GetIntInp(int,int,char *,unsigned *); /* input unsigned integer */
void printat(int,int,int,char *); /* formatted print function */


2-4
CHAPTER 2: INTERFACE DRIVERS

void ShowChannel (void); /* print current channel */
void EraseLine(int); /* erase line */
/*******~*****************x*************~~*******~*************~************~

int Mode=12,Flag=O,IntLev=7,Interrupt=OFF;
unsigned Param[lO],TP[lO];
long StpNusn;

/*********************************k*X**********~********************~********/
/* */
/* Main program */
/* */
/**********************************************************~**************/
-inO
I
int option,status=!TRYAGAIN;

/* default setup for MSTEP-5 */

TP LOI = 0; // select channel A
TP 111 = 255; // start up rate, 49 pps
TPVI = 100; // high speed run rate
`JP 131= 200; // acceleration/deceleration pulse count
TP [41 = 2; // 4 phase
TP [51 = 0; // full step
TP t61 = 0; // inverted Sl-5 outputs
TP t71 = 0; // internal clock
TP t81 = 0; // switching off at standstill
TP [91 = 768; // base address




/***********************************************~**********~*******~****~**/
/* */
/* Mode 12: Initialization. */
1" */
/*Arguments Return values */
/* --------- ------------- */
/* None 1: repeat this mode*/
/* again */
/* 0: no repeat */
/* */
/*******************************************************~*****************/
int model2()
I




2-5
PCF-M5 USER GUIDE


2.2 BORLAND TURBO `C' (VI .O - 2.0)

Small Model
Model: Small ("-ms") switch on command line
Passes: word size pointers (offset, no DS register)
Sequence: Arguments Passed Right to Left
Default Calling
Convention: Arguments Passed by Value



Example
`c' Call: tcs-mstep &Mode,Param,&StpNum, &Flag);
`c' Declaration: extern void tcs-mstepfint*,unsigned long*,int*l;



.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:

-tcs-mstep proc near
push bp : save base pointer
mov bp,sp : save stack pointer
; [bp+4] holds offset of Mode
. ; [bp+6] holds offset of Param
. ; [bp+8] holds offset of StpNum
. ; [bp+lO] holds offset of Flag
; Program execution here
. ;
. ;
POP bp *restore bp & sp prior
I to exit
ret ; return
_tcs-mstep endp



Other:
This information is provided for those wishing to create their own drivers:

. -tcs-mstep is declared "PUBLIC" in the .ASM file
l tcs-mstep is declared "extern" in the "c" file
l The .ASM file contains the ".model small" directive (MASM & TASM only)
l Add leading underscore "-" to all tcs-mstep occurrences in .ASM file
l tcs-mstep is a near call
l tcs-mstep must he in a segment fname_TEXT (where fname is the name of the file where tcs-mstep
resides), else Linker returns an error.




2-6
CHAPTER 2: INTERFACE DRIVERS



Medium Model
Model: Medium ("-mm") switch on command line
Passes: word size pointers (offset, no DS register)
Sequence: Arguments Passed Right to Left
Default Calling
Convention: Arguments Passed by Value



Example
`c' Call: tan-mstep (&Mode, Param, &StpNum, &Flag);
`c' Declaration: extern void tcm-mstepfint*,unsigned long*, int*);



.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:

-tom-nstep proc far ; dword pointer return address
push bp : save base pointer
mov bp,sp : save stack pointer
; [bp+C] holds off set of Mode
. ; [bp+8] holds offset of Param
. ; [bp+lO] holds offset of StpNum
. ; [bp+12] holds offset of Flag
; Program execution here
. ;
;
POP bp ,-restore bp & sp prior to exit
ret ; return
-toxn_mstep endp




Other:
This information is provided for those wishing to create their own drivers:

. -tcm-mstep is declared "PUBLIC" in the .ASM file
l tcm-mstep is declared "extern" in the "C"file
l The .ASM file contains the ".model medium" directive (MASM & TASM only)
l Add leading underscore "-" to all tcm-mstep occurrences in .ASM file
l tcm-mstep must be in a segment fnameTEXT (where fname is the name of the file where
tcm-mstep resides), else Linker returns an error.



Large Model
Model: Large ("-ml") switch on command line
Passes: dword size pointers (offset and DS register)
Sequence: Arguments Passed Right to Left
2-7
PCF-M5 USER GUIDE

Default Calling
Convention: Arguments Passed by Value



Example
`c' Call: tcl-mstep (&Mode, Pawn, &StpNum, &Flag);
`c' Declaration: extern void tcl-mstep(int*, unsigned long*, int?;



.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:

_tcl-mstep proc far : dword pointer return address
push bp ; save base pointer
mov bprsp : save stack pointer
; [bp+6] holds offset of Mode
. ; [bp+lO] holds offset of Param
. ; [bp+14] holds offset of StpNum
; [bp+18] holds offset of Flag
. ; Program execution here

. I


POP bp I
*restore bp C sp prior to exit
ret ;return
_tcl-xnstep endp


Other:
This information is provided for those wishing to create their own drivers:

. -tcl-mstep is declared "PUBLIC" in the .ASM file
l tcl-mstep is declared "extern" in the "C" file
l The .ASM file contains the ".model large" directive (MASM & TASM only)
l Add leading underscore "-" to all tcl-mstep occurrences in .ASM file
l Both code & data use dword (segment/offset) pointers
l tcl-mstep must be in a segment fname_TEXT (where fname is the name of the file where tcl-mstep
resides), else Linker returns an error.




Turbo C Example
/* */
1" Demonstration Program for MSTEP-5 */
/* Keithley Metrabyte Corporation "1
/* */
/* Language: Borland Turbo "C" */
/* File: TCSDEM0.C */
/* */



2-8
CHAPTER 2: INTERFACE DRIVERS



#include
#include
#include

#&fine Beep printf("%s","\7") /* make a beep sound */

#&fine TRYAGAIN 1
#&fine W-VIDEO 7
#define DEF-VIDEO 0
#define FUZADY 1
#&fine ON 1
#&fine OFF 0

/**********************************************************************/
/* */
1" The Following are the function Calls for different models: */
/* */
/* tcs-mstep(&Mode,Param,&StpNum,&Flag) : Turbo C small Model. */
/* tcm~mstep(&Mo&,Param,&StpNum,&Flag) : Turbo C medium Model. */
/* tcl~mstep(&Mode,Param,&StpNum,&Flag) : Turbo C large Model. */
/* */
/* This Program Uses the Small Model Function Call "/
/* */
/**********************************************************************/
/* DECLARE CALL structure */
extern tcs-mstep(int *,unsigned *,long *,int *);

/*************************************************************************/
int modeO(void); /* mode 0 */
int mo&l(void); /* mode 1 */
int mode2 (void); /* mode 2 */
int mode3 (void); /* mode 3 */
int model(void); /* mode 4 */
int mode5jvoid); /* mode 5 */
int mode6(void); /* mode 6 */
int mode7(void); /* mode 7 */
int mode8(void); /* mode 8 */
int modeg(void); /* mode 9 */
int modelO(void); /* mode 10 */
int modell(void); /* mode 11 */
int model2(void); /* mode 12 */
int setchannel(void); /* select channel */
int ErrHandler(int); /* error handler */
int MenuHandler(void); /* menu handler */
int CetLongInp(int,int,char *,long *); /* input get long integer */
void GetIntInp(int,int,char *,unsigned *); /* input unsigned integer*/
voidprintat(int,int,int,char *); /* formatted print function */
void ShowChannel(void); /* print current channel */
void EraseLine(int); /* erase line */
/**************************************************************~***************~

int Mode=12,Flag=O,IntLev=7,Interrupt=OFF;
unsigned Param[lO],TP[lO];
long StpNuin;




2-9
PCF-M5 USER GUIDE


/*************************************************************************/
/* */
/* Main program */
/* */
/*************************************f***********~~***~********~*********/
main0
I
int option,status=!TRYAGAIN;

/* default setup for MSTEP-5 */

TP[O] = 0; /* select channel A */
TP Ill = 255; /* start up rate, 49 pps */
TPVI = 100; /* high speed run rate */
TP C31 = 200; /* acceleration/deceleration pulse count */
TP[4] = 2; /* 4 phase */
TP[5] = 0; /* full step */
TP[6] = 0; /* inverted Sl-5 outputs */
TP[7] = 0; /* internal clock */
TP[I] = 0; /* switching off at standstill */
TP 191 = 768; /* base address */

.




.


/*************************************************************************/
/* */
/* Mode 12: Initialization. */
/* */
/*Arguments Return values */
/* --------- ------------- */
/* None 1: repeat this mode */
/* again "1
/* 0: no repeat */
/* */
/**********************************************************~****************~
int model20
(




.




2-10
CHAPTER 2: INTERFACE DRIVERS



2.3 MICROSOFT PASCAL (V3.0 - 4.0)

Medium Model
Model: Medium
Passes: word size pointers (offset address only)
Sequence: Arguments Passed Left to Right
Default Calling
Convention: Arguments Passed by Value



Example
PASCAL Call: Result: msp-mstep (Mode, Param,StpNum,Rlag)
PASCAL Declaration: type darray = array[O-91of word;
PROCEDURE: msp-mstep(VAR Mode: integer; VAR param; darray; VAR StpNum:
integer4; VAR Flag: integer):extemal;


.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:

msp_mstep proc far : far call (dword return address)
push bp ; save base pointer
mov bP,sP : save stack pointer
; [bp+G] holds offset of Flag
; [bp+8] holds offset of StpNum
. ; [bp+lO] holds offset of Param
. ; [bp+12] holds offset of Mode
. ; Program execution here
. ;
. :
mov ax,n ; Return Value for Function In ax register
POP bp ;
ret 8 ; return and pop bp & 3p values prior to exit
msp-nstep endp



Other:
This information is provided for those wishing to create their own drivers:

l mspmstep is declared "PUBLIC" in the .ASM file
l msp-mstep is declared external in the calling program
l msp-mstep resides in segment-TEXT (default of the .model command)




2-11
PCF-M5 USER GUIDE



Microsoft PASCAL Example
PROGRAM MSPDEMO(Input,Output);
(*************************************************************************)
(* Demonstration program for MSTEP-5 "1
(* Keithley Metrabyte Corporation "1
(* "1
(* Language: Microsoft Pascal "1
(* File: MSPDFMO.PAS "1
(* "1
(* To Compile: *I
(* Type: PL MSPDEWO.PAS ; "1
(" "1
(********k****************************************************************)
TYPE DARRAY = ARRAY[O..9] of WORD;

FUNCTION TICS:WORD;EXTERN;
FUNCTION KEYRD:WORD;EXTERN;

PROCEDURE MSP-MSTEP(
VAR Mode:INTEGER;VAR Param:DARRAY;VAR StpNum:INTEGERI;VAR
Flag:INTEGER);EXTERN;




(************X************************************************************)
(* "1
(*Mode 12: Initialization *I
(" "1
(***t*********************************************************************)
PROCEDURE ModelP;
VAR count,option:INTEGER;
BEGIN




END;




.

(******x******************************************************************)
(" *I
(" Main "1
(" *I
(*******************************************************************~*****)




2-12
CHAPTER 2: INTERFACE DRIVERS



BEGIN

TP[O] := (* select channel A
0; *I
TP Ill := (* start up rate, 49 pps
255; *I
TP [21 := 100; (* high speed run rate "1
TP t31 := 200; (* acceleration/deceleration pulse count *)
TP[4] := 2; (* 4 phase *I
TP[S] := 0; (* full step *I
TP[6] := 0; (* inverted Sl-5 outputs "1
TP[7] := 0; (* internal clock "1
TP[8] := 0; (* switching off at standstill *I
TP t91 := 768; (* base address *I
StpNum := 0;Flag := 0;IntLev := 7;




2.4 BORLAND TURBO PASCAL (VER 3.0 - 4.0)
Borland'sTurbo PASCAL supports a compact and a large memory model. The compact model
supports one code segment and multiple data segments. In this model, the code segment is limited to
f54Kwith assembly routine calls being near calls. The data segment is unlimited. The large model
permits unlimited code and data segments with assembly calls and data access being far calls.

The program (TINST.EXE) shippedwithTURBO PASCAL can change the calling convention so that
the user may not know which convention they are using. The default state is "OFF" or compact mode.
In order to ascertain which mode you are using, run the "TINST.EXE" program.


Compact Model
Model: Compact (Forces far call "OFF" in TINST.EXE)
Passes: dword size pointers (offset and segment)
Sequence: Arguments Passed Left to Right
Default Calling
Convention: Arguments Passed by Value



Example
PASCAL Call: tp-mstep (Mode, Param, StpNum, Flag);
PASCAL Declaration: type darray = array[O-91of word;
PROCEDURE: tp-mstep(VAR Mode: integer;VAR Param: darray;VAR StpNum:
integer4;VAR Flag: integer):external;




2-13
PCF-MS USER GUIDE


.ASM Subroutine:
(Either Model)

The following assembly code shows how the driver handles user arguments:

tp-mstep proc near ; near call (single word return address)
push bp ; save base pointer
mov bp,sp ; save stack pointer
. ; [bp+4] holds offset of Flag
. ; [bp+8] holds offset of StpNuxn
. ; [bp+12] holds offset of Param
; [bp+16] holds offset of Mode
. : Program execution here


. i
mov ax,n : return Value for Function In ax register
POP bp
ret 16 ; return 6 pop values prior to exit
tp-mstep endp


Other:
This information is provided for those wishing to create their own drivers:

. Use the $L `Metacommand' to link the object file containing external function tp-mstep, i.e. {$l
turbopas} (Link to file turbopas.obj).
. The VAR declarative forces pass by reference (address of variable) in the function declaration.
Default is pass by value (pushing the actual integer value onto the stack).
l tp-mstep is declared external in the calling program . Remember that in PASCAL, functions return
a value whereas procedures never do.
l The .ASM file contains an explicit declaration of the code segment containing tp-mstep. Turbo
PASCAL handles segments in a primitive manner which is not compatible with the `.model'
statements available in MASM or TASM. The function tp-mstep must reside in a segmentcalled
`CODE'! Turbo PASCAL will not accept any other segment name. If tp-mstep is not in segment
"CODE", the linker returns an "unresolved external" error. The Segment Declaration for "CODE" in
the .ASM file must appear as:

CODE SEGMENT WORD PUBLIC
ASSUME CS:CODE
.
. ; CODE GOES HERE

;~ODE ENDS



Large Model
Model: Large (Forces far call "ON" in TINST.EXE)
Passes: dword size pointers (offset and segment)
Sequence: Arguments Passed Left to Right



2-14
CHAPTER 2: INTERFACE DRIVERS



Default Calling
Convention: Arguments Passed by Value



Example
PASCAL Call: tp-mstep (Mode, Param, StpNum, Flag);
PASCAL Declaration: type darray = array[O-91of word;
PROCEDURE: tp-mstep(VAR Mode: integer;VAR Param: darray;VAR StpNum:
integer4;VAR Flag: integer):external;


.ASM Subroutlne:
(Either Model)

The following assembly code shows how the driver handles user arguments:

tp_mstep proc far ; far call (dword return address)
push bp ; save base pointer
mov bptsp - save stack pointer
. ; [bp+6] holds dwo:d of VAR4
. , [bp+lO] holds dword of VAR3
-
. ; [bp+14] holds dword of VAR2
. ,- [bp+18] holds dword of VARl
. ; Program execution here
. i
. ;
mov ax,n ; return Value for Function In ax register
POP bp
ret 16 ; return & pop values prior to exit
tp-mstep endp



Other:
This information provided for those wishing to create their own drivers:
is

l Use the $L `Metacommand' to link the object file containing external function tp-mstep. For
example; ($1 turbopas) (Link file turbopas.obj).
. The VAR declarative forces pass by reference (address of variable) in the function declaration.
Default ispass by value (pushing the actual integer value onto the stack).
l tp-mstep is declared external in the calling program along with the type of return value (integer).
Remember, in PASCAL, functions return a value procedures don't.
. The ASM file contains an explicit declaration of the code segment containing tp-mstep.



Turbo PASCAL Example
PROGRAM TP-DEMO(Input,Output);
{$L TURBOPAS)
($1-1
USES CRT,DOS;


2-15
PCF-M5 USER GUIDE


(*******************R******************************************)
(* Demonstration program for MSTEP-5 *I
(* Keithley Metrabyte Corporation "1
(" *I
(* Language: Borland Turbo Pascal "1
(* File: TP-DEMO.PAS "1
t* "1
(* To Compile: *I
(* Type: TPC TP-DEMO.PAS ; *I
i* "I
(*********k***************************************************)
TYPE DARRAY = ARRAY[O..g] of WORD;
LABEL CONTINUE,QUIT;
PROCEDURE TP_MSTEP(
VAR Mode:INTEGER;VAR Param:DARRAY;VAR StpNum:LONGINT;VAR
Flag:INTEGER);EXTERNAL;




(****************R********************************************)
(* *I
(*Mode 12: Initialization "1
t* *I
(*k***********************************************************)
PROCEDURE Model2;
LABEL BREAKOUT;
VAR count,option:INTEGER;
DONE : BOOLEAN;
BEGIN




.

END;




(********************************************************~**~*)
t* *I
(" Main "1
t* *I
(*************************************************************)




2-16
CHAPTER 2: INTERFACE DRIVERS


BEGIN

TPCOI := 0; (* select channel A *I
TP Ill :=255; (* start up rate, 49 pps *)
`J!Pt21 := 100; (* high speed run rate *I
TP 131 := 200; (* acceleration/deceleration pulse count *)
TPC41 := 2; (* 4 phase "1
TP [51 := 0; (* full step *)
TPC61 := 0; (* inverted Sl-5 outputs "1
`JX'C71 :' 0; (* internal clock *I
TPC81 := 0; (* switching off at standstill *I
TPC91 := 768; (* base address "1

StpNum := 0;Flag := 0;IntLev := 7;




END.




2.5 MICROSOFT FORTRAN (V4.0 AND UP)

Large Model
Model: Large
Passes: dword size pointers (offset and DS register)
Sequence: Arguments Passed Left to Right
Default Calling
Convention: Arguments Passed by Reference



Example
FORTRAN Call: call fmstep(Mode, Param( StpNum, Flag);
FORTRAN Declaration: None necessary in FORTRAN source file (Fortran assumes that
undeclared subroutines or functions are external. It is left to the linking
process to provide the required .LIB or .OBJ files. However, the function
name should conform to ANSI FORTRAN rules for integer functions.



.ASM Subroutines:
NOTE: FORTRAN integer functions (beginning with letters i, j, or k) return results in the ax
register whereas non-integer functions reserve 4 bytes on the calling stack for a far
pointer the result. Non-integer functions pass their arguments starting at location
to
bp+18 after the "push bp" and "mov bp,sp" instructions have been executed. Keithley
MetraByte's FORTRAN <--> Assembly routines predominantly use type integer to avoid
the non-integer problem. Using non-integer functions may be a problem when returning
pointers, floating point results, long integers, etc. The user should use the IMPLICIT
INTEGER (A-Z) declaration causing all Functions and Variables to be implicitly type

2- 17
PCF-M5 USER GUIDE

integer unless declared otherwise. Also note that FORTRAN calls by Reference. This
method places the address of the passed parameters (rather than the parameters
themselves) onto the stack at the time of the call to any function or subroutine. As a
convenience, PCF-M5 provides functions UNBYT and OUTBYT) for directly addressing
the registers and (KEYHOT and KEYRD) for checking Hot Key and reading a key from
the keyboard.




Integer (Default) Function or Subroutine
The following assembly code shows how the driver handles user arguments:

frnstep proc far ; dword pointer return address
push bp ; save base pointer
mcv bprsp ; save stack pointer
. ; [bp+6] holds offset of Flag
. ; [bp+lO] holds offset of StpNum
. ; [bp+14] holds offset of Param
; [bp+18] holds offset of Mode
. ; Program execution here
.
I


i

mov ax,n ; return Value for Function In ax register
POP bp
ret ;
fmstep endp



NOTES:

1. VAR3 = Return Value of Function
2. Function fmstep must be declared as an integer * 2 fucntion.



Microsoft FORTRAN Example
C************************************************************~*****
c
C Demonstration program for MSTEP-5
C Keithley Metrabyte Corporation
C
C Language: Microsoft Fortran
C File: MSFDEMO.FOR
C
c****************************************************************
program msfdemc

characterNULL,ESC,ch
integer*2 key,Mode,Flag,IntLev,Param(lO),TemPar(lO)
integer*4 StpNum

COMMON /ASCII/NULL,ESC
COMMON /ARG/Mode,Flag,Param,StpNum
COMMON /TEMPL?iTE/TemPar
COMMON /INTERRUPT/IntLev

2-18
CHAPTER 2: INTERFACE DRIVERS



ESC = char(27)
NULL = char(O)

C select channel A
TemPar(1) = 0
C start up rate, 49 pps
TemPar (2) = 255
C high speed run rate
TemPar(3) = 100
C acceleration/deceleration pulse count
TemPar(4) = 200
C 4 phase
TemPar(5) = 2
C full step
TmPar(6) = 0
C inverted Sl-5 outputs
TemPar(7) = 0
C internal clock
TemPar(8) = 0
C switching off at standstill
TemPar(9) = 0
C base address
TemPar(l0) = 768




end




c***************************************************************
C
C MO& 12: Initialization
C
c****************************************************************
subroutine model2(*)

integer*2 Flag,Param(lO),Mode,TemPar (lo), index,i
integer*4 StpNum
COMMON /ARG/Mode,Flag,Param,StpNum
COMMON /TEMPLATE/TexnPar

Mode=12
Flag=0




end




2 - 19
PCF-M5 USER GUIDE



2.6 MSTEP.LIB GENERAL PURPOSE LIBRARY
mstep.LIB This is a general purpose library file which provides control of the
MSTEP-5 boards. This file can be linked with programs written in C,
PASCAL, or FORTRAN to provide access to the MSTEP-5 operating
modes.


NOTE: This library cannot be used with TurboPASCAL. However, TurboPASCAL may be
used with Turbops.obj (see below).


The following is a brief description of the available call routines:

mscs-mstep(mode,param,stpnum,flag) : Call from Microsoft C Small Model
mscm_mstep(mode,param,stpnum,flag1 . Call from Microsoft C Medium Model
mscl-mstep(mode,param,stpnum,flag) : Call from Microsoft C Large Model
tcs-mstep(mode,param,stpnum,fIag) Call from Turbo C Small Model
tcm-mstep(mode,param,stpnum,flag) Call from Turbo C Medium Model
tcl-mstep(mode,param,stpnum,flag) Call from Turbo C Large Model
msp-mstep(mode,param,stpnum,flag) Call from Microsoft PASCAL
fmstep(mode,param,stpnum,flag) Call from Microsoft FORTRAN


Linking the Library "mstep.lib" to the user program is accomplished after program compilation by
including it in the link line as follows:

link userprog.obj,userprog,,user.lib_mstep.LIB;

userprog.obj is an object module produced by compilation of the user program.
userprog should be used for theresultant executable .EXE file.
user.lib is any other user library, if applicable.


To create the MSTE.LIB Library for PASCAL, C, or FORTRAN:

MASM /DBIN=O MSTEP.ASM
MASM /DBIN=O MSTEPPCF.ASM

LIB MSTEP+MSTEPtMSTEPPCF:




To create the MSTEP.QLB library for QuickBASIC 4.5:

MASM /DBIN=O MSTEP.ASM
MASM /DBIN=O MSTEPPCF.ASM

LINK /Q MSTEP.OBJ QBX.LIB,,,QBXQLB.LIB




To create the MSTE.BIN for BASIC:

MAIM /DBIN=~ MSTE.ASM
MASM /DBIN=~ MSTEPPCF.ASM


2-20
CHAPTER 2: INTERFACE DRIVERS


LINK MSTEPPCF t MSTE,MSTEP;
EXEPBIN MSTEP.EXE MSTEP.COM
MAKEBIN MSTEP.COM




For TurboPASCAL, the entry point is:

tp-rastep (mode,param,stpnum,flag) :Call from TurboPASCAL program

The user program should have the directive

{$L turbopas}

at the beginning of the user program. This directive will ensure that the TPC compiler/linker will
include the proper interface object.

TURBOPAS.OBJ (from the PCF-PIOINT disk)




2 - 21
PCF-M5 USER GUIDE




* * * * *




2-22
CHAPTER
3
BASIC INTERFACE DRIVERS

3.1 INTERPRETED BASIC (GW, COMPAQ, IBM, ETC.)

Medium Model (Only Model Available)
Model: Medium (Far Calls, Single Data)

Passes: word size pointers (offset and no DS Register)
Sequence: Arguments Passed Left to Right
Default Calling
Convention: Arguments Passed by Reference



.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:

Location 0 (Beginning of Code Segment)




mstep proc far ; far call (dword return address)
push bp ; save base pointer
mcv bprsp ; save stack pointer
; [bpt6] holds offset of Flag%
; [bpt8] holds offset of STP#
; [bptlO] holds offset of D%
; [bpt12] holds offset of MD%

; Program execution here



POP bp : restore bp 6 sp prior to exit
ret
mstep endp




Example:
Refer to Section 4.15 of the MSTEP-5 User Guide.

NOTE BASIC requires the .BIN file containing the callable subroutine "mstep(Mode%,
that
D%(O), STP#, Flag%)' reside at location 0 in the .ASM segment or to "jmp" (unconditional
jump) to the .BIN file. A BASIC "jmp " will always jump to location 0 in the .ASM code
segment.

3-1
PCF-M5 USER GUIDE



Creation of a .BIN file is accomplished as follows:
1. Create the .ASM Source Code File `EXAMPLE.ASM'
2. Assemble `EXAMPLE.ASM' thus creating `EXAMPLE.OBJ
3. Link `EXAMPLE.OBJ' to create `EXAMPLE.EXE
4. Run EXE2BIN on `EXAMPLE.EXE' (DOS Utility) to create `EXAMPLE.COM
5. Run MAKEBNEXE (Keithley MetraByte Utility) on `EXAMPLE.COM' to create
`EXAMPLE.BlN
MASM EXAMPLE ;
LINK EXAMPLE ;
EXEZBIN EXAMPLE.EXE EXAMPLECOM
MAKEBIN EXAMPLE.COM




3.2 QUICKBASIC

Medium Model (Only Model Available)
Model: Medium (far Calls, Single Data).
Passes: Word-size pointers (Offset and no DS Register).
Sequence: Arguments passed left-to-right.
Default Calling
Convention: Arguments passed by reference.




.ASM Subroutine:
The following assembly code shows how the driver handles user arguments:

QBPIOINT proc far ; far call (dword return address)
push bp ; save base pointer
mmr bp,sp ; save stack pointer
. ; [bpt6] holds offset of Flag%
. ; [bp+8] holds offset of D%
. ; [bp+lO] holds offset of STP#
; [bptlP] holds offset of MD%

; Program execution here



POP bp ; restore bp & sp prior to exit
ret
QBPIOINT endp




3-2
CHAPTER 3: BASIC INTERFACE DRIVERS



Example:
Refer to Section 4.16 of the MSTEP-5 User Guide.

NOTE When creating a .QLB file, it is good practice to make a .LIB of the same version as a
backup file.


Creation of a .QLB file is accomplished as follows:


1. Create the .ASM Source Code File `EXAMPLE.ASM


2. Assemble `EXAMPLE.ASM' thus creating `EXAMPLE.OBJ'


3. Link `EXAMPLE.OBJ' with the "/q" option to create `EXAMPLE.QLB


MASM EXAMPLE ;
LINK /q EXAMPLE ;




A .LIB file is created by:


1. Create the .ASM Source Code File `EXAMPLE.ASM


2. Assemble `EXAMPLE.ASM' thus creating `EXAMPLE.OBJ'


3. Use Utility LIB.EXE to add EXAMPLE.OBJ to `EXAMPLE.LIB'


(Remove old EXAMPLE.OBJ from Library)


LIB EXAMPLE.LIB -EXAMPLE


(Create New .OBJ) MASM EXAMPLE ;
(Add New .OBJ to Library) LIB EXAMPLE,LIB +EXAMPLE ;


4. To use the .QLB file in the QB integrated environment/editor, invoke QB.EXE with
the /l option (QB /l qlbname.qlb,) where qlbname.qlb is the file containing BASICsub.


5. To use the .LIB file with the command line complier (BC.EXE), simply specify
"EXAMPLE.LIB" in the link process.




3-3
PCF-MS USER GUIDE




* * * * *




3-4