Problems triggering a flash using nidaq
Show older comments
Hi,
I am trying to trigger a flash (Qflash X5d-R) using a NI-PIXe-6124 (nidaq) card. This is for the purpose of trying to obtain the carrier lifetime of a solar cell. This is the following code I am using, but several modifications have failed to trigger the flash.
% This m-file contains the actual flash pulse and data acquisition % ================================================================
function [final_time,final_data,base_ref,base_samp] = flash(data_points,duration_in,ref_limit,samp_limit,duration_out,voltage_out,signal,f,t_A); warning off
% ANALOG INPUT % ============
SampleRate_in = 500000; % sample rate in Hz Default: 5000000 Hz
data_points_in = duration_in * SampleRate_in;
% Create an analog input object with two channels
% -----------------------------------------------
ai = analoginput('nidaq','Dev1');
chan_in0 = addchannel(ai,0);
chan_in1 = addchannel(ai,1);
% Configure the analog input rate and trigger mode
% ------------------------------------------------
set(ai,'SampleRate',SampleRate_in)
set(ai,'SamplesPerTrigger',SampleRate_in)
%set(ai,'TriggerType','manual')
set(ai,'TriggerRepeat',ceil(duration_in))
set(ai,'LogFileName','data_file.daq')
set(ai,'LoggingMode','Disk&Memory')
set(ai,'LogToDiskMode','Overwrite')
% Set the scaling range
% ---------------------
sensor_min = -10;
sensor_max = 10;
units_min = sensor_min * 10;
units_max = sensor_max * 10;
sensor_range = sensor_max-sensor_min;
units_range = units_max-units_min;
% Channel 1
% ---------
set(chan_in0,'SensorRange',[sensor_min sensor_max])
set(chan_in0,'InputRange',[0 ref_limit])
set(chan_in0,'UnitsRange',[units_min units_max])
set(chan_in0,'Units','g''s (1g = 9.80 m/s/s)')
% Channel 2
% ---------
set(chan_in1,'SensorRange',[sensor_min sensor_max])
set(chan_in1,'InputRange',[0 samp_limit])
set(chan_in1,'UnitsRange',[units_min units_max])
set(chan_in1,'Units','g''s (1g = 9.80 m/s/s)')
% ANALOG OUTPUT % =============
SampleRate_out = 500000; % sample rate in Hz
data_points_out = duration_out * SampleRate_out;
% Set output voltage to zero
% --------------------------
ao = analogoutput('nidaq','Dev1');
chan_out0 = addchannel(ao,1);
set(ao,'SampleRate',SampleRate_out)
x0 = linspace(0,0,duration_out)';
putdata(ao,x0)
start(ao)
stop(ao)
delete(ao)
clear ao
% Create an analog output object with one channel
% -----------------------------------------------
ao = analogoutput('nidaq','Dev1');
chan_out0 = addchannel(ao,1);
% Configure the analog output rate and trigger mode
% -------------------------------------------------
set(ao,'SampleRate',SampleRate_out)
set(ao,'TriggerType','manual')
% DATA ACQUISITION % ================
% Put data into buffer, start device and trigger
% ----------------------------------------------
putdata(ao,voltage_out)
start(ao)
trigger(ao)
start(ai)
%trigger(ai)
pause(duration_in*1.5)
stop(ai)
% Obtain data for each trigger and get an average cycle of the measurement data
% -----------------------------------------------------------------------------
V_ref = [];
V_samp = [];
for m = 1:ceil(duration_in);
if duration_in-m > 0
t_trigger = [0 1];
n = 1;
else
t_trigger = [0 duration_in-(m-1)];
end
[data,time] = daqread('data_file.daq','Time',t_trigger);
n = floor(t_trigger(2)*f);
l_freq = SampleRate_in/f;
for i=1:n-1
data_1(:,i) = data((i-1)*l_freq+1:i*l_freq ,1);
data_2(:,i) = data((i-1)*l_freq+1:i*l_freq ,2);
end
V_ref(:,m) = mean(data_1,2);
V_samp(:,m) = mean(data_2,2);
t2 = time(1:l_freq,1);
clear data_1 data_2 data time
end
delete(ai)
clear ai
stop(ao)
delete(ao)
clear ao
delete('data_file.daq')
% Set output voltage to zero
% --------------------------
ao = analogoutput('nidaq','Dev1');
chan_out0 = addchannel(ao,1);
set(ao,'SampleRate',SampleRate_out)
putdata(ao,x0)
start(ao)
stop(ao)
delete(ao)
clear ao
% Average over every trigger cycle and scale back the data
% --------------------------------------------------------
x2(:,1) = mean(V_ref,2);
x2(:,2) = mean(V_samp,2);
x2 = x2.*sensor_range./units_range;
% Get the dark voltage
% --------------------
base_ref = abs(mean(x2(1:floor(l_freq/10),1)));
base_samp = abs(mean(x2(1:floor(l_freq/10),2)));
% TRIGGERING BY SOFTWARE % ======================
% Sawtooth signal
% ---------------
if signal == 1
% Delete the data points before the onset of the flash pulse
% this first routine is done for both the reference and sample signal.
% the onset value k is determined so that both signal show a sudden increase
% --------------------------------------------------------------------------
trigger_value = (max(x2(:,1)) - base_ref)/50 + base_ref;
k = [];
for i = 1:l_freq
if x2(i,:) > trigger_value &...
x2(i+1,:) > trigger_value &...
x2(i+2,:) > trigger_value &...
x2(i+3,:) > trigger_value &...
x2(i+4,:) > trigger_value &...
x2(i+5,:) > trigger_value
k = i;
break
end
end
% Define the final time length of the signal that will be given back to 'function'.
% It should be a bit larger then the applied length t_A,
% since the actual signal of the LED will always be a bit stretched out.
% ---------------------------------------------------------------------------------
l_sig = min(SampleRate_in*t_A*2,length(x2)-k); % In this case the time length is t_A*2
try
trigger_data = x2(k:l_sig+k,:);
trigger_time = t2(k:l_sig+k) - t2(k);
% This contains the second routine if the sample signal failes to produce an onset (k == [])
% in this routine, only the onset of the reference cell is determined.
% ------------------------------------------------------------------------------------------
catch
for i = 1:l_freq
if x2(i,1) > trigger_value &...
x2(i+1,1) > trigger_value &...
x2(i+2,1) > trigger_value &...
x2(i+3,1) > trigger_value &...
x2(i+4,1) > trigger_value
k = i;
break
end
end
% Define the final time length of the signal that will be given back to 'function'.
% It should be a bit larger then the applied length t_A,
% since the actual signal of the LED will always be a bit stretched out.
% ---------------------------------------------------------------------------------
l_sig = min(SampleRate_in*t_A*2,length(x2)-k); % In this case the time length is t_A*2
trigger_data = x2(k:l_sig+k,:);
trigger_time = t2(k:l_sig+k) - t2(k);
end
% Calibration signal
% ------------------
elseif signal == 2;
% Get the first maximum of the window signal
% ------------------------------------------
[mx,i] = max(x2(:,1));
k = i - SampleRate_in*t_A/2;
l_sig = min(SampleRate_in*t_A*2,length(x2)-k); % In this case the time length is t_A*2
trigger_data = x2(k:l_sig+k,:);
trigger_time = t2(k:l_sig+k) - t2(k);
end
clear t2 x2
% AVERAGING % =========
% Average the cycle into number of data points
% --------------------------------------------
period = floor(l_sig/data_points);
final_data = zeros(data_points,2);
final_time = zeros(data_points,1);
m = 1;
for i = 1:data_points
final_data(i,:) = mean(trigger_data((m-1)*period+1:period*m,:));
final_time(i) = mean(trigger_time((m-1)*period+1:period*m));
m=m+1;
end
Answers (0)
Categories
Find more on Analog Filters in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!