LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

write to measurement file timing

I am trying to make a VI that allows the user to turn on and name channels through the front panel. After the user has configured the channels, they can push a button and record voltages from the enabled channels and save them using the "Write to Measurement File".vi.  I would like the user to be able to record a measurement file that is consistent in length each time they push the button...in this case, 5 seconds of data.  The current VI doesn't appear to be doing this...everytime I push the record button, the data gets recorded for 0.045 seconds.  Apparently I must be missing something as this isn't behaving how I expected it to.  See attached VI.

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

It waits 5 seconds then saves the last 10 samples.  Because that is the way you programmed it.  The while loop returns only the data from the last iteration.

 

Two ways to do what you want: 1. Read 5 seconds * 200 samples/second = 1000 samples.  No loop required.

2. Read 10 samples at a time and accumulate the data until you have 5 seconds of data.  To avoid memory reallocations the way to do this is to Initialize an array with 1000 elements outside the loop. Wire it to a shift register.  Inside the loop Read the samples and use Replace Array Subset to put the new data into the initialized array. Wire the output of the shift register to the file VI.

 

You generally should not put any time consuming code inside an event structure.  Read the caveats in the detailed help for the event structure.  Consider a Producer/Consumer architecture.

 

Lynn

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

Thanks for the help.  Your 2nd solution sounds like it would work better for me, but I am have some difficulty trying to implement it.  I guess I don't understand what is wired into the Initialize Array. I attached the VI, from what I interpret from your description of option 2.  

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

Since you are reading multiple samples on multiple channels, you need a 2D array.  If you need the timing information from the waveforms, it gets somewhat more complicated, but this will give you the idea.

 

It is Replace Array Subset, not Array Subset which you need to use inside the loop.

 

I may have rows and columns interchanged.  I do not have any DAQ stuff to check.

 

Lynn

 

Accumulate data.png

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

Note that if you are taking continuous data from the DAQ board, you can use it to do the timing for you (and it will do a better job).  Calculate the number of points needed based on the acquisition rate and how much time you want data taken.  Then set the number of iterations of a FOR loop instead of a WHILE loop to take the data.

 

Also, I want to second Lynn's suggestion to use a producer/consumer architecture.  It would be VERY easy to run out of memory with unbounded array sizes in this program.  If you were writing data to disk as it was gathered, you would not have this issue.

0 Kudos
Message 5 of 6
(2,989 Views)

Thanks for the help guys.  I think I am going to try and take this in a different direction.  Looks like I will need to do my homework on the producer/consumer architecture, as I had not heard of it before.  

0 Kudos
Message 6 of 6
(2,977 Views)