Attached is a short matlab program that shows you how to open a visa session with an Agilent 33210A, 33220A, or 33250A in matlab and download an arbitrary waveform and output it with the function generator. The example is a very basic pulse waveform, you can create much more complex waveforms, I just wanted to make a simple example to get people started.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%{
AsciiArb is a sample program that demonstrates how to download an arbitrary waveform
into instrument volatile memory and play back the same with the configuration below:
This arb generates a 8192 point pulse waveform, of which the first 400 points define a
positive pulse from 0 volts to the maximum defined voltage amplitude.
Wave Shape: Arb
Amplitude: 2 Volt Peak to Peak
Offset: 0 Volt
Output Impedance: 50 Ohm
Output: Enabled
This example will work with the Agilent 33210A, 33220A, and 33250A
%}
% clears all variables, closes all open files
clear all; close all; clc;
%opens and creates a visa session for communication with function generator
fgen = visa('AGILENT','TCPIP0::156.140.92.62::inst0::INSTR');
set (fgen,'OutputBufferSize',100000);
fopen(fgen);
%Query Idendity string and report
fprintf (fgen, '*IDN?');
idn = fscanf (fgen);
fprintf (idn)
fprintf ('\n\n')
%Clear and reset instrument
fprintf (fgen, '*RST');
fprintf (fgen, '*CLS');
% Create arb waveform with 8192 points of 0-1 data
fprintf('Generating Waveform...\n\n')
rise=[];
for i = 1:1:10 % Set rise time (10 points) */
z = (i-1)/10;
y = num2str(z);
s1 = sprintf(', %s', y);
rise = [rise s1];
end
width=[];
for i= 11:1:411 % Set pulse width (400 points) */
y = num2str(1);
s2 = sprintf(', %s', y);
width = [width s2];
end
fall=[];
for i = 412:1:422 % Set fall time (10 points) */
z= (422 - i)/10;
y = num2str(z);
s3 = sprintf(', %s', y);
fall = [fall s3];
end
low=[];
for i = 423:1:8192 % Set remaining points to zero */
y = num2str(0);
s4 = sprintf(', %s', y);
low = [low s4];
end
%combine all of the strings
s = [rise width fall low];
% combine string of data with scpi command
arbstring =sprintf('DATA VOLATILE %s', s);
%Send Command to set the desired configuration
fprintf('Downloading Waveform...\n\n')
fprintf(fgen, arbstring);
%make instrument wait for data to download before moving on to next
%command set
fprintf(fgen, '*WAI');
fprintf('Download Complete\n\n')
%Set desired configuration.
fprintf(fgen,'VOLT 2'); % set max waveform amplitude to 2 Vpp
fprintf(fgen,'VOLT:OFFSET 0'); % set offset to 0 V
fprintf(fgen,'OUTPUT:LOAD 50'); % set output load to 50 ohms
fprintf(fgen,'FREQ 1000'); %set frequency to 1KHz
fprintf(fgen,'FUNC:USER VOLATILE');
fprintf(fgen,'FUNC:SHAP USER');
%Enable Output
fprintf(fgen,'OUTPUT ON'); % turn on channel 1 output
% Read Error
fprintf(fgen, 'SYST:ERR?');
errorstr = fscanf (fgen);
% error checking
if strncmp (errorstr, '+0,"No error"',13)
errorcheck = 'Arbitrary waveform generated without any error \n';
fprintf (errorcheck)
else
errorcheck = ['Error reported: ', errorstr];
fprintf (errorcheck)
end
%closes the visa session with the function generator
fclose(fgen);
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%{
AsciiArb is a sample program that demonstrates how to download an arbitrary waveform
into instrument volatile memory and play back the same with the configuration below:
This arb generates a 8192 point pulse waveform, of which the first 400 points define a
positive pulse from 0 volts to the maximum defined voltage amplitude.
Wave Shape: Arb
Amplitude: 2 Volt Peak to Peak
Offset: 0 Volt
Output Impedance: 50 Ohm
Output: Enabled
This example will work with the Agilent 33210A, 33220A, and 33250A
%}
% clears all variables, closes all open files
clear all; close all; clc;
%opens and creates a visa session for communication with function generator
fgen = visa('AGILENT','TCPIP0::156.140.92.62::inst0::INSTR');
set (fgen,'OutputBufferSize',100000);
fopen(fgen);
%Query Idendity string and report
fprintf (fgen, '*IDN?');
idn = fscanf (fgen);
fprintf (idn)
fprintf ('\n\n')
%Clear and reset instrument
fprintf (fgen, '*RST');
fprintf (fgen, '*CLS');
% Create arb waveform with 8192 points of 0-1 data
fprintf('Generating Waveform...\n\n')
rise=[];
for i = 1:1:10 % Set rise time (10 points) */
z = (i-1)/10;
y = num2str(z);
s1 = sprintf(', %s', y);
rise = [rise s1];
end
width=[];
for i= 11:1:411 % Set pulse width (400 points) */
y = num2str(1);
s2 = sprintf(', %s', y);
width = [width s2];
end
fall=[];
for i = 412:1:422 % Set fall time (10 points) */
z= (422 - i)/10;
y = num2str(z);
s3 = sprintf(', %s', y);
fall = [fall s3];
end
low=[];
for i = 423:1:8192 % Set remaining points to zero */
y = num2str(0);
s4 = sprintf(', %s', y);
low = [low s4];
end
%combine all of the strings
s = [rise width fall low];
% combine string of data with scpi command
arbstring =sprintf('DATA VOLATILE %s', s);
%Send Command to set the desired configuration
fprintf('Downloading Waveform...\n\n')
fprintf(fgen, arbstring);
%make instrument wait for data to download before moving on to next
%command set
fprintf(fgen, '*WAI');
fprintf('Download Complete\n\n')
%Set desired configuration.
fprintf(fgen,'VOLT 2'); % set max waveform amplitude to 2 Vpp
fprintf(fgen,'VOLT:OFFSET 0'); % set offset to 0 V
fprintf(fgen,'OUTPUT:LOAD 50'); % set output load to 50 ohms
fprintf(fgen,'FREQ 1000'); %set frequency to 1KHz
fprintf(fgen,'FUNC:USER VOLATILE');
fprintf(fgen,'FUNC:SHAP USER');
%Enable Output
fprintf(fgen,'OUTPUT ON'); % turn on channel 1 output
% Read Error
fprintf(fgen, 'SYST:ERR?');
errorstr = fscanf (fgen);
% error checking
if strncmp (errorstr, '+0,"No error"',13)
errorcheck = 'Arbitrary waveform generated without any error \n';
fprintf (errorcheck)
else
errorcheck = ['Error reported: ', errorstr];
fprintf (errorcheck)
end
%closes the visa session with the function generator
fclose(fgen);
I tried running your MATLAB code. And I had the following errors:
"
%%%%%%%%%%%%%%%%%%%%%%%%%%
Agilent Technologies,33250A,0,2.04-1.01-2.00-03-2
Generating Waveform...
Downloading Waveform...
??? Error using ==> icinterface.fprintf at 146
VISA: A timeout occurred
Error in ==> asciiarb33220A at 80
fprintf(fgen, arbstring);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
"
I think the program is able to understand the ID of the instrument but may be it needs to wait for more time. But, I don't understand this because you have use the "WAIT" (SCPI) command in the program. i.e.,
fprintf(fgen, '*WAI');
And when I try to re-run the program again, I get the following error.
"
??? Error using ==> icinterface.fopen at 82
The specified configuration: GPIB1::10::0::INSTR is not available.
Use INSTRHWINFO for a list of available configurations. Use INSTRFIND to
determine if other instrument objects are connected to the requested instrument.
Error in ==> asciiarb33220A at 25
fopen(fgen);
"
I don't understand why the port doesn't open. When I run the MATLAB command " INSTRFIND", the following message appears.
"
Instrument Object Array
Index: Type: Status: Name:
1 visa-gpib open VISA-GPIB1-10
2 visa-gpib closed VISA-GPIB1-10
"
Could you help me out please.
I have attached the MATLAB file that I ran and also the snapshot of the connection Expert showing the GPIB connection through which I'm communicating.
Regards,
Lokesh