Code covered by the BSD License  

Highlights from
Dynamic Signal Analyzer 34411A

image thumbnail

Dynamic Signal Analyzer 34411A

by

 

This program turns your DMM into a Dynamic Signal Analyzer.

talkTo34411A(sRate, sCount, range, address)
function [readings] = talkTo34411A(sRate, sCount, range, address)
%TALKTO34411A Code for communicating with the 34411A, L4411A, and 34410A DMMs.
% This function Connects, sets up, and gets the readings from the DMM
% The sRate argument sets the sample for the DMM. The sCount argument sets
% the sample or measurement count of the DMM. The range argument sets the
% voltage range of the DMM. The address argument is the IP address of the 
% DMM to connect via LAN. The function sets up and excutes the DMM to use
% as a digitizer
%   Creation time: 14-Feb-2012 15:11:04

%create IP address string
vAddress = ['TCPIP0::' address '::inst0::INSTR'];

% Find a VISA-TCPIP object.
obj1 = instrfind('Type', 'visa-tcpip', 'RsrcName', vAddress, 'Tag', '');

% Create the VISA-TCPIP object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
    obj1 = visa('AGILENT', 'TCPIP0::148.5.251.34::inst0::INSTR');
else
    fclose(obj1);
    obj1 = obj1(1);
end

%calculate input buffer for fetching measurements, each readings is 16 chars long
buffer = 16*500;

% Configure instrument object, obj1
set(obj1, 'InputBufferSize', buffer);

% Configure instrument object, obj1
%set(obj1, 'OutputBufferSize', 2000);

% Connect to instrument object, obj1.
fopen(obj1);

%preallocate array to store measurements
readings = zeros(1,sCount);

%Get the identity of DMM we are talking to
data1 = query(obj1, '*IDN?');
% print reply
fprintf('%s',data1);

%Reset at DMM to known state
fprintf(obj1,'*RST');

%Set the measurement function to DC Volts
fprintf(obj1,'FUNC "VOLT:DC"');

%build voltage measurement range command
command = ['VOLT:DC:RANG ' num2str(range)];
%Set the measurement range
fprintf(obj1,command);

%build aperture time command, this must match sample period
command = ['VOLT:DC:APER ' num2str((1/sRate))];
%send sample interval command
fprintf(obj1,command);

%Set the input Z to 10 MOhm
fprintf(obj1,'VOLT:DC:IMP:AUTO OFF');

%Turn off the peak measurements
fprintf(obj1,'VOLT:DC:PEAK:STAT OFF');

%Turn off auto zero, it slows down measurement speed
fprintf(obj1,'VOLT:ZERO:AUTO OFF');

%Turn off null function
fprintf(obj1,'VOLT:NULL:STAT OFF');

%Turn off stat function
fprintf(obj1,'CALC:STAT OFF');

%Set the trigger to immediate
fprintf(obj1,'TRIG:SOUR IMM');

%Set the trigger count to 1
fprintf(obj1,'TRIG:COUN 1');

%Turn off trigger delay
fprintf(obj1,'TRIG:DEL:AUTO OFF');

%build sample count command
command = ['SAMP:COUN ' num2str(sCount)];
%send sample count command
fprintf(obj1,command);

%Set pre trigger to 0 (which basically turns it off)
fprintf(obj1,'SAMP:COUN:PRET 0');

%This sets the sample rate source to internal timer
fprintf(obj1,'SAMP:SOUR TIM');

%build sample interval command
command = ['SAMP:TIM ' num2str((1/sRate))];
%send sample interval command
fprintf(obj1,command);

%Set the meas done output trigger from DMM to neg
fprintf(obj1,'OUTP:TRIG:SLOP NEG');

%initiate measurement, if trigger is immediate then this will trigger the
%measurement
fprintf(obj1,'INIT');

%check for error
data1 = query(obj1,'SYST:ERR?');
% print reply
fprintf('Any Errors-->%s',data1);

%read measurements or readings from instrument
fprintf(obj1,'Fetch?');

tempCount = sCount; %iterate value for scan count
i = 1; %loop tracking variable

%Loop until all the measurements are read
while tempCount > 0
    
    if tempCount >= 500 %if more than 500 readings in memory, read 500
        tempBin = fread(obj1,(16*500));%readings is 16 chars long
    else %if less than 500 readings read them all
        tempBin = fread(obj1,(16*tempCount));
    end
    %covert binary to char and then string
    tempChar = char(tempBin)';
    tempChar = strrep(tempChar, ',', ' ');
    
    t=strread(tempChar); %create array of double and store in temp variable
 
    %replace array of string values to array of doubles
    if tempCount >= 500 %if there 500 or more 
        if length(t) > 500 %if the array has an extra number get rid of it
            t(501) = [];
        end
        %build array of readings
        if i ~= 1
            readings((((i-1)*500)+1):(i*500)) = t;
        else
            readings(1:500) = t;
        end
    else %if there are less than 500 readings 
        if length(t) > tempCount %if the array has an extra number get rid of it
            t((tempCount+1)) = [];
        end
        if i ~= 1
            readings((((i-1)*500)+1):(i*tempCount)) = t;
        else
            readings(1:tempCount) = t;
        end
    end
    tempCount = tempCount - 500; %iterate down loop variable
    i = i + 1; %iterate up loop tracking variable
end

% Disconnect from instrument object, obj1.
fclose(obj1);

% Clean up all objects.
delete(obj1);

Contact us