Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

synchronous digital and analog I/O daqmx

Solved!
Go to solution

I have 2 PCI-6254s in a linux box and I am trying to synchronize analog input data (ai0:1) with incoming digital data (port0).  I feed a sample

clock to Dev1/PFI0.  (I am currently just using the I/O of one of the installed boards) Somehow I can't line up the digital and analog data.  I know this because I use the digital data to invert the polarity of the analog data yet the incoming digital data (printed from the buffer) doesn't correlate to what is happening to the sign of the analog data.

 

If I use the internal ai/sampleClock as the common terminal for analog and digital data the data looks fine and is repeatable.

 

thanks in advance for any suggestions.

0 Kudos
Message 1 of 5
(4,029 Views)

Hi ant1,

 

Are you trying to sychronize the analog input from one card with the digital input of another card? I'm asking this because you should be able to this using a single card. Assuming that you are using DAQmx Base with LabVIEW on Linux, there is unfortunately no example on how to do a Multi-Function Synchronization on your board. However, I was able to find such an example in DAQmx. Although DAQmx Base only has a subset of functionalities available to DAQmx, you should be able to replicate this example. I have made small modifications to the code to remove any VIs you might not have in your DAQmx Base palette.

 

If following this example does not solve your problem, perhaps you can post a snapshot of your block diagram.

S_Hong
National Instruments
Applications Engineer
0 Kudos
Message 2 of 5
(4,021 Views)

Hi S_Hong,

 

Unfortunately I am am not using Labview but just writing c code following the DAQmx ansi-c examples.  You're diagram is  

describes exactly what I am trying to do and I follow the same steps listed in the text under your diagram.  I have found that

the SetTerminalName function won't work in my environment so I configure both digital and analog SampleClock to the same

device "/Dev1/PFI0".

 

Here is a snippet of my code:

 

/* Set up the analog input channel  */

 

DAQmxErrChk (DAQmxCreateTask("",&AItaskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(AItaskHandle,"Dev1/ai0:1","",DAQmx_Val_Diff,-5.0,5.0,DAQmx_Val_Volts,NULL));        DAQmxErrChk (DAQmxCfgSampClkTiming(AItaskHandle,"/Dev1/PFI0",4000.0,DAQmx_Val_Falling,DAQmx_Val_ContSamps,4000));
DAQmxErrChk( DAQmxSetAIDataXferMech(AItaskHandle,"Dev1/ai0:1", DAQmx_Val_Interrupts));

 

        /* set up the digital channel  */

 

DAQmxErrChk (DAQmxCreateTask("",&DItaskHandle));
DAQmxErrChk (DAQmxCreateDIChan(DItaskHandle,"Dev1/port0/line0:31","",DAQmx_Val_ChanForAllLines));
DAQmxErrChk (DAQmxCfgSampClkTiming(DItaskHandle,"/Dev1/PFI0",4000.0,DAQmx_Val_Falling,DAQmx_Val_ContSamps,4000));
DAQmxErrChk( DAQmxSetDIDataXferMech(DItaskHandle,"Dev1/port0", DAQmx_Val_Interrupts));

DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(AItaskHandle,DAQmx_Val_Acquired_Into_Buffer,4000,0,EveryNCallback,NULL));
DAQmxErrChk (DAQmxRegisterDoneEvent(AItaskHandle,0,DoneCallback,NULL));

 DAQmxErrChk (DAQmxStartTask(DItaskHandle));
 DAQmxErrChk (DAQmxStartTask(AItaskHandle));

 The analog and digital data does not always line (are not synchronized).  Do you see anything balatantly wrong?

 

Thanks for your response,

Ant1

0 Kudos
Message 3 of 5
(4,000 Views)
Solution
Accepted by topic author ant1
The problem is that the two tasks aren't guaranteed to start at the same time since they aren't sharing a common start trigger.  This means there will probably be a non-deterministic number of samples of phase difference between the two acquisitions.  Unfortunately, the digital I/O on this board doesn't support any triggering functionality so you can't just use a common start trigger.  Probably the easiest thing to do given what you've described so far is to continue to use PFI0 as the sample clock for AI and change the clock for your digital task to /Dev1/ai/SampleClock.  You then need to make sure you start your digital task before the AI task.  This should effectively slave your digital clock to the clock of the analog task and effectively start the two at the same time.  Since each task is physically using a different signal as its clock (PFI0 vs. an exported version of ai/SampleClock), there will be a small amount of latency between the two.  However, this should be on the order of tens of microseconds so I wouldn't expect it to have any significant impact.  Also, since the digital task is effectively slaved to the clock of the analog task, it will effectively start and stop with the analog task regardless of whether you have called stop task on the digital task.  Hopefully this won't be a problem for your application.
0 Kudos
Message 4 of 5
(3,986 Views)

Thank you reddog. 

I followed your suggestions and my digital and analog data are now lined up

correctly.

0 Kudos
Message 5 of 5
(3,979 Views)