# Using Matlab With The Xtralien X100

### Overview

You can communicate with your X100 board using either USB or ethernet. In the code examples here we primarily use USB as this is available to every copy of MATLAB and will work on most versions from 2008 onwards. Please note that to interface MATLAB to X100 using the ethernet interface will require the instrument control toolbox (in order to access the tcpip function).

In order to talk to the X100 we use a simple set of human readable commands - typically sending a command and then waiting for a response. This command language is called CLOI (Command Language for Ossila Instruments). This has been designed to be as intuitive as possible so that most CLOI commands should do what they say and be easy to understand.

### Helper Functions

In order to make life easier we've created some little helper functions to handle the communications between MATLAB and the X100. In order to use them you just need to put them in the same directory as your MATLAB script (for advanced users you can also put them in a separate directory and add that directory to the MATLAB path using the addpath function).

Click here to download the MATLAB Helper Functions for the Xtralien X100.

### Getting started - the helper functions:

The below basic helper functions allow you to start making a wide array of programs. For a full list and description of helper functions click here.

You can download a zip file with the helper functions in here (version 0.91)

 Function Name Actions OpenCLOI Open an interface to a CLOI instrument (i.e. the X100 board) SMU1 Set the voltage on source measure unit 1 (SMU1) and measure the current SMU2 Set the voltage on source measure unit 2 (SMU2) and measure the current CloseCLOI Close the interface to a CLOI instrument (i.e. the X100 board)

### Identifying your X100 COM port or IP address.

To start communicating to the X100 you need to know the COM port number if you are using USB or the IP address if you are using Ethernet/Internet. If you aren't familiar with this you can find out how to identify the X100 COM port and IP address here.

### Getting going - some basic programs

So you've got the helper functions unzipped and you want to start coding. No problem - it's very straight forward. Here's some example programs. If you're new to programming the green lines are comments and aren't required - they're just there to explain everything.

#### Program 1 - output a voltage and measure a current.

