AnsweredAssumed Answered

Transfering an averaged waveform from MSO 3502 to PC matlab

Question asked by PGarland on May 4, 2011
Hi All,

    I'm attempting to transfer an averaged waveform from an MSO 3502 to PC via usb and Matlab, and have run into a bit of a snag. My code is as follows (adapted from some codes posted by others):

% Set up oscilloscope object (check visa address thru Agilent Connection
% Expert)

scope=instrfind('Type', 'visa-usb', 'RsrcName', 'USB0::2391::6051::MY50510663::0::INSTR', 'Tag', '');

if isempty(scope)
    scope=visa('AGILENT', 'USB0::2391::6051::MY50510663::0::INSTR');

% Set scope buffer, timeout and byte order



% Set timebase to main
fprintf(scope, ':TIMEBASE:MODE MAIN');
fprintf(scope, ':TIMEBASE:RANGE 1.5e-5');
fprintf(scope, ':TIMEBASE:POSITION 16.e-6')

% % Set acquisition mode, averages and trigger

fprintf(scope, ':ACQUIRE:MODE RTIM');
fprintf(scope, ':ACQUIRE:TYPE AVERAGE');
fprintf(scope, ':ACQUIRE:COUNT 64');
fprintf(scope, ':TRIGGER:EDGE:SOURCE CHAN2')
fprintf(scope,'TRIGGER:EDGE:SLOP POS');
fprintf(scope,'TRIGGER:EDGE:LEV 7.5');

% Specify data from Channel 1
fprintf(scope,':WAVEFORM:SOURCE CHAN1 ');
fprintf(scope,':CHAN1:COUPLING AC');
fprintf(scope,':CHAN1:SCALE 60 mV');
fprintf(scope,':WAV:POINTS:MODE RAW');
fprintf(scope,':ACQ:POINTS 1000');

% Now tell the instrument to digitize channel1
fprintf(scope,':DIGITIZE CHAN1');

% Set format and byteorder
fprintf(scope,':WAVEFORM:FORMAT WORD');
fprintf(scope,':WAVEFORM:BYTEORDER LSBFirst');

% Get the preamble block
preambleBlock = query(scope,':WAVEFORM:PREAMBLE?');


% read back the BINBLOCK

waveform.RawData = binblockread(scope,'int16'); fread(scope,1);

maxVal = 2^16;

%  split the preambleBlock into individual pieces of info
preambleBlock = regexp(preambleBlock,',','split');

% store all this information into a waveform structure for later use
waveform.Format = str2double(preambleBlock{1});     % This should be 1, since we're specifying INT16 output
waveform.Type = str2double(preambleBlock{2});
waveform.Points = str2double(preambleBlock{3});
waveform.Count = str2double(preambleBlock{4});      % This is always 1
waveform.XIncrement = str2double(preambleBlock{5}); % in seconds
waveform.XOrigin = str2double(preambleBlock{6});    % in seconds
waveform.XReference = str2double(preambleBlock{7});
waveform.YIncrement = str2double(preambleBlock{8}); % V
waveform.YOrigin = str2double(preambleBlock{9});
waveform.YReference = str2double(preambleBlock{10});
waveform.VoltsPerDiv = (maxVal * waveform.YIncrement / 8);      % V
waveform.Offset = ((maxVal/2 - waveform.YReference) * waveform.YIncrement + waveform.YOrigin);         % V
waveform.SecPerDiv = waveform.Points * waveform.XIncrement/10 ; % seconds
waveform.Delay = ((waveform.Points/2 - waveform.XReference) * waveform.XIncrement + waveform.XOrigin); % seconds

% Generate X & Y Data
waveform.XData = (waveform.XIncrement.*(1:length(waveform.RawData))) - waveform.XIncrement;
waveform.YData = (waveform.YIncrement.*(waveform.RawData - waveform.YReference)) + waveform.YOrigin;

delete(scope); clear scope;

The code will set up the scope fine and collect the averaged waveform properly (I can actually use the MEASure command to get peak to peak values and others), but when I attempt to transfer the waveform I get a query unterminated error, the preamble returns as null, and the binblockread command returns that there is no data to read. Funny enough, the code works fine for single shot (unaveraged) waveform transfer. I've searched for others reporting this problem, but have found nothing similar. If anyone has any suggestions as to workarounds for this, they would be greatly appreciated.