01-12-2015 10:18 AM
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
Solved! Go to Solution.
01-12-2015 10:25 AM
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
01-12-2015 10:28 AM
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.
01-12-2015 10:58 AM
Thanks for your reply.
could you provide me with a simple example ?
Regards
01-12-2015 11:16 AM
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.
01-12-2015 02:11 PM
You could also use the time elapsed function in a loop that resets every time you reach the desired time interval.
01-12-2015 02:28 PM
here's the way to go
01-12-2015 08:05 PM
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.
01-13-2015 02:34 AM
Thanks everyone for your responses !
01-30-2015 09:31 AM
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