This is about the simplest program it's possible to make. It's just three lines long (plus a load of comments to explain what we're doing) and sets the voltage and measures the current on SMU1.

%I generally like to start any script by clearing all current variables and
%closing all plots and files and interfaces - i.e. just starting with a
%clean slate:
clear all
clear global
close all
clc

%we also need to add the directory for the helper functions so Matlab
%knows where to find them(this could be anywhere you want but is usually in
%a subdirectory of this demo code. You only actually need to do this once
%per computer but it doesn harm to leave it in either.
addpath('./HelperFunctions')

%Open an interface to Xtralien using the OpenCLOI command.
%All we need to know is the COM port number (in this case COM3 but you can
%identify it by using Device Manager on Windows.
%The OpenCLOI function returns an instrument identifier which in this case
%we'll call Xtralien1 (if we had another instrument connected at the same
%time we could call that Xtralien2).
Xtralien1=OpenCLOI('COM3');

%first of all let specify what measurement range we're using.
%Range 	Max Current 	Accuracy
%1      100 mA          10 µA
%2      10 mA           1 µA
%3      1 mA            100 nA
%4      100 µA          10 nA
%5      10 µA           1 nA
%IMPORTANT NOTE:
%The range on the Xtralien needs to be set in hardware as well as software
%by using the small switches (see website or user manual).
SetRange(Xtralien1,'SMU1', 1) %Here we'll use range 1 on SMU1

%We also want to specify the measurement speed (slower=more accurate).
%You can specify an OSR rate from 1 (fastest) to 9 (slowest)
SetOSR(Xtralien1,'SMU1', 5);

%Now lets set the voltage on SMU1 to 1 volt and measure the current
%We do this by calling the SMU1 command which needs to know which
%instrument it is talking to (in this case Xtralien1m and what voltage to
%set (in this case 1 volt).
[V,I]=SMU1(Xtralien1,1)
%After it has set the voltage on SMU1, it returns the measured voltage as V
%and the measured current as I. Note that in most cases the set voltage and
%the measured voltage should be the same. However, in some cases (such as
%if the device you're trying to measure is short circuited) there could be
%a difference.

%Now that we've finished our measurement we can close the interface.
CloseCLOI(Xtralien1);

%That's it. Our first measurement taken.


#### Program 2 - Now to do something useful.

Now to do something useful. Lets write a current voltage sweep (also called and IV sweep or JV sweep) which is used for a wide array of devices (diodes, LEDs, OLEDs, etc).

%Open a CLOI interface to the Xtralien board using COM and call it Xtralien1
Xtralien1=OpenCLOI('COM3');

%first of all let specify what measurement range we're using.
%Range 	Max Current 	Accuracy
%1      100 mA          10 µA
%2      10 mA           1 µA
%3      1 mA            100 nA
%4      100 µA          10 nA
%5      10 µA           1 nA
%IMPORTANT NOTE:
%The range on the Xtralien needs to be set in hardware as well as software
%by using the small switches (see website or user manual).
SetRange(Xtralien1,'SMU1', 1) %Here we'll use range 1 on SMU1

%We also want to specify the measurement speed (slower=more accurate).
%You can specify an OSR rate from 1 (fastest) to 9 (slowest)
SetOSR(Xtralien1,'SMU1', 5);

%Now lets loop through some voltages. Here we're going to use the matlab
%syntax start:step:stop to create a sweep from -1 Volts to +1 volts in 0.1
%volt (100 mV) steps.
for set_voltage=-1:0.1:1
%for each voltage that we loop through we'll use the SMU1 command to
%apply the desired set_voltage and then measure the actual voltage (V)
%and current (I).
[V,I]=SMU1(Xtralien1,set_voltage);
%Now lets plot the data points so we can see what's happening. Note
%that we put the hold on so that we don't lose one data point when we
%plot the next.
plot(V,I,'X'); hold on;
%We can also display th data in the main matlab command widow if we want.
disp([V,I]);
end

%Now that we've finished our measurement we can close the interface.
%However, before we do it's always good practice to set the voltages back
%to zero again.
[V,I]=SMU1(Xtralien1,0); %set the voltage back to zero
CloseCLOI(Xtralien1); %and close the interface



Note that in this case we are taking a sweep point-by-point and that instead of using the "for" loop we could just use the SMU1_sweep command (see below example) which would take less programming and make the measurement quicker. However, there are a great many cases where being able to control a sweep directly is very useful as we'll see later on in example 4.

### Program 3 - Performing a sweep in a slightly more advanced way

In this program we collect exactly the same data as for program 2 but do it in a more advanced and efficient way. Rather than looping through the voltages using a "for" loop and then collecting and returning a single data point at a time, we use the X100 in-built sweep function to collect everything at one time and return it in one go. It's collects and returns the data more quickly and also makes the code simpler. However, there's always a down side and that is it becomes slightly less versatile.

%Open a CLOI interface to the Xtralien board using COM and call it Xtralien1
Xtralien1=OpenCLOI('COM3');

%first of all let specify what measurement range we're using.
%Range 	Max Current 	Accuracy
%1      100 mA          10 µA
%2      10 mA           1 µA
%3      1 mA            100 nA
%4      100 µA          10 nA
%5      10 µA           1 nA
%IMPORTANT NOTE:
%The range on the Xtralien needs to be set in hardware as well as software
%by using the small switches (see website or user manual).
SetRange(Xtralien1,'SMU1', 1) %Here we'll use range 1 on SMU1

%We also want to specify the measurement speed (slower=more accurate).
%You can specify an OSR rate from 1 (fastest) to 9 (slowest)
SetOSR(Xtralien1,'SMU1', 5);

%Now lets run a sweep using Xtraliens in-built sweep function. This time we
%don't need to do a for loop we just use the SMU1_sweep function. In this
%case we're going to sweep from -1 volt in 0.1 volt incriments to +1 volt.
%Note that we have the option of either performing a single or double
%sweep. A single sweep just goes from the start to stop voltage but a
%double sweep then does the same in reverse and sweeps back to the start
%voltage again. This is often useful for measuring hysterises in real
%devices.
[V,I]=SMU1_sweep(Xtralien1, -1,0.1,1,'single');
%Note that in this case V and I are now arrays of data rather than single
%data points (each with 21 rows and 1 column in this case).

%And again we can display in the main window
disp([V,I]);
%and plot on screen
plot(V,I);

%Now that we've finished our measurement we can close the interface.
%As usual lets set the voltages back to zero again first though.
[Vx,Ix]=SMU1(Xtralien1,0); %set the voltage back to zero
CloseCLOI(Xtralien1); %and close the interface



The same type of dual-SMU code can be used for a wide variety of devices such as transistors and sensors.