0

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. 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);

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.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • Where do you get the loading error? Maybe you can post a complete output log of your script. Reading the manual I guess is at the end where you upload data points. – Marcos G. Jul 18 '19 at 11:40
  • There is no output log as far as I know. The error occurs on the DS345 Function generator. Yes it is after the fwrite command – Muddassar Rashid Jul 18 '19 at 13:01

1 Answers1

0

I don't see anything wrong with your code.

Unfortunately I don't have access to Matlab right now.

In the meantime you might want to take a look at the method I proposed here.

It will allow you to see what is really on your port while you are sending data from Matlab to your function generator. This way you can be sure the data you are sending is correct and in particular if you are sending the right amount.

Marcos G.
  • 3,371
  • 2
  • 8
  • 16