LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a one shot from a boolean value

First of all, let me clarify that I've just begun working with LabView and I'm teaching myself how to do it, so go easy on me!

My program monitors and runs a microprocessor controlled HVAC unit. I want to keep a count of the number of times an overheat fault occurs during a test run cycle. This fault sets a boolean variable in my program. The problem is when the fault occurs, it stays "true" for 10-20 seconds before the temperature drops back down and I'm having trouble writing code that increments a counter only one time when the fault goes true. How do I write a piece of code that basically acts as a one-shot looking at a boolean variable?
********************************************
Amateur programmer for over 10 years!
********************************************
Message 1 of 12
(12,297 Views)
You could use two shift registers. One, containing an integer, that is incremented with each fault.

The second shift register keeps the fault state of the last iteration. A fault occurs if (1) the fault boolean is true AND (2) the previous fault boolean was false. In all other cases, no new fault has occurred.

There are many ways to do the boolean logic, the attached uses "implies", which in this particular diagram creates only a "false" for each new fault. Try it.
Message 2 of 12
(12,284 Views)
Worked like a champ, thanks! I must admit, I was surprised that with the hundreds of tools available in LabView there was not a "one-shot" type of tool available.
********************************************
Amateur programmer for over 10 years!
********************************************
0 Kudos
Message 3 of 12
(12,281 Views)
Have a look at the "boolean trigger", which is part of the OpenG toolkit.


From the description: This VI is used to detect rising and falling edges of the Boolean Input. "Rising Edge" is TRUE if Boolean Input is TRUE and was previously FALSE. "Falling Edge" is TRUE if Boolean Input is FALSE and was previously TRUE. This VI is intended to be used in loops to aid in user input polling.


🙂
0 Kudos
Message 4 of 12
(12,270 Views)
The one-shot aspect of your sample code worked, but now I'm stuck conditioning the "stop" of the while loop. I want the loop to increment the counter, than hop out of the while loop and continue the rest of the program. Your sample code had the "stop" condition cut off. How did you handle that?
********************************************
Amateur programmer for over 10 years!
********************************************
0 Kudos
Message 5 of 12
(12,250 Views)
I would really recommend to use the OpenG version. It's a reentrant subVI that remembers the state of the previous call instance using an uninitialized shift register.

I have attached it (LabVIEW 7.0, Please note the license agreement on the front panel) . Simply place it on your diagram. You can also inspect how it works by opening it. Enjoy!

For more information on the openG tool kit check this link. It has many more useful free tools.
0 Kudos
Message 6 of 12
(12,246 Views)
Thank you for posting to the National Instruments discussion forums.

Regarding your question about how to wire the stop condition of the while loop, it should work fine to wire the while loop to run only once. Wiring the while in this way is common when using a shift register as described in this thread.

Please take a look at the attached example to see if it clarifies any questions you may have.

Thank you, and have a great day!

Scott Yellig
Applications Engineer
National Instruments
0 Kudos
Message 7 of 12
(12,205 Views)
Scott, can I get your oneshot.vi example in 7.0? Thanks.
0 Kudos
Message 8 of 12
(12,145 Views)
0 Kudos
Message 9 of 12
(12,134 Views)
0 Kudos
Message 10 of 12
(9,144 Views)