Introduction
General Features
Timing Features
Analog Input Features
Analog Output Features
Digital Input Features
Digital Output Features
System Requirements

LabPac is a software support system designed for use with Scientific Solutions' DAS series interfaces, Lab Master DMA, Lab Master, Lab Tender, DADIO, and Base Board. LabPac software provides solutions for multiple needs, such as event counting, precision timing, digital input, digital output, analog input, or analog output. Repeatable functions, such as multiple sampling of analog inputs can be done using a hardware interrupt.

LabPac offers access to, input from, and control over laboratory/industrial instruments using high level languages. Because LabPac installs as a software interrupt, application programs can be developed in languages such as Advanced BASIC, FORTRAN, C, Pascal, APL, or Assembler. It replaces customized machine language programming with a library of powerful routines. The following is a brief description of many LabPac features.

General Features

Timing Features

Analog Input Features

Analog Output Features

Digital Input Features

Digital Output Features

SYSTEM REQUIREMENTS

1.) One or more of the following Scientific Solutions Boards

2.) DOS*or DOS session of Win31, Win95/98 *

3.) Minimum of 96 KB free system memory
 

*LabPac for DOS (this version) is for true DOS or compatilbe DOS session of Win31, Win95/98

*LabPac for Windows is for Win95/98 and WinNT operating as a 32-bit application (requires Scientific Solutions 32-bit driver for your hardware)

*LabPac for Linux is available for native Linux applications (requires Scientific Solutions Linux driver for your hardware)
 

return to top of Introduction


Installation

HARDWARE REQUIREMENTS
  Hardware Interrupt Handler
  9513A Timer/Counter
  External Signal
  External Triggers
  Digital I/O Handshaking
  Timer Sources
  DMA
SOFTWARE INSTALLATION
  Organization of the Diskette
  Copying Files
INSTALLING LABPAC IN MEMORY

 


LabPac is a software driver for Scientific Solutions hardware. Its function is to provide streamlined BIOS routines which facilitate the data acquisition and process control features on a McDAS, Lab Master DMA, Lab Master, Lab Tender, DADIO or Base Board. Information in this section explains features of LabPac. This is critical background information and should be read carefully before doing any programming.

LabPac is essentially a library of subroutines. It is, however, loaded and accessed differently than traditional libraries. For most compilers, libraries are set up as specialized files from which modular subroutines are loaded into a main program using the compiler's LINK utility. The main portion of LabPac, however, is a program that loads into the background and becomes memory resident in the computer. Once LabPac is loaded or run, it will be actively available to any application software until the computer is turned off or reset.

LabPac is structured to become an extension of DOS. Because it is a BIOS extension, it can be accessed by any language that runs under DOS. As a software driver, LabPac contains numerous subroutines that are divided into eight groups:

return to top of Installation


HARDWARE REQUIREMENTS

LabPac can maximize the normal data acquisition or process control functions on a Scientific Solutions Data Acquisition and Control interface. To use the default features on the hardware products effectively, follow the installation instructions in the manual provided with each product. Once one of the Scientific Solutions products is installed, LabPac will not require a board to be reconfigured unless a new application is designed using hardware features left uninstalled.

Scientific Solutions laboratory/industria1 products have many options. LabPac will require the use some of these options and support the use of others. Before installing any hardware, look over the following options to see if they will be useful in the application.


Hardware Interrupt Handler

Operating systems other than DOS have the ability to do multiple tasks in a shared environment. This means that two or more programs can be running simultaneously. DOS does not have this capability. It does allow for the program that is currently running to be interrupted so another program can run. Some LabPac features use this capability. This means that data collection or process control functions can be done at regulated intervals while the main program is involved with other tasks.

In order to use this capability, a hardware interrupt (IRQ) must be installed. Hardware interrupts used by LabPac can be generated from several sources. Normally timer/counter channel 1 is the IRQ source.

Since the interrupt handler is driven by a hardware IRQ, the designated timer/counter output must be connected to the proper IRQ line on the PC bus. Make sure that the chosen IRQ either has nothing else on it or that the other peripheral is tri-stated on the IRQ line. For example, most LabPac users will select IRQ7 for this feature. IRQ7 is also attached to the printer ports in the PC. Original IBM equipment and many other computers or printer port peripherals tri-state IRQ7 so peripherals such as Lab Master DMA can also use the line. However, if the printer port is not tri-stated, then no other equipment can share the line. If there are problems with sweep routines after installing LabPac, try using another IRQ line.


9513A Timer/Counter

When using a Lab Master DMA, Lab Master or Lab Tender the 9513A counter 1 is the usual interrupt source. Install the following features on your board to implement this source.


External Signal

To control the interrupt from outside the computer (e.g., a function generator) connect your signal to a 9513 source line and connect the timer to one of the interrupts. When running SWINIT, identify the IRQ line and timer channel used. You will need to start the timer using TIST or TIHDW with the proper source indicated. The external signal must have a minimum pulse width of 70 nS.


External Triggers

Analog to digital conversions on the DAS series, Lab Master DMA, Lab Master, and Lab Tender can be triggered using a hardware generated TTL signal instead of the default software generated signal. LabPac offers subroutines (AIHDW and AIDMA) which require this hardware signal.


Digital I/O Handshaking

LabPac contains several subroutines where the 8255A Mode 1 can be used. Mode 1 is designed for handshaking, i.e. external devices that send an independent signal to inform the receiver that the eight bits of data are coming. These devices usually require a return signal to let them know more data can be sent. Conversely, when sending data, these devices require an independent signal to know when data has arrived and return an acknowledgement signal when they have cleared their input buffer.

Mode 1 requires that handshaking fines be installed between the board and the external equipment. Thoroughly read the requirements for using Mode 1 in the hardware installation manual. If a strobed input mode is used, it is likely that the Input Buffer Full signal (a busy or acknowledge line) should be inverted. Each Scientific Solutions product has a jumper block set aside to invert the lines used for the Input Buffer Full signal. The technical discussion of the DINIT call in the Technical Reference chapter indicates which handshaking lines between the external device and the Scientific Solutions product must be installed.


Timer Sources

LabPac offers timing subroutines where an external source can be used to drive the 9513A counters. This feature can be used to count external events. It can also be used where timing periods not available from the onboard oscillator must be used. Additionally, the LabPac timer/counter features allow the use of gating on external sources. If these feature are used, carefully read the instructions for installing inputs to the external connectors of each board.

NOTE: The outputs from each 9513A counter can also be used to send information to external devices.


DMA

The McDAS series and the Lab Master DMA feature Direct Memory Access (DMA transfer) for the transfer of analog to digital information directly into RAM. One LabPac routine (AIDMA) uses the DMA feature to move the data into a memory buffer in a true background operation.

return to top of Installation



SOFTWARE INSTALLATION

The LabPac software package contains the software needed to develop application programs in any supported target language.
 

Organization of the Diskette

The LabPac distribution software contains the files necessary to support several high levels languages. In order to limit the number of files to take a look at, the LabPac software contains separate subdirectories for each language supported. The only files you need to look at are those in the root directory and those in the particular subdirectory that supports the desired programming language. Some directories may be compressed into a single file. You will have to uncompress the directory to use the files.

LABPAC Organization (typical)

APL <DIR>
ASSEMBLE <DIR>
BASIC <DIR>
C <DIR>
FORTRAN <DIR>
PASCAL <DIR>
TOOLS <DIR>
README  
LABMENU.EXE  
LABPAC.COM  

The file named LABPAC.COM is the most important file on the diskette. It is the device driver containing the subroutines to be used in the application.

Before the programs will work, this memory resident program must be loaded.

This is done very simply by typing in the command shown below or by placing the command line in an AUTOEXEC.BAT file.

LABPAC

The file named LABMENU.BAS is a menu driven demonstration and test program. It is written in Interpreted BASIC. The Tools chapter discusses how the program operates.

The file named README will contain up-to-date information on LabPac that supplements or extends the information in this manual.

The names with the <DIR> after them are subdirectories. The subdirectories contain interface modules and example programs for different languages.

In each of the language subdirectories there is one or more header files, such as LABHEAD.???, where the ??? extension refers to the application language. These files contain code to be used at the start of a program. Four types of variables are defined in each header file.

Files with .OBJ extensions are used by some compiled languages to access assembler subroutines or memory resident programs. These are used by languages such as FORTRAN, Compiled BASIC, or C. These object modules are designed so that an application program can pass information correctly to and from LABPAC.COM.

