Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx AI Task with many samples CH0, then many CH2, then many CH3

I need to acquire data from multiple channels and wish to perform signal averaging by acquiring many samples from each channel as quickly as possible.  There is a limited number of total samples to acquire or a limited time frame over which to acquire these samples.  This process will then be repeated some time later (making it sort of like burst mode sampling) or it will be repeated later by restarting again with a software restart.  Such a multichannel sampling task can be configured by assigning a physical channel list of ai0:2 and then using DAQmx Timing vi with type Sample Clock to set sample mode of Finite Acquisition with say 100 Samples per Channel.  This task however will continuously alternate between channels such as 0,1,2,0,1,2, etc.  It is desirable to avoid multiplexer switching and subsequent settling times and instead acquire all samples from channel 0 first, then switch to and acquire all samples from the next channel yielding a channel list of 0,0,0,0...1,1,1,1...2,2,2,2...

 

How can such a task be configured to acquire many samples from one channel and then many samples from another channel ?  The channels will need to each have different input ranges or gains (but all samples from a specific channel will have the same input range).  It seems the entire channel list must be used an as input to DAQmx Create Virtual Channel.  Doing that then requires that a different "name to assign" for every channel in the task including the duplicate channels.

 

How can different input ranges be assigned for each channel, either using Create Virtual Channel or afterwards ?

 

Attached a vi that uses a for loop to generate a list of channels and unique names but is there a better approach ?

0 Kudos
Message 1 of 11
(4,816 Views)

Hi SteveP,

 

It sounds like you're on the right track.

 

> It seems the entire channel list must be used an as input to DAQmx Create Virtual Channel. 

 

Yes, but not necessarily at the same time. You can split up the channel list into multiple calls to DAQmx Create Channel. That makes it easier to change the input range for each group of channels.

 

> Doing that then requires that a different "name to assign" for every channel in the task including the duplicate channels.

 

That's right. The "name to assign" is used to set the virtual channel name. On devices that support repeated channels, a task can have multiple virtual channels that are associated with the same physical channel, but the virtual channel names must differ so that the task can tell them apart.

 

> How can different input ranges be assigned for each channel, either using Create Virtual Channel or afterwards ?

 

Using DAQmx Create Channel: call DAQmx Create Channel multiple times. Pass it the same task each time, but change the physical channels, name to assign, and input range.

 

Afterwards: use the DAQmx Channel property node to set the AI.Max and AI.Min properties. You need to set the ActiveChans property to the virtual channel name(s) that you want to change.

 

AI.Max and Min.png

 

By the way, repeating channels like this is how SCXI multiplexing works, behind the scenes. All of the AI channels in a given SCXI chassis are connected to the same channel on the digitizer, and that channel is repeated in the scanlist as many times as necessary, sometimes with a different input range for each repeat.

 

Brad

 

 

 

---
Brad Keryan
NI R&D
0 Kudos
Message 2 of 11
(4,810 Views)

Hi Steve,

 

You'll probably also find the VI from this example helpful:

https://decibel.ni.com/content/docs/DOC-6901

 

 

Best Regards,

John Passiak
0 Kudos
Message 3 of 11
(4,807 Views)

Brad and John,

Thanks for the guidance and tips.  It seems that the minimum allowed for Samples per Channel is 2 either using the DAQmx Timing property node's SampQuant.SampPerChan input or using the DAQmx Timing.vi configured for Sample Clock and its samples per channel input.  That forces at least two complete cycles of the entire channel list to be acquired, thereby requiring time to accomplish that.  Any way to only acquire 1 set of all the channels ?

 

With very large such channel lists that might exceed the size of the device's channel scan list, are there any concerns or does the DAQmx driver take care of transfering the channels ?

 

Is there any capability within the DAQmx driver of having it do averaging itself ?

0 Kudos
Message 4 of 11
(4,791 Views)

Hi Steve,

 

Thanks for bringing this up.  I actually just switched my example to use Continuous samples--it previously used Hardware-Timed Single Point (I knew there must have been a reason I used HWTSP in the first-place!).  If you only want 1 set you could set Hardware-Timed Single Point like my example previously did.

 

However, some devices (namely, USB ones) don't support HWTSP.  So, an alternative solution might be to make a finite task of 2 samples, but only read back 1 sample (remember, a "sample" is the entire scan list which would include multiple copies of each channel in your case).

 

 

The channel list limit is also an interesting question.  Credit to Brad for explaining this to me:

 

There is a hardware-specific limit to the scan list.  It is 4,095 channels (specced as "scan list memory") on M/X Series, and 512 channels (specced as "configuration memory size") on E Series.

 

However, the hardware also supports a something internally called the "div counter" which allows for multiple copies of the same channel to be repeated without having to use extra scan list entries.  There is only one div counter for all channels, so the greatest common divisor must be picked.  For example:

 

