From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to synchronize DAQmx AI/AO finite samples?

Solved!
Go to solution

Hello,

 

I'm trying to implement an audio generator/analyzer with a NI USB-4431 DAQ card. A sine wave should be generated at the analog output and be measured at the same time at the analog input. There used to be an example "Multi-Function-Synch AI-AO.vi" in previous LabVIEW versions, but unfortunately it's not shipped with LabVIEW 2016 anymore. I found an example HERE, but I have a slightly different setup.

 

The example uses Continuous Samples, whereas I'm working with Finite Samples (because I don't have a stop button in my application). Currently I'm using the error lines to synchronize the output and input tasks. Is this the right way to do? Or is there a better solution?

 

DAQmx_Sync_AO_AI.png

 

Thanks,

Dietmar

 

0 Kudos
Message 1 of 12
(6,188 Views)
Solution
Accepted by topic author schuller

Hello Dietmar,

 

There is a small mistake in your code.

 

The right implementation can be found in this link

Multi-function Synchronization for AI and AO

 

Try to use the same concept where you set the start trigger signal in one channel, and waits for that signal in the AI channel.

 

Guilherme Correa
0 Kudos
Message 2 of 12
(6,153 Views)

@schuller wrote:

 

The example uses Continuous Samples, whereas I'm working with Finite Samples (because I don't have a stop button in my application). 

  


Dietmar,

 

     Your code seems to generate signals for a fixed number of seconds, which you program with Finite Samples.  I believe (and I'm sure I'll be corrected if I'm wrong) that you could also use Continuous Samples here, as you have no While Loop (requiring a Stop button to exit it) and thus aren't doing a second Read.

 

     I tell my students that the basic difference between Finite and Continuous samples is what happens when the samples have been acquired and the function exits.  In the Finite case, you have to call DAQmx Read to start the next acquisition, whereas with Continuous, it automatically starts the next Conversion.  Since your code following the Conversion stops the (Finite or Continuous) task, the result should (as I understand it) be the same.

0 Kudos
Message 3 of 12
(6,147 Views)

Bob_Schor wrote:

     I tell my students that the basic difference between Finite and Continuous samples is what happens when the samples have been acquired and the function exits.  In the Finite case, you have to call DAQmx Read to start the next acquisition, whereas with Continuous, it automatically starts the next Conversion.


Hi Bob,

I don't get the point here (Iikely because I don't fully understand the concept of Continuous Samples).

In all Continuous Samples examples, including Multi-Function Synch AI and AO, there's a while loop calling DAQmx Read.

So I can't see that it "automatically starts the next Conversion".

Or what do you mean with conversion?

0 Kudos
Message 4 of 12
(6,142 Views)

Suppose you set up to sample 1000 points at 1KHz.  When you say "DAQmx Read", the Analog Input system starts "sampling" and 1 second later (1000 points at 1KHz), the function finishes and delivers an Array of 1000 samples (or a Waveform, or whatever you specified).  

 

If you set up Finite Samples, nothing more happens.  If you put this into a Loop (to get multiple "connected" samples, a second at a time, until you are done), then you might have a gap between your samples (depending on what else you need to do in the loop before you get around to "looping" and starting the next Read).

 

If you set up Continuous Samples, the moment the Read finishes, the next sampling starts.  Now put this into a loop, and let's say you code inefficiently (like try to display the 1000 points from inside the loop) and the other code take half-a-second before the loop "loops".  So when you get back to the Read, it is still running (having converted half-a-second, or 500, of the requested samples), so a half-second later, it finishes and delivers the next 1000-point sample.  There is no interruption in the data stream, i.e. the data are sampled continuously.

 

Bob Schor

0 Kudos
Message 5 of 12
(6,130 Views)

Please see this similar thread for more info on special considerations when syncing AI and AO on your DSA board.  Both the input and output paths have special bandwidth-limiting filters that add delays to the signal path.  Correlating your output and input data streams to know which voltages were truly in correspondence at the output pin at the same instant in time requires much more careful attention than with a "regular" multifunction board.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 6 of 12
(6,124 Views)

The similar thread you mentioned closes with a link to:

Dynamic Signal Acquisition (DSA) Synchronization Basics

 

The problem is, according to the table in chapter 4 USB-443x devices do not support synchronization.

 

@Bob: Thank you very much for explaining!

0 Kudos
Message 7 of 12
(6,114 Views)

Well, at least they kinda sorta mostly don't support synchronization.  The context of that part of the manual seems to be about synchronizing AI tasks across multiple DSA boards.  Definitely not gonna work over USB.

 

However, I think you only need to sync AO with AI on the *same* board.  That should be more-or-less feasible.  You would need to share a start trigger between the tasks, and you'd need to understand the filter delays in the two signal paths.  You'll probably then just discard/ignore the first N points of AI, where N accounts for the fact that the AI sample that gets buffered was present at the input pin some short time in the past *and* that the AO sample at the output pin at that same time in the past was itself delivered to the converter an additional short time in the further past.

 

Dunno all details of your board, but some DSA's don't support common sample rates for AI and AO.  That'll be another gotcha.  Nevertheless, some semblance of sync is probably still possible.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 8 of 12
(6,101 Views)

One more question:
Is it possible to acquire data at multiple inputs at the same time?

I ask because I tried to synchronize the analog output and two analog inputs, but that doesn't work.

0 Kudos
Message 9 of 12
(6,054 Views)

A little more detail please?  First question is about multiple inputs, followup explanation focuses on AO to AI sync.  Unclear exactly you're aiming to do and the specific nature of what "doesn't work".

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 10 of 12
(6,051 Views)