NOTE: The assembler listings for all the object modules are contained in the ASSEMBLE subdirectory. They are provided as references if an object module needs modification for a language not directly supported on the LabPac diskette.

The two files labeled LABPAC are special library interface modules which work the same as the files with the .OBJ extension.

The other files in the subdirectory are demonstration programs. They provide examples of how to use LabPac subroutines with associated language.


Copying Files

Copy the files from the LabPac diskette to your working directory. You may need to decompress some of the files.

return to top of Installation



INSTALLING LABPAC IN MEMORY

Before any application programs make calls to LabPac, it must be made memory resident. To install LabPac in memory type LabPac at the DOS prompt. This will look something like the following:

C> labpac

LabPac Version x.xx Copyright 1981-2020 by Scientific Solutions

C>
 

It is recommended that you put LabPac as a line in your AUTOEXEC.BAT file. For use under operating systems that have a DOS session, such as Win95/98, if you put the LabPac line in the AUTOEXEC.BAT file, then it should be available under all DOS sessions.

Several command line options are available to change characteristics of LabPac. These options are:


Parameter values are considered to be entered in decimal unless preceded by zero in which case they will be considered in hexadecimal.

For example, for 256 analog input channels and a Basic vector of 0F2H use the following:

C> labpac /ai256 /b0f2

return to top of Installation


Interface Conventions
DRIVER ACCESS
  Call Format
  Interrupt Format
INITIALIZATION
VARIABLES
DATA ARRAYS
DATA FILES

DRIVER ACCESS

Each subroutine will be referred to as a "Function" or "Call." These terms reflect that LabPac subroutines can be accessed in two ways depending on the language used. Assembler programmers and others who use software or BIOS interrupts, will recognize the term "Function" to indicate a specific subroutine contained in the interrupt service routine. BASIC, FORTRAN and C programmers will recognize the term "Call" to indicate an external program or subroutine written in languages such as assembler or C to be used by their main program.


Call Format

While the format of a call (i.e., where variables or parameters are placed in the command line) varies in the different languages supported by LabPac, they all have four things in common. These are the label "labpac", a variable to return error codes or data, variables to pass parameters, and a name for each call.

Each language uses the reserved label "labpac" within every call. In Interpreted BASIC, the label is the value of a memory location within the resident portion of LabPac. At this location is a subroutine to recover the information BASIC saved while executing the call statement. This information is passed to the LabPac function being called. In FORTRAN, Compiled BASIC, or C the label refers to a subroutine found in the interface (OBJ) module. This module is incorporated into the application by the LINK utility. The function of the external call is to take the parameters from the C, Compiled BASIC or FORTRAN statement and save them on the stack. The interface module finds the saved information and places it in the registers required by the memory resident portion of LabPac. The module then calls LabPac using the intermpt format. On return from LabPac, an error code or data is placed in the proper variable and control is returned to the main program.

The variables, constants, or parameters used within the call format contain information for LabPac. The required variables are listed and explained under each function in the Technical Reference chapter.

LabPac returns information on every call. LabPac structure requires the inclusion of a variable to return error codes or sampled data. In this manual, the name "RESULT' is used for this variable. All error codes return as two-byte integers with the most significant bit set high. All data returns as two-byte integers with eight to sixteen bits of accuracy.

Every function has a name. While each function can have a different name, it is best to use the pre-assigned names to avoid confusion. In all references to calls in this manual, the function name is constant across languages. The assigned name is paired with a constant value (function number) which LabPac uses to identify the correct subroutine. The Technical Reference chapter contains a complete list of LabPac commands with a brief description of their function. For example, AISWST (Analog Input Sweep Starts) starts a timed hardware interrupt routine to collect samples from a set of analog inputs.


Interrupt Format

Certain languages do not allow linkable object modules. For these languages, use the software interrupt capability that the language provides. Software interrupt functioning includes filling a set of special registers, calling the interrupt, and checking the return value. First, the registers are filled with the proper parameters. Each function in the Technical Reference chapter documents which registers go with which variables. Second, the interrupt is called using the INT command or its equivalent. Finally, the AX register will return with the error codes or valid data. Check this value to insure the success of a call.

return to top of Interface Conventions



INITIALIZATION

LabPac contains several internal variables and tables which must be initialized before data acquisition and process control features can be used. Initialization is handled by the RESET, AIINIT, AOINIT, DINIT, TIINIT, and SWINIT routines. LabPac is modularly constructed so only those features you intend to use need to be initialized. This allows for a simpler internal structure and enhanced operation of the device driver. Initialization of resources must occur before they can be used.

The initialization process installs internal tables, and when necessary configures hardware. The default internal table sizes are as follows:

Table Name

Default Channels

Analog Input Channel Table

16 

Analog Output Channel Table

Digital Input Channel Table

Digital Output Channel Table

Timer/Counter Channel Table

On PS/2 Micro Channel computers, initialization occurs automatically when LabPac is installed.

return to top of Interface Conventions



VARIABLES

Most variables used within LabPac are two-byte integers. All analog or digital data that is either sampled from or written to the hardware are two byte integers in two's complement form. The form and range for data found in variables or cells of data arrays is shown in the table below.

Resolution

Range

16 bit 

-32,768 to +32,767 

12 bit 

-2048 to +2047 

8 bit 

-128 to +127 

Use the factory default jumpering on Scientific Solutions hardware as LabPac takes care of any offsets or justifications based on these defaults. On the Lab Master DMA or Lab Master the analog inputs can be jumpered for a unipolar input range. The best A/D converter output format to use is binary. The range of the analog input data on return from LabPac will be 0 to 4095.

LabPac has two functions requiring a filename. Each uses one string variable to pass that file name. These are the only exceptions to the use of integer variables. All variables are discussed in the Technical Reference chapter under each function.

return to top of Interface Conventions



DATA ARRAYS

Two types of data arrays are used by LabPac. The first type, used to store information such as a set of channel numbers or maximum rate data, are one-dimensional, 2-byte, integer arrays. These are simple to use because all the cells are contiguous in memory and can be found by identifying the correct cell.

The second type of array is a two-dimensional, two-byte, integer array, used to store data. Normally it is dimensioned as the number of sweeps by the number of channels. However, many languages transpose this order. Check the array dimension information for your language in the Using BASIC chapter through the Languages with Software Interrupts chapter.

In memory, the data would be arranged contiguously so that the data for all the channels on any one sweep were together. An example of nine sweeps by six channels, the samples for the six channels for sweep number one would be in the first six locations in memory. They would be followed by the six samples for sweep number two. The last six samples would be for sweep number nine.

For languages such as C or assembler, the data arrays are dimensioned as they appear in memory. However, care must be taken with Interpreted BASIC or FORTRAN. These languages dimension their arrays different from C. Instead of sweeps by channels, BASIC and FORTRAN use channels by sweeps. Make sure these are in the correct order or some very interesting data will appear.

return to top of Interface Converntions



DATA FILES

LabPac can save data into ASCII or binary files. ASCII files are in a standard format recognized by major database software or statistical/graphics packages. Binary files provide for efficient use of disk storage space and are recognized by most statistical packages.

Up to 20 files can be opened at one time from within LabPac. If more than eight files are to be open at one time, modify the DOS internal FILES parameter to recognize the number of files to be used. Shown below is an example of using the FILES command in the CONFIG.SYS file. This file is found on the diskette or the hard drive used to reset the system (see the DOS manual).

FILES = 20

Files in LabPac can be opened for either read or write operations. These two operations, however, cannot be done simultaneously on the same file. If a file is open for saving data (writing), then the same data cannot be read back from that file until it has been closed and then reopened for reading. The same holds for files opened for reading. They also must be closed before new data can be overwritten to them.

When a LabPac file is opened for saving data, more than one data buffer can be saved even though the data is collected at different times. The additional data is appended to the end of the file. This includes the channel and sweep header information. Once a file is closed, no new data can be added to it via LabPac. When that closed file is re-opened for writing it will be cleared of its contents.

Each binary file contains the data from the channel array entered as two byte integers followed by the values from the data array as two byte integers.
 

return to top of Interface Conventions


Developing an Application
INSTALLING LabPac IN MEMORY
GENERAL CONSIDERATIONS
  Program Structure
  Control Parameter Setup
  Initialization
  Main Program
  Subroutines or Procedures
  Exit Routine

