I am using a NI USB-6251 BNC as my data acquisition device. So far, I had only been using the inputs. Adding a scanclock to synchronise with the 1000Hz laser trigger works fine. Minimal example:
handles.session = daq.createSession('ni');
handles.ai0 = handles.session.addAnalogInputChannel(handles.card.ID,0,'Voltage');
set(handles.ai0,'Range',[-0.1,0.1]);
handles.session.Rate=1000;
handles.session.DurationInSeconds=0.1;
handles.session.NumberOfScans=100;
handles.scanclock = handles.session.addClockConnection('External','Dev1/PFI0','ScanClock');
handles.trig = handles.session.addTriggerConnection('External','Dev1/PFI0','StartTrigger');
handles.data = handles.session.startForeground();
When I now add an output channel and connect the output to the input, I get a delay between the two of over 20ms (the output finishes early / the first data point is already the 20th point of the output vector). Since the card can support > 1 MHz operation, this seems excessive. Any idea where I go wrong? The added code is:
handles.ao0 = handles.session.addAnalogOutputChannel(handles.card.ID,0,'Voltage');
MagHi = 3.5;
MagLo = -3.5;
MagInt = 0;
MagShots = 50;
MagCycles = 10;
MagLoop = [MagInt,linspace(MagHi,MagHi,MagShots+1),MagInt,linspace(MagLo,MagLo,MagShots+1)];
MagOutput = [repmat(MagLoop,1,MagCycles),MagInt]';
handles.session.queueOutputData(OutputVector);
I need the scanclock mode because the normal trigger mode dephases with the laser shot frequency after some shots even when they are norminally the same. Is there any way of synchronising input and output better? At the moment I can only think of using more measurement cycles per QueueOutput and simply throw away the first incomplete cycle. I believe that the hardware should be capable of synchronising, though.
Cheers, Chris