Matlab code for Keithely 6517B to test I-V curve

Hello, thank you so much for helping me. I am a beginner of matlab so plz help me about my code.
I am using keithely 6517B and RS232 to connect with my computer, and use this matlab code for testing the I-V curve.
There always a error 803 (the keithely connection problem), but I am make sure the rs232 cable is working well.
Is this code has some problem? Matlab is 2020a
Thank you so much
% Clear workspace
clear all;
close all;
clc;
% Connect to the Keithley 6517B using RS232-to-USB
instr = instrfind('Type', 'serial', 'Port', 'COM3'); % Change 'COM3' to the appropriate COM port
if isempty(instr)
instr = serial('COM3', 'BaudRate', 9600, 'DataBits', 8, 'StopBits', 1, 'Parity', 'none', 'FlowControl', 'none', 'Terminator', 'CR');
else
fclose(instr);
instr = instr(1);
end
fopen(instr);
% Initialize Keithley 6517B
fprintf(instr, '*RST');
% Configure voltage range and source function
fprintf(instr, 'SOUR:FUNC VOLT');
fprintf(instr, 'SOUR:VOLT:RANG 2');
% Configure current range
fprintf(instr, 'SENS:CURR:RANG 1e-7');
% Set the sweep parameters
startVolt = -1;
endVolt = 1;
scanRate = 0.01;
numPoints = abs(endVolt - startVolt) / scanRate + 1;
timeStep = 1 / scanRate;
% Perform the sweep
voltages = linspace(startVolt, endVolt, numPoints);
currents = zeros(1, numPoints);
for i = 1:numPoints
% Set the voltage
fprintf(instr, ['SOUR:VOLT ' num2str(voltages(i))]);
% Measure the current
fprintf(instr, 'MEAS:CURR?');
currents(i) = str2double(fscanf(instr));
% Wait for the next step
pause(timeStep);
end
% Disconnect from the Keithley 6517B
fclose(instr);
% Plot the IV curve
figure;
plot(voltages, currents, 'o-');
xlabel('Voltage (V)');
ylabel('Current (A)');
title('IV Curve');
grid on;

2 件のコメント

chrisw23
chrisw23 2023 年 4 月 20 日
編集済み: chrisw23 2023 年 4 月 20 日
I suggest to use serialport instead of serial and try to set RTS
device = serialport("COM3",9600);
setRTS(device,true)
use methodsview(device) or details(device) to see which methods to be used for communication like write / writeline...
see also the cmd serialportlist (Introduced in R2019b)
Walter Roberson
Walter Roberson 2023 年 10 月 21 日
I am using keithely 6517B and RS232
For that device, if I understand correctly, more common would be to use the RS422 (GPIB) interface with Tek VISA drivers.

サインインしてコメントする。

回答 (1 件)

sajjad sahaf
sajjad sahaf 2023 年 10 月 21 日

0 投票

Hi Minhu Huang,
Did you find any solution for your problem? I would appreciate it if you or anyone else could share your solution on how to remotely get I-V characterization using 6517B and Rs-232..

2 件のコメント

chrisw23
chrisw23 2023 年 10 月 24 日
The device is controllable by VISA and an option is to setup the communication in the VISA vendors tool set. Choose first between Keysight Connection Expert or NI Measurement And Automation Explorer (MAX and NI-VISA). Setup the device for RS-232 communication and check some basic SCPI commands like *IDN?. If this works you can start to use the device in Matlab using the vendors VISA interface via .Net. i.e.
NET.addAssembly("IVI.Visa")
session = GlobalResourceManager.Open(visaAlias,Ivi.Visa.AccessModes.None,timeout)
Walter Roberson
Walter Roberson 2023 年 10 月 24 日
If you are using Windows or MacOS there is also the option of using the built-in VISA; https://www.mathworks.com/help/instrument/visa-overview.html
(If you are using Linux then you cannot use NET.addAssembly() anyhow.)

サインインしてコメントする。

質問済み:

2023 年 4 月 19 日

コメント済み:

2023 年 10 月 24 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by