Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

awg70k matlab ict send waveform 2

Questions in this forum area are community supported. Tektronix does not regularly monitor or guarantee responses in this area.
Post Reply
Carl M
Tektronix Applications
Tektronix Applications
Posts: 796
Joined: July 30th, 2008, 4:45 pm
Country: United States

awg70k matlab ict send waveform 2

Post by Carl M » September 4th, 2014, 4:15 pm

improves upon Grant's awg70k send waveform. dynamically uses multiple writes to send any length waveform with any size buffer.
more matlab examples: viewtopic.php?t=133570

Code: Select all

%% awg70k matlab ict send waveform 2
%{
    send a large waveform within a modest buffer
%}

%% sample waveform
freq_a = 200e3;
freq_b = 0.4e3;
sampling_rate = 10e6;
duration = freq_b^-1 / 2; % seconds, half a cycle of freq_b

% adjust duration and sampling_rate to minimize rounding error
samples = round(duration * sampling_rate);
t = linspace(0, duration - sampling_rate^-1, samples);

w1 = freq_a*2*pi;
w2 = freq_b*2*pi;
y = sin(w2*t).*sin(w1*t);
%plot(t,y);

%% remote variables
visa_vendor = 'ni';
visa_address = 'TCPIP::134.62.36.164::INSTR';
buffer = 20 * 2^10; % 20 KiB
linefeed = 10;

%% connect to instrument
if exist('awg', 'var')
    fclose(awg);
    delete(awg);
    clear awg;
end
awg = visa(visa_vendor, visa_address, 'OutputBuffer', buffer);
fopen(awg);

%% basic io
r = query(awg, '*idn?');
fprintf(1, '%s', r);
fwrite(awg, '*cls');
fprintf(1, 'event status register cleared\n');
%fwrite(awg, '*rst')

%% status check
r = query(awg, '*esr?', '%s', '%d');
fprintf(1, 'event status register: %d\n', r);
% read all messages until No error
fprintf(1, 'messages:\n');
while 1
    r = query(awg, 'syst:err?');
    fprintf(1, '* %s', r);
    if strcmp(r, ['0,"No error"' linefeed])
        break
    end
end

%% awg70k requires single precision vectors
waveform_data = single(y);
waveform_name = 'test';
waveform_samples = length(waveform_data);
waveform_bytes = waveform_samples * 4;

%% command formatting
delete_waveform = sprintf('wlist:waveform:delete "%s"', waveform_name);
header = sprintf('#%d%d',length(num2str(waveform_bytes)), waveform_bytes);
create_waveform = sprintf('wlist:waveform:new "%s", %d', waveform_name, ...
    length(waveform_data));
write_waveform_binblock = sprintf('wlist:waveform:data "%s", %s', ...
    waveform_name, header);
assign_waveform_ch1 = sprintf('source1:waveform "%s"', waveform_name);

%% send commands to instrument
% delete_waveform is only necessary if waveform exists
% the error generated by delete_waveform can be ignored
fwrite(awg, delete_waveform);
fwrite(awg, create_waveform);
awg.EOIMode = 'off';
fwrite(awg, write_waveform_binblock);
if buffer >= waveform_bytes
    fwrite(awg, waveform_data, 'single');
else
    sample_buffer = floor(buffer / 4);
    for a = 1:sample_buffer:waveform_samples-sample_buffer
        fwrite(awg, waveform_data(a:a+sample_buffer-1), 'single');
    end
    a = a + sample_buffer;
    fwrite(awg, waveform_data(a:end), 'single');
end
awg.EOIMode = 'on';
fwrite(awg, linefeed);
fwrite(awg, assign_waveform_ch1);

%% status check after transfer
r = query(awg, '*esr?', '%s', '%d');
fprintf(1, 'event status register: %d\n', r);
% read all messages until No error
fprintf(1, 'messages:\n');
while 1
    r = query(awg, 'syst:err?');
    fprintf(1, '* %s', r);
    if strcmp(r, ['0,"No error"' linefeed])
        break
    end
end

%% gracefully disconnect
%fclose(awg);
%delete(awg);
%clear awg;
Tektronix Application Engineer

Post Reply

Return to “Older and Obsolete Signal Sources”

Who is online

Users browsing this forum: No registered users and 8 guests