LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I do the equivalent of a shift register with a variable start value?

Solved!
Go to solution

I have an array of samping frequency values (determined by an external signal) and I would like to extract one value at a time from this array to use as the sampling frequency for another signal.

 

The shift register almost does what I want. The problem is that I don't always want to start at element 0, but rather at the first positive sampling frequency value, which has a slightly different index each time. Once this value is reached, I want the index to increment by 1 each loop iteration (which it already does).

 

I have attached a VI for reference. Any suggestions?

0 Kudos
Message 1 of 10
(2,785 Views)

Please post the code in 2011 version

-----

The best solution is the one you find it by yourself
0 Kudos
Message 2 of 10
(2,778 Views)

You can acquire before you intialize shift register & index the required value by comparision for first iteration

AB
Kudos are Accepted
0 Kudos
Message 3 of 10
(2,777 Views)

Here is the 2011 version

0 Kudos
Message 4 of 10
(2,766 Views)

I need the DAQ to remain inside the while loop because the data is going to still be coming in while the sampling values are being extracted. Is there a way to do this that keeps the DAQ in the while loop?

0 Kudos
Message 5 of 10
(2,765 Views)

Laura121,

 

I can think of two ways to do that. One is to place a copy of the DAQ Assistant outside the loop. Take one reading to get the initialization value for the shift register then proceed as you are now doing for subsequent measurements.

 

The other way is do the initialization in a case structure. When  i = 0 (first iteration), initialize the shift register. For i > 0, use existing code.  This method would only require one DAQ Assistant.

 

It is not clear that your code or either of the approaches I described actually does what you said you want to do in the original post: "...extract one value at a time from this array..." Each time through the loop you take another set of readings, discard all the old data, and take one sample from the array at the index determined by the shift register.  This is not what I would consider extracting one value at a time from the array.  If you really want to go through the entire array, you need to do the sampling frequency extraction many times for each DAQ Read.

 

You also should have some error handling to consider the case where no element in the Array of Sampling Frequencies is positive or the case where you have reached the end of the array.

 

Lynn

0 Kudos
Message 6 of 10
(2,745 Views)

I posted a simplified version of my VI. In my actual version, there is an array that stores values from the previous loop iteration (this array grows in size each iteration).

 

When you talk about initializing in a case structure, does this case structure go outside the while loop? I am having troulbe understanding how to do the case structure when the true/false is dependent on calculations within the while loop.

0 Kudos
Message 7 of 10
(2,737 Views)
Solution
Accepted by topic author Laura121

The case structure is inside the while loop.  This is somewhat like the structure used for state machines.  Look at the attached VI. I did not test it.

 

You generally should avoid buiding an array inside a loop as it will eventually cause memory allocation problems (= program crash!).  It is better to allocate an array as large or larger than the maximum you expect to use outside the loop and use Replace Array Subset inside the loop.

 

Lynn

Message 8 of 10
(2,724 Views)

Just use index array and the index will be i+ start value (easy).  Once you determine your starting point (first positive freqeuncy as you said) wire this value inside the loop and add it to i.

0 Kudos
Message 9 of 10
(2,713 Views)

Thank you very much! That did the trick.

0 Kudos
Message 10 of 10
(2,671 Views)