01-22-2016 08:01 AM
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.
Solved! Go to Solution.
01-22-2016 08:10 AM - edited 01-22-2016 08:11 AM
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.
01-22-2016 08:13 AM
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.
01-22-2016 08:23 AM
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?