LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to write data to file with delay

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.

0 Kudos
Message 1 of 10
(3,323 Views)

Can you attach your current code, showing what you've tried?  That will make it easier to help you.

0 Kudos
Message 2 of 10
(3,320 Views)

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.

0 Kudos
Message 3 of 10
(3,303 Views)

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.

0 Kudos
Message 4 of 10
(3,297 Views)

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?).

0 Kudos
Message 5 of 10
(3,295 Views)

@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.

0 Kudos
Message 6 of 10
(3,291 Views)

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?

0 Kudos
Message 7 of 10
(3,288 Views)

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.

0 Kudos
Message 8 of 10
(3,280 Views)
I have a PCI-6036E and an SCC 68. It's what I am stuck with. Hence the lack of the analog trigger. That would have made everything much easier.

The V out controls a relay, the relay controls a voltage larger than 10 V which is the maximum we can supply.

The solenoid activates fine and the physical aspects of my goals are fine, I just need the data logging to match the physical output.

So I guess my biggest issue now is how to record all of this data, particularly the area around the trigger.
0 Kudos
Message 9 of 10
(3,272 Views)

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.

0 Kudos
Message 10 of 10
(3,259 Views)