Academic Hardware Products (myDAQ, myRIO)

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing data through case structure then while loop.

I am calculating the speed of an object(with the NIElvis II) as it passes through infrared sensors. my problem is in my 2nd part of the sequence structure I am getting a 0 from the previous part. I found out this is because the while loop/case structure is causing the value to go to 0 after the loop stops. I'll attatch my Vi if anyone can give me some insight. sorry if it is a little messy as I have been doing a lot of experimenting to fix the problem.

0 Kudos
Message 1 of 3
(6,473 Views)

 Kyreraza,

 

What you have here is a classic race condition.

Here you can learn more about what race conditions are.

 

You'll need to use something like a queue to force correct data flow.

You can find more about using queues in LabVIEW here.

 

You'll end up with something looking like this.

 

-CB

Casey B.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 3
(6,452 Views)

@Kyreraza wrote:

I am calculating the speed of an object(with the NIElvis II) as it passes through infrared sensors. my problem is in my 2nd part of the sequence structure I am getting a 0 from the previous part. I found out this is because the while loop/case structure is causing the value to go to 0 after the loop stops. I'll attatch my Vi if anyone can give me some insight. sorry if it is a little messy as I have been doing a lot of experimenting to fix the problem.


Here is what's happening:

 

  • In the lower while loop, the false case executes until the "x>y?" boolean turns TRUE.
  • Now the TRUE case and the inner loop start executing. At the same time, the "boolean" in the outer loop has already been read as FALSE.
  • Once the inner loop is stopped manually, the outer loop will iterate once more (because boolean was false the last time it got read!).
  • Now the inner loop will start over once more and starts from zero. The previous elapsed time is lost.
  • You need to stop the inner loop once more with the stop button (button is latch action!) and you get the elapsed time from the second run is later used to calculate the speed.

You figure out how to solve it. Should not be hard. Think dataflow! 😄

0 Kudos
Message 3 of 3
(6,445 Views)