LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Measurement, averaging, and writing to a file

(VI ATTACHED) I am monitoring multiple thermocouples and logging the data into a text file. I am having multiple small issues with the program. The program takes a user input which chooses the interval at which measurements are written to a file.

1. Is my file opening and closing every time the loop runs? If I leave headers in, I get one for every single measurement that gets taken. It's really annoying. Is there any way I can open the file outside of the loop and write to it inside the loop, or is it fine the way it is?

2. How does the 'Number of measurements' work in continuous data logging? It seems like there is some data structure that holds the number of measurements you choose to take. If you set your frequency to 1Hz and your number of samples to 10, will those samples be taken at a regular interval within the chosen period? 

Also, would it be more efficient to only measure once for each iteration of the loop?

3. When the user specifies 3s (for example) as the delay time, a measurement is recorded usually every 3 seconds, but every 4th or 5th measurement has a 4 second gap in between. This isn't a fatal issue, but it would be nice if I could be more accurate.

4. When the user specifies a time interval, how can I set up a function that averages the time first before passing to the measurement file? The average function in the math section would work, but it seems like it wants to know the number of elements that will be averaged beforehand. How do I know it will take an average over the entire interval (rather than some small part of it)?

5. Are there any glaring efficiency problems? Soon I will have to expand this to monitor 7 or 8 thermocouples, and I don't want to eat up all the processing power because I have some stupid error.

Any help is very appreciated, thank you.

0 Kudos
Message 1 of 4
(2,670 Views)

Let me try to address some of your questions.

 

1. I think the Express VI opens and closes the file each time it is called.  You can open the block diagrams to see what is inside. They are rather messy, partly because the VI has so many options.

 

To manage the opening and closing you can use the lower level file VIs.  It is genenerally good practice to open the file outside the loop, do as many writes as are needed inside, and close the file after the loop exits.

 

2. I presume 'Number of Measurements' is a DAQ Assistant parameter? I see nothing on your diagram with that name.  I do not have the DAQ Assistant, so I do not know what is inside.

 

3. Your architecture will have timing probrlems of several types. You have two time delays in parallel.  If both operate (both booleans = True), then the iteration time will be at least as long as the longer time. If one is 3 s and the other is 5 s, the loop cannot iterate faster than once every 5 seconds. The time to write the files and the time to acquire the data is also added to the time delay from the Elapsed Time VIs. There is no indication outside the DAQ Assistant of how long it takes to acquire the data.  As files get larger, the write times get longer. If the OS needs to fragment the file or move it to a larger disk space, the time may be quite significant.

 

Learn about the Consumer/Producer Design Pattern which comes with all recent versions of LV. This will allow separation of the timing of the data acquisition and the file writes.  One effect of this is that the data acquisition timing can be much more accurate than the time of the file writes, and it is the timing of the dat awhich is important, not when the files are written.

 

4. The point by point VIs do need to know how many points you want to process because they create an internal buffer to accumulate that many points. The Mean.vi from the Mathematics >> Probability& Statistics palette accepts arrays of any size and returns the mean.  Without seeing how you are acquiring the data, I cannot tell you what you need to do.

 

5. The biggest efficiency problem is that you have duplicated code (the identical case structures). When you add a thermocouple you need to modify the program to accomodate this.  In fact you will need a different progam for each number of thermocouples you have. It is much better to set up the program so that the data goes into arrays. In LV arrays are not fixed size and can expand as needed for more data. So, you coudl have a 2-dimensional array with a column for each thermocouple and rows for each data point. If the data from each thermocouple is stored in a different file, you could keep the file names in an array also and do the writes inside a for loop.

 

Lynn

Message 2 of 4
(2,657 Views)

How would I go about removing the duplicate case structures? Also, I'm starting to think the while loop only iterates once (while the program is open) because there are already loops built in to the Daq assistant. I can place one on a 10 second interval and the other on a one second interval and they still work fine. How could I set a program up where I could add thermocouples without having to change the code? How would I deal with different files being opened for each one?

0 Kudos
Message 3 of 4
(2,626 Views)

Start by carefully defining what you want to do.  Specify the minimum and maximum number of thermocouples (data channels). Describe how the user will select the number of channels.  Decide how to name the files. If you had 100 thermocouples, you would not want the user to be asked to select or name 100 files.  You also do not want the filenames hard coded into the File VIs because that will eventually compromise your data. Define the range of timing which will be used for the channels. Do all the measurements start at the same time?

 

Next, look at your hardware (data acquisition device). Make sure that the numbers of channels and samples are compatible.  This is not usually a problem with thermocouples but might become an issue for a large channel count.

 

Define how the data will be processed.  You have mentioned averaging. You may also have voltage to temperature scaling, cold junction compensation, and other factors to consider.  Remember that all of these things need to be done for every channel.

 

These things form your system specification. Once you have this specification, you can begin to design a system which will meet your needs.  The number of hardware modules needed has an impact on the data acquisition part of the software. Think about appropriate data structures and how data will be passed from one part of the program to another. Think about what will be done with or to the data at various stages in the process: acquire, separate by channel, average, display, save, ... At this point you can select a program architecture and start to write the program.

 

*****************

 

Now to your specific questions.

 

Duplicate case structures: Any time code is duplicated, think about two things. Should this code be a subVI? Should this code be inside a loop so that one copy of the code does the same thing to each channel of the data?

 

How to add thermocouples without changing code? 1. Set up the data acquistion (sorry, I do not think you can use the DAQ Assistant for this) so that the user can specify the number of channels.  Look at the DAQmx controls. 2. Have the data returned from the DAQ Read as a 2D array. Arrays will expand their length to accomodate the amount of data.

 

How to have multiple files without too many headaches? Create a file naming scheme which includes a "base" name, possibly provided by the user, and a suffix representing the thermocouple name or number, which will be programmatically generated. Suppose the base name is "Smoke Test" and the suffix is a sequential number. Then the file names become Smoke Test.1, Smoke Test.2, Smoke Test.3, ...

 

Have the user enter the save intervals into a combo box or an array. Internally in the program store the intervals in an array. Again the array will grow as needed for the number of channels.

 

In your situation it appears that all the channels are processed the same way except for the logging intervals. I would probably keep all the data in a 2D array of temperatures. One subVI would do the averaging and produce an array of averages for each channel (at whatever timing you select, such as 1/second).

 

The file save loop would keep track of the time at which each file should be written (arrays and shift registers). The filenames would also be in an array. When it is time to save, Index the data from the 2D temperature array and index the filename from the filename array.

 

Everything scales.

 

Lynn

 

Message 4 of 4
(2,616 Views)