LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to repeat a subset of case statements a fixed number of times

Solved!
Go to solution

I have a state machine with a case structure containing about 30 cases. Whenever case #20 is called, what is the best way to repeat cases #20 throught #25 within the case structure 10 times before moving on to another case number?

0 Kudos
Message 1 of 5
(3,156 Views)

There are a probably a number of "best"! Is this a "fixed" thing, or do you need the flexibility to repeat other sections at other times? Is it going to be the same number of repeats? How do you signal the transition from one state to the next? You could have a selector there that determines whether to go back to the previous (i.e 20) or on to the next (i.e.26 or whatever is outside of the "block" being repeated). Then keep track of the repeat count, with a shift register, incremented each time through the block's loop, reset to zero when the count has reached a predetermined value. This shift register could even be encapsulated to allow the target value to be "set" in another section of your program, "incremented" each time through, and "checked" where you need to know whether the incremented number = target.

 

Many other ways possible too, just a quicky off the top of my head.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



Message 2 of 5
(3,147 Views)

Once you hit case 20, initialize a counter at 0, feed it to a shift register.

 

1) move your cases to:

20 >> 21 >> 22 >> 23 >>24 >>25

 

2) at case 25:

If counter <= 10:

counter += 1

25 >> 20

else:

25 >> 26

 

That should be relatively straight forward.

 

Edit: LV_Pro beat me to it! I guess thats why he's a pro Smiley Tongue

Cory K
Message 3 of 5
(3,145 Views)

Yes it is fixed, and I use an enum to go between states, as in the LV state machine template. I thought about using a shift register, I just wasn't sure how to set up the counter for just five of the cases, but I think I can get there by combining the cases into one case and using a for loop.

 

Thank you.

0 Kudos
Message 4 of 5
(3,133 Views)
Solution
Accepted by topic author chuck72352

Put the shift register outside of the case structure that changes states.

Set it to 1 initially.

 

Through every single case, pass it straight through without modifying it.

The only case that might modify the value is case 25.

 

If the value is 9 or less, move back to case 20 and increment the counter by 1.

If the value is 10, move to case 26, and reset the counter back to 1.

Cory K
Message 5 of 5
(3,106 Views)