Keithley Instruments, Inc. warrants that, for a period of one (1) year from the date of shipment (3 years for Models 2000, 2001, 2002, and 2010), the Keithley
Hardware product will be free from defects in materials or workmanship. This warranty will be honored provided the defect has not been caused by use of the
Keithley Hardware not in accordance with the instructions for the product. This warranty shall be null and void upon: (1) any modification of Keithley Hardware that is made by other than Keithley and not approved in writing by Keithley or (2) operation of the Keithley Hardware outside of the environmental specifications therefore.
Upon receiving notification of a defect in the Keithley Hardware during the warranty period, Keithley will, at its option, either repair or replace such Keithley
Hardware. During the first ninety days of the warranty period, Keithley will, at its option, supply the necessary on site labor to return the product to the condition prior to the notification of a defect. Failure to notify Keithley of a defect during the warranty shall relieve Keithley of its obligations and liabilities under
this warranty.
Other Hardware
The portion of the product that is not manufactured by Keithley (Other Hardware) shall not be covered by this w arranty, and Keithley shall have no duty of obligation to enforce any manufacturers' warranties on behalf of the customer. On those other manufacturers’ products that Keithley purchases for resale, Keithley
shall have no duty of obligation to enforce any manufacturers’ warranties on behalf of the customer.
Software
Keithley warrants that for a period of one (1) year from date of shipment, the Keithle y produced portion of the software or firmw are (Keithley Software) will conform in all material respects with the published specifications provided such Keithley Software is used on the product for which it is intended and otherwise in
accordance with the instructions therefore. Keithley does not warrant that operation of the Keithley Softw are will be uninterrupted or error-free and/or that the
Keithley Software will be adequate for the customer's intended application and/or use. This warranty shall be null and v oid upon an y modification of the K eithle y
Software that is made by other than Keithley and not approved in writing by Keithley.
If Keithley receiv es notification of a K eithle y Software nonconformity that is co v ered by this warranty during the w arranty period, K eithle y will review the conditions described in such notice. Such notice must state the published specification(s) to which the Keithley Software fails to conform and the manner in which
the Keithley Software fails to conform to such published specification(s) with sufficient specificity to permit K eithle y to correct such nonconformity. If Keithley
determines that the Keithley Software does not conform with the published specifications, Keithley will, at its option, provide either the programming services
necessary to correct such nonconformity or develop a program change to bypass such nonconformity in the Keithley Software. Failure to notify Keithley of a
nonconformity during the warranty shall relieve Keithley of its obligations and liabilities under this warranty.
Other Software
OEM software that is not produced by Keithley (Other Software) shall not be covered by this w arranty, and Keithley shall have no duty or obligation to enforce
any OEM's warranties on behalf of the customer.
Other Items
Keithley warrants the following items for 90 days from the date of shipment: probes, cables, rechar geable batteries, diskettes, and documentation.
Items not Covered under Warranty
This warranty does not apply to fuses, non-rechargeable batteries, damage from battery leakage, or problems arising from normal wear or failure to follow
instructions.
Limitation of Warranty
This warranty does not apply to defects resulting from product modification made by Purchaser without Keithley's express written consent, or by misuse of any
product or part.
Disclaimer of Warranties
EXCEPT FOR THE EXPRESS WARRANTIES ABOVE KEITHLEY DISCLAIMS ALL OTHER WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
WITHOUT LIMIT ATION, ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. KEITHLEY DISCLAIMS ALL WARRANTIES WITH RESPECT TO THE OTHER HARDWARE AND OTHER SOFTWARE.
Limitation of Liability
KEITHLEY INSTRUMENTS SHALL IN NO EVENT, REGARDLESS OF CAUSE, ASSUME RESPONSIBILITY FOR OR BE LIABLE FOR: (1) ECONOMICAL, INCIDENTAL, CONSEQUENTIAL, INDIRECT, SPECIAL, PUNITIVE OR EXEMPLARY DAMAGES, WHETHER CLAIMED UNDER
CONTRACT, TORT OR ANY OTHER LEGAL THEORY, (2) LOSS OF OR DAMAGE TO THE CUSTOMER'S DATA OR PROGRAMMING, OR (3) PENAL TIES OR PENALTY CLAUSES OF ANY DESCRIPTION OR INDEMNIFICA TION OF THE CUST OMER OR OTHERS FOR COSTS, DAMAGES, OR
EXPENSES RELATED TO THE GOODS OR SERVICES PROVIDED UNDER THIS WARRANTY.
The print history shown below lists the printing dates of all Revisions and Addenda created for this manual. The Revision
Level letter increases alphabetically as the manual undergoes subsequent updates. Addenda, which are released between Revisions, contain important change information that the user should incorporate immediately into the manual. Addenda are numbered sequentially. When a new Revision is created, all Addenda associated with the previous Revision of the manual are
incorporated into the new Revision of the manual. Each new Revision includes a revised copy of this print history page.
Revision A (Document Number 80370)...............................................................................................August 1996
Revision B (Document Number 80370)....................................................................................................July 1998
All Keithley product names are trademarks or registered trademarks of Keithley Instruments, Inc.
Other brand and product names are trademarks or registered trademarks of their respective holders.
About this manual
Quality control
Keithley Instruments manufactures quality and versatile products, and we want our documentation to reflect that same quality. We take great pains to publish manuals that are informative and
well organized. We also strive to make our documentation easy to understand for the novice as
well as the expert.
If you have comments or suggestions about how to mak e this (or other) manuals easier to understand, or if you find an error or an omission, please fill out and mail the reader response card at
the end of this manual (postage is prepaid).
Conventions
Procedural
Keithley Instruments uses various conventions throughout this manual. You should become
familiar with these conventions as they are used to draw attention to items of importance and
items that will generally assist you in understanding a particular area.
WARNING
CAUTION
NOTE
When referring to pin numbering, pin 1 is always associated with a square solder pad on the
actual component footprint.
A warning is used to indicate that an action must be done with great
care. Otherwise, personal injury may result.
A caution is used to indicate that an action may cause minor equipment damage or the loss of data if not performed carefully.
A note is used to indicate important information needed to perform an
action or information that is nice-to-know.
Notational
A forward slash (/) preceding a signal name denotes an active LOW signal. This is a standard
Intel convention.
Caret brackets (<>) denote keystrokes. For instance <Enter> represents carriage-return-withline-feed keystroke, and <Esc> represents an escape keystroke.
Driver routine declarations are shown for C and BASIC (where applicable).
Hungarian notation is used for software parameters. In other words, the parameter type is
denoted by a one or two letter lower case prefix:
ccharacter, signed or unsigned
sshort integer, signed
wshort integer, unsigned
llong integer, signed
dwlong integer, unsigned
For example, wBoardAddr would be an unsigned short integer parameter.
An additional p prefix before the type prefix indicates that the parameter is being passed by reference instead of by value. (A pointer to the variable is being passed instead of the variable
itself).
For example, pwErr would be an unsigned short integer parameter passed by reference.
This notation is also used in BASIC although no distinction between signed and unsigned vari-
ables exists.
In BASIC, all parameters also have a type suffix:
$character, signed or unsigned
%integer, signed or unsigned
&long integer, signed or unsigned
Routine names are printed in bold font when they appear outside of function declarations, e.g.,
ReadStatus.
Parameter names are printed in italics when they appear outside of function declarations, e.g.
sControls.
Constants are defined with all caps, e.g., ALL_AXES. Underscores {_} must be replaced by
periods {.} for use with BASIC.
Combinational logic and hexadecimal notation is in C convention in many cases. For example,
the hexadecimal number 7Ch is shown as 0x7C.
C relational operators for OR and AND functions — “| |” and “&&” — are used to minimize the
confusion associated with grammar.
Table of Contents
1Programming Overview
Installing the 5312 software ............................................................................................................................... 1-2
Compiling and linking ....................................................................................................................................... 1-2
Microsoft C or Microsoft QuickC .............................................................................................................. 1-2
Borland or Turbo C/C++ ............................................................................................................................ 1-3
Microsoft QuickBASIC ............................................................................................................................. 1-3
Program in C ...................................................................................................................................................... 2-2
Program in BASIC ............................................................................................................................................. 2-4
Program in Pascal ............................................................................................................................................... 2-5
Interrupts in C or Pascal ..................................................................................................................................... 3-2
Interrupts in BASIC ........................................................................................................................................... 3-2
General notes on using interrupts ....................................................................................................................... 3-3
Disable index interrupt .............................................................................................................................. A-4
Enable index interrupt ............................................................................................................................... A-5
Read status ............................................................................................................................................... A-10
Windows 3.1 .............................................................................................................................................. C-2
Windows 95 ............................................................................................................................................... C-2
Form modules ............................................................................................................................................ C-6
Problem definition ..................................................................................................................................... D-2
Problem solution ........................................................................................................................................ D-2
ii
List of Illustrations
ADriver Routine Descriptions
Figure A-1Read status .............................................................................................................................................. A-11
Figure C-1Main user menu ......................................................................................................................................... C-3
Figure C-2Main user menu with demo modes pulled down ...................................................................................... C-4
The 5312 driver includes the batch file, INSTALL.BAT, to install the software. The batch file
takes one argument, which is the path where you will install the software. For e xample, to install
the software on the C drive into a subdirectory called 5312, enter on the command line:
install c:\5312
Use the same path for the installation of all drivers. This puts all include files, examples, etc.,
together. This is especially important when using QuickB ASIC, where you will ha ve to combine
many libraries into a quick library.
A BASIC subdirectory, a C subdirectory, and a Pascal subdirectory will be created off of the
directory you specify, and you may delete any unneeded subdirectories to save disk space.
Compiling and linking
The following paragraphs describe how to compile a program using the 5312 dri v er with the v ar ious supported compilers. It is assumed the source file is named DEMO.C for C, DEMO.BAS
for BASIC, and DEMO.PAS for Pascal.
Microsoft C or Microsoft QuickC
To compile and link on the command line, enter the following:
s small model,
m medium model,
c compact model,
l large model
Turn stack checking off with the /Gs switch (option) if you use interrupts. For CodeView compatibility, include the /Zi switch.
To use the 5312 driver in the QuickC environment, perform the following steps:
1. In the Make menu, select the Set Program List option.
2. After naming the Make file, select Edit Program List, and enter the names of the source file
(DEMO.C) and the appropriate library (e.g. te5312s.lib for small model).
3. In the Options/Make menu, select the Compiler Flags option and set the appropriate memory
model (this model must match the library in the make list). If you use interrupts, turn stackchecking off.
(C)
(QuickC)
Model 5312B Software Developer’s GuideProgramming Overview1-3
Borland or T urbo C/C++
To compile and link on the command line, enter the following:
tcc -m
bcc -m
where x is:
s small model
m medium model
c compact model
l large model
For Turbo Debugger compatibility, include the -v option.
To use the 5312 driver in the Borland environment, perform the following steps:
1. In the Project/Open Project menu, type in the name of the project file you want to create.
2. In the Project/Add Item menu, enter the names of the source file (DEMO.C) and the appro-
priate library (e.g. te5312s.lib for small model).
3. In the Options/Compiler/Code Generation menu, set the appropriate memory model (this
model must match the library in the Make list). If you use interrupts, turn stack-checking off.
x
demo.c te5312
x
demo.c te5312
Microsoft QuickBASIC
If you use compiled BASIC exclusively and never program in the QuickBASIC environment,
you can link the library te5312b.lib into your application.
bc demo.bas;
link demo.obj,,,te5312b.lib
x
.lib
x
.lib
(Turbo C)
(Borland C)
To compile and link for CodeView compatibility, enter the following:
bc /Zi demo.bas;
link /CO demo.obj,,,te5312b.lib
If you use the QuickBASIC environment, you first have to run the batch file QLB5312.BAT.
This batch file will need modification, depending on which QuickBASIC version you use. The
necessary modifications are explained by the remarks in the batch file itself.
The batch file creates two files: te5312qb.qlb and te5312qb.lib. Library te5312qb.qlb is a quick
library for use in the QuickBASIC environment and te5312qb.lib is the command line equivalent. Therefore, you will develop your program with te5312qb.qlb and then in the final compilation, link with te5312qb.lib.
To use the 5312 driver in the QuickBASIC environment, enter the following:
The libraries te5312b.lib and te5312qb.lib are similar but not identical. Library te5312b.lib calls
two routines not contained in the library itself: te5312IndexAlert and te5312WrapAroundAlert.
These two routines must be included in your source code if you need to link te5312b.lib into
application program. The file INTR5312.BAS contains stub versions of these routines that you
can use as a guide, or you can compile and link the file itself into the application. Since
te5312b.lib has unresolved references, it cannot be converted into a quick library.
The library te5312qb.lib is created by the batch file by compiling INTR5312.BAS and linking
the resulting object file with te5312b.lib. It has no unresolved references and can be converted
into the quick library te5312qb.qlb. A program developed in the QuickBASIC environment
using te5312qb.qlb can be compiled on the command line and linked with te5312qb.lib without
modifying the source code. See the information on using interrupts with BASIC.
Borland T urbo Pascal
To compile and link on the command line, enter the following:
tpc /$S- demo
If you use interrupts, be sure to turn stack-checking off. Turn off stack-checking by including
/$S on the command line as shown or by including the line {$S-} in the program source code.
To compile for Turbo Debugger compatibility, include the /v option.
To use the 5312 driver in the Turbo Pascal environment, enter the following:
turbo demo
The source file must include the line: uses te5312p;. If you use interrupts, be sure to turn stack
checking off. Turn off stack-checking through the Options/Compiler menu or by including the
line {$S-} in the program.
Programming fundamentals
To quickly write simple applications for the 5312, follow the structure of the example programs
provided in section 2. For C, include the file te5312.h. For B ASIC, include the TE5312.B AS file.
For Pascal, always specify the te5312p unit.
Call te5312InitSw first to initialize the software. Then call te5312InitBoard once for ev ery 5312
board in the system. To use the other driver routines, you must be familiar with the concept of
board, axis, and global numbers.
Each board in the system will be sequentially assigned a number from 0 to 5, called the board
number, used to identify the board in calls to other routines. Each time te5312InitBoard is
called, another board number is assigned. If only one board is installed in the system, calling
te5312InitBoard once assigns a board number of zero.
Likewise, each axis in the system will be sequentially assigned an axis number from 0 to 23,
used to identify a particular axis in calls to other routines. Each time te5312InitBoard is called,
three more axis numbers are assigned.
Each board is also assigned a global number from –1 down to a possible –6. Global numbers can
be used in place of axis numbers in routines that write to an encoder. In these cases all the encoders on the corresponding board will be written at the same time.
// interrupt counters
static unsigned short wCarryA, wCarryB;
static unsigned short wIndexA, wIndexB;
void main()
{
unsigned short wBoardAddr;
long lCntA, lCntB;
short sStatA, sStatB;
short sIRQNum;
// get the address
printf("\nEnter the base address the 5312 is strapped "
"at in hexadecimal - ");
scanf("%x", &wBoardAddr);
// get the IRQ number
do{
printf("\nEnter the interrupt request line used (2 to 7) - ");
scanf("%u", &sIRQNum);
}while((sIRQNum < 2) || (sIRQNum > 7));
// initialize the software
te5312InitSw();
// initialize the board (assume the board has at least two axes)
te5312InitBoard(wBoardAddr, 2);