problem writing data to a function generator using GUI.
Show older comments
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 Comments
Jan
on 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
on 30 Jan 2019
Edited: Jan
on 30 Jan 2019
Answers (0)
Categories
Find more on Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!