LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Adjustment of program; counter might be off

Hi everyone.  I have a program which for the most part is performing as I need, however it seems to be out of sync in one count.  The program does the following:

 

Reads in "Input Data", does a "conversion" and calculates the running standard deviation of incoming data.  In this example if you run the program, the STDev at the first point is zero and on the second read in it is 0.1 (STDev of both).

 

Once the standard deviation falls below 1, it triggers a counter which increments a case structure.

 

The counter counts from 1-10, and the case structure reads in the next incoming 10 data points, while simultaneously initializing the standard dev (boolean true).

 

Once 10 points are read in (built an array), other numerical computations are performed and the "conversion" math is updated with a new value for calculations called "corresponding value change".

 

Returns to reading in "Input Data" with the new "corresponding value change" for conversion and starts the STDev calculations on the new incoming data.  STDev initialize is false.

 

Everything works fine, upon triggering the program reads in 10 data points and calculates the new corresponding value.  However, the next  read-in point with the updated value should technically be zero, because STDev initialize is now false and there is only one point coming in.  This is not the case however, it seems to be using previous "Input Data" values for STDev. I have implemented every possible variation that I can think of for the counter and STDev initializing but I cannot get it to begin new STDev calculations at the first input data after the 10 read-ins.  Does anyone have any suggestions as to how this can be modified?  Thank you.     

 

Also, please ignore the cosmetics of the program, it is still a work in progress and looks messy.

0 Kudos
Message 1 of 7
(2,631 Views)

My best advice is start from scratch. The problems are more than a few cosmetics. I looked at this for a couple of minutes and just ended up with a headache.

 

1.Take a while loop.

2.Add a counter that increments by one each loop.

3.Add an array that has one data value appended to it each loop.

4.Use shift registers for (2) and (3)- this should force you to keep things clearer.

5. Have a case that executes IF your counter is 10. Do this by using the 'equals' VI to compare count with 10 and linking to a true/false case- not a set of 10 cases switch directly by the number.

6. In the case, do your calculations on the content of array (3). Then clear array (3) and set counter (2) to zero.

7. No reverse wiring, magic numbers that activate functions, or excessive use of cases.

 

Message 2 of 7
(2,613 Views)

It's a bit hard to read with all that right-to-left wiring. Why don't you combine cases 1..9 into one?

Did you place that feedback node or did it get inserted automatically?

Message 3 of 7
(2,606 Views)

Thanks for the suggestions.  I suppose I can do it the way you are both suggesting, so I can make an array with a size of 10 rows, then once the triggered counter hit 10 I would use those values to calculate.  I am wondering if I will still run into this problem with the STDev initialization though, I don't think they are related.  I will give it a go.  

 

Also, the feedback node appeared automatically.

0 Kudos
Message 4 of 7
(2,600 Views)

baseball07 wrote:

Also, the feedback node appeared automatically.


Most likely you created a wire cycle by accident (such accidents are much more likely if you wire in all directions as you did here!). The feedback node will delay the output by one iteration, something you probably don't want.

 

(Also see these two ideas: Idea 1, Idea 2 for further discussions and arguments)

Message 5 of 7
(2,596 Views)

HI 

I've tested your vi and there are some coments:

 

the logic that you are using to trigger the counter is not very clear but I will assume that it's working fine. 

If you run the program with front panel of the point by point std deviation, it runs the StdDev of a set of only 1 point actually (I put a probe on the subvi and runned). 

I am not sure if the vi is doing what you expect it to do. the point by point vi should be calculating the std dev to every point you are inputting but you are innitializing the vi every iteration until the counter reaches 10. Then it passes the previous STD calculation.

If you want the std calcualtions to be reseted on every 10 points then you should revise your logic.  

 

I also noticed that the cases 1 through 9 are doing the exact same thing, you could just type 1..9 on the case structure without having to repeat your code. 

 

Cou can provide more details about your logic ?

 

RKO
Message 6 of 7
(2,582 Views)

Hi thank you for the responses. 

 

In addressing the feedback node, yes they are connected as I intended, however I was not aware that it caused a delay in an iteration which could be part of my issue.  The way I have the code is that the STDev value triggers (resets) the counter for the case structure when it goes below 0.  This is fine, but then I am simultaneously initializing the STDev block as the counter running from 1-10 is going which is causing the feedback.  If I don't initialize it while the counter is running, the running STDev value will be less than 1 so the counter will always be triggered to 0 at each iteration.   

 

Having said this, since I cannot implement a feedback loop to keep the STDev at 0 while the counter is running, I need another way to indirectly trigger the counter when the STDev falls below 1.  Is this logic clearer now?  I attached another vi which I removed some unnecessary items and updated the case structure to run 1..9.   

0 Kudos
Message 7 of 7
(2,568 Views)