Showing results for 
Search instead for 
Did you mean: 

starting a case structure and a while loop simultaneously

Go to solution


I am trying to start a case structure and a while loop at the same time and then use the results of the while loop to trigger another case structure. More specifically, I start my device and ramp the device to certain speed. This takes 3 seconds. When max speed is reached, I want to use the code in the while loop to monitor the device's signal output and count peaks. When the certain number of peaks is achieved, I want to use this trigger the second case structure to decelerate and then accelerate the device. 

I can control the device's speed and monitor the device's output for peaks independentally, but I cannot merge the two processes together. 

Do I really need the code to monitor signal output and look for peaks in a while loop? I could end the process with the final state. I still then am not sure about the timing and using the peak detection output to trigger the next case structure. 

Thank you. 

0 Kudos
Message 1 of 6

It is generally a bad idea to have loops inside of loops like this.  Instead, use the state machine to go back to states that need repeated.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 6

When a block diagram is too large to fit on a 1920x1080 monitor, it is a major sign that you are doing it wrong!


Your block diagram is almost four times that size.


Scrap it and start over using a proper architecture like a state machine.



Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
0 Kudos
Message 3 of 6

Does the code even work? I see unecessary sequence frames and race condition everywhere. Then you are building an array at a while loop boundary and if the program never stops you will run out of memory eventually.


In addition, yuo need to tell us what "at the same time" actually means. Typically this cannot be achieved, just approximated. What is the allowed tolerance? (... same nanosecond? ... same day?). Are you on windows or a RT target?

LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 4 of 6

The part of the code that controls the device works and the code with the while loop and state machine to look for peaks works in a stand alone program.

I need the state machine to start looking for peaks three seconds after the device is started, so no, they don't need to start at the 'same' time. I didn't know how to initiate the state machine at the correct time, so I was trying to start them simultaneously (as in msec, not days apart) and use the wait function to delay the state machine by 3 seconds.

I am coming to realize that my code is a mess and that I need to completely rethink the architecture.

0 Kudos
Message 5 of 6
Accepted by Miller37

Here's what you say you want to do:

  1. Start Device.
  2. Monitor Motor.  If not "up to speed", repeat Step 2.
  3. Monitor Signal Output and Count Peaks.  If < "certain number" , repeat Step 3.
  4. Decelerate Device.  [Not sure if you are monitoring, but you get the idea].

This is a (very crude) State Machine -- you do one thing, and based on some condition, you decide what to do next (and then do that, as well).  Some of these "states" will probably have time intervals in them, governed by your needs (for example, Step 2 could be a simple "Wait 3 seconds", though it might be better to say "every 100 msec, get the motor speed and compare ...".


By looking in LabVIEW's Examples (including its Sample Projects), you can find examples of State Machines.  There is also the JKI State Machine available on the LabVIEW Tools Network.


Bob Schor

Message 6 of 6