LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Elapsed time inside case structure does not work properly

Solved!
Go to solution

I need to make a next programm: there is a switch and a LED. When you turn on the switch LED turns on with given seconds delay (if you turn the switch off during this delay - LED won't turn on), then when you turn the switch of - LED turns off with second given delay (if you turn the switch on during this delay - LED won't turn off). I have created the code on the picture, but it works correctly only on the first time I turn the switch on and off, then it starts to turn on and off without or with a very low delay

I have tried to set up auto reset after reaching the time target of Elapsed time but it didn't solve the issue.

 

I'm pinning my code, can someone please help me fix this issue?

0 Kudos
Message 1 of 5
(657 Views)

You did not include your typedef, so we cannot test. Also please set a reasonable default value for the delay. Zero is probably not reasonable.

 

Your loop needs a small wait, no need to spin it millions of times per second. The entire thing looks very convoluted. I am sure there is a better way.

 

0 Kudos
Message 2 of 5
(627 Views)

There is my typedef

0 Kudos
Message 3 of 5
(584 Views)

This is an example of "too much information (and not enough of the Right Stuff) has led you astray".

 

You are correct that Boolean Controls can exist in four "states", On, Off, and On (or Off) "Pressed".  What you missed (or overlooked) is that Boolean Controls have six "Mechanical Actions" that governs under what conditions they switch to On or Off (which are the two values that they take when you use them as controls in LabVIEW.

 

By default, the oval On/Off switch is a "Switch when pressed".  This mean that when you press it (and hold it), its value changes at the time you press it -- any time you read it after it is pressed, including when you remove your finger and "stop pressing it", it will retain the "switched" value until ... you press it again.  This is the "usual" behavior we expect of, say, a light-switch -- we flip it (or maybe move it very slowly), and once the contact is made, it has been "switched".

 

There may be a time you want a "push-button" that is on only while you are pressing it.  That's Mechanical Action "Switch until Released".

 

The most "interesting" Mechanical Action is "Latch when released", which is the default Action for "rectangular" Booleans, such as the Stop button.  When you push it, it switches, and stays "switched" until you read it, at which point it reverts to its "default" value (which, for Booleans, is False, unless you mess with it!).  Why is this useful?  If you don't know, try to figure it out for yourself, ask your Instructor, ask Google, or read the LabVIEW Help.

 

So get rid of the Switch Control type.  You have a While Loop, where you read a Boolean Switch (which can be either On or Off).  You want to compare the value of the Switch "now" with the value the Switch had the last time you read it.  What does LabVIEW have (hint -- it is not a "Tunnel") that lives on the left and right edges of a While Loop that can give you the previous value of a Control, so you can compare "Control in this Loop" with "Control in the previous Loop"?

 

Bob Schor

0 Kudos
Message 4 of 5
(554 Views)
Solution
Accepted by topic author Ferius

See if this can give you some ideas....

 

altenbach_0-1690724814729.png

 

0 Kudos
Message 5 of 5
(549 Views)