%% AWG MATLAB ICT Send Waveform 3 % Date 10-9-2009 % ================== % Send a waveform the an AWG using the Real format % % PREREQUISITES % ================== % ALL MATLAB ICT Control 1 (Hello World) % ALL MATLAB ICT Control 2 % AWGxxxx MATLAB ICT Send Waveform 1 % AWGxxxx MATLAB ICT Send Waveform 2 % ================== % % COMPATIBILITY % ================== % AWG5000, AWG5000B, AWG7000, AWG7000B % ================== % % TESTED & DEVELOPED % ================== % Microsoft Windows XP SP3 % TekVISA 3.3.2.7 % MATLAB Version 7.9.0.529 (R2009b) % Instrument Control Toolbox Version 2.9 % GPIB: National Instruments PCMCIA-GPIB (ni488k.sys v2.6.0f0) % AWG5012B v3.3 % ================== %% variables visa_vendor = 'tek'; visa_address = 'GPIB0::4::INSTR'; buffer = 2 * 1024; samples = 1200; cycles = 2; %% pre-processing % example waveform step = (2 * pi) / samples; cycles = cycles * 2 * pi; t = 0:step:cycles-step; y = single(2*sin(t)); clear t step cycles; % free up memory % example marker % initialize marker 1 all low m1 = zeros(1,samples,'uint8'); % set marker 1 bits 2 to 11 high m1(2:12) = 1; % encode marker 1 bits to bit 6 m1 = bitshift(uint8(logical(m1)),6); %check dec2bin(m1(2),8) % initialize marker 2 all low m2 = zeros(1,samples,'uint8'); % set marker 2 ouput clock = sampling rate, starting low m2(2:2:end) = 1; % encode marker 2 bits to bit 7 m2 = bitshift(uint8(logical(m2)),7); %check dec2bin(m2(2),8) % merge markers m = m1 + m2; %check dec2bin(m(2),8) clear m1 m2; % stitch wave data with marker data as per progammer manual binblock = zeros(1,samples*5,'uint8'); % real uses 5 bytes per sample for k=1:samples binblock((k-1)*5+1:(k-1)*5+5) = [typecast(y(k),'uint8') m(k)]; end clear y m; % build binblock header bytes = num2str(length(binblock)); header = ['#' num2str(length(bytes)) bytes]; %% instrument communication % initialize the instrument awg = visa(visa_vendor,visa_address,'InputBufferSize',buffer, ... 'OutputBufferSize',buffer); fopen(awg); % create waveform destination fwrite(awg,[':wlist:waveform:new "newwave1",' num2str(samples) ',real;']); % write waveform data cmd = [':wlist:waveform:data "newwave1",' header binblock ';']; bytes = length(cmd); if buffer >= bytes %cmd fwrite(awg,cmd) else awg.EOIMode = 'off'; for i = 1:buffer:bytes-buffer %length(cmd(i:i+buffer-1)) fwrite(awg,cmd(i:i+buffer-1)) end awg.EOIMode = 'on'; i=i+buffer; %length(cmd(i:end)) fwrite(awg,cmd(i:end)) end fclose(awg); % delete all instrument objects delete(instrfindall); clear awg; %% Notes %{ % The real waveform type is not a voltage, but a scaling factor. Maximum % value is 1 while minimum value is -1. The resulting output voltage can be % calculated by the following formula: my_real_wfm(sample) * % (amplitude_setting/2) + offset_setting = output_voltage % % The real waveform type uses 5 bytes per sample while the integer type % uses 2 bytes. % % The integer type allows for the most efficient and precise control of an % AWG % % The real type allows for dynamic scaling of waveform data at run-time. % This allows for math operations or changing bits of precision (i.e. AWG5k % (14-bit) to/from AWG7k (8-bit), AWG7k 8-bit mode to/from AWG7k 10-bit % mode) minimal degradation of sample data. %}