LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to collect data for n seconds after pressing button

Solved!
Go to solution

Hello. Any help would be greatly appreciated. I have done my best to learn from other examples in the forum, but I am still struggling to find a solution. My vi is attached below. Thank you!

 

My goal is to generate a continuous signal. Then by pressing the "Collect Data" button, this signal is recorded (amplitude vs time) for n seconds. After n seconds, the user is prompted to save the n seconds of data. Throughout all of this, the signal must continue to be generated.

 

My vi has 2 issues:

1. The "Elapsed Time" resets to 0 after the 1st data collection, but it continues to repeatedly count from 0 to n even when "Collect Data" is false. As a result, the "Elapsed Time" is not at 0 when the "Collect Data" button is pressed again. The good news is that once the desired "Elapsed Time" is reached, the "Collect Data" button is turned off.

2. Only 0.1 seconds of data is recorded and not the desired n seconds. Once the "Collect Data" is pressed, I wanted the signal to start being loaded into an array. Once the desired "Elapsed Time" is reached, then this array (with n seconds of data) is then saved. At least that was my idea.

Capture.JPG

0 Kudos
Message 1 of 21
(5,560 Views)

Look at all the inputs to the Export Waveforms to Spreadsheet File.

 

You might want to consider "Appending" the data.  Also supply a filename.

0 Kudos
Message 2 of 21
(5,548 Views)

Thank you for your comment, RavensFan. I think hardwiring the filename will not work for my application since I will be saving different files each time the "Collect Data" button is pressed.

 

I would think that my goal is a common one, so are there any sample vi's for this? I imagine that someone that knew what they were doing could code this in a few minutes. I am still struggling to find a solution by myself and in these forums. Thank you!

0 Kudos
Message 3 of 21
(5,492 Views)

1) Reset the Elapsed Time node when Collect Data changes value (think feedback node)

2) When time has elapsed, you are only collecting the last data set.  Everything else is being thrown out.  Consider , while Collect Data is true, appending to an array stored in a shift register.

Message 4 of 21
(5,480 Views)

Thank you, Mancho00. With your suggestion of a boolean feedback node and a comment RavensFan gave to someone else years ago, my "Collect Data" switch now works perfectly!

 

I am still having trouble with building the array. Each time I press "Collect Data," somehow I need to zero the array and load the real-time signal into this array for n seconds. Once "Time has elapsed" is TRUE, then this array is saved.

 

My vi does the following, which is a problem:

1) 0.8 seconds of data is saved when data is collected for 1 second if "Collect Data" is TRUE as soon as the vi starts.

2) 6.9 seconds of data is saved when data is collected for 1 second if "Collect Data" is clicked TRUE after running the vi for 10 seconds

 

(For troubleshooting, I have hardwired the File Save Path for now.)

WorkingBoolean.JPG

0 Kudos
Message 5 of 21
(5,471 Views)

Well, the simulation takes time to run (more than the time it takes to get the number of samples you configured it for), so you might not get a waveform that is as long as your desired data collection time.

Secondly, you'll want to append the waveform inside the case structure. Right now you're constantly appending, which you don't want.  Replace the feedback node with a shift register.  Initialize with an empty waveform outside the loop, and in the false case replace with an empty waveform.

 

wvfm shift.PNG

Message 6 of 21
(5,453 Views)

Thank you, Mancho00, for your help. With your advice, the generated signal is now recording correctly.

 

I have been unsuccessful with the final addition to my vi. In addition to recording the generated signal, I also want to record a separate analog voltage input and save both in the same file. I am receiving the error, "The application is not able to keep up with the hardware acquisition." I have used the same USB-6259 DAQ to continuously measure two analog voltage inputs at 500kHz each. But my current vi is unable to record the signal and analog input at just 100kHz each. Is the signal generation really that consuming? My vi is shown below and also attached.

 

 

N Seconds of Data.JPGN Seconds of Data_2.JPG

0 Kudos
Message 7 of 21
(5,423 Views)

Any help would be greatly appreciated!

0 Kudos
Message 8 of 21
(5,385 Views)

You are using Express VIs , which put limits on what you can do simultaneously (one of the key features of LabVIEW's Data Flow model).  You are collecting a lot of data, and you are now doing two Data Collection tasks in parallel (which is fine), but it looks like your Data Storage part of the code is being done sequentially (i.e. "Collect, Save, Collect some more, Save some more).

 

Look up the Producer/Consumer Design Pattern, which frequently uses a Queue to pass the data from a Producer Loop (which has the DAQmx Read that gets the data at the rate and amount you specify, "blocking" while the data are being acquired, but then putting the Data on a Queue which takes very little time, almost instantaneous) and a Consumer Loop which asks "Are there Data?  If so, do something with it, like write it to disk, else keep waiting".  The Consumer "blocks" while it is "consuming" the Data, for example, while it is writing to disk, but as long as it can "Consume" at the same rate that the Producer is "producing", the two routines can usually utilize the "free time" that the other loop is blocking to "do two things at the same time".

 

Herem is an NI White Paper that discusses this in more detail.  While you are "learning", do a Google Search for "Learn 10 Functions in NI-DAQmx" and get rid of the Dreaded DAQ Assistants in your loops, replacing them with DAQmx functions.  

 

Bob Schor

0 Kudos
Message 9 of 21
(5,371 Views)

Thank you, Bob_Schor, for your help. Below is my first attempt at a producer/consumer architecture. I've looked at over a dozen examples on the forums and read several resources, including the NI White Paper you linked.

 

I am trying to start simply by creating a vi that records n seconds of waveform data (time and magnitude) when the "Collect Data" button is pressed. Once n seconds have elapsed, the data is saved. In the future I hope to record two waveforms with synced time to the same file (time, magnitude A, magnitude B). Would this require 2 producers and a single consumer?

 

The "Collect Data" button still turns on/off correctly, but the save file is empty. What am I missing? My vi is attached and shown below. Thank you!


Producer Consumer.JPG

0 Kudos
Message 10 of 21
(5,357 Views)