07-23-2012 05:03 PM
Hi there,
I'm hoping somebody on here can help point me in the right direction for this. My system at this point is still pretty simple, I'm just collecting data from 2 RTDs and a pressure transducer, outputting them to the front panel and occasionally writing them. I have the architecture set up at parallel timed loops running at the frequency I would ideally like them to run. i.e. I want the RTDs to update every second or so and the pressure transducer to update every .5s, I want to write to file at a user defined rate and I want the front panel to update every half a second (matched with the pressure transducer).
Now in the structure I have written, it has to execute all of the while loops once before it can restart the sequence. Technically the code works, but it takes ~1.5s for the RTDs to collect and update and so the whole VI takes ~1.5s to complete.
I don't care if the RTDs are slow to update, but as I use the transducer as a gauge of cell pressure I need to know at a high frequency what the pressure is in the cell and I don't want to wait 2s for the information.
I know I'm starting to enter into a much more advanced architecture for this and ive spent the last 6 hours googling trying to find out a procedure for how this works but I cannot figure out a way to have the whiles stop waiting for the RTD loop to finish. I'm assuming it involves splitting the VI into multiple VIs and building a library but the resources I could find about that were not very helpful to a beginner like myself. If anyone could point me in the right direction on where I should look next that would be great!
Thanks,
Zach
Solved! Go to Solution.
07-23-2012 06:27 PM
Zach,
Since you have created the DAQ tasks elsewhere, we cannot see how you have them set up. Continually Starting and Stopping tasks may be slower than setting up a continuous task and letting it run.
You did not indicate what DAQ hardware you are using. Often it is better to let the clock in the DAQ device set the timing rather than relying on software timing. The pressure loop reads 1000 samples at a time and averages them. If you are not sampling at 2000 S/s or faster, the loop will finish late because of waiting for data. In both DAQ loops you are not using the timing information. Acquire the data as arrays rather than waveforms.
The Dequeue functions in the bottom loop have no timeouts so that loop will not iterate until all three queues have data. Since the Pressure loop runs faster than the RTD loop, the pressure queue will slowly fill up.
The top and bottom loops compete for the data. The Preview Queue Element does not remove data from the queue, but the Dequeue Element functions in the bottom loop does. If the data is removed form the queue before the top loop looks at it, it will never get saved. With your setup there is no way to assure that you get all the data or that you do not read and save the same data more than once.
You have nothing set up to stop any of the loops. Are you using the Abort Button to stop your VI? If so, STOP! Another aprticpant on the Forums has stated: "Using the Abort button to stop a VI is like using a tree to stop a car. It works but may have unintended consquences!" Things like closing files, releasing queues, closing DAQ tasks, and other things cannot happen when the program is aborted. You do not shut off your computer by pulling the plug. You should shut down your program in an orderly manner also.
OK. I have pointed out some of the things which may keep your program from running as you wish. What can you do about them?
1. You probably do not need timed loops. Regular while loop should be good enough.
2. Put a Stop button on the front panel. Put the terminal in the indicator loop (at the bottom) and connect it to a Send Notification function and to the loop condition terminal (stop sign). Put Wait on Notification functions in each of the other loops. Put a timeout shorter than the minimum loop time on each one so the lops can run.
3. See comments above about hardware timing of DAQ Reads.
4. Use Dequeue timeouts to set the loop timing in the loop where the data is used. Also make sure that all the data gets dequeued. You need to think about your overall timing requirements and what the bottlenecks are. Unless you expect this system to grow to much larger dat sets, I would probably acquire ALL the data (Pressure and RTD) at the same rate and reduce the amount displayed by averaging as you are doing for the pressure data now. If you want different final data rates, simply average different amounts of the data.
5. It might be worthwhile to learn how state machines work. The display, averaging, and file saves could be managed in one loop by a simple state machine while allowing more flexibility in timing.
6. Another good reason to consider a state machine is that the initialization and shutdown processes can easily be managed in corresponding states. At present you are not doing anything with errors. A state machine would allow you to handle errors (such as the user canceling the file selection) without shutting down the program.
Lynn
07-24-2012 11:12 AM
So splitting the readout queues on the bottoms for RTDs and the pressure transducer did end up doing the trick!
Some of this is setup intentionally, like the preview queue element which I dont want to interfere with the data in the queue at all (each read would cause a hiccup in the front panel read out if it dequeued). I also don't wish to write every data point, im actually only wishing to record between every 50th and every 200th point.
I am extremely new to this (just picked it up 2 weeks ago) and i'm still learning how to optimize the code, so thank you for all the suggestions on that! Now that I have the core code working and I know how to use it I can spend some time optimizing it, like the state machine example (which I need to read again cause I didn't really understand it the first time). I'll be spending the next day or two working on these suggestions now.
Thanks for all the help!
07-24-2012 10:14 PM
I am glad I was able to help. Since you are new to LabVIEW, I recommend the Getting Started tutorials available on line if you have not already worked though them.
Lynn