Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronizing analog input and output

I am in the middle of converting some Traditional NI-DAQ code to the DAQmx API (I am using C++).  Most of it is going quite well: my code complexity has been greatly reduced and (since upgrading to 7.4) my CPU usage has plummeted.  However, in one particular case I need my input and output buffers to be synchronized.  I.e. sample 0 of my input buffer should be read at the same instant sample 0 of my output buffer went out on the line.  In Traditional NI-DAQ, I synchronized my input and output start triggers using the following method (which I believe I found in an example somewhere):

error = Select_Signal(addr, ND_PFI_6, ND_OUT_START_TRIGGER, ND_LOW_TO_HIGH);
error = Select_Signal(addr, ND_IN_START_TRIGGER, ND_PFI_6, ND_LOW_TO_HIGH);

This then allowed me to setup my input thread, then initialize everything in my output thread and when my output got the start command, so did my input.  The result was that I could perfectly match buffers of output data to buffers of input data (after taking all the appropriate buffering into account).

When I try the same method with the DAQmxConnectTerms function, my buffers don't line up.  They are off by 15-20 ms out of a 400ms buffer (sampling at 10kHz).  I tried cutting out the middle man of PFI6 with similar results.  So my current "synchronize" block looks like this:

error = m_fnConnectTerms("/Dev1/ao/StartTrigger", "/Dev1/ai/StartTrigger", 0);

I get no error.  This also seems to cause my output loop to hang after a few seconds, although that could be a side effect of something else that I haven't tracked down yet.  Is there a better way to do what I'm trying to do here?  Perhaps it is a misunderstanding of the way buffering works on the M series cards (I am currently using a 6221).
0 Kudos
Message 1 of 4
(3,868 Views)
"m_fnConnectTerms" should be DAQmxConnectTerms.  I'm dynamically loading the DLL.

0 Kudos
Message 2 of 4
(3,863 Views)

Don't use Connect Terminals. Use the technique shown in this example program

C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Synchronization\Multi-Function\ContAI-Read Dig Chan

which is the sharing of sample clocks via the DAQmxCfqSampClkTiming function where the sample clock source of one task is set to the clock of the other task.  This example slaves a digital input task to an analog input task but the idea is the same for your application.

 

Message 3 of 4
(3,861 Views)
Thank you!  That seems to have done the trick.  I actually looked at that example earlier today and didn't think it was what I needed.  I have to unlearn everything I did in the Traditional NI-DAQ days.

Thanks again.

-John

0 Kudos
Message 4 of 4
(3,855 Views)