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.
Solved! Go to Solution.
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.
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.
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?
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.
Here's what you say you want to do:
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.