LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building a Waveform (DBL) Array Inside a While Loop.

Howdy,

I saw this post (http://forums.ni.com/ni/board/message?board.id=170&thread.id=306147) a while ago and I'm trying to do something really similar.  I've created VI, which you can see below, and there were 2 questions about it that I wanted to ask.

1.  Given that I plan on sampling at 1Hz using the CF-6004, will this be efficient?  I originally wanted to build an array of 1Hz sample and then writing this array into the file instead of constantly writing to the file.  This leads me to my next question.

2.  How do I build an array as Dennis Knight suggests in message 5 of 9 in this thread: http://forums.ni.com/ni/board/message?board.id=170&thread.id=306147?
-------------------
"if you want to save every 15 minutes, use an elapsed time function and wire the 'time has elapsed' output to a case statement. Put your file write inside the case statement. Use a shift register and a build array and pass this to your write function. After the write is complete, clear the array."
-------------------
Would I have to do something along the lines of what's describe here: http://forums.ni.com/ni/board/message?board.id=170&message.id=179767?  More specifically, would I have to something along the lines of creating another loop inside of my while loop, have an index enabled tunnel and then read from that - I'm not sure where a Build Array would fit in here?  If so, how would I configure this setup so that I maintain my 1Hz sampling rate?  Do I use a time delay somewhere in that loop - thereby having 2 time related VIs: 1 for writing to the file, and another for collecting samples?

I apologize for the n00b questions.  Thanks for the help.

Mark
0 Kudos
Message 1 of 2
(3,421 Views)
Hi Mark,

The code you posted will be somewhat inefficient because you are starting and stopping the task inside the while loop.  It is better to start and stop outside the loop and perform the acquisition inside.

However, I would consider taking a step back and approaching this from a different angle.  If you don't have a need to write to a file "on the fly" (i.e. as you are acquiring data), then you need not worry about the elapsed time VI or the case structure.  Instead, continually build an array of data as your loop iterates and then pass the final array to the file after you exit the loop.

To build the array, you can either:
1.  Pass the output from the DAQmx read to the exit of the loop and enable indexing, or
2.  Use a combination of a shift register and a build array function.

For both of these, you'll likely want to change the polymorphic instance of the DAQmx read VI to Analog » Single Channel » Single Sample » DBL.  Also, add a wait function to your while loop and specify 1000 ms so that the loop will iterate every one second.
Eric C.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(3,379 Views)