LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set a boolean variable to be true each x amount of time

Solved!
Go to solution

hello,

 

Any ideas of how to create a boolean variable in labview which will be true only let's say each 2 seconds ? the rest of the time it should be false

 

 

 

Regards

Charis

 

0 Kudos
Message 1 of 10
(7,336 Views)

Charis,

 

what is the context of such a "variable"?

The question is very important as it is a common mistake to have "variables" in dataflow programming languages like LabVIEW.

 

That being said, you have to implement a loop with proper timing to toggle the boolean value. You have to look for good propagation methods to make this value available in other parts of your software.

If the software is a single loop, the implementation is easy. It requires a shift register and a state machine (which includes other states as well performing the actual task of the program).

If the software is more complex, propagation from your "toggle loop" can be done by an Action Engine or a notifier.

 

Also, you have to define how long the boolean should be true as you only stated how long it should be false (2 seconds)....

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 10
(7,327 Views)

Look into the quotient/remainder function to create a circular buffer.  Use a small number for ms wait, and based on the current remainder, output true.  Otherwise, output false.  That way, it'll flip for each period you choose for the ms wait only every x amount of times.

0 Kudos
Message 3 of 10
(7,325 Views)

Thanks for your reply.

 

could you provide me with a simple example ? 

 

 

Regards

0 Kudos
Message 4 of 10
(7,310 Views)
Solution
Accepted by charis21

If you have OpenG installed, there is a Periodic Trigger VI that does what you describe, assuming that you only want the boolean to be true for a split second as Norbert noted.

aputman
0 Kudos
Message 5 of 10
(7,299 Views)

You could also use the time elapsed function in a loop that resets every time you reach the desired time interval.

0 Kudos
Message 6 of 10
(7,273 Views)
Solution
Accepted by charis21

here's the way to go

Untitled.png

0 Kudos
Message 7 of 10
(7,262 Views)

Don't forget the wait function.  This is especially true in a case where he's looking to have a general time.  It's always true inside of a while loop for performance reasons.

0 Kudos
Message 8 of 10
(7,238 Views)

Thanks everyone for your responses ! 

0 Kudos
Message 9 of 10
(7,214 Views)

Hasn't anyone else noticed that the openG "Periodic Trigger" function has an off-by-one bug?  In my test program, the pulse period is always 1 msec longer than that requested.  The root of the problem is that it uses a > comparison rather than >= to decide when to pulse.

 

I usually use my own similar function that's based on a floating point >= using "High Resolution Relative seconds" from vi.lib instead of the integer msec tick count.

 

Snippet at bottom to illustrate openG bug.  Will require that you have the openG Periodic Trigger function on your system.

 

 

-Kevin P

 

openg periodic trigger off-by-one.png

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 10 of 10
(7,076 Views)