LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stopping a while loop using the time difference of two tick counts

Solved!
Go to solution

Hi Guys,

 

I'm currently writing a code which test how long does it take for a formula node to perform its operation. The program uses a while loop to perform the calculation, and the program stops after calculating when tick count has reached 10 seconds. The program then displays the number of iterations it does in 10 seconds. 

 

So initially I created 2 frames of sequence structure. In my first frame I have my initial tick count, and in my second frame I have my final tick count and the while loop. I used the subtract function and divide the output by 1000 to get the time difference. Then using the comparison function, I set if output > 10 then the program should stop, to do this I linked the output of the comparison function to the stop button inside the while loop. 


However, when I tried to run the code, the program just didn't run. Hence I created a similar program which puts the last tick count in new frame sequence. When I ran this code, the program never stopped. 

 

Do you guys have any idea what went wrong with my codes.

 

Thank you!

Erry

Download All
0 Kudos
Message 1 of 4
(3,041 Views)

Both programs show that you don't understand dataflow - the basic model of LabVIEW. In both cases, a Boolean is passed into a while loop. That value is not refreshed until the while loop finishes. In the first example, your Boolean is true and the while loop will only run once. In the second, the initial Boolean is false which means the loop runs forever since you cannot pass in an updated value.

 

If you simply want to time that formula node, put it by itself in that frame. Create a third frame and calculate elapsed time there.

0 Kudos
Message 2 of 4
(3,030 Views)
Solution
Accepted by topic author JappyJapz

Dataflow!

 

In both VI's the stop terminal of the while loop is controlled by a boolean whose source is ouside of the while loop.  So that loop will either run once, or run forever, depending on the value of the boolean that is calculated before the loop starts and shows up at the tunnel going into the loop.

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 3 of 4
(3,028 Views)

Thanks for letting me know! I figured out from the beginning that there is something wrong with the data flow. I've solved the problem by putting the end tick count inside the loop. Thanks a lot guys!

0 Kudos
Message 4 of 4
(3,024 Views)