There are a couple of ways to do this:
- If you use the FPGA to detect the rising edge of the trigger-> then you need the additional breakout box
- Use a DAQmx digital input task that is synchronized to the acquisition. This task samples the trigger with a predefined rate (say 10kHz) and saves the data to disk.
Method 1 is built into ScanImage and requires the additional breakout box.
Method 2 you can reuse the DAQ breakout boxes, but you will need to write a bit of (fairly simple) code to set up the digital input task. Sample code is provided below.
function captureDigitalInput(tf)
persistent hTask
if nargin < 1
tf = true;
end
if tf
deviceName = 'PXI1Slot4';
line = 'port0/line0';
sampleRate = 1000; % Hz
if ~isempty(hTask) && isvalid(hTask)
hTask.delete();
end
hTask = most.util.safeCreateTask('My digital input Task');
hTask.createDIChan('PXI1Slot4',line);
hTask.cfgSampClkTiming(sampleRate,'DAQmx_Val_ContSamps');
sampleRate = hTask.sampClkRate;
fprintf('Actual sample rate: %f\n',sampleRate);
% synchronize to scanimage
set(hTask,'sampClkTimebaseRate',10e6);
set(hTask,'sampClkTimebaseSrc',['/' deviceName '/PXI_Clk10']);
% set up trigger
hTask.cfgDigEdgeStartTrig('PXI_Trig1'); % frame clock is exported to PXI_Trig6 on the back plane
% setup callback
everyNSamples = 1000;
hTask.registerEveryNSamplesEvent(@everyNSamplesCallback,everyNSamples,true);
hTask.start();
else
hTask.clear();
end
end
function everyNSamplesCallback(obj,src,evt)
persistent hPlot
if isempty(hPlot) || ~isvalid(hPlot)
hFig = figure;
hAx = axes();
hPlot = plot(hAx,src.data);
else
hPlot.XData = 1:length(src.data);
hPlot.YData = src.data;
end
end