Generate a Swept Sinusoid Using VISA and Capture Waveform Using Quick-Control Oscilloscope
This example shows how to use a function generator to generate a swept sinusoid waveform and also how to capture it using an oscilloscope.
For a complete list of supported hardware, visit the Instrument Control Toolbox product page.
Requirements
This example was tested using a Keysight Technologies® 33522B function generator and a Tektronix® TDS 1002 oscilloscope. The GPIB addresses of the function generator and oscilloscope are GPIB0::5::INSTR and GPIB0::11::INSTR, respectively. The function generator is configured to generate a 2V p-p swept-sinusoid (20 to 200 Hz) with an offset of 1V every 100 ms on channel 1. The oscilloscope is configured to acquire a waveform on channel 1.
Configure the Oscilloscope
Configure the oscilloscope using a Quick-Control (oscilloscope).
scopeResource = "GPIB0::11::INSTR"; ch = "CH1";
Create an oscilloscope object and open a connection to the instrument.
scope = oscilloscope; scope.Resource = scopeResource; connect(scope)
The autoSetup
function automatically adjust channels, vertical, horizontal, and trigger controls based on connected signals.
autoSetup(scope)
Enable and configure channel 1.
enableChannel(scope,ch); configureChannel(scope,ch,"VerticalCoupling","DC")
Configure the channel to display at 1 VOLTS/DIV.
configureChannel(scope,ch,"VerticalRange",1)
Set probe attenuation to 1x (options include 1, 10, 100).
configureChannel(scope,ch,"ProbeAttenuation",1)
The AcquisitionTime
property represents the waveform duration in seconds. Setting the AcquisitionTime
will change the SEC/DIV
control accordingly. AcquisitionTime
typically corresponds to 10 divisions (or one screen of data).
scope.AcquisitionTime = 0.25; scope.TriggerLevel = 2.56; scope.TriggerSource = ch; scope.TriggerSlope = "rising"; scope.TriggerMode = "normal"; disp(scope)
oscilloscope: TEKTRONIX,TDS 1002 Instrument Settings: AcquisitionStartDelay: 'Not supported' AcquisitionTime: 0.25 s ChannelNames: 'CH1', 'CH2', 'MATH', 'REFA', 'REFB' ChannelsEnabled: 'CH1' SingleSweepMode: 'off' Timeout: 10 s WaveformLength: 2500 Trigger Settings: TriggerLevel: 2.56 TriggerSource: 'CH1' TriggerSlope: 'rising' TriggerMode: 'normal' Communication Properties: Status: 'open' Resource: 'GPIB0::11::INSTR' lists of methods
Configure the Function Generator
Configure the function generator to generate a sweep waveform using a VISA-GPIB object.
fgenResource = "GPIB0::5::INSTR";
vfgen = visadev(fgenResource)
vfgen = GPIB with properties: ResourceName: "GPIB0::5::INSTR" Alias: "FGEN_2CH" Vendor: "Agilent Technologies" Model: "33522B" BoardIndex: 0 PrimaryAddress: 5 SecondaryAddress: 65535 NumBytesAvailable: 0 Show all properties, functions
Configure the sweep amplitude and offset.
writeline(vfgen,"SOUR1:VOLT +1.0") writeline(vfgen,"SOUR1:VOLT:OFFS +1.0")
Enable sweep mode.
writeline(vfgen,"SOUR1:FREQ:MODE SWE"); writeline(vfgen,"SOUR1:SWE:STAT ON"); writeline(vfgen,"SOUR1:SWE:SPAC LIN");
Configure the start and stop frequencies.
fstart = 20; fstop = 200; writeline(vfgen,compose("SOUR1:FREQ:STAR %d",fstart)); writeline(vfgen,compose("SOUR1:FREQ:STOP %d",fstop));
Configure the time taken to sweep from the start frequency to the stop frequency as sweepTime
.
sweepTime = 0.1;
holdTime = 0;
returnTime = 0;
writeline(vfgen,compose("SOUR1:SWE:TIME %0.1f",sweepTime));
Configure time to remain at the stop frequency as holdTime
.
writeline(vfgen,compose("SOUR1:SWE:HTIME %0.1f",holdTime));
Configure the time required to return to the start frequency as returnTime
.
writeline(vfgen,compose("SOUR1:SWE:RTIME %0.1f",returnTime));
Configure the trigger.
writeline(vfgen,"TRIG1:SLOP POS"); writeline(vfgen,"TRIG1:SOUR IMM");
Acquire the Waveform
Acquire waveform data using the oscilloscope. The AcquisitionTime
property represents the waveform duration in seconds. The WaveformLength
property represents the number of points in the waveform data.
y = readWaveform(scope); t = linspace(0,scope.AcquisitionTime,scope.WaveformLength);
Plot the Waveform
plot(t,y) ylim([0.5,3.5]); title("Acquired waveform (sweep)") xlabel("Time (s)"); ylabel("Voltage (V)");
Clean Up
Clear the workspace when you are finished.
disconnect(scope) clear scope vfgen