04-07-2023 02:52 PM
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
Solved! Go to Solution.
04-07-2023 06:30 PM
Use Build Array to insert a new element to the array stored in the shift register.
04-07-2023 08:49 PM
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
04-08-2023 02:44 PM
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
04-08-2023 11:52 PM
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.
04-09-2023 09:18 AM - edited 04-09-2023 09:30 AM
@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.
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;
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.
04-10-2023 10:02 AM
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
04-10-2023 10:03 AM
Sorry, here's the VI.
Dave
04-10-2023 10:18 AM
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>
04-15-2023 02:18 PM
Thank you for the excellent description of how the SHIFT REGISTER works! I appreciate it.
DAve