LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question on calling a sub-vi

I made a vi called Average This Number.vi that I intend to use to smooth out some data in a variety of places in a large application. The problem is that it locks up the system when I call it. (The Abort Execution is not available in the application.) I made test.vi to simulate the large application. If I set the RUN input (Average This Number.vi) to false or leave it open, it seems to OK. If I set it to true, it locks up the system. The logic puzzles me because it seems to be just backwards. Also, I get the feeling there is a better way to call the sub-vi. Please take a look at the attached vi's and tell me what I'm doing wrong. Please also let me know if there is a better way to smooth the data presented at "number in" o
n the test.vi. I'm using LabVIEW v.6.1 and will be build an application using App Builder.
Download All
0 Kudos
Message 1 of 6
(3,330 Views)
Your system locks up because the while loop starts to run and there is no way to stop it. The conditional terminal is set to continue if true and when you set it to true in your main vi, you don't have a mechanism to change it to false and stop the loop. I'm not sure what you're really attempting to do. How do you get an average from a single number? If you want to get the mean of several numbers, then you should just use Mean.vi. It's located in the Mathematics>Probability and Statistics palette. It requires an array of numbers as an input.
0 Kudos
Message 2 of 6
(3,330 Views)
I can now see why there is a problem when the while loop is enabled. However, why does it work when turned off or not connected? It works nicely in this mode. I considered using mean.vi, but it works with an array and there is no array to work with. The purpose for the averaging need is to effectively slow down the jittery digital display as shown on the front panel. The display is annoying to look at. Normally I'd slow down the while loop from where the value originates, but I cannot because that would adversely affect the sampling rate for data acquisition. The averaging vi is based on a vi I found on the NI web called RANDOM~2.VI This vi was apparently developed for instructional use and specifically addressed my application need. I'm just having diff
iculty using it as a sub-vi. Again, why does it work when turned off?

Thank you for your response, and please further advise.
0 Kudos
Message 3 of 6
(3,330 Views)
The subVI runs and terminates when the value is false becausee every while loop executes at least once. The only reason that you seem to be getting the correct number out is because you don't initialize the shift registers. If you were to terminate the main vi after only one loop, the output of the subVI would be 1/4 of the input value. You have to guarantee that the subVI is called at least 4 times otherwise the data is garbage. The whole scheme seems a bit complicated in order to add a few microsends of computation time and the bit of overhead to call a subVI. You'd be better off putting a 0 msec delay in the main VI. If you have flicker, you might also want to try setting the indicator to Synchronous Display.
0 Kudos
Message 4 of 6
(3,330 Views)
Hi Dennis, For clarification, the main vi always runs at 100mSec for at least 10 seconds. This will satify the minimum of running four times. Yes, it does seem complicated, and I have to wonder if there is better way.

At this point it seems appropriate to not use this as a sub-vi. Instead, place the function directly into the main program where it is needed. Admitedly, I'm a little inexperienced with the requirements of data flow between vis.

For clarification, it's not "flicker" that I'm having a problem with. (Some call it digit bobble.) The problem I'm having is due to a certain amount of unavoidable electrial and mechanical noise from the load cell. To make matters worse, there are many digits displayed (i.e. 29743.35 Lbs)
The system full scale is 350,000 Lbs. I'm lucky to get a zero reading between +/- 5.00 Lbs!. You can imagine what the display looks like. I've been tempted to fix the last few digits to zero (i.e. make 29743.35 to display as 29740.00). But this seems cheap and I don't think the customer will be impressed.

Thanks,
Dave J.
0 Kudos
Message 6 of 6
(3,330 Views)
If you want to see why your subvi works when you have a false wired, try running the vi with your main front panel open, as well as the diagram of your subvi, and turn on highlight executioning on your subvi. Add an indicator to both iteration counters of your main VI and your subvi. You should see the following. When you wire a false into your subvi, your while loop will still execute one time, visible by the 0 in the iteration counter of your subvi. What happens then is that your main VI executes another loop and after it loops 3 times, your subvi will finally post the same output as your input. I would definitely take a look at it with the highlight executioning on to really understand what's happening. Hope this helps!

Jim Cahow
Applications Engineer
Natio
nal Instruments
0 Kudos
Message 5 of 6
(3,330 Views)