How to synchronise input and output on a NI device in scanclock mode

2 views (last 30 days)
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');
%%Settings
MagHi = 3.5; % B+ current in amps
MagLo = -3.5; % B- current in amps
MagInt = 0; % Intermediate level for switching, usually (MagHi+MagLo)/2
MagShots = 50; % Shots per B+/B- for one data point
MagCycles = 10; % Number of data points
MagLoop = [MagInt,linspace(MagHi,MagHi,MagShots+1),MagInt,linspace(MagLo,MagLo,MagShots+1)]; % start with intermediate level, 1 B+ for switching, MagShots B+, int. level, 1 B- for switching, MagShots B-
MagOutput = [repmat(MagLoop,1,MagCycles),MagInt]'; % Make output vector for DAQ card (' transposes)
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

Answers (1)

Chris
Chris on 30 Aug 2013
Edited: Chris on 30 Aug 2013
Just a quick update...
In digital trigger mode, there is also a delay between input and output, but only about 4 shots/ms at 1000Hz rate. I'm just using longer cycles now and discard some bits. The duty cycle is somewhat reduced and I don't have as good of an additional 'layer of chopping', but I don't see any way of fixing this...

Community Treasure Hunt

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

Start Hunting!