LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I capture all voltage data into an array and find the MAX array value?

Solved!
Go to solution

I took an example VI from the NI Examples list for reading voltage values.  I'd like to adapt it to capture all the voltage values measured while the voltage values are being read, and then STOP reading voltage values, and subsequently identify MAX and MIN values from the previously collected voltage values.  I added BUILD ARRAY and MIN and MAX functions to get the attached VI, but it appears to output only the LAST value as both MIN and MAX, which tells me I am failing to create an array...so, how do I capture all the voltage values and have the MIN and MAX functions identify the largest and smallest values collected while the voltage measurement was running? 

 

In other words, the first thing I want to do is measure (and collect) a bunch of voltage values, e.g. less than 5000 data points, secondly STOP collecting the voltage values, and THIRDLY identify the MAX and MIN values as the last thing the VI does and display the MIN/MAX values as the output of the VI.

 

I thought I could store the values in the shift register, and then, build an array out of them after the loop is done...  I am very confused about how to construct this because my VI simply reads the last voltage value that it reads....what am I missing?  Please see my attempt attached here.

 

Thank you for some advice.

Dav

0 Kudos
Message 1 of 10
(1,216 Views)

Use Build Array to insert a new element to the array stored in the shift register.

-------------------------------------------------------
Control Lead | Intelline Inc
0 Kudos
Message 2 of 10
(1,189 Views)

Thank you for the VI...I have one question...I think I do not understand how the shift register works.

 

Does the shift register save only one value at a time, as opposed to an array of values?  Or does the shift register store a growing array?

 

Also, when I start the VI, it stops itself almost immediately...it is not waiting for me to select STOP.  It should collect voltage values until it is stopped. Why does it shut itself down?  It appears not to collect or display any voltage values at all.

 

Thank you,

Dave

0 Kudos
Message 3 of 10
(1,175 Views)
Solution
Accepted by dav2010

A Shift Register is a simple memory element capable of remembering one number, the number that was written to it from its left edge.  It will return this number when read from its right edge.  In a While Loop with a Shift Register that has "3" wired to it from the outside, goes straight across to the right side with an "Increment" function in the middle of the Loop, when it enters the loop for the first time, it will contain 3, which gets incremented to 4, and "saved" in the Register.  The second time through the Loop, it has 4, incremented to 5.  If you stop it after exactly 100 loops, it will have 103 in the right Shift Register, and will return this value if you wire an indicator (outside) the Loop to it.

 

If you want to save each result generated inside a Loop in an Array, you don't use a Shift Register, you simply bring the value to the right edge of the Loop through what LabVIEW calls a "tunnel".  A While Loop, by default, has a "Last Value" tunnel, and passes out the Last Value wired to it.  A For Loop, on the other hand, has (again, by default), and "Indexing Tunnel" which, if you look closely at it, is a box with [ ] (a pair of square brackets, suggesting an array) inside it, and outputs an Array consisting of all the numbers wired to it while the Loop ran.

 

If you want to accumulate all the values in a While Loop, don't use "Build Array" (that's so "LabVIEW 7") -- right-click the output tunnel (which will be a colored square), select "Tunnel Mode", and choose "Indexing Tunnel".

 

Bob Schor

Message 4 of 10
(1,136 Views)

I think one of the reasons your program stops immediately is because you are getting an error. 

To know whether or not you are getting an error, try to use "simple error handler.vi" as shown below. Let us know your error number so we can better assist you. 

GRCK5000_0-1681015924943.png

 

 

0 Kudos
Message 5 of 10
(1,121 Views)

@GRCK5000 wrote:

I think one of the reasons your program stops immediately is because you are getting an error. 

To know whether or not you are getting an error, try to use "simple error handler.vi" as shown below. Let us know your error number so we can better assist you. 

GRCK5000_0-1681015924943.png

 

 


My magic 8-Ball says "The error is assuredly a buffer overflow."

 

NEVER use an external loop throttle with a DAQmx single sample read on a continuous acquisition Task!  The loop will not be able to keep up with the samples the device is taking and storing into its internal buffer.

 

Better options;

  • GOOD Use a wait of @200msec and an N sample read with samples to read set to -1 (all available samples)  Change the mode of the build Array to concatenation.
  • BEST Remove the Wait entirely and read N samples where number of samples to read ÷ acquisition rate @= 200msec.  And let the Task throttle the loop. 

For extremely high sample rates you may need to read the device specifications on available buffer size and read more often but, you never need to display data faster than a human eye can see.


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 10
(1,105 Views)

Hi,

I added the simple error handler as you suggested and got the following:

 

Error -200220 occurred at DAQmx Create Channel (AI-Voltage-Basic).vi:1780001

0 Kudos
Message 7 of 10
(1,079 Views)
0 Kudos
Message 8 of 10
(1,078 Views)

 

Thank you for the two suggestions.  Where do I find your (BEST) option???

--->"N sample read with samples to read set to -1 (all available samples)"  I think I can find how to set 

"N channel, 1 sample" but not "N channel, -1 sample"--> how do you do this, set to negative 1??

 

But, that breaks my wire to the right shift register.  When I changed the mode of the BUILD ARRAY to concatenate, the wire restored itself.

 

Should the VI run whether it's physically connected to the cDAQ or not?  Some of my work I do in the lab, and some at home; can i test the VI at home without the cDAQ connected to the PC?

 

When I add the simple error handler.vi, it says the following:

 

Error -200220 occurred at DAQmx Create Channel (AI-Voltage-Basic).vi:1780001

Possible reason(s):

Device identifier is invalid.

Device Specified: Dev1

Task Name: _unnamedTask<1>

0 Kudos
Message 9 of 10
(1,075 Views)

Thank you for the excellent description of  how the SHIFT REGISTER works!  I appreciate it.

DAve

0 Kudos
Message 10 of 10
(1,013 Views)