Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuing a loop for a set amount of time

Hi,
 
I'm am trying to alter a previously written program have run into a problem.
The program is set up so that when the input exceeds a set level an output voltage to a buzzer is created; the buzzer continues as long as there is an input.  What I need it to do is to continue this output for a set amount of time.
I've been searching the forum and found this straight forward solution from adamsjr.
 
"The easiest way to do this is to use a two Tick Count functions. The first
one is outside of a While loop, the second one is inside of the While loop.
Wire the first one through a tunnel into the While loop, add on the appropriate
ms (5*1000), wire the sum to one input of a compare function. Wire the
other input of the compare function to the second Tick Count function. Exit
the loop when the compare shows the second Tick count value is greater than
the summed value."
 
I've got placed the output subVI into a while loop and followed the above directions and this doesn't seem to work. I'm wondering if I would also have to include the input subVI into the loop or is there another possible solution
 
Thanks ahead of time,
Kristen
0 Kudos
Message 1 of 5
(4,370 Views)
Hi Kristen,
 
The reason why this might not work for you is probably because your subVI might take longer than five seconds to run.  I would implement the solution that adamjr has suggested ONLY around the piece of code that contains the buzzing function to keep the buzz going for five seconds.
0 Kudos
Message 2 of 5
(4,356 Views)
Hi Tolga,
 
Thanks for the advice, I've given the solution a shot, and still have had limited success.  I find that the code is sporadic in its operation. I've attached the code that I'm working on.  Would it work if the tick count was outside of the sequence loop?
 
Also, is there a way to tell if the subVI's are taking longer than 5 seconds? I don't really think that it is because the program is relatively straight forward.
 
Thanks again,
 
Kristen
0 Kudos
Message 3 of 5
(4,346 Views)

Hi Kristen,

 

You have the compare function implemented incorrectly.  You need to make sure that the first terminal of the "Greater than or equal" function connected to the output of the sum, and the second terminal to the tick count in the while loop.  The first terminal corresponds to x parameter and the second terminal is for the y parameter.  So if x is greater than or equal to y, then the loop will need to exit.

 

You can see how long a subVI is taking if you put a flat sequence structure within your subVI around the entire subVI code.  The first frame would only have a tick count going into an indicator, the middle frame your normal code, and then the final frame would contain another tick count wired into another indicator.  Then you can subtract the second indicator value from the first and get hold long it took to execute the middle (core) of your code for that subVI.

I highly suggest using the highlight execution and probes and other debugging techniques such as breakpoints to diagnose where the data is being held up.

0 Kudos
Message 4 of 5
(4,316 Views)

 



Message Edited by TMC-NI on 04-21-2008 11:07 PM
0 Kudos
Message 5 of 5
(4,316 Views)