LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Timers and Switch Cases

Solved!
Go to solution

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??  

Tim
0 Kudos
Message 1 of 9
(5,758 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 9
(5,757 Views)

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

 

 

Tim
0 Kudos
Message 3 of 9
(5,742 Views)
Solution
Accepted by topic author smoothdurban

I guess you may be interested in this kind of logic. Just pull it into your vi and run it.

 

Switch cases.png

 

Switch cases 1.png

 

Good luck.

-----

The best solution is the one you find it by yourself
Message 4 of 9
(5,733 Views)

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.

 

 

Tim
0 Kudos
Message 5 of 9
(5,725 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 9
(5,724 Views)

@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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 7 of 9
(5,723 Views)

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. 

0 Kudos
Message 8 of 9
(4,748 Views)

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. 

0 Kudos
Message 9 of 9
(4,730 Views)