LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Moving average SubVI does not update data in Real Time Host VI

Solved!
Go to solution

Hello!

I have Real Time Host VI which evaluate data from NI 9215 block of cRIO 9073. It takes data from analogue inputs and calculates phase shift. It works well with connected hardware and shows results. I need to obtain moving average value of phase shift, so I add Moving Average SubVI, where the inputs from main VI - new value (measured phase shift) and time in ms, and output - moving average value. When I run Real Time Host VI it gives me only one data and stop obtaining any new data from SubVI. It even does not update real time measured values. So the problem somewhere in adjustment with SubVI. How it can be solved? How I can obtain running Real Time Host VI with updating Moving Average value from SubVI?

 

Thank You.

Download All
0 Kudos
Message 1 of 4
(3,527 Views)

1) If 'stop' is false, execution of your main loop will pause until 'stop' is true. That and the fact I don't understand why you have a 'wait' inside your SubVI makes me think that you need to understand how dataflow works. A node (e.g. subVI, structure) cannot execute until all of it's inputs have received data and it will only finish once all of its outputs have been evaluated.

2) As you have wired the initial value to the shift register, it will reset  the values on the shift register. Only unitialised shift registers will hold their value between executions of the SubVI.

3) Why don't you use the Mean Pt by Pt VI? I believe this calculates a moving average.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 2 of 4
(3,510 Views)
Solution
Accepted by topic author mathijsen

Your problem is that you have a loop that runs until the Stop button is pressed inside of your subVI.  If you are trying to use a Functional Global Variable, you have a few things wrong.

1. The loop should only run once.  Wire a TRUE to the stop conditional terminal.

2. The shift register should not be initialized.  That is how it can keep old elements in a history.  Use a First Call? with a case structure so that you only initialize the history array inside of the loop on the first time the VI is called.

 

But if you really want to make your life easier, just use the Mean PtByPt.vi.  NI has done all of the work for you.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 4
(3,507 Views)

I would suggest next time to post the vis themselves and not just images.

I am unsure of how you are trying to implement this.  An issue that  I see is with the loop counter going into the division.  They way you did it, the loop counter (i) is always zero.  It will not matter what the other input is, the I and R outputs will always be zero.  How are you setting the size of the array?  It is defined by a control, but I don't think you are using it as an input to the vi.

If I was writing this function I would build the array up to a specified size and then substitute each new value for the oldest value, computing the mean each time.  Is this what you were trying to do?

Randall Pursley
0 Kudos
Message 4 of 4
(3,498 Views)