As a software driver, LabPac provides streamlined BIOS routines which facilitate the data acquisition and process control features on various Scientific Solutions products including the MC-DAS series, Lab Master series, Lab Tender series, DADIO, and Base Board products. Information in this chapter concerns the installation of LabPac and putting together an application to access the memory resident driver.
 

INSTALLING LabPac IN MEMORY

The main portion of LabPac is a program that becomes memory resident in the computer. LabPac is accessed directly through a BIOS level software interrupt. LabPac has command information and data pointers passed to its internal functions without passing through DOS. Data is sent to the driver a block at a time, thus lowering the overhead and increasing speed.

Once LabPac is installed, it will be actively available to any application program running under DOS until the computer is turned off or reset. The difference between LabPac and a library is that a program only needs to link in the interface module and not the entire body of LabPac code. This cuts down on the size of the code within the application program. Each function of LabPac is accessed through the same subroutine within the interface module. A command parameter within the Call to the interface determines which function is executed.

The driver program, LABPAC.COM, is installed by entering the program name at a DOS prompt, or by adding the line in the AUTOEXEC.BAT file (see the Installation chapter for details).

When LabPac installs, it becomes memory resident with an address pointer placed in the reserved location for software interrupt 66 hexadecimal (INT66H vector). INT66H is an interrupt vector set aside for user supplied applications. More than one application may use this vector. See the Interrupt Service Structure chapter for additional technical information on how LabPac works.

There is a utility program in the TOOLS subdirectory that provides feedback on Calls made to the LabPac driver. The program, CATCH, is useful during the development stage of an application. CATCH will intercept the software interrupt, report on the LabPac function being called, and return status information on the success of the Call. This information is written to the display for convenience during debugging. See the Tools chapter for details on using CATCH.

return to top of Developing an Application



GENERAL CONSIDERATIONS

Developing Data Acquisition & Control applications using LabPac is relatively straight forward. Using the Call or software interrupt methods from different languages is documented in their user manuals. The Using BASIC, Languages with Interface Modules, and the Languages with Software Interrupts chapters of this manual provide LabPac specific details for different supported languages.

Often the most perplexing aspect of Data Acquisition & Control applications is interpreting the design requirements into a software controlled interface. It is useful to map out the different stages of the application in a flow chart before developing the software. This will clarify the needs for acquiring data, data storage, statistics, data transformations, and graphics. Once these needs are blocked out, the different modules of the application software can be developed. The information contained in the rest of this chapter is general, oriented to developing the overall application.


Program Structure

While every application is different, each program will have the same general structure. When developing the application, use the following procedure as a guideline:


Control Parameter Setup

In some languages variables or labeled constants are required as Call parameters, while other languages make the definition of variables/constants optional. Start the program by defining the LabPac command constants and error code labels. This information is contained on the LabPac software in header files named LabPac.???. There is a header file for each supported language. Most languages have an easy method for including header files in the program. Instructions are included for each language in the Using BASIC, Languages with Interface Modules chapters, to the Languages with Software Interrupts chapter.

Define, dimension, or equate all constants, variables, string variables, and data arrays before executing any calls to LabPac. Some languages, such as Interpreted BASIC, have dynamic workspace allocation. When background programming is used while new variables, etc, are being defined, data will probably end up in the wrong location. By setting up all constructs at the start of the program, the required workspace is defined and becomes constant.

Many LabPac functions require data arrays or channel arrays. From the data requirements for the application the size of the arrays can be determined. The space to be used for the arrays should be allocated at this point in the program. If it can be determined, make sure data arrays used in DMA Calls are on segment boundaries.

If data files are going to be used with LabPac functions, the string space used for the file names should be allocated at this point in the program.


Initialization

LabPac contains several internal tables which must be initialized before data acquisition and process control features can be used. LabPac is modularly constructed so only those features you intend to use need to be initialized. This allows for a simpler internal structure and enhanced operation of the device driver.

The initialization process installs internal tables and configures some hardware features. The initialization functions identify key dimensions of Scientific Solutions hardware features used to construct the internal tables. To clear the memory resident driver of previously installed hardware information, use the RESET command as the first initialization routine.

Follow this with installation of the analog I/O, digital I/O and timer/counter features (AIINIT, AOINIT, DTNIT, TIINIT). The initialization routines can be called several times for multiple boards. On the first Call, the first channel will be assigned the value zero and the rest of the channels assigned consecutive numbers. After the first Call, subsequent channels will be assigned numbers starting from the last channel number assigned. For example using AIINIT, assume two Lab Masters and one Lab Tender are in the same system. If the first Call is for the Lab Master with eight differential channels, its eight channels will be assigned to channels zero through seven. If the second Call is for the Lab Tender with 32 single-ended channels, they will be assigned channels eight through 39. Finally the third Call is for the Lab Master with 64 single-ended channels. The channels will be assigned numbers 40 through 103.

If background interrupt-driven processes will be used, place the TIST and SWINIT functions in the next subroutine. See the LABMENU.BAS example program provided with the LabPac software.


Main Program

The main body of application code follows. This section will take many forms. For short programs, it will contain the code in the order it will be executed. For long programs it will more likely take the form of a series of calls to subroutines or proceedures with logical decision code between calls. Each subroutine may be used multiple times.


Subroutines or Procedures

Commonly used subroutines can include data collection, output control, trigger detection, interactive screen displays, error messages, graphics routines, statistics routines, or data transformations. The common thread of these routines is that they are used more than once in the application. Placing them in a subroutine saves workspace and simplifies the overall code used in the program.

Many applications can have some form of error detection and processing procedure. When an error is detected, a subroutine should be available to process the message and execute some qualifying procedure.


Exit Routine

The exit routine should close all files opened or created by LabPac. If EMS memory was used, the buffers allocated to LabPac should be returned to the Memory Manager using the FREE function. It is a good idea to end the program with a RESET Call.
 

return to top of Developing an Application


 Techniques
FOREGROUND PROCESSES
  RAW Calls
  Setting Up Arrays
  Sampling Sets of Channels
  Using EMS Memory
  Software Triggers
  Digital Trigger
  Timed Trigger
  Analog Trigger
  Peak Detection
  Controlling Hardware Interrupts
  Saving Time of Day
HARDWARE PROCESSES
  Counting/Timing Events
  Simple Hardware Triggered ADC
  Burst Mode ADC
  Simultaneous Analog I/O
  Tracking DMA Transfers
BACKGROUND PROCESSES
  Background Sweeps
  Calculating Interrupt Timing
  Use of STATUS Calls
  Pre/Post Sampling

 

The intent of this section is to discuss with examples several techniques for using LabPac routines to develop complete applications. The section is divided into three parts. The first part deals with processes that occur completely in the foreground. These routines proceed in a stepwise fashion with the main program stopping to finish each task before proceeding. The second part deals with hardware triggered processes, These routines have specific hardware requirements that must be in place for the functions to work. The final part deals with background/foreground processing. These techniques coordinate hardware triggered functions with regular foreground tasks.

FOREGROUND PROCESSES

Foreground processes are any subroutines that start and complete a task before returning control to the main program.


RAW Calls

The most elementary function that is performed is to set a channel to a value or to read a single value from a channel. These are known collectively as RAW Calls. Each routine simply transmits a given value or returns the current data value on the channel. AIRAW, DIlIAW, and TIRAW will return the current value on the specified input channel. These Calls are useful when one sample from one channel is required. For example, a calibration routine for the analog input could use the AIRAW Call to sample current data and then report the value to the display while adjustments are being made to the ADC. This might look something like the following:

600 CHAN = 0

610 CALL LABPAC(CHAN, IVAL, AIRAW)

620 RVAL = IVAL / 204.8

630 LOCATE 10,20: PRINT "RAW DATA = "; IVAL; "VOLTAGE = ";RVAL

640 A$ = INKEY$

650 IF A$ = "" GOTO 610

AORAW and DORAW will send one sample to the analog or digital output channel without preserving the current status of the channel. This is useful when a change is dictated by the software with pre-set values. DOSET, DOCLR, and SCRAW will read the current status of the digital output channel, modify that value with a masking value, and return the new value to the digital output channel. These operations are very useful when only certain lines or bits are to be toggled while preserving the current value of the remaining bits. For example, the following will set lines 1 and 5 to TTL high while not changing the remaining six lines in the 8-bit port.

600 OMASK = 34

