LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Acquiring 1 data sample from DAQmx

Hi folks,

 

I'm trying to acquire data from a Force sensor connected to an DAQ card in sync with some other devices. Problem is, the other devices run at a much lower frequency.

 

Reading just one sample from DAQmx in a timed loop often results in errors because the software can't keep up with the hardware acquisition, so my solution is to read N samples from the DAQ at a certain frequency and then discard N-1 by indexing the 0th element of my output and recording just that (Image attached).

 

However, I found this page from 10 years ago which says "DAQmx does not allow the user to specify whether the newest or oldest data is read from the FIFO; it always reads the newest and clears the remaining FIFO." If it is FIFO, how is it reading the newest data? Shouldn't it be reading the oldest?

 

My question boils down to this: should I be indexing the first or the last element/row of my output in order to get the data that was acquired when the loop started?

 

Any alternative suggestions on recording just 1 sample are also welcome. Note that I can't stop the DAQ and start it within the loop becuase that reduces the frequency below my threshold for recording data.

0 Kudos
Message 1 of 8
(5,287 Views)

Please do not attach pictures of code -- attach the code itself (i.e. the VI).  This will allow us to (a) determine which version of LabVIEW you are using, (b) see the other "cases" of your Case Statements, (c) get LabVIEW Help for functions that are unfamiliar, and (d) modify and test your code.

 

What DAQmx device are you using?  When you describe "in sync with other devices", can you describe this a bit more completely?  Is this with the same DAQ device?  Are all of the samples "analog input"?  How many channels and at what data rates?

 

Bob Schor

0 Kudos
Message 2 of 8
(5,274 Views)

I've attached the VIs now. The first one uses the DAQ alone for reading a force sensor, whereas the second VI integrates the DAQ and a USB device.

 

The DAQ is an NI m series model. The other sensor I'm using is an APDM motion tracking accelerometer/gyro/magnetometer set plugged in directly to the PC via USB. I'll soon have to add an optical tracking system as well. These sensors cannot be connected to the NI DAQ card. I'm pretty sure the data I'm getting from the APDM sensors is not analog. 

 

Also, if I use a timed loop, how can I set the source to be the same as the external DAQ timing source?

Download All
0 Kudos
Message 3 of 8
(5,263 Views)

@fj11 wrote:

 

The DAQ is an NI m series model.  Which one?  Specify model number, please.  I'm puzzled by your remark that you can't set this up to give you a single sample when you ask for it, as I've never encountered this difficulty.  Should this, in fact, be true, you can always simply acquire 100 samples at 10KHz (which will take 0.01 sec), average them (to remove the noise), and have a "representative sample" of the data over that 10 msec period.

 

The other sensor I'm using is an APDM motion tracking accelerometer/gyro/magnetometer set plugged in directly to the PC via USB. I'll soon have to add an optical tracking system as well. These sensors cannot be connected to the NI DAQ card. I'm pretty sure the data I'm getting from the APDM sensors is not analog.

 

Errr -- I'm not happy about the APDM VI (mainly because I don't "get" what you are trying to do).  I see MatLab code, DAQmx code, Frames (I don't like frames).  I'm not sure what's going on.  But what I'd recommend is to think about writing a LabVIEW "wrapper" that you can call that will "do what needs to be done" to return you a data point (or an array of data points) from your accelerometer.  You would then put this sub-VI (let's give it the catchy name "Get Acceleration") in your other routine with the DAQ card that's providing the timing ... 

 

Also, if I use a timed loop, how can I set the source to be the same as the external DAQ timing source?

 

Simple, don't use a Timed Loop, let your DAQ device provide the timing.  For example, if you sampled continuously at 10KHz and took 100 samples, your Read DAQ function would return values every 10 msec (at 100 Hz).  If this is the timing you want for your "slower" devices, just get them to sample when the DAQmx device returns data, which (a) forces them to run at 100 Hz, and (b) ties their I/O to the I/O coming from DAQmx.


Bob Schor

Message 4 of 8
(5,229 Views)

Thanks for your reply Bob.

My original question remains unanswered. I'm not interested in averaging data over time. My objective is to get the sample at the exact same time (or as temporally close as possible) as the APDM data. The link I've provided says the latest data is read from the FIFO, but the use of FIFO should imply that the oldest is read first. If my daq runs at 1000Hz for 100 samples, should I use the 0th column or the 99th column of my output data to read the first sample? I'm pretty sure it should be 0, but the link seems to suggest otherwise.

 

I'm puzzled by your remark that you can't set this up to give you a single sample when you ask for it, as I've never encountered this difficulty.

The trouble is not getting a single sample, but simply that the software can't keep up if I put it in a timed loop. The more I play around with stuff, the more I realise that having a DAQ task in a timed loop is a bad idea.

 

Simple, don't use a Timed Loop, let your DAQ device provide the timing.  For example, if you sampled continuously at 10KHz and took 100 samples, your Read DAQ function would return values every 10 msec (at 100 Hz).  If this is the timing you want for your "slower" devices, just get them to sample when the DAQmx device returns data, which (a) forces them to run at 100 Hz, and (b) ties their I/O to the I/O coming from DAQmx.

Thanks, that's what I'm doing now. What I don't understand is how I'm getting my data at intervals of 10ms (reading 100 samples at 10000Hz) even though the data acquisition itself takes 10ms before a file write task. Is the writing to file a sub millisecond operation?

0 Kudos
Message 5 of 8
(5,209 Views)

I'll repeat my first question -- what exactly is your DAQ device?  I would like to verify that you cannot take a single sample with this device, and if that truly is impossible, to help you resolve how to do "the best you can".  But I cannot do that if you refuse to tell me the device ...

 

Bob Schor

0 Kudos
Message 6 of 8
(5,198 Views)

Sorry, didn't have access to the device over the weekend. It's an X series USB 6343 device (not M as I mentioned earlier).

0 Kudos
Message 7 of 8
(5,167 Views)

Thank you.  Attached is a VI that reads one point at a time from a 6343, plotting each point on a Chart.  I have it doing it at the rate of 10 points/second for 100 points, but I could also have made it work whenever I pushed a button -- it's the call to the One Sample Read that does the trick.

 

You'll notice the Task constant, "SingleSample".  This is a Task that I created in MAX for the 6343, where I told it to take a single sample from Analog Input 0 whenever I told it to (what NI calls "On Demand"), saving the Task with the name "SingleSample".  When I wrote the VI, I clicked on the Task input for the DAQmx Start function, chose "Create Constant", then clicked the downward Triangle which brought up my MAX Tasks.  I chose SingleSample.

 

Single Sample from 6343.png

This should do exactly what you said you needed.

 

Bob Schor

0 Kudos
Message 8 of 8
(5,157 Views)