Uploading a Arbitary waveform to DS345 function generator

6 views (last 30 days)
I am having difficulty in uploading an arbitrary waveform on to the DS345 function generator via the Instrument Control Toolbox in Matlab.
I have used the manual provided here (see page 3-8) to try to achieve this.
In the code, I generate an array of straight lines and I want to upload an arbitrary vector waveform, which means using the LDWF command. The manual suggests that I should send the 16-bit binary data followed by a checksum which is simply the sum of the data array.
The error I get is 'LOADING ERROR...' which implies that it has been waiting for 10s for the data stream and nothing has arrived. so it timeouts with the 'loading error'. Would appreciate any help/guidance possible.
The code I use is:
%% Instrument Control of DS345 Signal Generator
clear all
clc
COMtype = 'COM4';
% Find the a serial port object
obj1 = instrfind('Type', 'serial', 'Port', COMtype , 'Tag', '');
% Create the serial port object if it does not exist
% otherwise use the object that was found.
if isempty(obj1)
obj1 = serial(COMtype);
else
fclose(obj1);
obj1 = obj1(1);
end
N = 512;
Sum = 0;
number = 10;
data = zeros(number,1);
X = zeros(number,1);
Y = zeros(number,1);
obj1.OutputBufferSize = N;
fopen(obj1);
checkConnection =strcat( query(obj1,'*IDN?') );
if strcmp(checkConnection,'StanfordResearchSystems,DS345,43862,1.04') ~=1
disp(['Device Connection not working... Query msg ' ...
checkConnection])
else
disp(['Connection to ' checkConnection(25:29) ' established.'])
end
% Generating Function
for i = 1:number
X(i) = 1*i;
Y(i) = 0;
data(2*i-1) = i;
data(2*i) = 0; %8*i*(-1 + 2*(mod(i,2)));
Sum = Sum + (data(2*i-1) + data(2*i));
end
figure(1)
plot(X,Y)
grid minor
checksumdata = sum(data);
data(2*number+1) = checksumdata;
% size(data)
% convert into 16-bit binary array
data = int16(data);
dataBin = dec2bin(data,16);
checkLDWF = strcat(query(obj1,['LDWF? 1,' num2str(2*number)]));
if checkLDWF =='1'
disp('Ready to Download...')
end
pause(1)
disp('downloading...')
disp('sending DataBin...')
fwrite(obj1,dataBin,'short','async')
stopasync(obj1)
fclose(obj1);
  1 Comment
Ido Nitsan
Ido Nitsan on 7 Oct 2020
Hi Rashid,
Did you manage to find a solution by any chance? I'm facing the same problem...
Thanks!

Sign in to comment.

Answers (1)

Naveen Venkata Krishnan
Naveen Venkata Krishnan on 7 Oct 2019
Hello Rashid ,
I think there might an issue while communicating with the instruments. Make sure that you have downloaded the right instrument drivers. You can use this link to download instrument driver for DS345.
If you have already downloaded one, try implementing this example to visualize the wave form in the function generator. Below are some links that might be helpful to you while working on it.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!