AnsweredAssumed Answered

Synchronizing Trigger and Signal

Question asked by patricia.stahn on Sep 16, 2013
I've got two signals (trigger and signal). As described befor I download them to the 33500B Waveform Generator with amodified version of the arbTo33500.m function. 


The problem is, that the two signals aren't synchronized, even if the plot of the two functions showing that they start at the same time in each period. Depending on the SampleRate (fs) , th signal frequency and the outputbuffer size, the trigger is moved forward and backward around 100 ms. 

(CODE)
%% funktiongenerator für arbitary signal+
clear all;
WaveGen = visa('Myinstrument');%visa adress from agilent connection expert, use copy and paste
fs=200000; %Abtastrate
amp=2; %Amplitude des Ausgangsignals
choise=6; %pulsierte Töne =6  
freq=20000; %Frequenz Sinussignal
[Signal,SigName,TrigName,SigTrig]=SigArbitary(choise,fs,freq); (<-Signal generation)
k=8^10;
buffer = length(SigTrig)*k;
set(WaveGen,'OutputBufferSize',(buffer+125));
%open connection to 33500A/B waveform generator
try
   fopen(WaveGen);
catch exception %problem occurred throw error message
    uiwait(msgbox('Error occurred trying to connect to the 33500, verify correct connection','Error Message','error'));
    rethrow(exception);
end
%Query Idendity string and report
pause(2);
fprintf (WaveGen, '*IDN?');
idn = fscanf (WaveGen);
fprintf (idn)
fprintf ('\n\n')
fprintf(WaveGen,'*cls');% clear errors
%calculate output buffer size
%open connection to 33500A/B waveform generator

pause(2);
%create waitbar for sending waveform to 33500
mes = ['Connected to ' idn ' sending waveforms.....'];
h = waitbar(0,mes);

%Reset instrument
fprintf (WaveGen, '*RST');

%make sure waveform data is in column vector
if isrow(Signal) == 0
   Signal=Signal';
end

if isrow(SigTrig) == 0
   SigTrig=SigTrig';
end
%set the waveform data to single precision
Signal=single(Signal);
SigTrig=single(SigTrig);

%scale data between 1 and -1
Signal=Signal/(max(abs(Signal)));
SigTrig=SigTrig/(max(abs(SigTrig)));

%update waitbar
waitbar(.1,h,mes);




%send waveform to 33500

fprintf(WaveGen, 'SOURce1:DATA:VOLatile:CLEar'); %Clear volatile memory
fprintf(WaveGen, 'SOURce2:DATA:VOLatile:CLEar'); %Clear volatile memory

fprintf(WaveGen, 'FORM:BORD SWAP');  %configure the box to correctly accept the binary arb points
%fprintf(WaveGen, 'FORM:BORD NOrM');  %configure the box to correctly accept the binary arb points
arbBytes=num2str(length(Signal) * 8); %# of bytes

SigHeader= ['SOURce1:DATA:ARBitrary ' SigName ', #' num2str(length(arbBytes)) arbBytes]; %create header
SigBinblockBytes = typecast(Signal, 'uint8');  %convert datapoints to binary before sending
fwrite(WaveGen, [SigHeader SigBinblockBytes], 'uint8'); %combine header and datapoints then send to instrument
pause(1);
SigTrigHeader= ['SOURce2:DATA:ARBitrary ' TrigName ', #' num2str(length(arbBytes)) arbBytes]; %create header
SigTrigBinblockBytes = typecast(SigTrig, 'uint8');  %convert datapoints to binary before sending
fwrite(WaveGen, [SigTrigHeader SigTrigBinblockBytes], 'uint8'); %combine header and datapoints then send to instrument
fprintf(WaveGen, '*WAI');   %Make sure no other commands are exectued until arb is done downloadin

