From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Boolean toggle time in while loop?

Solved!
Go to solution

Hey everyone,

 

I need to toggle a Boolean variable for a short period of time (~0.5 seconds but it does not have to be exact as long as it can be changed) when the trigger signal is on.

- basically the Signal variable should remain False until Trigger indicator is True

- then Signal should turn True for ~0.5 sec and turn back False after

 

The program needs to be in the main while loop (data acquisition loop). Use of timing could affect the data acquisitive (not shown in sample program).

 

I attempted doing this with a case structure and a flat sequence but unsuccessfully. Any suggestions are welcome. THANKS YOU FOR YOUR HELP!!!

 

boolean_time.png

0 Kudos
Message 1 of 8
(5,541 Views)

Hi mat,

 

as soon as you provide some timing in your while loop you will notice your example to be working...

Put a 500ms wait into that loop!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(5,526 Views)

First you have a race condition between the delay and the local variable. Second, you have no delay in the "off" state. Hence your sequence will be one of the following:

 

1. Wait 500ms

2. Turn LED on

3. Turn LED off

4. Repeat

This would show an LED always off

 

Or

1. Turn LED on

2. Wait 500ms

3. Turn LED off

4. Repeat

This would show an LED always on

 

You will want to assign a delay to your off time as well as switching the delay to the time delay express vi (this has error terminals for controlling execution). To find the time delay, type "Time Delay" into quick drop.

Charles Chickering
Architecture is art with rules.

...and the rules are more like guidelines
0 Kudos
Message 3 of 8
(5,522 Views)

Thanks for the qucik replies... This didn't solve the problems but perhaps I did not explain it well. With the changes I always get the Triger and Signal going T when >10 and F when condition <10.

 

I need an impluse signal only once once the condition: Dial > 10 is met. Basically when Dial > 10 i need to send an audio "beep" (controlled by Signal boolean varialbe). Just one short "beep" every time Dial > 10. 

 

1. Signal off

2. Dial >10

3. Signal on

4. Wait 0.5 sec

5. Signal off (regardless of Dial value).

6. Repeat everytime Dial > 10

 

Thank you for your help

 

 

 

0 Kudos
Message 4 of 8
(5,506 Views)
Solution
Accepted by topic author m@t

Something like this?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 8
(5,491 Views)

This works!!! Thanks a lot... I haven't used the event structure but this works perfectly.

0 Kudos
Message 6 of 8
(5,466 Views)

Unfortunately, the event structure is not a good choice of you are e.g. polling an external voltage.

 

The "signal" is true for one iteration whenever the voltage goes from below to above the threshold. It stays off for all other cases.

 

 

Here's what you can do in the more general case. much more lightweight. 😉

 

 

Download All
Message 7 of 8
(5,458 Views)

This also works really well!!! Thanks for improving the efficiency of the code 🙂 

Cheers.

0 Kudos
Message 8 of 8
(5,436 Views)