610 CHAN = 0

620 CALL LABPAC(CHA, OMASK, RESULT, DOSET)


Setting Up Arrays

Often a set of channels needs to be monitored. This process requires a list of channels which will be sampled, a time interval between each burst of samples, and a data array to store the data. Conversely, when driving a set of channels the data array supplies the information to be provided to the set of channels at the timed interval.

In the data set Calls, the list of analog or digital channels to be sampled is placed in a Channel Array. The cells in the array are filled with the channel numbers in the order they are to be sampled. If the element in the array is a negative channel number, the corresponding timer/counter channel is sampled or re-loaded. For example, if a sweep of data consists of a read from channel 3 and a read from channel 5, the first element of the array named CHANNEL is set to 3 and the second element is set to 5.

500 CHANNEL(0) = 3: CHANNEL(1) =5

In the data set Calls the information to be sent is taken from the data array or conversely the information from sampled channels is stored in the data array. Information is stored in a sweep major manner: the first element contains data for/from the first sweep, first channel; the second element contains data for/from the first sweep, second channel, etc. Graphically this appears:

Sweep 1

Channel 1 

Sweep 1

Channel 2 

Sweep 1

Channel 3 

Sweep 2

Channel 1 

Sweep 2

Channel 2 

Since this is how two-dimension arrays are stored in memory it is often easiest to dimension the array as # of Sweeps by # of Channels for row major languages such as C. Column major languages such as FORTRAN or BASIC should be dimensioned as # of Channels by # of Sweeps. This means that an individual sample can be addressed in C as:

IBUF[SWEEP_N][CHANNEL_N]

or in FORTRAN or BASIC as:

IBUF(CHANNEL_N,SWEEP_N)

When a new sample is specified using the same data array, the new samples will replace the current contents of the data array. The data array cells do not have to be zeroed out between calls.

The maximum number of cells in the data array is 32,767. To calculate the number of cells use:

NCELLS = NSWEEPS * NCHANS

Pay close attention to whether the application language has zero-based indices or one-based indices. In C the first sweep, second channel data would be in array [0,1]; in FORTRAN the data would be accessed as array (2,1); or in Interpreted BASIC the same data is ARRAY(1,0).


Sampling Sets of Channels

When medium to high speed data set sampling is required, the MAXimum Rate functions are recommended. These routines use a Timer/Counter Channel to clock the time between sweeps. The interval timer must be established with the TIST Call for the time period between the start of each sweep of channels.

AIMAX and DIMAX will sample a set of channels into an array. In the following example three analog input channels are sampled fifty times each with sweeps at ten millisecond intervals.

600 CHAN(0) = 3:CHAN(1) = 6:CHAN(2) = 8

610 TCHAN = 3:SRC = 1 4:PERIOD = 10

620 NSWEEPS = 50:NCHANS = 3

630 CALL LABPAC(TCHAN,SRC,PERIOD,RESULT,TIST)

640 CALL LABPAC(TCHAN,NSWEEPS,NCHANS,CHAN(0),IDATA(0,0),RESULT,AIMAX)

AOMAX and DOMAX will output samples from an array to a set of channels. For example the following will output five ascending voltage levels on channel 0 and five descending levels on channel 1 at one second intervals.

590 DIM IDATA(1,4)

600 CHAN(0) = 0:CHAN(1) = 1

610 TCHAN = 3:SRC = 1 5:PERIOD = 100

620 NSWEEPS = 5:NCHANS = 2

630 IDATA(0,0) = 0: I DATA(1,0) = 2047

640 IDATA(0,1) = 500:IDATA(1,1) = 1500

650 IDATA(0,2) = 1 000:IDATA(1,2) = 1000

660 IDATA(0,3) = 1500:IDATA(1,3) = 500

670 IDATA(0,4) = 2047:IDATA(1 ,4) = 0

680 CALL LABPAC(TCHAN,SRC,PERIOD,RESULT,TIST)

690 CALL LAB PAC(TCHAN,NSWEEPS,NCHANS,CHAN(0),IDATA(0,0),RESULT,AIMAX)


Using EMS Memory

Expanded Memory, often referred to as the LIM EMS standard (Lotus, Intel, Microsoft Expanded Memory Specification), refers to computer memory beyond the 640KB DOS limit using techniques called paging and bank switching. LabPac requires an EMS memory manager or a 386 Virtual Memory Manager. To use expanded memory, three Calls are available (ALLOC, ACCESS, & FREE).

ALLOC allocates a block of EMS memory and returns a two-word handle or buffer number. This handle is used in place of any data array pointers when using the large or compact memory model programs. The handle consists of two parts: the segment address of the EMS memory and a block number assigned by the EMS Memory Manager. ALLOC can be used as follows:

handle = (unsigned long)labpac(ALLOC, nelements);

All LabPac routines using data arrays automatically map the EMS memory. The following code segment indicates how the EMS buffer handle can be used to indicate the data array location.

labpac(AIMAX, timer, nsweeps, nchans, chans, handle);

labpac(WRITE, filehandle, nsweeps, nchans, chans, handle);

If the application program needs to access any expanded memory, Call the ACCESS function with the proper handle. At this time the block of memory can be read from or written to the EMS memory segment starting at offset zero.

To release a block of memory after it is no longer needed, use the FREE function as follows:

labpac(FREE, handle);


Software Triggers

When the need arises to sample data after a certain event has happened, external triggers are used. If the triggering event is an analog input, the AISC function can be used. If the triggering event is a set of one or more digital inputs, the DISC function can be used. If the triggering event is time or count related, the TISTAT function can be used.


Digital Trigger

The DISC function detects a bit combination on a particular digital input channel. The routine requires the Digital Input Channel Number, a mask of the bits to look at, and a value to describe the on/off pattern for the masked bits.

The DISC function has two modes of operation depending on the mask. If the mask is non-zero the function returns as soon as the input lines corresponding to the set bits identified in mask equal value bits. If the mask is zero than the function returns as soon as any of the input lines corresponding to set bits in value change state. Note that in either mode it is possible to set up the DISC parameters so that the function will not return (i.e., the digital channel mask never meets the trigger condition). The following program fragment waits for a falling edge on digital input channel 0, bit 1.

labpac(0,2,2); //Make sure line is high

labpac(0,2,0); //Wait for the falling edge


Timed Trigger

In some applications a pause or delay is needed before the next section of code executes. For other applications a set of functions need to be done at set intervals. For these applications timer/counter channels can be utilized to provide accurate timing.

When the application requires a pause or delay, start a timer channel with a mode which will give you the range of delay desired. Use 11 for microseconds, 14 for milliseconds, or 15 for hundreths of seconds. Use the value of zero for the period. After starting the counter with the TIST function, use the TISTAT function to create a delay in the program. For example to delay one second, use 15 for the mode, zero for the period, and 100 for the value in TISTAT.

600 TCHAN = 3:SRC =15:PERIOD = 0

610 STATVAL = 100

620 CALL LABPAC(TCHAN, SRC, PERIOD, RESULT, TIST)

630 CALL LABPAC(TCHAN, STATVAL, RESULT, TISTAT)

The use of a counter trigger is similar, replace the timer source with an external source. The successive TISTAT Calls will then wait until the desired number of external counts is recorded.

Occasionally applications need to execute a task or set of tasks at the start of given time intervals. Repetitive functions in the application are executed at equal intervals. One technique to track the time interval is to monitor the output state of a timer/counter channel. The TISTAT routine can wait for the output of a timer/counter to go high as shown in the following fragment. After the task is complete, use the TISTAT routine to wait for the end of the next interval.

mask = 0x0808 //Waitfor channel 3 to go high

labpac(TISTAT, 3, mask);

There are two problems with the preceeding algorithm. First, if the task is complete before the timer/counter output goes back low, the next task could start before the given time interval is completed. To guard against this, add a TISTAT Call that waits for the timer/counter output to be low.

labpac(TISTAT, 3, 0x0008);

The second problem is that the high interval may be too short. If the timer/counter source is less then 100seconds, the TISTAT routine may not see every high pulse from a timer/counter started with TIST. To remedy this problem, start a timer channel with the TILH routine. Set the low and high output values about equal and such that their sum equals the desired time interval. The complete procedure might appear as follows:

700 TCHAN=3:SRC = 11:LOW = 500:HIGH = 500 '1 mS

710 LOWVAL = &H0008:HIGHVAL = &H0808

