LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

nested while loops, inside loop not stopping correctly

I have nested while loops and am creating a state machine.

My first while loop is inside a case struture, creating my state machine. The case is to take readings. When the stop button is pressed, the while loop should quit and the state passes to the next state - Ask to save data.

My outside loop is to stop the overall program, without asking to save or anything, just stop.

Needless to say, they aren't doing what they are supposed to be doing.

Help please, my file is attached

Teresa Entwistle
0 Kudos
Message 1 of 7
(3,660 Views)
Teresa,

A state machine is a while loop, with a case structure inside. The loop executes repeatedly, until the "exit" state sends a "stop" to the while loop.

I am in the process of reviewing your code, and will email the results to you. I wanted to post here because this may be a common problem.

You can also go to the Topics section. There is some discussion there about program designs, which a state machine is. There is a sample posting there of mine that is kind of a state machine (with execution and reiteration controlled outside of the program, by a caller.) This will give you something of an idea.

Additionally, you can search NIs website for examples of state machines. These are prolific designs, and you should be able to find one.

If
you cannot, please let me know and I will create a simple example and place a copy on the design discussion Topic on this site.

Good luck.
0 Kudos
Message 2 of 7
(3,660 Views)
I have posted a simple (and working, what a bonus!) state machine in the Discussion about Designs in "Topics" at the bottom of the overview page.
0 Kudos
Message 7 of 7
(3,660 Views)
Bring the boolean 'stop program execution' inside the inner while loop. Then, OR the ouput of this boolean with the stop data boolean. The resulting signal will stop the inner loop whenever each key is pressed. Next, you will need to wire the 'stop program execution' to the outer while loop and setup a value for each case. I modified your original attachment.
>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 3 of 7
(3,660 Views)
Hi VT92,

I tried to run the modified code, but it would execut one iteration then stop.

Terry
0 Kudos
Message 4 of 7
(3,660 Views)
You have to wire a true to all of the other case to keep the state machine running...
>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 5 of 7
(3,660 Views)
Well, slap me upside the head. I guess that was too easy. I have it working now. Thanks for the help.
0 Kudos
Message 6 of 7
(3,660 Views)