Showing results for 
Search instead for 
Did you mean: 

How to control sample duration during data acquisition

Go to solution

I managed to collect 16 channels of analog signals (write to measurement file VI) manually using a boolean start/stop control.  I would like to allow the user to set a sample duration on the front panel (e.g., 20 seconds) and initiate the sampling by clicking a start button.  The user can also terminate the data dump before the end of the set duration by clicking a stop button.  I looked at several countdown timer examples but couldn't figure out how to incorporate it to my VI.  Any suggestions and examples will be much appreciated.

0 Kudos
Message 1 of 11

You could change the DAQ Tasks to be Finite Samples.  The number of samples would be the duration divded by the sample rate.  Use the DAQmx Task Done VI to check to see if the task is complete.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 11

I tried opening your VI in both LabVIEW 2013 and LabVIEW 2014 -- all I got was a blank screen with what looked like labels for 3 controls or constants.  So I'm unclear why you are having trouble, as it should be a very easy task to use DAQmx to (a) configure your 16-channel A/D task, (b) start acquisition, (c) stream the data to disk, and (d) stop it at any time using a boolean Stop button.


If you want to stream data, you should consider a Consumer/Producer pattern -- have the loop generating the samples (the A/D loop) running at some fixed speed (your sampling rate) put the data onto a Queue.  Have a Consumer loop looking at the Queue, and as fast as stuff appears on it, take it off and write it to disk.  Note that when stopping the system, you want to stop the Producer first, and stop the Consumer only after it finishes writing the data to disk (it should "time out" while waiting to dequeue stuff).




P.S. -- if something I've written doesn't make sense or sound familiar, consider looking at Examples or doing a Web search -- you'll learn a lot.  Also, there are some awesome tutorials on DAQmx on the NI site.

0 Kudos
Message 3 of 11

Thanks for the responses.  I have attached the vi in pdf.  I have found a timer program online and will try to incorporate it in my VI to control the duration of data dump (write to measurement file).

0 Kudos
Message 4 of 11

No, you've attached some pictures of your VI.  Why not just attach the VIs themselves?  It would've been quicker to do that than to take screen shots and convert it to pdf and upload it.

(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 11
Accepted by topic author jchow89
You are making things far too complicated. For one, there is the Elapsed Time function on your palette. Second, as already mentioned, there is a basic arithmatic relationship between samples per second and number of samples read. Use that, you are going to get more samples than requested anyway. Lastly, your code shows two analog read tasks. You can't do that unless there are two separate devices.
Message 6 of 11

Thanks for the pointer ... the Elapsed Time function gives me the results I want.  Yes, I have 2 devices - a USB-6008 and a USB-6009. Not sure if they can be synced since each has only 1 PFI line.  From what I read, you need 2 PFI line to sync 2 devices -- 1 for timeing and the other for triggering.

0 Kudos
Message 7 of 11

@billko wrote:

No, you've attached some pictures of your VI.  Why not just attach the VIs themselves?  It would've been quicker to do that than to take screen shots and convert it to pdf and upload it.

What he did was sort of interesting (and probably pretty fast). Apparently he printed the block diagram directly to pdf output using the print command and a special print driver (I have one of those too!).

This has clear advatages over screenshots, because it also shows all other cases of case structures.


Still, We always prefer actual VIs. 😄

Message 8 of 11

Knight of NI: I attached a VI with my first post but Bob_Schor was not able to open it (or just blank).  That's why I attached pdfs.  I here attach a VI (created using LV 2013 SP1) and see if you can open it.

0 Kudos
Message 9 of 11

It is not clear is you want the user to select (1) 20 seconds of indvidual measurements or (2) 20 seconds worth of your measurement sets that are 1000 data points at 1000 Hz.  If (1) then your timing needs to be handled in the task setup.  If (2) then your timing needs to be handled in the loop.


I have found setting up DAQ task in NI MAX or directly into the project to be easier and less cluttered.  But I guess that is more of a preference.

0 Kudos
Message 10 of 11