LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to change the state ?

Hey LV Programmers,
         I have a while loop counter and linked to the while loop counter, I have four different cases (which is out side the while loop) to execute. My goal is to change the case for every 30 counts of the while loop counter. For example, let’s assume that I have Cases 1, 2, 3 and, 4. For the 31st count I have to change the state from case 1 to case 2. For the 61st count I have to change the state from Case 2 to Case 3. For the 91st count I have to change the state from Case 3 to Case 4. For the 121st count I have to change the state again from Case 4 to Case 1 and so on…. I tried different things but it didn’t work. I appreciate your support.

0 Kudos
Message 1 of 9
(3,723 Views)
Krishna,

First, the case structure must be inside the loop. The iteration value is not available outside the loop until the loop stops executing. There are ways around that, but they are more advanced topics.

Second. Use the Quotient and Remainder function in the numeric palette. Divide i by 30 and the quotient will be the 0,1,2,3 sequence you want. If your loop will run more than 159 times you will need to deal with the quotient getting larger than 3.

Lynn
Message 2 of 9
(3,711 Views)
There are many ways to do this, one possibility is shown in the attached example (LabVIEW 7.0).
 
It executes case 1 for 0...29, case two for 30..59, etc. but I am sure you can tewak it for your desired switching points.
Message 3 of 9
(3,706 Views)
Hello Sir,
                I would like to do something like the program that I've attached to this message but its not working. Case structure must be independent of the loop but should rely on the loop count to change it's state. Can you please help me with that. I appreciate your support.

Message Edited by Kay Kay on 04-10-2006 01:05 PM

Message Edited by Kay Kay on 04-10-2006 01:07 PM

0 Kudos
Message 4 of 9
(3,658 Views)

If you want the Case Structure's state to be reflected by the While Loop's iteration count, you need to put the Case Structure inside the While Loop.  Alternatively, you could create a parallel loop and put the case structure in there, and use a local or global variable to write the first loop's iteration count, and read that variable in the parallel loop.   But from your sample code, the most straight-forward solution should be to drop the Case Structure inside the While Loop.

-D

0 Kudos
Message 5 of 9
(3,649 Views)
Hello Sir,
                The problem is, when I use the case structure inside the loop to control certian instruments, for every loop count, the instrument is bugged by the program and its state is verfied because of which, am not getting the desirable performance as I'm working on a nanoseconds scale. And hence, I thought it would be a better option if I can take out the case stucture so that the instrument will not be bugged for every loop count and will change it state only after 30 loop counts and so on...
0 Kudos
Message 6 of 9
(3,644 Views)
Then why can't you have the Case Structure in the loop, and have the Default case do nothing, which would be the case that runs the majority of the time, and then have another case that runs only intermitently, like every 30 iterations?  If this solution doesn't work, then perhaps you need to describe the problem a little more clearly, perhaps with a more instructive sample VI.  But it seems to me that a case structure with an empty default case should be what you include in the While Loop.
 
-D
0 Kudos
Message 7 of 9
(3,641 Views)
Is it possible to use notifiers or occurances to have the case structure outside the loop? I'm not to sure how to use either of those so I can't answer my own question. Smiley Tongue
0 Kudos
Message 8 of 9
(3,625 Views)
This can be done if the Notifier value is recieved and used for a case structure that is inside another parallel while loop ( that is running simultaneously, along with the loop where the Notifier is being sent)
0 Kudos
Message 9 of 9
(3,612 Views)