MATLAB® is a well-known interactive software environment and programming language with more than 1,000,000 users. MATLAB is used to generate waveforms for instruments, acquire and analyze measurements, and build test systems. You can analyze and visualize data in MATLAB using interactive tools and command-line functions for data analysis tasks such as signal processing, statistical analysis, digital filtering, and curve fitting. MATLAB supports using IVI instrument drivers with the MATLAB Instrument Control Toolbox.
This note demonstrates how to use Keithley’s Model 3706 Six-Slot System Switch with an integrated DMM to illustrate how to configure and control Keithley instruments from the MATLAB software environment using Keithley IVI instrument drivers. Although we are using an IVI instrument driver for a Keithley 3706 switch in this example, all Keithley IVI drivers can be installed and operated in much the same way. Following the steps outlined here allows you to use MATLAB easily to interface with any Keithley instrument that is supplied with an IVI-COM or IVI-C instrument driver
IVI (Interchangeable Virtual Instrument) drivers are designed to allow a software development environment to control instruments using a set of commands common to a group or class of instruments. For instance, all DMMs have many of the same capabilities, regardless of the manufacturer. Using an IVI instrument driver helps system designers create tests and solutions that are independent of a particular individual instrument model because the same IVI command set can be interpreted by a number of similar instruments. Keithley Instruments provides IVI drivers for many of its most popular instrument models.
MATLAB software supports open instrument standards including IVI instrument drivers with the MATLAB Instrument Control Toolbox. Once the IVI instrument driver is installed on your computer, you can automatically generate a MATLAB driver (wrapper) from the IVI instrument driver by following the instructions in the MATLAB IVI chapter in the documentation. As a convenience to Keithley instrument users, we have created many of these MATLAB drivers for you. This guide will walk you through installing and configuring the Keithley IVI driver and then the associated MATLAB driver for your instrument. This guide will also provide helpful hints on getting started using MATLAB to acquire your data.
Before you start
Before installing software drivers for your instrument, make sure you can communicate with your hardware. Keithley Instruments products have a number of PC interface options. For example, the Model 3706 System Switch/DMM can be controlled via GPIB, LXI (Ethernet), or USB. The IVI driver supports all of theseconnection types.
Follow the instructions that came with your instrument to connect it physically to your PC using the interface of your choice.
Before installing the IVI driver, two software utilities must be installed on your system:
- Virtual Instrument Software Architecture (VISA)
- IVI Shared Components
- If you already have these utilities installed, continue on to the next section. Otherwise, the Keithley IOLayer, which will install both of these components, can be downloaded at: http://www.keithley.com/data?asset=50932.
Note: Check the release notes included with the version of the IVI driver you plan to install to verify its compatibility with the versions of VISA and the IVI shared components you plan to use.
Installing the Keithley IVI Driver
Once you have installed the Keithley IOLayer (or the IVI shared components and VISA separately), you are ready to install the IVI driver for your instrument. Locate the driver on the product CD or the specific instrument page at www.keithley.com.
The name of the installer for the Model 3706 System Switch/DMM is Ke37XX.126.96.36.199.msi, which indicates the model family and driver version. Installers for other instruments employ similar naming conventions. Copy the file to your hard drive and then open it. An installation wizard will appear (Figure 1).
Once the installation process is complete, the IVI driver will be installed and operational.
Installing the MATLAB driver
Next, locate the MATLAB driver designed for use with the Keithley product with which you will be working. These drivers use the file extension *.mdd and can be downloaded at www.keithley.com or on MATLAB Central available through www.mathworks.com/keithley. Note: MATLAB Central is maintained by The MathWorks, the creators of MATLAB. For example, the filename for the Model 3706 MATLAB driver is called: ke37XX.mdd.
Download this file to your local hard drive and make sure it is in your MATLAB working directory.
MATLAB needs to locate the MATLAB instrument driver, so now make sure MATLAB is installed on your computer. Note: MATLAB version R2008a or newer is required to use MATLAB with IVI instrument drivers such as those discussed in this application note.
After you start MATLAB, you should see the *.mdd file appear in the current directory window. If not, browse to the driver file you downloaded and save the file to your working directory.
Now that you have loaded the MATLAB driver as well as the IVI driver for your instrument, you can take control of the instrument from the MATLAB command line by executing the following command to create the object (obj):
>> obj = icdevice('ke37XX.mdd','GPIB0::16::INSTR')
For these commands, 'ke37XX' is the name of the IVI driver, 'ke37XX.mdd' is the name of the MATLAB driver (*.mdd file), and "GPIB0::16::INSTR" is a VISA reference used to find the instrument location. In this example, we are using GPIB (General Purpose Instrument Bus) to connect to the instrument. VISA can also use USB or Ethernet to connect to this instrument. Interface options vary by instrument model.
If you chose to install the Keithley IOLayer as part of the “Before You Start” section, you can use the Keithley Configuration Panel to help discover the instrument location for you.
Using the driver in MATLAB
Now you can access the instrument driver from the MATLAB command line using the IVI driver functions. First, let’s look at some basic functions you can use to get familiar with the object we created:
Step 1: Connect to the instrument
This command opens a VISA session with the instrument, enabling further communication. Make sure to call the connect function immediately after creating the object.
Step 2: Verify instrument connection
Instrument Device Object Using Driver: ke37xx
Type: IVI Instrument
Manufacturer: Keithley Instruments
DriverType: MATLAB IVI
The display(obj) function returns information about your instrument, such as the IVI driver version number and the communication status. The communication Status should be “open” once the connect(obj) function has been called.
Step 3: Resetting the instrument
The ‘devicereset(obj)’ function resets the 3706 instrument to its default state.
Step 4: Open the Driver Editor
>> midedit 'ke37XX.mdd'
This command opens the MATLAB Instrument Driver Editor (see Figure 2). From here, you can view the organization of the MATLAB functions and properties and see how to access the commands that are applicable to your application.
For example, you can navigate through that list of components to Groups/Measurement/Functions and find the function called ‘measure’. To access this command, first create a group (called “Measurement” in the example) by entering:
>> Measurement = get(obj,'Measurement')
Then, you can find the help for that function from the command line like this:
The Help message for this function reads: Performs a measurement and returns the last reading taken.
To execute the function in MATLAB, use 'invoke':
>> meas = invoke(Measurement,'Measure')
Calling this function prints a response like this to the commands line: meas = 0.0065
In this example, this command returned a measurement of 6.5mV.
In this way, MATLAB users can access all the features of an instrument through its IVI driver interface.
Note: The MATLAB Instrument Control Toolbox also provides a graphical tool called Test & Measurement Tool that allows you to configure and control your Keithley instruments without writing MATLAB script. In fact, Test & Measurement Tool automatically generates MATLAB script as you interact with the tool. Visit www.mathworks.com/tmtool for more information on using Test & Measurement Tool.
Here is an example of a test that shows you how to use many of the common IVI functions in MATLAB and then returns a series of readings:
Example of a MATLAB Test:
%This example test Measures and plots 100 DC voltage
%readings with the Model 3706 DMM using a reading buffer.
% The text following a '%' (percent sign) on a line are
%comments explaining the following code.
%Creates an object 'obj' which we will use to communicate to an
%instrument through the IVI instrument driver.
obj = icdevice('ke37XX.mdd','GPIB0::16::INSTR');
%Connects us to the instrument by opening a VISA session
%using GPIB in this case.
%These 4 lines create variables that link to the Groups
%in the driver we will access.
Measurement = get(obj,'Measurement');
Measurementbuffer = get(obj,'Measurementbuffer');
Measurementbufferreadingdata = get(obj,'Measurementbufferreadingdata');
%Setting 3 properties in the Measurement Group using the set function.
set(Measurement ,'AutoRange', 'on');
%Creating a reading buffer of size 100 on the
%3706 by invoking the Create function in the
%Measurementbuffer group. This function takes the
%Buffer name and size as parameters.
invoke ( Measurementbuffer, 'Create','MyBuf',100);
%Filling the buffer 'MyBuf' with readings by invoking
%the MeasureMultiple function in the Measurement Group.
%This function takes the Buffer name as a parameter.
%Retrieving the buffer readings in 'MyBuf' by invoking the
%GetAllReadings function in the Measurementbufferreadingdata Group.
%This function takes the Buffer name as a parameter.
%The readings are placed in a variable called readings.
readings = invoke(Measurementbufferreadingdata,'GetAllReadings','MyBuf');
%Retrieving the relative timestamps from the buffer 'MyBuf'
%by invoking the GetAllRelativeTimeStamps function in the
%This function takes the Buffer name as a parameter.
%The readings are placed in a variable called timestamps.
timestamps = invoke(Measurementbuffertimestampdata,'GetAllRelativeTimeStamps','MyBuf');
%Plots the readings vs. timestamps on a graph and
%sets the axis labels appropriately.
%disconnect VISA session with Model 3706
MATLAB® is a well known software environment and programming language used to generate waveforms for instruments, acquire and analyze measurements, and build test systems. MATLAB supports using IVI instrument drivers with the MATLAB Instrument Control Toolbox.
Connecting MATLAB to the IVI driver structure for an instrument offers a quick and easy method of getting your instrumentation up and running in the MATLAB software environment. Combining the power of MATLAB as an analytical tool with precision measurement capabilities from Keithley Instruments simplifies advanced measurement and analysis challenges by eliminating many of the difficulties users have traditionally faced learning how to interface their instrument and their software environment.
Find more valuable resources at TEK.COM
Copyright © Tektronix. All rights reserved. Tektronix products are covered by U.S. and foreign patents, issued and pending. Information in this publication supersedes that in all previously published material. Specification and price change privileges reserved. TEKTRONIX and TEK are registered trademarks of Tektronix, Inc. All other trade names referenced are the service marks, trademarks or registered trademarks of their respective companies.