720 CALL LABPAC(TCHAN,SRC,LOW,HIGH,RESULT,TILH)

730 CALL LABPAC(TCHAN, HIGHVAL, RESULT, TISTAT)

740 'PLACE DESIRED TASK HERE

910 CALL LABPAC(TCHAN, LOWVAL, RESULT, TISTAT)

920 GOTO 730


Analog Trigger

The AISC function detects rising or falling analog signal edges. The routine requires an analog input channel, the pre-trigger level, and the post-trigger level. Tnis allows the specification of a level and a noise band for the trigger signal. The AISC function returns after the dual conditions have been met. In the following example analog input channel 5 is used to detect an analog trigger at aproximately 4 Volts.

600 CHAN = 5: PRE = 800: POST = 816

610 CALL LABPAC(CHAN, PRE, POST, RESULT, AISC)


Peak Detection

The AISC function also provides for threshhold detection. There may, however, be a need for a peak detector or localized maxima/minima detector. One way to detect extrema would be to collect a series of data and analyze the data after the fact. If the extrema is a trigger for other events we need to detect peaks in real time.

The following example looks for a local maxima. When a sample with a higher value than the previous maximum is identified, it is saved as the new maximum and the count reset. After a predetermined number of counts without a new maximum being found, the saved value is declared to be the peak value. The method provides some noise rejection although it does suffer in that there is a lag between reading the peak value and realizing that it is the peak value. This code can also be used to detect a minima by replacing max with min and checking if sample is less than min.

** Look for localized peak **

max= -32766

count= 0

while count < NSAM PLES

sample= labpac(AIRAW, 0)

if(sample > max)

max= sample

count= 0

else

increment count

endif

endwhile


If we are just counting peaks and they are of a known height, we can use the theshold detector routine to count crossings as follows:

** Count crossings **

while time<maxtime

peek= labpac(AISC, channel, LOW, HIGH)

increment count

endwhile


Controlling Hardware Interrupts

While the Scientific Solutions hardware is capable of fast data acquisition and process control, sometimes the computer interrupt traffic may make it difficult for the computer to acquire data at the maximum rate. One major limiting factor is that the CPU is constantly being interrupted by processes other than LabPac. If you are not able to acquire data at the full rate and you suspect this is due to other tasks interrupting the CPU, you can turn off the interrupt process. To turn off or mask the interrupts, follow these steps.

Use the ITCLR call to disable the desired interrupts. The discussion of the INTCLR function in the Technical Reference chapter identifies the common functions used with each IRQ line. When OFFFFh is in the register, all IRQs are masked off or disabled. Use this value to disable all IRQs as in the following example:

oldint = labpac(lNTCLR, Oxffffh)

Note that OLDINT is set equal the mask of interrupts that were turned on previous to this call so that the status of the IRQ Control Register can later be restored.The sixteen bits in this register correspond with the sixteen IRQ lines. Each bit number matches its IRQ number (i.e., bit zero is for IRQO). When a bit in this register is enabled (set to one), then the corresponding IRQ is disabled. When a bit in the register is set to zero, the corresponding IRQ is left alone.

If one of the IRQs that was already enabled (i.e., LabPac background process server) is to be left alone, be sure not to add the value that sets the corresponding bit to zero. See the example below for disabling all TRQs except number seven.

oldint = labpac(lNTCLR, Oxff7fh)

After finishing data collection at a maximum rate, always restore the IRQ Control Register to its previous status. If the previous value was saved as illustrated in the above examples, simply call INTSET using the value in OLDINT.

labpac(lNTSET, oldint)

NOTE: While the IRQ vectors are disabled in this fashion, the PC systemboard clock will stop keeping time and the disk drive motors will not stop.


Saving Time of Day

When the DOS clock is turned off for high speed or uninterrupted data collection, the system clock is stopped and will lose time. To reset the DOS clock from the computer's real-time clock use BIOS interrupt function 2 to read the clock, translate the time values from BCD to binary, and use DOS function 2DH to set the clock. Date and Time software supplied with the computer can also be used.

The Lab Master series, Lab Tender, and McDAS series boards can preserve the time of day on the Timer/Counter Channels 1 & 2. This is done through the SETTIME and GETTIME functions. SETTIME would be used before the clock interrupt is cleared with the TNTCLR function. After the time intensive task or before exiting the LabPac application, use GETTIME to reset the DOS clock. GETTIME can also be used during the application to retrieve the time-of-day for time stamping purposes.

return to top of Techniques



HARDWARE PROCESSES

Hardware processes are those routines that rely on some aspect of the hardware interface to start or cause some action.

Counting/Timing Events

External events can be counted or tracked by tying the signals to the source or gate pins of the 9513A timer/counter IC on the Lab Tender, Lab Master series, or McDAS series interfaces. The events can be tracked by starting a counter channel with the TIST routine. The current count of events can be identified at any time using the TIRAW routine. The following example starts timer/counter channel 3 to count events arriving at source pin 5.

600 TCHAN = 3: SRC = 5: PERIOD = 0

610 CALL LABPAC(TCHAN,SRC,PERIOD, RESULT,TIST)

1050 CALL LAB PAC(TCHAN,EVCOUNT,TIRAW)

1060 LOCATE 5,70:PRINT HEX$(EVCOUNT)

NOTE: In BASIC all counts above 32767 will be presented as negative numbers. The HEX$ conversion can be used to preserve the counts as a positive value.

Timer/counter channels can be read as part of input sweep routines. A negative channel number is interpreted by the SWST and MAX routines as a timer/counter channel. The read integer data is placed in the data array the same as for the analog or digital input channels. On output sweeps the data is output to the timer/counter channel's Load Register.

Some applications call for counting events within a precise interval of time. One way of handling this is to have one counter gated by another. The following example determines how many pulses occur on SRC3 during one second. Externally connect OUT2 to GATE4.

labpac(TILH,2,15,1 ,100); //10Msec. low - one sec.high

labpac(TIST,4,3+256,0); //count pulses on SRC3

labpac(TISTAT,0,0x404); //wait for high gate

labpac(TISTAT,0,0x400); //wait for low gate

count = labpac(TIRAW,2); //read number of counts


Simple Hardware Triggered ADC

A necessary condition to accurate high speed A/D sampling is a consistent equally spaced signal to start conversions. This is important because at higher speeds the reliability of data depends on equal sampling intervals. Using the external start feature on the Lab Master DMA, Lab Master and Lab Tender is the surest way to generate equal intervals.

One method for generating an external start is to bring an external signal from a source that sends rising edge pulses at accurate intervals. Use the LabPac AIHDW or AIDMA calls to collect the data.

The other method for generating an external start is to use one of the 9513A counters. To physically install one of these counters, run a line from one of the OUT pins on a board's 9513A connector to the external start pin. Some boards may already have a counter connected in this fashion. Refer to the manual on your particular Scientific Solutions' board. Use the LabPac timer routines to set the rate for the output signal from the counter. The following example provides a 40KHz sampling rate (based upon a 1Mhz 9513A clock).

labpac(TIST,S,11 ,25);

labpac(AIDMA,0,500,5,data);

The previous AIDMA Call may have returned the DMAERR error code. This is because the data buffer crossed a DMA page boundary. To prevent this from happening, start with two data buffers, allocated contiguously. Determine which buffer does not cross a boundary as follows.

int dma1[50001[4], dma2[5000][4];

p_addr = fp.seg(dma1) * 16 + fp.off(dma1);

if(p_addr >> 8 = = p_addr + 4000) >> 8)

{

buffer = dma1;

}

else

{

buffer = dma2;

}


Burst Mode ADC

Some applications call for a set of analog inputs to be sampled as a group at regular intervals instead of continuously at equal intervals between any two conversions. The routines AIMAX and AISWST/AIRSWST will sample their sweep of channels in this fashion. To minimize the time interval between any two conversions within the burst of channels, the AMDW and AIDMA routines can be used with a gated timer as the trigger. The timer/counter can be started with the TIST function as discussed earlier. To bunch the samples together, a gated pulse train is required. This is accomplished by cascading a timer started with a TILH function into the gated trigger timer. For example, to create a timer signal for a four channel sweep with 10 microseconds between samples and 100 microseconds between sweeps, connect OUT4 to GATES and use the following code:

labpac(TILH, 4, 11, 60, 40); //60 secs. low - 40 secs. high

