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.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

On demand (loop-based) acquisition and DAQ sampling rate

Hi, good day. I currently have an on-demand configured counter which measures angular position within an while loop (working fine). At the same time, i have another separate loop which contains an AI task set at sampling rate 1kHz that measures something else. Both loops share the same condition boolean thus are able to stop at the same time (well, almost).

I have problem correlating these 2 loops, if say my counter acquisition takes 1s to complete, my other AI loop would have probably ran 2 or 3 times due to the fast 1kHz acquisition time. I've tried setting the AI task sampling to Continuous and put it into the same loop as the counter but this prevents my loop and counter from stopping instantaneously, because even if i stop the loop, the program has to wait for the AI task to complete before executing exit which causes a slight delay.

Is there any way to solve this?
0 Kudos
Message 1 of 2
(2,609 Views)

Hello ATMA,

I am a little confused about your post.  I built an exemplary VI to show the different behaviors, and I cannot figure out how you are creating the behavior you are seeing. Below is how my program is set up, and the fast loop stops immediately.



The only way I can replicate the behavior you are seeing is by using Functional Global Variables.  If this is the case, then I would recommend using a local variable instead (like my example).

Your method of putting the two (with AI continuous) in the same loop should work as well.  The things to make sure you have include setting up the task timing (to your 1kHz sampling rate), and have the samples to read on your DAQmx read set to -1.  This reads all the available values in the buffer, and should not hang up the program at all when stopped. 

In order to still control the rate of your counter (using software) you would have to only sample once every X times your loop ran (so if your loop is set to run once every 10ms, you want to read every 10th loop).  The programming would look something like this:


Depending on your DAQ device, you could also used a buffered counter.  This means that you provide a sample clock to read the value of the counter and latch it into a buffer.  Your sample clock would be running at 1Hz in your example.  The catch with this is that you need an external clock source since the counters do not have one of their own.  What we usually do is to use another task (e.g. AO task) to generate the sample clock and then specify that as the source for our counter. This way, you could read both tasks at the same time and everything with the timing could be controlled in hardware.

I hope this helps you out,  If I am misunderstanding the setup or if you have any questions, please post back.



Message Edited by Neal M on 12-12-2007 12:18 PM
Neal M.
Applications Engineering       National Instruments        www.ni.com/support
Download All
0 Kudos
Message 2 of 2
(2,583 Views)