Code covered by the BSD License  

Highlights from
Agilent N6700B Power Supply - MATLAB Example

Agilent N6700B Power Supply - MATLAB Example


Adarsh Narasimhamurthy


Allows MATLAB to connect to an Agilent N6700B Power supply using SCPI, and set the output voltage.

N6700_Demo(voltage, chanIndex, overVoltage, currentProtState)
function [outputVoltage] = N6700_Demo(voltage, chanIndex, overVoltage, currentProtState)
% Function for communicating with an Agilent N6700B power supply.

% The function comprises of the following steps to communicate with the
% instrument:
%   1)  Create an interface object
%   2)  Connect to the instrument
%   3)  Configure properties
%   4)  Set the voltage and current values
%   5)  Disconnect from the power supply
% voltage        : Voltage value the N6700 should output (double datatype)
% chanIndex      : Channal index (double datatype)
% overVoltage    : the over-voltage protection (OVP) level of the output channel.
%                  The values are programmed in volts. If the output voltage exceeds
%                  the OVP level, the output is disabled. (double datatype)
% currentProState: enables or disables the over-current protection (OCP)
%                  function (boolean datatype)
% outputVoltage: Output voltage the N6700B is currently generating
% outputVoltage = N6700_Demo(5, 1, 10, 1);

% Copyright 2012 The MathWorks, Inc.
% Creation Time: 29 March 2012

% create a device object using TCPIP protocol
n6700 = tcpip('', 5025);

% setup relevant object properties
n6700.InputBufferSize = 8388608;
n6700.ByteOrder = 'littleEndian';

% connect to the instrument

% setup the instrument and the output voltage
chanlist = ['@' num2str(chanIndex)];
fprintf(n6700, '*RST');
fprintf(n6700, sprintf(':SOURce:VOLTage:LEVel:IMMediate:AMPLitude %f,(%s)', voltage, chanlist));
fprintf(n6700, sprintf(':SOURce:VOLTage:PROTection:LEVel %f,(%s)', overVoltage, chanlist));
fprintf(n6700, sprintf(':SOURce:CURRent:PROTection:STATe %d,(%s)', currentProtState, chanlist));
fprintf(n6700, sprintf(':OUTPut:STATe %d,(%s)', 1, chanlist));

% check if the above operations have been completed successfully
opcComp = sscanf(query(n6700, '*OPC?'), '%d');
while opcComp ~= 1
    opcComp = sscanf(query(n6700, '*OPC?'), '%d');

% measure the output voltage a 1000 times to calculate accuracy,
% repeatability and stability of the Agilent N6700B Power Supply

outputVoltage = zeros(1, 1000);
for i = 1:1000
    C = textscan(query(n6700, sprintf(':MEASure:SCALar:VOLTage:DC? (%s)', chanlist)), '%f', 'Delimiter', ',');
    outputVoltage(i) = C{1};

% close the object, and clear the workspace of the object
clear n6700;

% generate the required plots
subplot(1,2,1); plot(outputVoltage); 
xlabel('Iteration Number        '); 
ylabel('Output Voltage Reading  ');  
title ('Output Voltage Stability'); 
axis tight; hold all;

subplot(1,2,2); hist(outputVoltage, 1000);
xlabel('Output Voltage Value    ');
ylabel('Number of Occurences    ');
title ('Output Voltage Histogram');
axis tight; hold all;



Contact us