03-21-2012 03:17 PM
Really Simple Question.
I want to use a case structure which will alternate between two different results based on a timer expiring. For example:
5 sec Case -> true
5 sec Case -> false
repeat.
I will be writing data to file so any method that would cause the VI to sleep for the 5 second duration would not be ideal.
Any Ideas??
Solved! Go to Solution.
03-21-2012 03:21 PM
I assume this is in a loop so you will have the repeat part handled for you. Given that place the current time in a shft register. Each iteration check the current time with that in the shift register. Once your time period has elapsed (in your case 5 seconds) change you case selection (another shift register) and replace the time in the shift register with the current time.
03-22-2012 07:11 AM
I understand how to compare current time with previous time using a shift register I am a little confused on how I would use the second shift register to change my case selection.
Any way you could throw together some sample code of this?
I'm sure it wouldn't take long.
Thanks
03-22-2012 08:35 AM
I guess you may be interested in this kind of logic. Just pull it into your vi and run it.
Good luck.
03-22-2012 09:20 AM
Hey Thanks for the great feed back.
I was able to find another solution.
I was able to create two timers setting on to twice as long as the the other.
Timer #1 was set to 5 sec and would not automatically reset. Timer #2 was set to 10 sec and would automatically reset. When timer #1 exceeded five seconds it would change the case from true to false. When timer #2 exceeded 10 seconds it reset timer one thus changing the case to true and repeating the whole process. Seems to work really well.
03-22-2012 09:25 AM
P Anand's approach is basically the same thing I was suggesting only I was keeping track of th etime myself in it's own shift register. I tend to avoid express VIs but there are cases were they are useful such as this.
03-22-2012 09:27 AM - edited 03-22-2012 09:28 AM
@smoothdurban wrote:
Hey Thanks for the great feed back.
I was able to find another solution.
I was able to create two timers setting on to twice as long as the the other.
Timer #1 was set to 5 sec and would not automatically reset. Timer #2 was set to 10 sec and would automatically reset. When timer #1 exceeded five seconds it would change the case from true to false. When timer #2 exceeded 10 seconds it reset timer one thus changing the case to true and repeating the whole process. Seems to work really well.
This may work but it is a comparatively complex and convoluted solution. From a code readability stand point either my or P Anand's suggestions are much easier to understand when looking at the code. It's generally a good idea to follow the KISS principle, as in keep it simple.
06-07-2017 10:36 AM
Hi! My problem is similar to this one except I have more than one case structure that'd I'd like to loop between. I have attached a Labor Contraction labview program. The problem is that we'd like to figure out the best way to be able to automatically start/stop the program and be able to set how much time it goes through each case and be able to repeat however many times (in order to have multiple contractions because each time it runs through that's one contraction).
We tried doing something similar to what you did above with the T/F cases and a select but because we have more than two cases to get through it doesn't work the exact same and we've been having trouble manipulating the select options in order to run through the program as needed.
06-08-2017 04:08 PM
You can follow the structure that is mentioned here: http://digital.ni.com/public.nsf/allkb/6F6B9F4E149C80578625652800784764?OpenDocument
This, on each of the Cases therefore you will have hoy much time elapses on each case.