generate a swept sinusoid using visa and capture waveform using quick-凯发k8网页登录
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 .
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