LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

initialising for 10 shift registers in a for-loop

I have a program with a For-Loop, which will loop only once in a while to record a value. I used shift registers to capture the average of the 10 values (hence have 10 shift registers on the left side of the loop). I have problems iniialising all the 10 shift registers everytime the program is run. They seems to still contain values from previous runs.

I can't add constants to the left of the shift registers since everytime when the For-Loop looped once, they will be all zeros and don't record any values. I have read about about the case-structure way to overcome that problem in the discussion forum, but that only works for 1 shift register. How about having 10 shift registers to record 10 previous values?

Or is it possible to inilialise the entire program (block diagram) when the program is run. The option in the Operation > Initialise to default values, seems to be useful for the front panel only, the values in the shift registers are still there from previous runs.

I'm quite desperate now, and would appreciate if anyone can offer some advice...Many thanks.

Hanxin.
0 Kudos
Message 1 of 13
(3,368 Views)
Instead of using 10 shift registers use a ten element array.
Use a shift register to keep track of a pointer and place the value into that location.
Another way would be to use a queue as a stack.
Greg Bush CLAD
0 Kudos
Message 2 of 13
(3,349 Views)
There's an option of detecting if the VI is being executed for the first time (after starting the program) under the Advanced-Synchronisation palette.

You can use this to selectively initialise the shift registers on the first loop the first time the program is run. Stick a small case statement wired to the "i" terminal of the FOR-Loop. Then place another CASE statement inside this (for CASE 0) and wire the "First Call?" Boolean to it. If the outer loop is zero, the second case is called. If the program is called for the first time, put your initialised values in here, and pass the new values on instead of the shift-registers.

It's a bit ugly, but it should work.

Here's a pic as an example.

Hope this helps

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 3 of 13
(3,334 Views)
Hi, tanks for both replies...

To Shane, I have tried to build your recommended program but how can I then always capture the last ten values coming in from the For-Loop?

Hanxin.
0 Kudos
Message 4 of 13
(3,302 Views)
And for bushman,

how do I use the pointer to point to the elements of the arrays? I cant think of it.

tanks.
0 Kudos
Message 5 of 13
(3,295 Views)
Try this. It's not the neatest, but I trough it together quickly.
GB
Greg Bush CLAD
Message 6 of 13
(3,290 Views)
Many tanks bushman,

But the main problem is that I have a while-loop constantly running to read data from a file, and a For-Loop within it calculate the mean when a certain number of data is collected. This For-Loop thus run only once in a while. Thus, the mean values calculated has to be stored within the For-Loop itself. In your solution, it is a while loop.

I have attach the picture of he block diagram, i hope it cam can you better understand the problem. Tanks.





Hanxin.
0 Kudos
Message 7 of 13
(3,272 Views)
Your For loop has a one wired to the interation. You only run it once?

Unfortunately, I don't have LV 7 on this machine, but what I gave you will work.
The Boolean I had "Trigger to save data is connected to the Trigger and gate 2 express vi.
The mean value you calculate and have connected to the add function is the new value variable in my example and gets connected to the Replace Array Subset input.

Take note: In your example you are adding all the previous means together, but not averaging them.

ALso, in your example, you are always adding all ten elements together and averaging them. This will create math errors. That is why on the example that I sent you I checked if number of entries is less then 10. If it was, I used the Array subset, added the elements together and averaged the number of elements. You will find this is dependable and accurate.
Greg Bush CLAD
0 Kudos
Message 8 of 13
(3,263 Views)
Hi bushman,

Yes, the "For-Loop" (wired to 1) is for performing the summing of values when there is a trigger. The "while-loop" outside will loop continuously to read off signals saved in a file. If there is trigger, the "For-Loop" looped once to calculate the mean and to pass it on in the shift registers. Then it will continue to detect for other triggers before looping ONCE again.

What you have suggested is brilliant, but the problem is that with the shift registers on the "While-Loop" (while runs non-stop to read signals from the files), the values saved will be gone when the "While-Loop" is looping.

I hope i explained the situation a little better this time...pls advise again if possible. Thanks.

Hanxin.
0 Kudos
Message 9 of 13
(3,251 Views)
...I have been trying, but still wont work, does it mean i have to open and close the program whenever i run it? This will be too troublesome!!!

Hanxin.
0 Kudos
Message 10 of 13
(3,218 Views)