07-05-2012 09:56 AM
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!
Solved! Go to Solution.
07-05-2012 10:06 AM
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
07-05-2012 10:15 AM
07-05-2012 10:16 AM - edited 07-05-2012 10:17 AM
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?
07-05-2012 10:25 AM - edited 07-05-2012 01:58 PM
@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.