08-05-2013 03:23 PM
Hey guys,
Sorry for keeping posting similar questions. I was trying to take data using a while loop and take average within the loop. When I tried to run the attachment VI and set the rate to be 1000s/s and 10samples per average, it stopped automatically after 10 sec, if the rate is 10,000s/s, it stopped even sooner, but it behave normally when there's no average taking. Does someone know the reason why this happened?
Also, I really want to know the time between every 2 iterations (loops). Initially I appended the waveforms and checked the data file to see if there's a relatively large time gap, but then I realized that when using Append function, the trigger time of the second waveform is ignored. Is there any other way to do it so that I can save the data from every iteration as well as the trigger times?
Thanks!
Jude
08-05-2013 04:13 PM - edited 08-05-2013 04:14 PM
The problem is the same one crossrulz described to you in your last thread about this ... except, this time you have an array with 10 elements coming into your FOR loop, so it runs through 10 times. If you don't wire an "N" to the top left-hand corner, LV has to find another way to determine how many times to run it. PLEASE read everything you can about FOR and WHILE loops in LV, including the help files that you've got on your computer, before you get ambushed by them again.
Why does it happen only when you take averages? Go through your code carefully, it's hiding in plain sight.
The time between iterations? Approximately zero (most likely a few computer clock cycles). Follow the instructions in Part 1 of this answer again.
Cameron
08-05-2013 04:14 PM
Jude,
Do you get any errors when it stops after 10 seconds? A buffer overflow error?
When you are sampling at 1000 samples per second and reading 10 samples on each iteration, you must have 100 iterations per second or you will not be "keeping up" with the data being acquired. I do not have any idea how fast the Append Waveforms VI is but as the waveform grows new memory allocations will be required and that cna be slow.
Since you are averaging the data you acquire, what is the purpose of creating a new waveform of the same length as the original but with all the values equal to the mean? Why not just write the mean value to the chart and to the file? I do not ahve nay way to test so the code shown at the top of the image below may not be identical to wht you have but it can show the concept.
Lynn
08-06-2013 10:23 AM
Lynn,
Thanks for replying!
I didn't get any errors. The programme actually did not completely stop. It was still running, but the chart was like frozen and the data did not take data anymore. And when I click the stop button in the while loop, the data file saved was only 1kb and contains almost nothing.
Yeah I agree that 100 iteration per sec is too fast and may cause some problem, I'll probably change the method of data averaging.
The reason that I created a new waveform with same length is that the waveform I built before the shift register has dt=1/rate, so I made the new waveform with same dt to append them together. It seems that the clock time on the wave chart will show something like year 1903 if I append two waveforms with different rate.
Someone has told me that I don't need to append the waveforms together when using chart, so does it mean that if I just wire the data to the chart and it will automatically shows the accumulated waveform?
And could you tell me what the array function near the waveform chart2 is called? I get really confused by those array functions sometimes.
Thank you!
Jude
08-06-2013 10:38 AM
Cameron,
Thanks for replying!
I think this might not be like last time. I used the FOR loop because there might be multiple channels so I have an array of waveforms, each of which is constructed by 10 elements, instead of just an array of 1 0elements. And to make sure it works I later did wire the channel numbers to the FOR loop, but the same problem still showed up. Beside, everytime I ran the code, it worked well in the first 10 seconds. If it's because of the unwired FOR loop, I guess the error will happen immediately?
Thank you!
Jude
08-06-2013 10:43 AM
It's EXACTLY like the last time, because you have a 10-element array going into your FOR loop. Whether the elements are single data points, waveforms, clusters, arrays, strings, Booleans, elephants, or whatever, there are still ten of them.
Cameron
08-06-2013 10:56 AM
Jude,
That is a Build Array primitive set to show only one element. It converts the 1D array from the for loop to a 2D array. The chart needs a 2D array to show multiple plots. The 1D array contains one element for each of the channels in the data acquisition. By making this a 2D array (which contains only one row) the chart interprets each element as a point of a different plot. So it should generate as many plots as you have DAQ channels. I did not test so it is possible that you need to transpose the 2D array to get the data to the right places.
The code I placed above the case structure should produce results very similar to all of your code below it with regard to the chart and the file.
You can use Execution Highlighting to help figure out which part of the code is blocking execution. Wait until it freezes and then turn on Exectuion Highlighting. The part which has not finished will have a green arrow.
Lynn
08-06-2013 11:23 AM
The element is waveform so it's not 10-element array because "10" stands for points in EACH waveform.
It now depends on how many global channels there are, which is 2 in this case, so I wired the FOR loop "N" with number of channels from a property node. And it didn't solve anything whenever it's 2 or 10.
08-06-2013 12:08 PM
OK, have it your way.
08-07-2013 09:35 PM
Hi Jude,
Were you able to take Lynn's advice and run with Highlight Execution to gain a better understanding of where your code is hanging?
I would also recommend using the available debugging tools (probe and step into) to gain a better understanding of how your code is behaving. Below is a link that explains the debugging tools.
http://www.ni.com/gettingstarted/labviewbasics/debug.htm