problem writing data to a function generator using GUI.

Hi everyone,
I wrote a GUI code that transfers an arbitrary waveform to a function generator. I use a slider button to change\select the amplitude of the waveform in real time. My problem is, that each time I touch the slider button, the (waveform) signal "jumps" for a short moment (I think to zero - it happens very fast) and only then changes to the selected value(confirmed it by conneting the function generator to a scope). It drives my laser crazy. How can I solve this problem? I think it may be related to the period of time in which the function generator reads the waveform data.
function CONST_Amp_Callback(hObject, eventdata, handles) %Set pulse amplitude
AM_Vpp= [-2.5 0]; %low and high voltages
n=16348; %temporal resolution (dont change)
ignition_pulse_amplitude = 1; % fraction of full power
DAC_max=16383;
waveform=zeros(1,n);
waveform(1:ignition_pulse_end_ind)=DAC_max.*ignition_pulse_amplitude;
waveform(ignition_pulse_end_ind+1:full_pulse_end_ind)=DAC_max.*lasing_pulse_amplitude;
handles.time = time;
handles.waveform = waveform;
if handles.DG1000Z.Value == 1
DG1000Z_device = instrfind('Type', 'visa-usb', 'RsrcName', 'USB0::0x1AB1::0x0642::DG1ZA171301033::0::INSTR', 'Tag', '');
% Create the VISA-USB object if it does not exist
% otherwise use the object that was found.
if isempty(DG1000Z_device)
DG1000Z_device = visa('NI', 'USB0::0x1AB1::0x0642::DG1ZA171301033::0::INSTR'); %Create VISA object
%% USB VISA descriptor can be checked using ULTRA software
else
fclose(DG1000Z_device);
DG1000Z_device = DG1000Z_device(1);
end
WF_STR='DATA:DAC VOLATILE,'; %Digital to analog convertor
for i=1:length(waveform)-1
WF_STR=[WF_STR num2str(waveform(i)) ','];
end
WF_STR=[WF_STR num2str(waveform(end))];
set(DG1000Z_device,'OutputBufferSize',length(WF_STR) + 40);
fopen(DG1000Z_device);
fprintf(DG1000Z_device,[':SOUR1:APPL:ARB ' num2str(n.*pulse_rep_rate) ] ); %Set the waveform of CH1 to ARB (arbitrary waveform)...
fprintf(DG1000Z_device,'VOLT:UNIT VPP');
fprintf(DG1000Z_device,['VOLT:HIGH ' num2str(AM_Vpp(2))]);
fprintf(DG1000Z_device,['VOLT:LOW ' num2str(AM_Vpp(1))]);
fprintf(DG1000Z_device,WF_STR);
fprintf(DG1000Z_device,':OUTP1 ON'); %Turn on the output of CH1 of the function generator
fclose(DG1000Z_device);
end
Thanks for helping!!

2 commentaires

Jan
Jan le 29 Jan 2019
Without seeing any details of your implementation, how could we suggest a modification? There is no magic "do not cause jumps" switch in Matlab.
Katherine Akulov
Katherine Akulov le 30 Jan 2019
Modifié(e) : Jan le 30 Jan 2019
Sorry, it is the first time i'm posting here. Here is the code of one of the buttons (I have a few buttons to chenge the duration and amplitude of the signal):
function CONST_Amp_Callback(hObject, eventdata, handles) %Set pulse amplitude
CONST_Amp_display_Callback(handles.CONST_Amp, eventdata,handles);
set(handles.CONST_Amp_display,'String',sprintf('%d',(get(handles.CONST_Amp, 'value'))));
AM_Vpp= [-2.5 0]; %low and high voltages
n=16348; %temporal resolution (dont change)
ignition_pulse_width=(handles.IGNITION_TIME.Value); %[msec]
ignition_pulse_width=ignition_pulse_width.*10^-3; %[sec]
pulse_length=str2double(handles.Pulse_Length.String); %[msec]
pulse_length=pulse_length*10^-3; %[sec]
if handles.radioConstAmp.Value == 1
lasing_pulse_amplitude=(handles.CONST_Amp.Value).*10^-2; % fraction of full power
elseif handles.radioFileAmp.Value == 1
lasing_pulse_amplitude=0.7;
end
ignition_pulse_amplitude = 1; % fraction of full power
DAC_max=16383;
pulse_rep_rate=str2double(handles.Rep_Rate.String);
full_pulse_end_ind=round(pulse_length.*pulse_rep_rate.*n);
ignition_pulse_end_ind=round(ignition_pulse_width.*pulse_rep_rate.*n);
time=linspace(0,1./pulse_rep_rate,n);
waveform=zeros(1,n);
waveform(1:ignition_pulse_end_ind)=DAC_max.*ignition_pulse_amplitude;
waveform(ignition_pulse_end_ind+1:full_pulse_end_ind)=DAC_max.*lasing_pulse_amplitude;
handles.time = time;
handles.waveform = waveform;
plot(handles.time,handles.waveform)
if handles.DG1000Z.Value == 1
set(handles.Device2,'Value', 0);
DG1000Z_device = instrfind('Type', 'visa-usb', 'RsrcName', 'USB0::0x1AB1::0x0642::DG1ZA171301033::0::INSTR', 'Tag', '');
% Create the VISA-USB object if it does not exist
% otherwise use the object that was found.
if isempty(DG1000Z_device)
DG1000Z_device = visa('NI', 'USB0::0x1AB1::0x0642::DG1ZA171301033::0::INSTR'); %Create VISA object
%% USB VISA descriptor can be checked using ULTRA software
else
fclose(DG1000Z_device);
DG1000Z_device = DG1000Z_device(1);
end
WF_STR='DATA:DAC VOLATILE,'; %Digital to analog convertor
for i=1:length(waveform)-1
WF_STR=[WF_STR num2str(waveform(i)) ','];
end
WF_STR=[WF_STR num2str(waveform(end))];
set(DG1000Z_device,'OutputBufferSize',length(WF_STR) + 40);
fopen(DG1000Z_device);
fprintf(DG1000Z_device,[':SOUR1:APPL:ARB ' num2str(n.*pulse_rep_rate) ] ); %Set the waveform of CH1 to ARB (arbitrary waveform)...
fprintf(DG1000Z_device,'VOLT:UNIT VPP');
fprintf(DG1000Z_device,['VOLT:HIGH ' num2str(AM_Vpp(2))]);
fprintf(DG1000Z_device,['VOLT:LOW ' num2str(AM_Vpp(1))]);
fprintf(DG1000Z_device,WF_STR);
fprintf(DG1000Z_device,':OUTP1 ON'); %Turn on the output of CH1 of the function generator
fclose(DG1000Z_device);
end
When I used an oscilloscope to observe the function generator's pulses, I noticed a "jump" and after it, the desired pulse. This "jump" drives the laser (which is powered by this pulse) crazy.

Connectez-vous pour commenter.

Réponses (0)

Modifié(e) :

Jan
le 30 Jan 2019

Community Treasure Hunt

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

Start Hunting!

Translated by