LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Average Value Returns as Zero

Solved!
Go to solution

I'm trying to take a few readings from an oscilloscope. I made a simple VI to test all of the parameters for the oscilloscope and make sure that everything was working before implementing the oscilloscope in a much more elaborate VI. I want to have voltage at a certain level (say, 2 V) then take a reading from the oscilloscope, add that value as a new element in an array. After doing this 100 times the VI will add the average value to a spreadsheet and then increase the voltage (to 2.05 V or something) and take 100 more measurments and average/record them. I was able to take ten sets of 100-sample averages and write them to an array (see notbroken.png) on one file, but when I try to do it in the real program (see broken.png) I check my spreadsheet and each entry is "0.000." Note that I've also created a program that controls the power supply independently and verified that I know how to control it properly; in fact, the only non-zero column is the one which reads the voltage that the program is telling the power supply to output. 

 

I've literally written out each step that my "not broken" program does to find the average value and then done the same for the broken program and I can't find a single discrepancy. Any and all help would be greatly appreciated!

Download All
0 Kudos
Message 1 of 5
(2,679 Views)
Solution
Accepted by topic author vweltin

At a quick glance I think you need shift registers on your loops so that you pass the data from the previous iteration to the next one.

 

Lynn

Message 2 of 5
(2,674 Views)
Interesting, I didn't think I needed shift registers, as the "not broken" program worked fine without them, but it seems as though adding shift registers to the broken program has fixed it! Thank you for helping out a newbie 🙂
0 Kudos
Message 3 of 5
(2,661 Views)

Lynn is correct about the shift registers if you want to stick with most of the current code. However, in your case you could simply do autoindexing (get rid of these "initialize array" and "replace array subset"!.)

Since your inner loop runs for a know number of iterations, you shold also use a FOR loop instead of a while loop (you can show the conditional terminal to stop early if needed).

 

Of course debugging pictures is difficult for us. Why don't you attach the actual VIs?

0 Kudos
Message 4 of 5
(2,659 Views)

@vweltin wrote:

I've literally written out each step that my "not broken" program does to find the average value and then done the same for the broken program and I can't find a single discrepancy. Any and all help would be greatly appreciated!


Here's an exact analysis.

 

Both of your programs are broken, but the one with the FOR loop iterates only 10 times, thus you get arrays with one nonzero value (the last one) when the loop terminates. (Just because the average is nonzero, does not mean it is correct!)

Your code with the while loop iterates 11 times, but your array only has 10 elements, meaning that in the last iteration you try to replace an element that does not exist and the array remains at all zeroes.

 

In both programs, there will never be more than one non-zero element in the array.

 

0 Kudos
Message 5 of 5
(2,650 Views)