The VLSI Systems Lab
Informations System Lab
Stanford University


GPIB Functions for use with Octave or Matlab
Michael D. Godfrey

The M-files in these directories provide an interface to the CEC GPIB interface card in a PC. The code should work with any PC running DOS or OS/2, using the CEC software product CECHP.EXE level 3.15 or above, and Matlab 4.0 through 4.2c2. Since in the past the Mathworks has changed the fread/fwrite interface in Matlab, there is no way of knowing whether later versions of Matlab will work correctly with this code. Workarounds have always been found in the past.

There is one major problem with the Matlab interface: Matlab does DOS file opens on any name given in the fopen('fname','xx') command. It does not check to see if 'fname' actually is a device, not a file. Sadly, DOS handles files and devices differently. The key difference is in the way binary mode is set. So, if under Matlab you do fopen('ieee','wb') where 'ieee' is the name of the GPIB device handler, the Matlab file open does not set binary mode. The effect of this is that transfers from Matlab to devices are treated as ASCII. ^Z causes the transfer to be terminated, since it is the wonderful DOS end-of-file indicator. Luckily, data coming from a device into Matlab all gets through, so this works as if binary mode had really been set. The instrument that this currently affects, in our set, is the HP8180A Data Generator. This instrument expects test vectors in binary (it also uses 2 GPIB addresses! watch for that in the code). Any test vector that contains ^Z () causes a failure. I reported this to the Mathworks and got the standard response: We will consider this as a candidate feature in Matlab 5.0. As we all know, the Mathworks does not accept the concept of an error in their code. When we get a copy of Matlab 5.0 we will see what happens. (Note: This has now been found out. Matlab 5.0 and above cannot use this code as it is since they do not allow direct access to drivers at all. Much of the higher level instrument control code can still be used, of course.)

Much of this code was originally written by Dan Naar when he was working for Dick Lyon at Apple Advanced Technology. Then the code was interfaced to a MEX coded routine using the Apple version of Matlab and a national Instruments Apple GPIB card. This system was made more complex and harder to maintain due to the need for the MEX code, and due to problems with the NI GPIB software.

I ported the code to the PC, wrote the M-file interface to the CEC GPIB card, modified many of the higher level routines, and implemented new instruments.

You will notice that the filenames are pretty obscure. This is due to the decision to keep within the DOS 8.3 length limit. This makes the code much less readable, but allows it to run on a plain DOS machine. (Even DOS sessions under OS/2 (the way we run Matlab) can use long (up to 254 characters) names.)

This code is in a continuing state of development and change as our needs dictate. One very incomplete item in the current files is in the directory named menus. This is a start on a menu-based version of the instrument interface using the Matlab (4.0 and above) GUI. Right now it is nothing more than a feasibility test.

Anyone who adds new facilities or support of new instruments is encouraged to send me their code. I will try to maintain an up-to-date copy of all files on our ftp site.

The hardware and software required or supported include:

1. PC/AT compatible sufficient to run Matlab 4.0

2. A CEC (Capital Equipment Corp. phone: 617-273-1818) GPIB card that supports their CECHP.EXE DOS software. (CECHP.EXE is a program which modifies the BIOS I/O to believe that a file named IEEE exists, but this file is in fact the GPIB card.)

3. A copy of MATLAB 4.0, through 4.2c.2 or possibly above.

4. I do not think any toolboxes are needed. The frequency response code uses FFT routines, but these are in the base Matlab.

5. We use OS/2 (currently WARP Connect) on all our PC's. This is very convenient and it works well, but is not required.

6. At present Matlab uses a lot of memory and has memory leaks. It is probably possible to run it in 8MB but 16MB is better, and 24MB is better still. This has nothing to do with the GPIB interface, which runs fine and uses hardly any memory. Matlab just runs slow due to swapping in small memory systems.

The currently supported instruments are:


instrument name function
Keithley 617 electrometer
Keithley 230 voltage source
HP-54601A scope
HP-3314A function generator
HP-8180-A Data Generator
HP-8182-A Data Analyzer
Arbitrary Device (Low level command interface to any instrument)

There was a time when the TEK-2440 was supported, but we do not have one and the code has faded badly. There are notes in the relevant code which indicate how the TEK-2440 differs from the HP-54601A. The functions that are supported by higher-level routines that call the instrument routines include:

1. Measurement of transistor IV-curves.

2. Measurement of static circuit behavior.

3. Measurement of frequency response behavior of circuits.

4. Loading of test vectors and acquisition of results.

To obtain this code download the file gpib.zip/

 

Last updated on 27 October 2001