LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx Read behavior question

I have a vi that reads voltage using DAQmx Read. After creating the task, the vi sits in a loop reading and waiting until a voltage greater than 3 volts appears on a pin (device insertion detection). Originally, the vi kept the task open and went on to measure more voltages, process them, etc. With this setup, it seemed that the time that was spent in the "waiting for device" loop was applied to the "measure device" loop. For example, if the vi spent 3 seconds waiting for the device, then the "measure device" loop quickly ran up to the 3 second mark in less than 1 second, putting data in there from when it was waiting for the device (unwanted data). This was worked around by destroying the "waiting for device" task and creating a new one to measure the device. I was just curious as to why this happens. Is there a better solution (e.g. reset timing, reset buffer, etc) than what I came up with? Thanks everyone in advance for your replies!

 

I'm using LabVIEW 8.5 with a USB-6211 DAQ. Not sure which version of DAQmx I'm using, but the read functions are both Analog 1D Waveform NChan 1Samp running continuously at 10Hz (1 sample per channel).

 

-Ken 

0 Kudos
Message 1 of 6
(3,254 Views)

Why don't you post your VI so we can see what you are doing while we read along with your description.  It is difficult to follow along or be able to suggest anything if we can't see what you are doing now.Smiley Wink

0 Kudos
Message 2 of 6
(3,248 Views)

Ah, yes... that would probably help! Sorry about that.

 

 

0 Kudos
Message 3 of 6
(3,234 Views)

I think the problem is the way you are setting up the timing in your "measure device" loop.  That loop has no timing built into it whatsoever.  You are relying on iteration counts to determine when you are going on to each state.  The iteration number is determining which state you are in based on an awkward case structure.  You've tied your states to iteration number rather than to time.  If you change your timing, it forces you to redo your case structure and rebuild your "states".

 

There is some timing going on in that loop.  Any given iteration is going to take as long as the code in it takes to run.  But the only thing that could cause those iterations to take longer is the DAQmx code waiting for a sample to come in.  This is where your timing breaks down.  You start your DAQ tasks in the first loop with continuous samples.  So during those 3 seconds, you've started accumulating samples at a rate of 10 Hz.  By the time your code gets to the read portion, some of those samples may have already been acquired.  You may have read 5 samples or so in the DAQ buffer before you read the first one.  So that iteration will occur quickly, so will the next and the next, until the number of iterations of your acquisition loop have caught up to all the data that is acquired.  From there on out, the loops will slow down to your intended pace of waiting for the sample to come in and then reading it.

 

What you need to do is set that measure device loop to be a state machine.  Take the time before it starts and store it in a shift register, then compare the current time to that value and determine when all the transitions need to take place.  You may want to read all the samples in the DAQ buffer right as the loop starts (rather than 1 at a time).

0 Kudos
Message 4 of 6
(3,222 Views)

I see now that that was not the best way to do the timing. I'm going to change this to the method you suggested. Could a "Wait Until Next ms Multiple" set at 100ms work here, also? Just wondering.

 

-Ken

 

Hey, GO RAVENS! Well, next year.

0 Kudos
Message 5 of 6
(3,215 Views)
I think a 100msec wait (or wait until next mult) in the loop along with reading all samples in the buffer right before that loop starts (to flush the buffer) should give better timing.  Go ahead and try it.  It isn't a major change to the code and will help show whether it could solve the problem.
0 Kudos
Message 6 of 6
(3,204 Views)