10-11-2011 12:52 PM
Hello all,
I am having issues with a labview program. The goals of this project are simple:
1) Acquire a voltage input and convert this input into a pressure value (bar)
2) When the pressure reaches a certain value, the program must go through the following process:
a) have a user input time delay
b) trigger an output voltage of 10 V
3) The value of pressure and output voltage (either 0 V or 10 V) is then recorded in a spreadsheet.
I can easily satisfy the first goal. The data is converted to DBL and using a specific bars/volt ratio, the pressure is calculated. This value is then sent to the "Write to Spreadsheet.VI" Then, I use a greater than or equal to symbol to decide if the pressure is above our desired threshold. The T/F output of this symbol is sent to a case structure where if F, the V out is 0, if T, the V out is 10 V. This voltage is sent to the same spreadsheet.
I have tried to establish a delay in changing the voltage if the Case is True, however it always errors or does not seem to be working properly: not all records of the data aqcuisition are recorded in the spreadsheet, and the voltages recorded only coincide with pressures that are measured above the threshold (there should be some values of pressure above the threshold when the Vout is still 0 due to the delay).
In all, how can I introduce this delay, have my write to spreadsheet record more samples, and have the delayed Vout coincide with the correct Pressures recorded?
Any help would be great. I'm really new to this.
10-11-2011 12:56 PM
Can you attach your current code, showing what you've tried? That will make it easier to help you.
10-11-2011 06:57 PM
I am sorry, I was posting from my work computer and didn't have access to the file... I have attached it now. Please excuse the clutter, its a bit messy.
10-11-2011 07:32 PM
You'll need a slightly more complicated program in order to do what you want. I recommend learning about state machines in LabVIEW. You need a few states:
1) wait for threshhold pressure
2) delay
3) set output to 10V
4) wait for stop
Put the DAQ Assistant outside the case structure so that it executes regardless of which case you're in. In order to continue to acquire and log data during the delay period, you can't use a Wait. You need your loop to continue cycling during that time. You can set up a delay like this by storing the time at which the delay started in a shift register, then checking if the difference between that time and the current time is greater than the delay time; if so, advance to the next case. You'll probably also want to put the Write to Spreadsheet File outside the main case structure since you'll need to log data during every state except the initial waiting period; you could put it in a separate case structure that's either true or false (rather than having several states). I'm attaching your VI, revised very quickly and not tested, to do what I think you're trying to accomplish.
It's not a good idea to keep creating and clearing your analog output task inside the loop. Configure it once outside the loop, write to it inside the loop, and clear it when the loop terminates. Also, there's no reason to set your DAQ Assistant for Continuous Samples at some high rate, since you're discarding all that data and only taking a single sample at a time. Finally, all while loops in LabVIEW that run for an indefinite period of time should have a wait in them somewhere; otherwise they'll run as fast as possible, preventing the computer from doing anything else.
10-11-2011 07:42 PM
I do want the VI to write each data point to the spreadsheet, if possible. I wanted to clear that up. We are analyzing combustion, so the pressure rise is relatively quick. Therefore, it is necessary that we record a lot of data points (hence the high rate). In my research I noticed that write to spreadsheet might not be what I want, as it opens and closes the file for each data point (not sure if that is the case?).
10-11-2011 07:49 PM
@CameronC wrote:
I do want the VI to write each data point to the spreadsheet, if possible. I wanted to clear that up. We are analyzing combustion, so the pressure rise is relatively quick. Therefore, it is necessary that we record a lot of data points (hence the high rate). In my research I noticed that write to spreadsheet might not be what I want, as it opens and closes the file for each data point (not sure if that is the case?).
Do you also need the trigger to act on the very first data point above the threshhold? That will be difficult to achieve purely in software, at the sample rate you're using. The DAQ Assistant can be set to log data automatically, at high speed; you may want to consider that option. How long will it take the system to get to the trigger point? If not long, you could log all the data, then find that point later. Write to Spreadsheet File is definitely not the way to go, unless you're looking at very short sample times for which you can accumulate all the data in memory, then write it out all at once when the loop exits.
10-11-2011 07:59 PM
The trigger must act as soon as possible. Instantly... probably not, but in the ms range would be preferred. That seems to be exactly the trouble I was running into, the VI would error out and say that it was trying to reference data that is not available. If all I can get in a data log is the original voltage from the DAQ, and simultaneous Vouts (0 or 10 V). That's all I need. We just need to know at what specific point the trigger is activated (the trigger initiates a solenoid, and all data after that will be analyzed). I really appreciate the help.
On a somewhat related note, where can I get the best learning material for labview?
10-12-2011 12:10 AM
What's your hardware? You may have the ability to set the analog output to be triggered by the analog input, which will give you a much faster response than you could accomplish in software alone. Also, I have to wonder why you're using an analog output rather than a digital output to trigger a solenoid.
You can possibly likewise do a triggered acquisition, where you don't start recording data until the trigger condition is met. I'm not an expert in high-speed acquisition - I always have to experiment a bit before I get the options right. I don't know if you'll be able to do it with the DAQ Assistant, or if you'll need to use the DAQmx functions directly. Letting the hardware do as much as possible is a win-win - you get faster performance with less code.
I can't suggest any specific LabVIEW resources - I've learned it through experimentation and reading lots of documentation, but that doesn't work for everyone. Searches on this forum should help you find recommendations for learning material.
10-12-2011 12:35 AM
10-12-2011 04:30 PM
Unfortunately, without a hardware trigger, your options are limited. You could try modifying the VI I posted. Instead of converting the retrieved data to a single integer, retrieve it as an array. You can then scan that array in a for loop, looking for the trigger point. To get the output voltage, the easiest solution is to initialize an array of the same size as the array you read from the AI, containing the current voltage output, and combining that with the array of AI data. However, that's not very memory-efficient. I highly recommend removing the DAQ assistant, avoiding "Dynamic Data" (on of NI's worst ideas for LabVIEW, in my opinion) and using the DAQmx functions directly. If you make some progress but are having problems, upload your code and I'd be happy to take a look at it.