labpac(TIST, 5, 11+ 0x20, 10); //10 secs. gated by above


Simultaneous Analog I/O

Some applications call for a set of analog inputs to be sampled while simultaneously stimulating with an analog output waveform. Usually the sequence of events is to output the stimulus, wait for the reaction to settle, then sample the data.

In the following example, timer/counter channel 3 determines the rate of stimulus change. Timer/counter channel 4's low output time determines the delay between the stimulus and the start of sampling. Timer/counter channel 4's high output time enables the conversions and should be equal to the number of samples times the conversion rate. Timer/counter channel 5 determines the conversion rate. To create a timer signal for a four channel sweep with 25 microseconds between samples triggered 20 microseconds after an analog output, connect OUT4 to GATES and OUT3 to GATE4. Use the following code:

//20 S before first sample - 100 S for 4 channels

labpac(TILH, 4, 11 + 0xe0, 20, 100)

labpac(TIST, 5, 11+ 0x20, 25) //25 S per conversion

labpac(AIDMA, 0, nsweeps, 4, databuf);

labpac(TIST, 3, 11, 1000); //1000 S between outputs

labpac(AOMAX, 3, nsweeps, 1, chan, outdata);


Tracking DMA Transfers

Real-time applications may require the identification of when a burst of samples has been transferred to the data buffer. To identify when a set of samples is in the data buffer, start a counter channel with the end-of-conversion status signal as the source. On the Lab Master DMA, connect the DONE jumper and use source 3. On the McDAS series use A/D DONE as the source. Use TISTAT to determine when the set of samples is available as follows:

labpac(TIST,3,3,0); //count DMA transfers

labpac(TIST,5,1 2,25); //high speed conversion

labpac(AIDMA,0,500,1,data);

labpac(TISTAT,3,250); //wait for buffer half full

return to top of Techniques



BACKGROUND PROCESSES

Background processes are those routines that start a task and return control to the main program before completing the task. The task will be completed by hardware interrupt processes.


Background Sweeps

When both a stimulus is to be provided and a response measured, and the sampling frequency is low to medium speed, the Sweep Start functions are recommended. These functions use the interrupt handler installed by the SWINIT routine. The time between sweeps is clocked by the Timer/Counter Channel installed using a TIST routine. These Calls take the user parameters and set up a background procedure which performs the actual work.

This background action allows two or more processes to proceed at the same time. An application program can write data to the screen as it is being collected or a stimulus can be provided at the same time as monitoring a subject's response.

The LabPac interrupt handler monitors a service cycle for timed interval processes. The service cycle consists of four parts. Each part is responsible for monitoring the status of timed interval sampling or sending of data for a set of one or more channels (referred to as a sweep of channels). The four types of sweeps are: analog input, digital input, analog output and digital output. The status of each type of sweep is monitored by its own "process context". This is a subroutine that checks to see a) if any sweep is in progress or b) if it is time to conduct a sweep. There are four process contexts, one for each sweep.

When the LabPac interrupt handler is called by the CPU, the main routine to monitor the service cycle is run. The routine acknowledges to the CPU and the Scientific Solutions hardware that the interrupt was received. The status of the service cycle is then checked and one of the process contexts is called. One process context is serviced on each hardware interrupt. The full service cycle consists of the running of all four process contexts. Thus it takes four hardware interrupts to complete one full service cycle. See the Interrupt Service Structure chapter for more details.


Calculating Interrupt Timing

With analog inputs in particular, there is always the danger for an overrun to occur in the service cycle. An overrun is when the process context calculates it is time to begin a sweep and the previous sweep of the same type is still in progress. The possibility of an overrun increases if too many channels need to be processed and not enough time has been allowed in the service cycle. This is also more likely to happen if another type of sweep is started with not enough time allowed to do both sweeps. See the Interrupt Service Structure chapter for a discussion of factors to consider in determining interrupt timing.

The minimum recommended time interval for one complete service cycle is 800 microseconds. This equates to 1250 complete service cycles per second. When calculating parameters for the time interval on the interrupt source, divide the service cycle interval to be used by four to get the time interval between each hardware interrupt.

