Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

AI with timed loop

Hi,
 
I am using NI USB-6229 for AI measurements, reading all channels. see enclosed VI.
It is important to my application:
1. to read data in fixed period of 100ms.
2. to read the most recent samples.
So, I have placed DAQmx Read twice in Timed Loop uses build-in timing source 1kHz and period of 100ms.
The explanation for placing DAQmx Read twice is: one with number of samples per channel = -1 while ignoring data (serves as clear buffer), and another with number of samples per channel = number of samples to read (to achieve most recent samples).
 
In the enclosed VI, DAQ Sample rate = 2000Hz, Samples per channel = 100, and I expect Timed Loop Iteration Duration to be at least 50ms (100/2000 = 0.05s = 50ms). in actual fact, Iteration Duration < 10ms.
 
My question is why Iteration Duration < 10ms, do I miss something?
 
thanks,
Avivit.
0 Kudos
Message 1 of 5
(3,677 Views)
Hello Avivit,

I tried out your code on my system and it seems to be working correctly (I have attached a screenshot of the front panel). I am running Windows XP and I used a board with 16 analog input channels. Is your DAQmx Read function returning 100 samples for each channel in the array? Also, if you reduce the period of your timed loop to be something such as 50ms or slightly less, will it finish late? If it claims it is taking < 10ms to execute, it should not finish late unless it is actually taking the full 50ms. Another thing that may be useful to try is to use a regular while loop and measure the amount of time the loop takes to iterate. I hope this helps,


Message Edited by dansch on 07-07-2008 08:25 PM
Daniel S.
National Instruments
0 Kudos
Message 2 of 5
(3,649 Views)
Hello Daniel,
 
Thanks for your answer.
 
Did you try out my code with the same board (NI USB-6229) as I am using?
My DAQmx Read function returning 100 samples for each channel in the array, and I can see few iteration of Timed Loop 'Iteration Duration' of about 50ms and then it falling down to about 2ms. It seems like, DAQmx Read with samples per channel = -1 NOT clear the buffer, and Timed Loop 'period' > 50ms cause DAQmx Read to read old samples from the buffer (takes 2ms).
Reducing the period of timed loop to be 50ms makes it working correctly, but it's too fast for my application.
 
While using a regular while loop, the amount of time the loop takes to iterate is 50ms, but when I have added 'Wait Until Next ms Multiple' with 100ms, like in Timed Loop structure, the same symptom appears.
 
My goal is to read most recent samples in a fixed period of 100ms, so my crooked solution (see enclosed VI) is to add delay before DAQmx Read (to let DAQ acquire samples), use DAQmx Read Properties: OverWrite Unread Samples and RelativeTo Most Recent Sample, and then read data from buffer.
I hope it is working correctly...
 
Avivit.
0 Kudos
Message 3 of 5
(3,613 Views)
Hi Avivit,

I am curious if you have looked at the data returned when you read "-1" samples to clear the buffer.  Are you getting any data?  I have a hunch that this is a side-effect of the way our USB devices transfer data.  USB transfers so that the device is told to send data in the largest chunk size possible for efficiency purposes. So if the chunk size is (let's say) 100 samples, the buffer will fill up 100 samples at a time.  When you read "-1" that means that you want all samples available.  However, there might not be any available in the buffer since we may not have sent a packet of data.

However, what you are doing now, Overwrite and Read Most Recent, should give you the behavior you desire.  If that is working for you, I would stick with that.
------
Zach Hindes
NI R&D
0 Kudos
Message 4 of 5
(3,586 Views)

Hi,

I have looked at the data returned when I read "-1" samples, and I am getting data as following:

When period = 100ms I am getting data around 100 samples, when period = 50ms no data available, and when period = 60ms I am getting data around 20 samples. So when period > 50ms there is data availble to read before reading the desired data.

However, I would stick with my solution.

Thanks, Avivit.

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