From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

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
(6,043 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
(6,034 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
(6,032 Views)

Thanks for your reply.

 

could you provide me with a simple example ? 

 

 

Regards

0 Kudos
Message 4 of 10
(6,017 Views)
Solution
Accepted by topic author 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
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 10
(6,006 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
(5,980 Views)
Solution
Accepted by topic author charis21

here's the way to go

Untitled.png

0 Kudos
Message 7 of 10
(5,969 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
(5,945 Views)

Thanks everyone for your responses ! 

0 Kudos
Message 9 of 10
(5,921 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

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 10 of 10
(5,783 Views)