LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with resetting an average block

I am having problems with programming an average block.  I've attached my code.  I am trying to determine an average by allowing the user to start and stop the averging cycle.  When the start avg button is pressed, averging begins.  When the stop avg button is pressed, averging ends.  For simplicity, I've connected a constant of 5 to the input of the integral express vi.  Thus when the start avg button is pressed, the average value should read a constant 5.  This works well the first time the user begins and ends the loop.  When the user presses the start avg button a second time, the averaging no longer works.  I've investigated and determined that the previous value stays within the integral express vi.  In other words when the inner loop is reinitialized, the value within the integral does not go back to zero.  I've looked everywhere and tried  a bunch of things, but cannot figure how to get the average to work properly.  What I want to do is allow the user to begin and end averaging by the press of  buttons and allow this process to be repeated several times without closing the vi.  Also, I am using Labview 8.0

Thanks.
0 Kudos
Message 1 of 4
(2,793 Views)
Hello,

I think that for the program to work how you want you will need to pass the iteration count of the inner while loop between the iterations of the outher while loop with an unitialized shift register, using the First Call?.vi to get the shift register going.  See the attached image.  Let me know if this does not do what you are looking for.

Cheers!





Message Edited by jmcbee on 04-08-2008 03:15 PM

Message Edited by jmcbee on 04-08-2008 03:15 PM
0 Kudos
Message 2 of 4
(2,784 Views)
You are really complicating the issues by stacking loops inside loops. All you need is a single while loop, for example as in the atached quick modification. See if it makes sense.
 
It will average as long as the "average" button is true (set to switch when pressed). The reset button restarts the averaging.
 
 
0 Kudos
Message 3 of 4
(2,766 Views)
Thanks jmcbee and altenbach.  Jmcbee, your method works fine if the user wants to pause the averaging process and then resume.  However, I need something that would allow the user to average, stop averaging, and then begin a new averaging cycle, not resume the previous averging.

I incorporated altenbach's method of having 2 shift registers and initializing them to 0 outside the inner loop.  This method seems to work great.  Altenbach, I need to have an inner loop inside of the outer loop because I am opening a data file in the outter loop; then in the inner loop data is acquired, calculated, averaged, and writen to a spreadsheet file.  When the inner loop is complete (when the user stops the averaging process), the data file closes.  The user is then at the beginning of the outer loop and is able to open a new data file (when the outer loop cycles for the second time).  I am not experienced enough in Labview to complete this process more eloquently.  Hopefully with more practice and experience, I can streamline this process and write a better and efficient program.
0 Kudos
Message 4 of 4
(2,736 Views)