Academic Hardware Products (myDAQ, myRIO)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to track "i" value inside a conditional loop?

I want to build a while loop that has a conditional loop inside of it.  When the conditional loop is set from false to true I want to capture the current iteration "i" value of the while loop.  When the conditional loop is still true I want to find the difference between the initial "i" when the conditional loop started and what the current "i" value is.  The difference between the two values will then be multiplied to a constant and output to an indicator.  How can I do this?
0 Kudos
Message 1 of 7
(9,541 Views)
what is a "conditional loop"? (A regular while loop inside a case structure perhaps?)
0 Kudos
Message 2 of 7
(9,538 Views)
I should have called it a Case Structure instead of a conditional loop.  I included the basic structure of that I want in the following attachment.  How do I set the initial value of i in the while loop when the case structure is set to true?
0 Kudos
Message 3 of 7
(9,530 Views)

Just use a shift register. (And by all means, place a small wait inside that loop, you don't want it to consume all CPU).

 

0 Kudos
Message 4 of 7
(9,528 Views)

This is close but I need to be able to do is some how save the initial value of "i" when the case structure is set to true and hold on to that value as the while loop continues to run.  With each new iteration of the loop the case structure needs to find the difference between the current "i" value and the initial "i" value.  This difference should continue to increase as long as the case structure is set to true.  Thanks for the help.

 

0 Kudos
Message 5 of 7
(9,511 Views)
Why do you even need to use the [i] at all? You could just use a shift register that you increment in the true case and reset in the false case.
 
Anyway, if you only need the "Monitor Value", use one of the upper, alternative code examples. (Choice depends on what should happen if the constant changes during a run. Test, compare, and modify as needed.)
 
If you really need to keep track of [i] (current and initial, etc.), use an additional shift register to sense the TRUE-FALSE transition on the button. One possible solution is shown in the lower part of the attached example. Let me know if you have questions.
0 Kudos
Message 6 of 7
(9,508 Views)

Christian,

Thanks for the help.  The last vi that you posted worked great with each of the three examples.  I did not even consider tracking inside the case structure.  I am off and working with the new ideas.  Again thanks.

0 Kudos
Message 7 of 7
(9,485 Views)