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 check a certain condtion for 5 seconds continuously

hello,

 

I have a certain condition that I would to like to check for 5 seconds and if it is true all through the 5 seconds, I want to indicate it to the user. I tried using a Shift register. Is there a bettter way to do it?

0 Kudos
Message 1 of 6
(3,115 Views)

First of all, you need to think what the word "continuously" means in talking about digital computers which do things "digitally" on a clock, i.e. not "continuously".  

 

Next, you have to define what you mean by "a certain condition".  It sounds like you want to sample something at some frequency and do a boolean Test (i.e. "Is this condition True or False?") on each sample.

 

Now you also have to think "What else, if anything, do I want to be doing "at the same time"?

 

So here's one way to do this.  Sample "whatever" at 1MHz (once a microsecond) in a For Loop that has a conditional Stop.  Change the Stop to a Continue (so that a True output from your test keeps the loop running).  Wire the output of your test to both the Continue and the output "last value" tunnel, and set the Loop count for 5 million.  If it does all 5 million samples always "True", then the loop will output "True" and you'll know you were True for 5 seconds.  However, if any of the 5 million tests were False, the loop will stop and return False.

 

Now, this will probably grind the rest of your code to a halt as you are testing at a (probably unreasonably) high sampling rate and can't do much of anything else.  What if you sampled at 1 KHz?  Well, you could certainly keep a parallel loop probably going at 95% (or faster!) full speed.  These are some of the things you need to consider.

 

Bob Schor

0 Kudos
Message 2 of 6
(3,109 Views)

shift register is good, try adding elapse timer as well....

5 sec.png

0 Kudos
Message 3 of 6
(3,073 Views)

I think the most important question is:

Is it important to stop before the 5s elapsed if the signal is OFF?

 

If you answer NO to that question, i recommend you to use hardware clocked finite acquisition for 5s. That means that you do not hog the CPU during acquisition and the hardware configuration determines the sample times, e.g. the "blind spots for very fast toggles of the signal". Using a high sampling rate results in lots of data which could induce challenges for the system (e.g. memory issue, slow data analysis,...). Low sampling rates reduce these challenges, however they increase the "blind spots".

 

The biggest disadvantage in this approach might be that the software waits for the acquistion. That can lead to the perception of unresponsive software at the user side. Maybe you should talk with future users of the software what they do prefer.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 4 of 6
(3,048 Views)

I tried it with your VI. When I call it from another VI, the value of condition inside the while loop doesn't update as I increase it. 

Download All
0 Kudos
Message 5 of 6
(3,021 Views)

Hi apok,

 

Ok I figured it out since the subvi loop does not stop; I think I have to use in Main Vi to update condition values. 

My subvi reinitializes everytime it is called which makes the timer to not reset. Is there a work around for it..

 

 

0 Kudos
Message 6 of 6
(2,990 Views)