Hello everyone, I converted the example programs provided with the 33521A and 33522A to Matlab and attached them below. There are 9 examples ranging from how to program the instrument to ouput a simple sine wave, to more complex examples showing how to create a Sequence.
%{
Arb Sequence is a sample program that demonstrates how to define an Arb Sequence which consists
of one or more different arb segments and play back the same using the following configuration:
Wave Shape: Arb Sequence
Frequency: 40 KSa/Sec
Amplitude: 2 Volt Peak to Peak
Offset: 0 Volt
Output Impedance: 50 Ohm
Channel1 Output: Enabled
Caution: All un-saved data present in volatile memory will be erased.
Save information before proceeding to this example program.
%}
% 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.215::inst0::INSTR');
fopen(fgen);
%Query Idendity string and report
fprintf (fgen, '*IDN?');
idn = fscanf (fgen);
fprintf (idn) %prints *IDN? results to the screen
fprintf ('')
%Clear and reset instrument
fprintf (fgen, '*RST');
fprintf (fgen, '*CLS');
pause (1);
%Clear volatile memory
fprintf(fgen,'SOURce1:DATA:VOLatile:CLEar');
%Loading arb files into waveform memory.
fprintf(fgen,'MMEM:LOAD:DATA "INT:\BUILTIN\SINC.ARB"');
fprintf(fgen, '*WAI'); % wait for operations to complete before moving on
fprintf(fgen,'MMEM:LOAD:DATA "INT:\BUILTIN\CARDIAC.ARB"');
fprintf(fgen, '*WAI'); % wait for operations to complete before moving on
fprintf(fgen,'MMEM:LOAD:DATA "INT:\BUILTIN\HAVERSINE.ARB"');
fprintf(fgen, '*WAI'); % wait for operations to complete before moving on
%Build a sequence descriptor string consisting of arb waveform segments.
sequencename = 'mySequence';
sinc = '"INT:\BUILTIN\SINC.ARB",5,once,maintain,12';
cardiac = '"INT:\BUILTIN\CARDIAC.ARB",50,repeat,highAtStart,35';
haversine = '"INT:\BUILTIN\HAVERSINE.ARB",0,once,lowAtStart,10';
sinc2 = '"INT:\BUILTIN\SINC.ARB",0,once,highAtStartGoLow,7';
%combine all of the above strings into one string
SeqDescriptor = [sequencename ',' sinc ',' cardiac ',' haversine ',' sinc2];
%Calculate the header of sequence command.
strLength = length(SeqDescriptor);
header = num2str(strLength); %converts to string
headerlength = length(header);
digits = num2str(headerlength); %converts to string
%Combine the header information and the sequence.
sequencestring = ['SOURce1:DATA:SEQ #' digits header SeqDescriptor]
%Set desired configuration.
fprintf(fgen, sequencestring);
fprintf(fgen, '*WAI');
fprintf(fgen,'SOURce1:FUNCtion:ARBitrary mySequence');
fprintf(fgen, '*WAI');
fprintf(fgen,'SOURCE1:VOLT 2');
fprintf(fgen,'SOURCE1:VOLT:OFFSET 0');
fprintf(fgen,'OUTPUT1:LOAD 50');
fprintf(fgen,'SOURCE1:FUNCtion:ARB:SRATe 40000');
fprintf(fgen,'SOURce1:FUNCtion ARB');
%Enable output.
fprintf(fgen,'OUTPUT1 ON');
% Read Error
fprintf(fgen,'SYST:ERR?');
errorstr = fscanf (fgen);
% error checking
if strncmp (errorstr, '+0,"No error"',13)
errorcheck = 'Arb sequence generated without any error';
fprintf (errorcheck)
else
errorcheck = ['Error reported: ', errorstr];
fprintf (errorcheck)
end
%closes the visa session with the function generator
fclose(fgen);