05-10-2010 01:18 AM
Hi all,
Apologies in advance for what is likely to be a stupid question...
In the attached VI there's a while loop that emits a random number every 10 seconds. That's used as one operand of a ternary operator, while the other operand is the constant 9000. A switch on the front panel is used as the condition of the ternary operator, and the output goes to a numeric indicator on the front panel.
The behavior I want is when someone toggles the switch, the indicator immediately toggles between 9000 and whatever random number was last generated. Instead, the indicator only updates when the next random number is emitted from the while loop. So it seems that the timer inside the while loop (which, from the documentation, sounds like it only controls the execution timing of the while loop) is actually controlling the timing of the entire program. Putting another timer outside the loop with a smaller interval (e.g. 5ms) doesn't seem to help.
Any ideas? Why is the Wait Until Next ms Multiple inside the while loop controlling the timing of the entire program?
Thanks,
Mike
05-10-2010 07:48 PM
Hello shadowmatter,
Welcome to the forums. A couple of notes for you here. 1. There is never a stupid question on the forums as long as you are trying to learn. 2. The forum has a number of very talented members and I personally think of it as one of the stronger online communities around. 3. You've posted on our hardware board. This is more likely to be looked at by people who know more details on interfacing with external hardware. The LabVIEW forum can be found here.
That being said, let's see if we can take a crack at this here for you. The timer helps to delay a loop or other structures that you have it in (a structure being anything on the "Structures" pallet).
What this means is the loop will be delayed the ten seconds and then because of the dataflow paradime of LabVIEW, your indicator will not be done until the loop exits and passes out its value. I know it's real exciting to hop right into LabVIEW programming, but you might be a little more fruitful with your time if you review Learning LabVIEW in Three Hours. I am guessing that if you read through this that my post will make a little more sense and you will be a little closer to the answer you are looking for.
05-10-2010 07:50 PM
Hey Mike,
The problem is that the while loop doesn't return data until you break out of it. Since the wait is inside the loop, it takes the full 10 seconds to break out of the loop. Since the rest of your program is waiting on the data from the while loop, the while loop hangs the rest of your program (also see Data Flow).
The attached code should do the trick, although there are many other ways to accomplish what you need. I threw the event structure in there since 10 seconds is a long time to wait if you want to break out of the loop sooner. For more LabVIEW specific questions I would try posting to the LabVIEW forum for a faster response--this thread is technically for NI's Counter hardware.
Best Regards,