Example Test Code

function DDS_Test()
%example of programming and executing a command sequence

t=connect();

% clear command sequence
fwrite(t,clear_command());

%set Starting Frequency
%start command sequence and set frequency
fwrite(t,set_freq(5E6));

%wait for trigger
fwrite(t,wait_trigger());

%RAMP Up
fwrite(t,ramp_DDS_freq(1,5E6,8E6));

% wait for end of ramp
fwrite(t,wait_ramp());

%RAMP Down
fwrite(t,ramp_DDS_freq(.5,8E6,5E6));
%

% wait for end of ramp
fwrite(t,wait_ramp());

%RAMP up again
fwrite(t,ramp_DDS_freq(.2,5E6,6E6));

% wait for end of ramp
fwrite(t,wait_ramp());

%RAMP up again
fwrite(t,ramp_DDS_freq(.1,6E6,1E6));

%execute commands
fwrite(t,execute());

%% Pause for the communication delay, if needed.
pause(2)

disconnect(t);

end

function t=connect()
%% Create TCP/IP object 't'. Specify server machine, Remote and Local port number.

t = udp('192.168.1.154', 37829,'LocalPort',4629);

%% Set size of receiving buffer, if needed.
%set(t, 'InputBufferSize', 30000);

%% Open connection to the server.
fopen(t);

%% Pause for the communication delay, if needed.
pause(1)
end

function y = clear_command()
%returns command sequence for clearing previous command sequence in unicode
y=native2unicode(hex2dec('C0'));

end

function y=wait_ramp()
%returns command sequence for the wait until end of ramp command in
%unicode

y=[native2unicode(hex2dec('C1')),native2unicode(hex2dec('A8'))];

end

function y = wait_trigger()
%returns command sequence for the wait until trigger command in
%unicode

y=[native2unicode(hex2dec('C1')),native2unicode(hex2dec('A4'))];

end

function y=set_freq(freq)
%returns command sequence for the setting the dds frequency command in
%unicode
%freq is dss frequency in Hz

y=[native2unicode(hex2dec('C1')),set_DDS_freq(freq)];

end

function y=execute()
%returns command sequence for executing the command sequence in
%unicode

y=[native2unicode(hex2dec('C4')),native2unicode(hex2dec('00'))];

end

function disconnect(t)
%% Disconnect and clean up the server connection.
fclose(t);
delete(t);
clear t
end

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License