Read LCR meter via Matlab

Loading

LCR-Meter 4297A Agilent

In this post I would like to devote myself to something else. It’s not about retro technology, it’s about a little thing that makes working in the office/lab easier. One of the many measuring devices I deal with is an old Agilent LCR meter. As is known, the LCR Meter 4297A can be used to measure the inductance, capacitance, etc. of electrical components and generally of structures which are assigned to the electronics / electrical engineering sector. Roughly speaking, the 4297A actually only measures current / voltage, the phase relationship between the two and the energy direction. And at a certain frequency. All parameters such as L, C, R, X, Y, Q, PHI, … are then mathematically calculated and output from these parameters. The frequency here can be set from 1MHz to 3GHz (in 100kHz steps). Ideally, the measuring device can measure not only in one frequency point, but also in many. By “many” is meant here that the measuring device can generate frequency tables with 32 entries. There are eight of these tables. This makes it possible to display the course of a measured variable in the form of a curve. However, this is quite cumbersome. The contents of the tables must be exported and saved manually (as “csv” files) table by table. This means that each table must be selected individually. Then select the “Export List View” dialog – then specify a storage path and file name. Only now are the first 32 records exported. This process must be repeated eight times in total. It is saved on a 3.5 inch floppy disc – the only available medium. You could also hang the 4297A optiona on a LAN and set up file sharing. However, manual export is not spared. The .csv files can now be opened on a “normal” computer. They must then be put together manually in postprocessing. Only now can a diagram be made from the data. Here Matlab from Matworks is a good tool, which is often used in our laboratories as part of training.

NI GPIB – USB Controller

To simplify this cumbersome process considerably, I created a small script that communicates with the measuring device using the SCPI commands (Standard Commands for Programmable Instruments). That means: The measuring device is connected to a PC via a GPIB-USB controller. A Matworks Matlab installation including the required toolboxes is located on the PC. The Matlab script should now simply switch through the tables in sequence and read out the contents of the individual parameters and save them in an array. The content of the arrays is then displayed directly in a plot. However, this method only uses the contents of the tables. It would of course also be possible to set any desired frequency directly in a loop using the script, read out the measured values, select the next frequency, etc. This would max. Total 29990 points over the entire frequency range. The eight tables, each with 32 points, only allow 256 points. For now, however, that is sufficient and also much faster.

Transmission Line 50 Ohm termination resistor
line is terminated

The example shows the impedance curve (Z curve) of a 50 Ohm transmission line. The end of the line is terminated with a 50 ohm resistor. The frequency range is 1MHz to 3 GHz. The situation is different if the line is open or closed briefly. The electromagnetic wave is then not converted into thermal energy at the end of the line, as in the “matched” system, but is reflected back into the system.

line is shortened

The following very simple Matlabscript enables the reading of the measuring device parameters. The script serves as an example of how to get the measurement data quickly. The programming manual of the manufacturer of the LCR meter lists all SCPI commandos and plenty of examples with which you can communicate with the measuring device.


%auslesen der agilent LCR Keule 4287A
%gekodet von ingmar bihlo Ende November 2017

%anschluss über gpib ni adapter
%LCR gpip adresse: 5
%%
%vorarbeiten an LCR Keule
%
% Es müssen 8 Tabellen mit je 32 Punkten definiert sein
% (power und average ist egal, wird nicht ausgelesen)
% die CALibration muss gemacht worden sein
% unter "measurement parameters" muessen vier parameter definiert sein
% zb. Z, qhi, R, L, etc... diese sind dann in den variablen param1 bis 4
% enthalten

%%

% gpib interface oeffnen und identifier lesen
g = gpib('ni', 0, 5);
g.InputBufferSize = 100000; % Set the buffer size
fopen(g);
fprintf(g, '*IDN?')
idn = fscanf(g);
fclose(g);

