Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

how to minimize the delay of triggered output

Solved!
Go to solution

Hi, I am trying to use PCI6111 to execute some Matlab commands with external triggers. The counter is used for counting triggers. I tested the delay between the edges of the trigger and the executing of analog output, and found it fluctuated around 2 ms to 6 ms. Is there some way to minimize the delay? Thanks!

Here is the Matlab codes:

%% setup counter;
s = daq.createSession('ni');
s.addCounterInputChannel('dev1', 'ctr0', 'EdgeCount');
s.Channels(1).ActiveEdge = 'Falling';
get(s.Channels(1),'Terminal'); % return PFI8

% add ananlogputput to work as new triggers;
s1 = daq.createSession('ni');
s1.addAnalogOutputChannel('dev1',[0],'Voltage'); % AO0

%
VolumeNumber=400;
FramePerVolume=2;
TotalTrigger=VolumeNumber*FramePerVolume;

%%
VaOn=2;
VaOff=-2;
outputSingleScan(s1,[VaOff]);
%%
ii=0;
s.resetCounters;
NN=s.inputSingleScan;
Nlast=0;
while NN<TotalTrigger
    NN=s.inputSingleScan;
    N=mod(NN,2);
    if N==1 && NN==Nlast+1;
        disp(NN)
        outputSingleScan(s1,[VaOff]);
        Nlast=NN;
    elseif N==0 && NN==Nlast+1;
        disp(NN)
        outputSingleScan(s1,[VaOn]);
        Nlast=NN;
    end
end
disp('Done~')

0 Kudos
Message 1 of 18
(4,766 Views)

Hello Confu,

 

What kind of delay would you be expecting? i.e. ns us 1 ms? Also, are you calling this code using the Data Acquisition Toolbox from MathWorks?

Matt G.
Product Manager
National Instruments
0 Kudos
Message 2 of 18
(4,735 Views)

1 ms would be enough. But current test shows it fluctuates between 2 ms and 6 ms. Yes, I am using Matlab toolbox. Any suggestions? Thanks a lot!

0 Kudos
Message 3 of 18
(4,733 Views)

The delay between the analog output start trigger signal and the first edge of the AO Sample Clock is, by default, 2 ticks of the onboard timebase.  By default, that timebase is 20MHz, so the expected delay is 100ns.  That delay should (a) be deteministic, and (b) never be in the ms range unless you are configuring it as such.

 

How are you verifying the delay between receiving the start trigger and the analog ouptut sample clock?  Or am I misunderstanding the issue?

Cody A.
0 Kudos
Message 4 of 18
(4,728 Views)

Thanks, Cody. I tested the delay with an oscilloscope, with inputs of both the trigger and the AO output.

0 Kudos
Message 5 of 18
(4,722 Views)

Hi Confu,

 

I'm not a MATLAB expert by any means, but it looks like you are determining when to actually output data by waiting for the counter input to increment, rather than using an actual hardware trigger.  Since the output generation is software timed, you are a victim of the inherent jitter of the operating system.  The 100ns delay between trigger and output I mentioned earlier ONLY applies if you are using a hardware start trigger.

 

If deterministic (consistent) latency between receiving a trigger and outputting data is important for your application, then you will need to use a hardware trigger.  Based on what I've read in the MATLAB Data Acquisition Toolbox documentation, that API does not support hardware triggering for analog output tasks.  Therefore, I think you probably have two options:

  1. Switch to a different language that supports the full DAQmx API (LabVIEW, C, .NET)
  2. Reach out to MathWorks support for help on modifying/using the Data Acquisition Toolbox.
Cody A.
0 Kudos
Message 6 of 18
(4,718 Views)

Thanks a lot, Cody. I will try Labview then.

0 Kudos
Message 7 of 18
(4,716 Views)

Quick tip: In LabVIEW, take a look at the "Voltage - Finite Output" shipping example in the Example Finder.  It has native support for hardware triggering.

Cody A.
0 Kudos
Message 8 of 18
(4,714 Views)

Thank you, Cody,

 

My task is (1) counting the falling edge of an external trigger signal,

                 (2) If the number is odd, display a given pattern on a 2nd monitor (it is SLM actually)

                 (3) If the number is even, display another given pattern.

 

Could you please recommend some example to follow? Thank you so much!

 

Confu

 

0 Kudos
Message 9 of 18
(4,703 Views)

Hi Confu,

 

What is your requirement for latency between receiving a trigger and outputting a waveform?  

 

Because you need to output a different waveform on every other trigger, you need onboard signal processing to determine whether the trigger is odd or even then output the appropriate waveform.  Multifunction DAQ cards such as the 6111 do not have this capability, so it will have to be done in software, which increases both latency and jitter.

 

Depending on your latency requirements, it may be feasible with a standard DAQ card on an RT Operating System, but your best bet is switching hardware to a card with an onboard FPGA, such as one of our R Series devices.

Cody A.
0 Kudos
Message 10 of 18
(4,701 Views)