% input('Taste');
%update waitbar
waitbar(.8,h,mes);
%Set desired configuration for channel 1
command = ['SOURce1:FUNCtion:ARBitrary ' SigName];
%fprintf(WaveGen,'SOURce1:FUNCtion:ARBitrary GPETE'); % set current arb waveform to defined arb testrise
fprintf(WaveGen,command); % set current arb waveform to defined arb testrise
command = ['MMEM:STOR:DATA1 "INT:\' SigName '.arb"'];
%fprintf(WaveGen,'MMEM:STOR:DATA1 "INT:\GPETE.arb"');%store arb in intermal NV memory
fprintf(WaveGen,command);
%update waitbar
waitbar(.9,h,mes);
command = ['SOURCE1:FUNCtion:ARB:SRATe ' num2str(fs)]; %create sample rate command
fprintf(WaveGen,command);%set sample rate
fprintf(WaveGen,'SOURce1:FUNCtion ARB'); % turn on arb function
command = ['SOURCE1:VOLT ' num2str(amp)]; %create amplitude command
fprintf(WaveGen,command); %send amplitude command
fprintf(WaveGen,'SOURCE1:VOLT:OFFSET 0'); % set offset to 0 V

% %send Trigger to 33500
%fprintf(WaveGen, 'SOURce2:DATA:VOLatile:CLEar'); %Clear volatile memory
fprintf(WaveGen, 'FORM:BORD SWAP');  %configure the box to correctly accept the binary arb points
%fprintf(WaveGen, 'FORM:BORD NOrM');  %configure the box to correctly accept the binary arb points
%arbBytes=num2str(length(Signal) * 4); %# of bytes
% header= ['SOURce2:DATA:ARBitrary ' TrigName ', #' num2str(length(arbBytes)) arbBytes]; %create header
% binblockBytes = typecast(SigTrig, 'uint8');  %convert datapoints to binary before sending
% fwrite(WaveGen, [header binblockBytes], 'uint8'); %combine header and datapoints then send to instrument
%fprintf(WaveGen, '*WAI');   %Make sure no other commands are exectued until arb is done downloadin
%update waitbar
waitbar(.8,h,mes);
%Set desired configuration for channel 1
command = ['SOURce2:FUNCtion:ARBitrary ' TrigName];
%fprintf(WaveGen,'SOURce1:FUNCtion:ARBitrary GPETE'); % set current arb waveform to defined arb testrise
fprintf(WaveGen,command); % set current arb waveform to defined arb testrise
%command = ['MMEM:STOR:DATA "INT:\' TrigName '.arb"'];
command = ['MMEM:STOR:DATA2 "INT:\' TrigName '.arb"'];
fprintf(WaveGen,command);
%update waitbar
waitbar(.9,h,mes);
command = ['SOURCE2:FUNCtion:ARB:SRATe ' num2str(fs)]; %create sample rate command
fprintf(WaveGen,command);%set sample rate
fprintf(WaveGen,'SOURce2:FUNCtion ARB'); % turn on arb function
command = ['SOURCE2:VOLT ' num2str(amp)]; %create amplitude command
fprintf(WaveGen,command); %send amplitude command
fprintf(WaveGen,'SOURCE2:VOLT:OFFSET 0'); % set offset to 0 V


% fprintf(WaveGen,'SOURce2:FUNCtion PULS');%function channel 1
% fprintf(WaveGen,'SOURce2:FUNCtion:PULS:TRAN:LEAD 1E-6');%function channel 1
% fprintf(WaveGen,'SOURce2:FUNCtion:PULS:TRAN:TRA 1E-6');%function channel 1
% fprintf(WaveGen,'SOURce2:FUNCtion:PULS:WIDTh 200E-6');%function channel 1
% fprintf(WaveGen,'SOURce2:FUNCtion:PULS:PER 0.533'); %frequency channel
% fprintf(WaveGen,'SOURce2:VOLTage +4.0');% voltage channel -1
% fprintf(WaveGen,'SOURce2:VOLTage:OFFS 2.0');% offset channel 1

%STARTE SIMULINK
%sim('DemomodelRobert_1x16chan');

pause(3.3) %Pause um das System einzustellen
% input('Taste');
fprintf(WaveGen,'OUTPUT1 ON'); %Enable Output for channel 2
fprintf(WaveGen,'OUTPUT2 ON'); %Enable Output for channel 2


fprintf('Arb waveforms downloaded to channel 1 und 2\n\n') %print waveform has been downloaded
%get rid of message box
waitbar(1,h,mes);
delete(h);

%Read Error
fprintf(WaveGen, 'SYST:ERR?');
errorstr = fscanf (WaveGen);
% error checking
if strncmp (errorstr, '+0,"No error"',13)
   errorcheck = 'Arbitrary waveform generated without any error\n';
   fprintf (errorcheck)
else
   errorcheck = ['Error reported: ', errorstr];
   fprintf (errorcheck)
end

pause(20); %Ausschalten nach ca. 1 Minute
fprintf(WaveGen,'SOURce1:AM:STATe 0');
fprintf(WaveGen,'*cls');% clear errors
fprintf(WaveGen,'OUTPut1 0');%channel 1 off
fprintf(WaveGen,'OUTPut2 0');%channel 2 off
fclose(WaveGen);

I don't know how these things are conected ?

Thanks a lot in advance


Patricia  

Outcomes