ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Events and while loops -- better way?

How can I do this better? :

Say I have a while loop with a boolean in it called "Done?". It's wired
to the while loop's control boolean via a NOT gate, and of course the
loop exits when the boolean is pressed.

This eats up CPU cycles and so is very inefficient. Is there a way to do
this better?

-- Stephen
0 Kudos
Message 1 of 3
(2,737 Views)
> Say I have a while loop with a boolean in it called "Done?". It's wired
> to the while loop's control boolean via a NOT gate, and of course the
> loop exits when the boolean is pressed.
>
> This eats up CPU cycles and so is very inefficient. Is there a way to do
> this better?

Not really any way of doing it better.

It doesn't waste a ridiculous amount of CPU power if you put, say, a 100ms
delay in the loop- this is short enough for the user not to notice a delay
when pressing it, but means your program only does the check ten times a
second. You ARE already putting a delay in the loop, of course ;).
0 Kudos
Message 2 of 3
(2,737 Views)
In article <39CF734C.262A5958@comm.mot.com>,
stepheb@comm.mot.com wrote:
> How can I do this better? :
>
> Say I have a while loop with a boolean in it called "Done?". It's
wired
> to the while loop's control boolean via a NOT gate, and of course the
> loop exits when the boolean is pressed.
>
> This eats up CPU cycles and so is very inefficient. Is there a way to
do
> this better?
>
> -- Stephen
>




As yet another method:

Place your boolean along with the invert in a Case structure, say in
the true case, place a false in the false case, wire the output of the
case to the done, and then use one of several types of triggers to
select the true case. As a possible trigger, read the count from the
iteration counter, divide it by 1000 using the quotient an
d remainder
function, and when the remainder = 0 read the boolean. This causes a
read every that is selectable between every 10, 100, 1000, 10000...
cycles, depending on your divisor. You could also set up a trigger
using the real time clock, this would give timing that was not
dependent on loop times.

Hope this gives you some help.

Marlin Rhea



Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 3 of 3
(2,737 Views)