num1all=0; % initialisieren der variablen für den summenvector
num2all=0;
num3all=0;
num4all=0;
freq=0;

fopen(g);
%read list parameters (frequency points)
fprintf(g, ':SOUR:LIST?');
fpoint=fscanf(g);
listchar=strsplit(fpoint,',');
list=[cellfun(@str2num, listchar(:,1:end))]
clear listchat; clear fpoint;

%analyze list content
points=freq(1);

for i=1:8
%Tables selecten
fprintf(g, strcat(':SOUR:LIST:TABL 0',num2str(i)));
pause(1); %pause 1s zum umschalten der tabelle

%parameter1 abholen
fprintf(g, ':DATA:FDAT1?'); %parameter 1 anfragen
par1=fscanf(g); %parameter 1 holen

string1=strsplit(par1,','); %parameter 1 string nach komma zerlegen
%num1=[cellfun(@str2num, string1(:,1:end))] %parameter 1 strings in dec konvertieren
num1=[cellfun(@str2num, string1(:,1:end))];
num1all=[num1all,num1]; %parameter1 aktuell mit parameter1 aus vorherigem durchlauf concentenaten

fprintf(g, ':DATA:FDAT2?');
par2=fscanf(g);
string2=strsplit(par2,',');
num2=[cellfun(@str2num, string2(:,1:end))]
num2all=[num2all,num2];

fprintf(g, ':DATA:FDAT3?');
par3=fscanf(g);
string3=strsplit(par3,',');
num3=[cellfun(@str2num, string3(:,1:end))]
num3all=[num3all,num3];

fprintf(g, ':DATA:FDAT4?');
par4=fscanf(g);
string4=strsplit(par4,',');
num4=[cellfun(@str2num, string4(:,1:end))]
num4all=[num4all,num4];

%read list parameters (frequency points)
fprintf(g, ':SOUR:LIST?');
fpoint=fscanf(g);
listchar=strsplit(fpoint,',');
listraw=[cellfun(@str2num, listchar(:,1:end))];
list=listraw(:,2:end); %von pos2 das feld schreiben (an pos ist die anzahl der zeilen)

for c=1:3:96
freq=[freq,list(c)]; %von jedem 3. wert aus list ein neues array bilden
end

clear listchat; clear fpoint;

pause (1);
end

%%

%ausgabevariablen festlegen
frequency=freq(:,2:end);
param1=num1all(:,2:end);
param2=num2all(:,2:end);
param3=num3all(:,2:end);
param4=num4all(:,2:end);

%%
% Cell array richtig uma drahn
x1=param1(1:32);
y1=param1(33:256);
param1 = [y1 x1];

x2=param2(1:32);
y2=param2(33:256);
param2 = [y2 x2];

x3=param3(1:32);
y3=param3(33:256);
param3 = [y3 x3];

x4=param4(1:32);
y4=param4(33:256);
param4 = [y4 x4];
%%
%uerberflüssige variablen loeschen
clear c; clear i; clear list; %clear freq;
clear par1;clear par2;clear par3;clear par4;
clear string1;clear string2;clear string3;clear string4;
clear num1all;clear num2all;clear num3all;clear num4all;

fclose(g);

%plotten der ergebnisse
figure(1);
plot(frequency,param1);
grid on; hold on;
xlabel('Frequency [Hz]'); ylabel('Measurement Parameter1 |Z| [Ohm]');
title('Agilent LCR Keule');

figure(2);
plot(frequency,param2);
grid on; hold on;
xlabel('Frequency'); ylabel('Measurement Parameter2');
title('Agilent LCR Keule');

figure(3);
plot(frequency,param3);
grid on; hold on;
xlabel('Frequency'); ylabel('Measurement Parameter3');
title('Agilent LCR Keule');

figure(4);
plot(frequency,param4);
grid on; hold on;
xlabel('Frequency'); ylabel('Measurement Parameter4');
title('Agilent LCR Keule');

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.