You are sampling ai0 4 times, ai1 8 times, then ai2 12 times.  The div counter would be set to 4, and your scan list memory would be filled with 6 entries {ai0, ai1, ai1, ai2, ai2, ai2}.  The hardware would repeat each entry 4 times.

 

You are sampling ai0, ai1, and ai2 each 100 times.  The div counter would be set to 100, and your scan list memory would be filled with 3 entries {ai0, ai1, ai2}.

 

You are sampling ai0 100 times, ai1 100 times, and ai2 3 times.  The div counter would have to be set to 1 (greatest common divisor), and the scan list memory would contain an entry for each of the 203 channels.

 

The driver manages the div counter for you based on the number of times you scan each channel.  In your case it probably makes the most sense to keep the number of scans consistent between channels.

 

 

There isn't currently any capability within DAQmx to perform calculations on acquired data within the driver, but the averaging should be pretty easy to implement.  I've added a modified version of the code I linked earlier to this thread that should do what you are asking for.

 

 

 

Sequential sample and average.png

 

 

Best Regards,

John Passiak
0 Kudos
Message 5 of 11
(4,781 Views)

John,  I am using an X series USB-6343 and so I will have to check whether it supports HWTSP.  If not, then I will look into checking when one sample set has finished being acquired and then read that out or just request AI Read to return 1 sample.  For now I am averaging over one 60 Hz power cycle.  I can envision though there may be other situations where that second channel list acquisition requirement might prevent somethign else from being able to be done.

 

I plan on sampling at the Maximum AI Conv Rate instead of the default rate which adds on an extra 10 usec to allow the multiplexer to settle.  That will enable more points to be acquired for averaging.  Since the same channel is being acquired repeatedly, settling time should not be an issue.  I will throw away some of the first points that will be taken just after the channel is switched.

 

It could be useful if the driver supported sort of the opposite of the div counter, whereby one could specify a channel and then how many times to sample it instead of having to fill the channel list with the same channel over and over again.

 

Steve

 

0 Kudos
Message 6 of 11
(4,774 Views)

Hi Steve,

 

USB X Series does not support HWTSP--the latency and non-determinism of USB makes the normal use-case for HWTSP impractical.  The 2 full iterations of the scan list shouldn't be a problem that I can forsee--as soon as you stop your task in software the 2nd scan will stop and if you want to do anything else with the AI you'd have to stop the task anyway.  The only real downside that I can think of is that the buffer would be twice as large as you needed (and you can't manually set the buffer size to one sample either).

 

Sampling at the maximum rate makes sense to increase the number of points you can averge, and throwing away the first few points is also a good idea (keeping in mind the settling time chart from the 634x specifications😞

 

2011-08-19_115940.png

 

 

I agree that having a user-configurable div counter would be quite a bit more elegant than calling DAQmx Create Channel hundreds thousands of times.  I'm not sure how common this use case is, but it's certainly worth a post at the Idea Exchange if you think it should be considered for inclusion within the driver.

 

 

Best Regards,

John Passiak
0 Kudos
Message 7 of 11
(4,758 Views)

It turns out that calling DAQmx Create Channel thousands of times takes about 100 msec per thousand channels on a CoreDuo P8700 2.5 GHz with DAQmx 9.4 and LV 11.  I am creating a total of about 8000 channels in order to acquire the maximum number of conversions over one 60 Hz power line cycle on a board capable of 500,000 kHz acquisition rate.  Any way to greatly reduce this time (other than modifying the driver) ?  Test vi attached.  I have posted this question to the LabVIEW discussion at

http://forums.ni.com/t5/LabVIEW/Speed-up-time-of-AI-Create-Channel-vi-task-containing-thousands/td-p...

 

 

0 Kudos
Message 8 of 11
(4,668 Views)

Hi guys,

 

I'm building an aplication with LabView 8.5 and a NI-PCI6221 Mseries board with the DAQmx driver. Now I can define the same range for all channels but to optimize my readings  I need to configure diferent ranges for each channel, for example ch0  +10/-10 V; ch1  +5/-5V, ch2  +5/-5V...

I think you all are working in this way, so your help will be welcome if you can give me some tips or examples.

 

Lot of TKS,

 

 

Beluja
"...you see, but you do not observe" (Sherlock Holmes)
0 Kudos
Message 9 of 11
(4,602 Views)

To SteveP,

 

Unfortunately there isn't really a way to reduce the amount of time required to create the high number of channels required--but the plus side is that you should only have to do it once at the start of your program.  You can keep the task handle in memory and re-use it as necessary for your application.

 

 

To beluja,

 

The code I posted earlier has the option to specify the range for each channel, but it also has extra stuff since it is sampling each channel multiple times.  If you want to have multiple channels at different ranges, all you have to do is call DAQmx Create Channel multiple times.

 

 

Best Regards,

John Passiak
0 Kudos
Message 10 of 11
(4,594 Views)