Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

how do I synchronize multiple ai

I need to synchronize two (or more) AI channels with at least one AO channel.  So far, it's been straightforward to sync one AI with the AO.  I used the method in the "simultaneously_started_aiao.vi" example, and it works fine.

The problem is when I add another AI channel, it is not in sync with the others; it seems to have some random timing that wanders around.

Now, I could use a single task with multiple inputs, but this won't allow me to set separate voltage limits (gain) and sample rates for each input channel, so I I'm forced to use two separate tasks.

However, I'm not allowed to have two starts on ai (even with separate tasks), nor can I set a trigger on, say, ai1 with ai0 as a source.  I tried something in (attached) simultaneously_started_aiao1.vi, but it's not working, and I'm stuck.

Any ideas?


Also, separate question:  The first data point of the ai in the example (simultaneously_started_aiao1.vi) is always off - rerun it a few times and you'll see that the ai data's first point is off by a "random" amount.  Why does this occur?  It's clearly not correct.

Thanks for any help!

(Running Labview 7.1)

0 Kudos
Message 1 of 11
(4,273 Views)
You are not forced to use separate tasks for separate gains but you cannot use separate sample rates for two channels. The only way to get different sample rates is to stop one task before starting another and if you do that, then you cannot acquire both channels at the same time. To use different gains, just add another DAQmx Create Channel to the existing task or put a single DAQmx Create Channel inside a for loop and pass it arrays of channels and gains. Select a single sample rate.
0 Kudos
Message 2 of 11
(4,260 Views)
Thank you for your help.  I'm not sure that this is correct; in my implementation using two different sampling rates seems to work correctly; each AI has its own task, and the sample rate information is passed into DAQmx timing blocks.  The resulting data seems to be correct, though I certainly could be misinterpreting things.

But in any case, I can manually set the sample rates to be identical, but the sync is still not there between the two AI channels.  I'll try your advice in putting both AI's in the same task, and adding a channel within the task (w/separate max/min) and see if that works.
0 Kudos
Message 3 of 11
(4,249 Views)
The only reason you are able to set two different sample rates is that one task is starting and stopping and then the other task is starting and then stopping. Since you have no loop, this only happens once and your VI stops. If you are doing something like using the run continuous button, stop using that! Use a single task and use a while loop around the code you want to keep running. It looks like there was once a while loop but you removed it.
0 Kudos
Message 4 of 11
(4,246 Views)
In the actual application (not the example attached) there is a while loop running the whole system, and the AI data looks correctly multiplexed, it's just not synchronized properly (only AI0 is in synch with AO0; AI1 comes in correctly, but with "wavering" timing relative to AI0/AO0). I'll have to check further to see if I really am getting different sample rates, or if it's a scaling illustion elsewhere (it could well be).

I'm sort of surprised by the equal sample rate limitation; I recall that this was no problem in older multifunciton DAQ boards (pre-DAQmx).  In fact, I remember having to choose my relative sample rates carefully to avoid multiplexing artifacts (switching noise from the boards).  But I can live with a single sample rate on the input now that the hardware is plenty fast.
0 Kudos
Message 5 of 11
(4,242 Views)
You have never been able to select different sample rates on boards that did not have separate sample clocks (i.e. most NI boards). Traidtional DAQ was no more able to change the hardware than DAQmx. If you were using different sample rates on the same board, then you were doing the same as in your example. It would do one acquistion, stop, start the new acquisition, stop, etc.
0 Kudos
Message 6 of 11
(4,234 Views)

Hi Joe42,

I don't know if you've noticed Dennis' icon? It was made specially for him for 10,000+ posts. The guy knows what he's talking about. Like Dennis mentioned, you can create different channels for ranges and input types (voltage and current, etc.) but they all must have the same timing. You can sample at the fastest rate you need and then decimate the data afterwards, but that's the closest you'll get with the same piece of hardware.

Loquito

0 Kudos
Message 7 of 11
(4,216 Views)

Hi Joe,

Welcome to the forums! I wanted to expand some on the answers that Dennis and Loquito provided. Loquito’s suggestion that you sample faster than you need to and then decimate (or skip/throw out the extra samples) in post processing was a great tip. This would let you put both channels in the same task, sample at a high rate, and achieve the necessary synchronization with the appearance of different sample rates. The image below is what Dennis was referring to when he said “To use different gains, just add another DAQmx Create Channel to the existing task”. Each Create Channel function would have a different physical channel input wired to it, but you could then wire different gain values.

The reason that you can only have one task of any given type running at a time is that the second task’s DAQmx Start, Write, or Read Functions would need the Reference Clock, which is in use and reserved by the first task. I am sure that when you were creating this code you experienced resource reserved errors. This is also why you were only able to get the code to work by removing the second start function. By removing the start function, you let the second task auto-start once the resources were freed (i.e. after the first task finished). You can only have one task of each type running on a single device, for example you can have 1 analog output and 1 analog input, but not two analog inputs at the same time on the same card. It sounds like we have a work around though.

Regards, Mallori M.



Message Edited by mallorim on 05-06-2008 03:45 PM
Mallori M
National Instruments
Sr Group Manager, Education Services

ni.com/training
0 Kudos
Message 8 of 11
(4,204 Views)

I'm have the same issue with synchronizing multiple AI channels with a single trigger source.  I have attached both the front panel and the block diagram for a reference.  I am using the NI cDAQ-9174 chasis with a NI 9402 (slot 1) module and NI 9205 (slot 4) module.  It seems whatever channel is created first is in sync with the trigger source while the second channel in not (returns something around 0).  I have tried to putting both channels in the same DAQmx Create Channel.vi with the same results, just the first channel is in sync.  If I each channel individually I get a signal in the channel.

 

Any ideas?

Download All
0 Kudos
Message 9 of 11
(3,693 Views)

Hi BPyke,

 

Just for clarification, what happens when you get a signal in a channel?

 

Regards,

Jordan G. 

LabVIEW Product Marketing Engineer
National Instruments
0 Kudos
Message 10 of 11
(3,667 Views)