LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timing a Case Selector

I have a case structure inside of a while loop.  The case has three cases and I want it to select the first for 64 cycles of the while loop.  Then I want it to select the second for 500 cycles of the while loop.  Then I want it to select the third for 2500 cycles of the while loop.  Is there a way that I can time the case selector to choose a case for so many cycles?  Is there a counter that I can increment every loop and when it gets to a certain value it will change states?  That is my idea of how to solve it anyway, but if anyone has any idea's let me know.
0 Kudos
Message 1 of 12
(4,199 Views)

Hi Musser,

      Sounds like you're on the right track.  Nesting your while loop inside another while-loop (or For-loop) might be "clean" solution as well.

These examples - with/without error handling - use two for-loops.

When they give imbeciles handicap-parking, I won't have so far to walk!
Download All
0 Kudos
Message 2 of 12
(4,188 Views)
Dynamik's suggestion is a really good one. In case you wanted some options, here's another.
 
There's a VI called Threshold 1D Array. If you input an array of numbers, such as [1,5,9,25], then you can input a scalar value and the VI will give you the fractional index of where that number would fall in the array. For instance, if you input the number 3 for the array above, LabVIEW would see that 3 is half-way between 1 and 3 (indexes 0 and 1), so it would return 0.5 as the fractional index.
 
My idea is to put your loop iteration counts for each case in an array and then input this array and the current loop's iteration as the scalar into Threshold 1D Array. So your array would look like this: [0, 64, 564, 3064, etc.]. Then you could round down the fractional index and change it to an I32, and voila, you'll get 0 for the first 64 iterations, 1 for the next 500, 2 for the next 2500, and so on. I've attached a quick example demonstrating this. Hope this helps!
Jarrod S.
National Instruments
0 Kudos
Message 3 of 12
(4,163 Views)
This really helps alot, thanks.  I am not very good with labview, I was wondering how I would mod this to start at 1 go to 2 when it hits 64, go to 3 when it hits 564, and go to 0 when it hits, 3064?
0 Kudos
Message 4 of 12
(4,143 Views)

more ideas. Smiley Happy

 

When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 5 of 12
(4,129 Views)
I think this solution is even more simple, check the attachment
 
B Bakels
Labview CLD , Engineer/Manager

Promedes and DSM
using LV 7.1, 8.0, 8.2, 8.5 and 2009 SP1
http://www.promedes.nl
0 Kudos
Message 6 of 12
(4,095 Views)
except for the ranges being wrong (second span should be 64..563), it is simpler bartb -  wish I'd thought of it. Smiley Happy
When they give imbeciles handicap-parking, I won't have so far to walk!
0 Kudos
Message 7 of 12
(4,078 Views)
lol its was late..... 😉
Labview CLD , Engineer/Manager

Promedes and DSM
using LV 7.1, 8.0, 8.2, 8.5 and 2009 SP1
http://www.promedes.nl
0 Kudos
Message 8 of 12
(4,048 Views)
Hey, I was wondering if there was a simple way with this implementation to start the case statement over again?  If I wanted to do case 1 64 times, case 2 500 times and case 3 25000 times and then go back to case one and loop through, how would I do that.  Would I have to change the while loop to a for loop?  If I were running other blocks off of the while loop, could I have a for loop inside the while loop just for the case statement? 
0 Kudos
Message 9 of 12
(4,015 Views)
You could have a for loop inside a while loop. That would definitely work, or you could take the remainder of the While Loop's iteration count when divided by 3064 (=500+2500+64). Whichever's easier...
Jarrod S.
National Instruments
0 Kudos
Message 10 of 12
(3,999 Views)