Interrupt timing can be calculated as either a time interval or a frequency (i.e., times per second). The terms used in the following calculations are: Interrupt (hardware interrupt); Source (9513A counter's input source); Count (i.e., number of times to count the signal at the Source) and Skip (the number of complete service cycles between sweeps). Three formulas are needed as shown below for calculating time intervals. See the Interrupt Service Structure chapter for the corresponding frequency calculations.

Interrupt Interval = Source Interval * Count
Service Cycle Interval = 4 * lnterrupt Interval
Sweep Interval = Service Cycle Interval * Skip
As an example using a 100 microsecond Source interval, let the Count for the source interval equal 75 and the Skip between sweeps equal 20. The following calculations apply.
Interrupt Interval = .1 mS * 75 = 7.5 mS
Service Cycle Interval = 7.5 mS * 4 = 30 mS
Sweep Interval = 30 mS * 20 = 600 mS
For this example, these values mean that a hardware interrupt will occur every 7.5 milliseconds. It will take 30 milliseconds to complete one of LabPac's service cycles. There will be a sweep every 600 milliseconds or 1.67 sweeps per second.


Use of STATUS Calls

When the sweep start function returns, the sweep data is not necessarily present in the data array. Each of the background processes has a status routine which will return the current value in the sweep counter. The AISTAT, AOSTAT, DISTAT and DOSTAT Calls are useful in identifying how many sweeps have occurred in a background process. For example, the application starts a background process and proceeds to some other operation(s). After finishing with those routines it needs to wait until the background process is finished. The end of the background process can be determined as follows:

labpac(AOSTAT,0)

In slow moving real-time applications, the background process stat Calls can be used to identify when a set of samples are available for use by graphics, statistical, or transforming processes. In the following example a loop is set up to identify when each set of samples has arrived in the data array so their position on a strip chart display can be calculated and the screen updated.

labpac(AISWST, 1, nsweeps, nchans, chan, data);

for (s=0; s<nsweeps; ++s);

{

labpac(AISTAT, nsweeps-l-s);

for (c=0; c<nchans; ++c)

{

graph (s, c, data[s][c];

}

}

The timer/counter channels have a status routine, TISTAT. This routine was discussed earlier under Software Triggers. The ATDMA routine has a status function, DMASTAT. This function identifies when the DMA process has been completed. This function will not return until all DMA transfers are completed.


Pre/Post Sampling

Sometimes samples of input data are required prior to the trigger condition. These samples are known as pre-trigger samples. To acquire pre-trigger samples we use repeating input sweeps. These are similar to regular input sweeps with the addition that after acquiring a complete set of samples for the required sweeps, the repeating sweep function will restart the process, overwriting the data buffer. This allows a continuous sampling of the input channels. In order to detect the trigger condition, the STAT Call is used to identify which sweep is currently sampled. With this information examine the contents of the corresponding cell in the data array containing the current sample for the scrutinized input channel.

After determining that the trigger has occurred, stop the process with the SWAB routine. If post-tsigger samples are required, use a STAT function to wait for the post-trigger samples to be acquired and then abort the sweep process. An example of this overall process can be found in the Example Applications chapter.


Double Buffering - PingPong

A specific input repeating sweep technique which allows continuous sampling of data sets larger than 64K is called double buffering or pingpong buffering. This algorithm has a repeating analog input sweep to collect samples into a large data buffer. The foreground process monitors the progress of the repeating sweep and then starts writing the input data to a file after the sweep reaches the half full mark. After the file writing routine, the foreground routine waits until the input sweep process is finished with the second half of the data buffer. The second half is then written into the file. The process is repeated until some end condition is met.

file = labfile(CREATE, "data")
labpac(AIRSWST, 1, 3200, 10, channels, data)
repeat
  labpac(AISTAT, 1600)
  labpac(WRBIN, file, 1600, 10, channels, data)
  labpac(AISTAT, 0)
  labpac(WRBIN, file, 1600, 10, channels, data[600] )
until done
labpac(AISWAB)
labpac(CLOSE, file)
return to top of Techniques


Tools

CATCH
SCRIPT
LABMENU
  Initialization
  Analog Input
  Input From One Channel
  Multi-Channel Input
  Multi-Channel Data Display
Saving Multi-Channel Data Sets
  Digital Input
  Analog Output
  Digital Output
  Timing/Counting
In the TOOLS sub-directory you will find two programs to help you design LabPac programs. The SCRIPT program allows you to enter LabPac commands and parameters from the keyboard. The commands will be executed and the return value and data displayed on the monitor. CATCH is a memory resident program which will report all calls made to LabPac.

In the root directory of the LabPac disk is the program LABMENU, which can also be of assistance in designing programs. It is an Interpreted BASIC program. All three utility programs are described in this chapter.

CATCH

The utility program CATCH.COM, found in the TOOLS sub-directory, is a memory resident program. After installation, CATCH can report on all Calls made to LabPac. CATCH can write to the monitor the name of the Call, the values of the parameters used in the Call, and the result or return value from the Call. Having this information available during development of an application is extremely useful to identify problems in the main program and to troubleshoot system problems when unexpected results occur.

Since CATCH will intercept only Calls to LabPac, LabPac must be installed before installing CATCH. To make CATCH memory resident, type CATCH at the DOS prompt as follows:

C> CATCH

After capturing a Call to LabPac, CATCH will report the function name, parameter values and return value on the display in the following format:

[functionname parameterlist -- RESULT]

In the default installation, CATCH will report all information to the monitor and allow execution of the Call by LabPac. Writing of the function name, parameter list or return value to the monitor can be suppressed using a set of toggles with the CATCH command. Execution of the Call by LabPac can be suppressed, allowing the Call to return to the application without being executed. The following options are available:

/a - do not print result from LabPac

/c - do not allow LabPac to receive the Call

/f - do not print function name before calling LabPac

/p - do not print parameters before calling LabPac

To use one of the parameters, place it after the CATCH command as follows:

C> CATCH /C

If CATCH is already memory resident, running CATCH with an option(s) will toggle the current setting of that option(s). The options that can be used after CATCH is installed are:

/a - print result from LabPac

/c - allow LabPac to function

/f - print function name before calling LabPac

/p - print parameters before calling LabPac

/r - remove CATCH from memory

return to top of Techniques



SCRIPT

The SCRIPT program, found in the TOOLS sub-directory, allows you to enter LabPac commands and parameters from the keyboard. The commands will be executed and the return value and data displayed on the monitor. To run SCRIPT, type SCRIPT at the DOS prompt as follows:

C> SCRIPT

LabPac>

The program will respond, as shown, with a LabPac prompt. At this point any LabPac command can be entered at the keyboard with its parameter list. First type in the function name. Follow the name with a space and the parameters. Separate each parameter with a space. For example:

LabPac> reset

787

LabPac>

In the example, the return value of 787 decimal from the RESET function indicates the installed LabPac is Version 3.13. that is, 787 decimal is 313 hex. In the following example, the TIST command starts timer/counter channel 3.

LabPac> tist 3 13 1500

0

LabPac>

Parameters used in SCRIPT are decimal by default. To enter hexadecimal numbers, start the number with a "0x". To enter octal numbers, start the number with a "0". See the SET command below for an example of hexadecimal usage.

All LabPac functions are implemented in SCRIPT. There are some additional commands available to provide necessary auxilliary functions. One of these additional commands is HELP. To get a list of all commands type HELP. To get help on a specific command, type HELP commandname as in the following example:

LABPAC>help aiinit

To create a channel array or data array use the SET command. NOTE that input data arrays do not have to be created prior to an input command. The arrays can be given any name. In the following example, the arrays "aochans" and "aodata " are created. After each SET command a prompt will appear to fill the cells in the array with the desired decimal values.

LabPac> set aochans 4

Channels> 01 2 3

LabPac> set aodata 3 4

Sweep0> 0x0 0x10 0x20 0x30

Sweep l> 0xl 0x11 0x21 0x31

Sweep2> 0x2 0x12 0x22 0x32

LabPac> aoswst 1 3 4 aochans aodata

0

To exit SCRIPT, use the 'QUIT' command.

return to top of Techniques



LABMENU

The LabPac software includes a menu-driven program, LABMENU.EXE. Menu selections provide access to and control over the LabPac/hardware interface system. Use them to test the functionality of the system and to determine which routines to use in dedicated applications. For some applications this menu program may be sufficient to meet all programming needs. It can also be a convenient starting point for developing BASIC applications. Use of the menu program is explained in this chapter.


Initialization

Make sure you have loaded LABPAC.COM prior to running the LABMENU.EXE program.

To enter the menu program, type LABMENU at a command prompt, like this;

C:\ LABMENU


If LABPAC.COM was not loaded into memory, the error message "Divide Overflow" may display or the software will not display the LabPac version number and stop.

As LABMENU starts running it displays a Scientific Solutions copyright notice and then goes to the initializing routines. The program may prompt you for the particular Scientific Solutions' board you are using.

LabMenu Version 3.02

Copyright 1981-2000 by

Scientific Solutions
 
 

A menu program to test drive

LabPac Version x.xx
 
 

F1 Initialize LabMaster

F2 Initialize LabTender

After initialization, the following "Main Menu" will appear on the monitor

LABMENU
 
 

[Esc] Exit to Dos

F1 Analog Input

F2 Digital Input

F3 Analog Output

F4 Digital Output

F5 Timing/Counting

To enter one of the submenus, depress the function key (F1 to F4) listed in front of the option. For example, depress F2 to select the Digital Input submenu. A new menu will appear.

Depress the Esc key while in the Main Menu to exit the program, returning to DOS.

Depress the Esc key while in a submenu to return to the Main Menu.


Analog Input

The transfer of data from the analog to digital converter to LABMENU is handled by the Analog Input routines. The submenu is as follows:

ANALOG INPUT
 
 

[Esc] Return To Main Menu

F1 Read Analog Channel

F2 Start Analog Input Sweep

F3 Display Analog Data

F4 Stop Analog Input Sweep

F5 Start Maximum Rate Sweep

F6 Save Data to File

The choices allow data to be collected either one channel at a time or as sets of channels and samples. Data can be displayed in an oscilloscope format or saved as ASCII data files.


Input From One Channel

Option Fl will take one sample from one channel and display the result on the screen. Without clearing the Analog Input Menu from the screen, the following prompt will appear to identify the input channel.

Channel?

Type in the number between 0 and 256 that corresponds to the analog input channel to be sampled followed by a carriage return. An A/D conversion will be performed and the returned decimal value displayed on the screen under the above prompt as follows.

Result = 357


Multi-Channel Input

Options F2 and F5 allow for samples to be collected on up to 16 channels for 500 samples/channel. After selecting either option, the screen will clear. A prompt will appear requesting the time interval to use between the sampling of a set of one or more channels. For option F2 the base rate is in microseconds. For option F5 the base rate is in milliseconds. After typing in a value followed by a carriage return, a prompt will appear for the number of sweeps or bursts of channels to collect. Type in a number between 1 and 500 followed by a carriage return. A third prompt will appear to identify the number of channels to include. Type in a number between 1 and 16 followed by a carriage return. At this point the display will appear as follows where the parameters will be listed followed by a set of choices.

SWEEP PARAMETERS
 
 

Sweep timing (base rate): 200

Number of sweeps: 500

Number of channels: 8
 
 

[Esc] Return without Sweep

F1 Start Sweep

F2 Enter Channels

F3 Edit Channels

When multiple channels are selected, the Channel Array used by the sweep and maximum rate routines must be filled to identify which channels are to be used and the order that the channels will be sampled. Option F2 will present a set of prompts for the channelnumbers, Tn the example eight prompts will appear. The channels can be used in any order. Option F3 allows the order of the channels to be changed.


Multi-Channel Data Display

In the Analog Input Menu, option F3 will display the contents of the data array in an oscilloscope format. The last values entered for the number of channels and number of samples will be used to index the data array.


Saving Multi-Channel Data Sets

Option F6 creates a file to save the contents of the data array. The following prompt will appear for the name of the file:

File Name?

Type in the name of the file complete with DOS path. The file will be created at that location. The data array will be transferred to this location in ASCII format. The last values entered for the number of channels and the number of samples will be used to index the data array. After the data is transferred the file will be closed.


Digital Input

The transfer of data from the digital input ports to LABMENU is handled by the Digital Input routines. The submenu is as follows:

DIGITAL INPUT
 
 

[Esc] Return To Main Menu 

F1 Read Digital Channel 

F2 Start Digital Input Sweep 

F3 Display Digital Data 

F4 Stop Digital Input Sweep

F5 Start Maximum Rate Sweep

F6 Save Data to File

The options in the Digital Input Menu operate the same as the corresponding options in the Analog Input Menu.


Analog Output

The transfer of data from LABMENU to digital to analog converters is handled by the Analog Output routines. The submenu is as follows:

ANALOG OUTPUT
 
 

[Esc] Return To Main Menu 

F1 Write Analog Channel 

F2 Start Analog Output Sweep 

F3 Start Repeating Sweep 

F4 Stop Analog Input Sweep

F5 Start Maximum Rate Sweep

The choices allow data to be output from one channel at a time or from sets of one or more channels. The data can be entered at the keyboard or recalled from data files.

Options F2, F3 and F5 allow for samples to be output on up to 16 channels for 500 samples/channel. After selecting any of these options, the screen will clear. A prompt will appear requesting the time interval to use between the sending of a set of one or more channels. For options F2 and F3 the base rate is in microseconds. For option F5 the base rate is in milliseconds. After typing in a value followed by a carriage return, a prompt will appear for the number of sweeps or bursts of samples/channel to send, Type in a number between 1 and 500 followed by a carriage return. A third prompt will appear to identify the number of channels to include. Type in a number between 1 and 16 followed by a carriage return. At this point the display will appear as follows where the parameters will be listed followed by a set of choices.

SWEEP PARAMETERS
 
 

Sweep timing (base rate): 4

Number of sweeps: 20

Number of channels: 2
 
 

[Esc] Return without Sweep

F1 Start Sweep

F2 Enter Channels

F3 Edit Channels

F4 Enter Data

F5 Edit Data

F6 Read Data File

When multiple channels are selected, the Channel Array used by the sweep and maximum rate routines must be filled to identify which channels are to be used and the order that the channels will be sampled. Option F2 will present a set of prompts for the channel numbers. In the example eight prompts will appear. The channels can be used in any order. Option F3 allows the order of the channels to be changed.

Option F4 allows the data array to be filled from the keyboard. A series of prompts will appear for the number of cells determined by the number of channels times the number of sweeps.

Option F5 allows the editing of the data array. Prompts will appear to identify which cells to change and what new values to enter.

Option F6 allows the data array to be filled from a pre-existing ASCII data file. The following prompt will appear for the name of the file:

File Name?

Type in the name of the file complete with DOS path. LABMENU will look for the file at that location. The data will be transferred from this location. The last values entered for the number of channels and the number of samples will be used to index the data array. After the data is transferred the file will be closed.


Digital Output

The transfer of data from LABMENU to digital output ports is handled by the Digital Output routines. The submenu is as follows:

DIGITAL OUTPUT
 
 

[Esc] Return To Main Menu

F1 Write Digital Channel

F2 Start Digital Output Sweep

F3 Start Repeating Sweep

F4 Stop Digital Output Sweep

F5 Start Maximum Rate Sweep

The options in the Digital Output Menu operate the same as the corresponding options in the Analog Output Menu.


Timing/Counting

The Timing/Counting Menu presents options to start, stop, and read the contents of 9513 cdunters. The submenu is as follows:

Timing
 
 

[Esc] Return To Main Menu

F1 Start Timer

F2 Stop Timer

F3 Read Timer

F4 Set Clock Mode

F5 Read Clock

Option F1 will start one of the five timer/counter channels. Without clearing the screen a prompt will appear to identify the timer/counter channel. Enter a number between 1 and 5 followed by a carriage return. A second prompt will appear to identify the source of pulses to count. Enter a number between 0 and 15 followed by a carriage return. A third prompt will appear to identify the number of pulses to count. Enter a zero for counting up as an accumulator. Enter a number between 2 and 32,767 for counting down as a timer.

Option F2 will stop one of the five timer channels.

Option F3 will read the contents of one of the five timer channels and display the decimal value on the screen.

Option F4 will read the current time-of-day from the computer's system clock and install it on timer channels 1 and 2.

Option F5 will continuously read the contents of timer channels 1 and 2 and display the values as the time-of-day.
 

return to top of Techniques


Using BASIC
INTERPRETED BASIC
  The Header File
  Call Format
  Defining Terms
  Getting Started
  Error Checking
DEMONSTRATION PROGRAMS
  Aidemo.bas
  Aodemo.bas
  Didemo.bas
  Dodemo.bas
  Tidemo.bas
  Labmenu.bas
COMIPILED BASIC
  IBM Compilers
QuickBASIC Versions 2.0 & 3.0
  QuickBASIC Version 4.0
  The Header File
  Defining Terms
  Call Format
  Interface Modules
TURBO BASIC
  The Header File
  Call Format
  Interface Modules

This chapter discusses issues when programming in Interpreted BASIC or one of its compiled versions. The first part of the chapter explores elements needed to develop an application in Interpreted BASIC. The second part of the chapter indicates programming differences between Interpreted BASIC and its compiled forms.
 

INTERPRETED BASIC

Application programs can easily be written in Interpreted BASIC. Issues such as starting the application, error checking and string management are discussed in the paragraphs below. The LABMENU.EXE application program supplied with LabPac is written in QuickBasic 4 and contains many programming examples.


The Header File

Essential information for accessing LabPac functions from an application is contained in a header file in the BASIC section of the LabPac software. Every Interpreted BASIC application program should contain the LABHEAD.BAS file as the first section of the program. This file contains definitions of the function labels used by Calls, default I/O address variables, and an error checking routine. Additionally LABHEAD.BAS identifies where LABPAC.COM is loaded into memory.

LABHEAD.BAS is a text file and can be printed out using the DOS PRINT command. List it on the monitor using the following command:

TYPE LABHEAD.BAS

The different features of LABHEAD.BAS are described below.

Line DEFINT indicates that all variables are defined as integers unless otherwise specified through special symbols (i.e., $, %).

From all other languages, the memory resident portion of LabPac is accessed directly through software interrupt 66 hexadecimal. Interpreted BASIC, however, has structural features which do not allow direct access to LabPac through software interrupts. Instead, interrupt vector Fl hexadecimal is used to store a memory pointer to an entry subroutine for Interpreted BASIC in LabPac.

DEF SEG, LABSEG etc.. look at the Fl hexadecimal interrupt vector to identify the segment and offset of the address where LABPAC.COM was loaded into memory. The segment portion of the address is placed in the variable LABSEG. The offset portion of the address is placed in the variable LABPAC.

The application is then enabled to use Calls through that address to LabPac with the DEF SEG = LABSEG command. If the BASIC PEEK, POKE, BSAVE, BLOAD, or CALL (to user defined routines other than LabPac) statements are used in the application, return to the default segment address for the BASIC workspace using the statement shown below:

DEF SEG

After the execution of those commands return to the memory address for LabPac using the following statement:

DEF SEG = LABSEG

If the default segment is not reset to the LabPac segment, then Calls to LabPac may cause the computer to crash.

These DEF SEG, LABSEG=, DEG SEG Lines must be in all Interpreted BASIC applications.

Next group of statements identify which function numbers go with which Calls.

The 'MAXxx =' statements identifies the maximum values that the different channels can take.

Next statements identifie which hardware IRQ line is to be used.

Next group of statements define the default address parameters for each of the five Scientific Solutions boards. Lab Master and Lab Master DMA use the same address. If one or more of these boards are installed at a default address place one or more of the following statements on the appropriate line number in your application program. Delete lines that will not be used.

5 TENDER% = 1

6 MASTER% = 1

7 DADIO% = 1

8 BB% = 1

The purpose of these lines is to identify which of the default address variables are activated in the application. LabPac automatically initializes features on an Mc-DAS 16xx MicroChannel product, so its address parameters are not contained in LABHEAD.BAS. The address variable names and their default values used in LABHEAD.BAS are shown in the following table. If the boards are used at an address other than the default address, then these numbers would need to be changed to reflect the new base address.

Variable

Usage

ATOD A/D Control Register
  Lab Master Series = 0714h
  Lab Tender = 0330h
DTOA D/A Control Register
  Lab Master Series = 0710h
  Lab Tender = 0334h
LTIMER 9513A Data Port
  Lab Master Series = 0718h
  Lab Tender = 0338h
PIO Digital I/O Control Port
  Lab Master Series = 071Fh
  Lab Tender = 033Fh
DA DADIO D/A Ctrl = 0730h
DIO DADIO DI/O Ctrl = 073Bh
Base Board 8255A CTRL Ports
  BB0 = 0210h
  BB1 = 0214h