LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use boolean value to switch between several numerical values

Solved!
Go to solution

Hi everyone.

I’m new to Labview, so I’m sorry if this is very elementary or if I have overlooked an earlier question and solution regarding the same.

 

I would like to use a Boolean value to switch between different numerical values. The Boolean value switch each 60 second, and I would like to pass through the following numerical values in the order they are written: 300, 800, 1500, 300, 1500. The program shall then start again from the beginning of this cycle and continue running through this cycle.

 

I have considered case structures, stacked sequence and so on, but can’t find a solution that can handle more than two states and will continue to run through this cycle infinitely. Perhaps some kind of state machine, but I have no experience with this…?

 

Hope that one of you experts can help me. Thanks in advance. 

0 Kudos
Message 1 of 7
(2,649 Views)

When the boolean is true, increment a number that is passed around a shift register. Use this value as an index to index the array containing your values 300, 800, 1500, 300, 1500. If the index becomes bigger than the array size, et it back to zero.

0 Kudos
Message 2 of 7
(2,644 Views)
Solution
Accepted by topic author ChrisDK

Hi Chris

 

I've attached a file for you

 

One loop does what you are asking, switch between the numbers when a boolean changes

 

Second loop does the same as the first loop but much simpler using the wait functions instead of the watch.

 

Best Regards

Anders

Message 3 of 7
(2,600 Views)

@ToeCutter wrote:

When the boolean is true, increment a number that is passed around a shift register. Use this value as an index to index the array containing your values 300, 800, 1500, 300, 1500. If the index becomes bigger than the array size, et it back to zero.


It is easier for the reset if you use the Quotient & Remainder to get the remainder of your index divided by the number of items in your array.  Just do this when you increment.  So your process should really be 1) check value, if FALSE, go back to 1, 2) increment value, divide by array size to get remainder, 3) use Index Array with the remainder value to get the value you want to output.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(2,598 Views)

Tim, You know I got nothing but love for you brother.

 

Tools>>Options

Capture.PNG

Just check the boxes.


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 7
(2,588 Views)

Jeff·Þ·Bohrer wrote:

Tools>>Options

 

Just check the boxes.


I always have those on.  What are you trying to get at?

 

EDIT:  Whoa.  What?  Why isn't the constant folding working inside of the case structure?  Or is it just not showing that it is really constant folding?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 7
(2,572 Views)

Thank you all very much for your input and solutions. 

 

@A.Rohde the reason why I would like to use the watch instead of the wait function, is that I'm going to use it as a part of larger producer-consumer structure program. Here I have experienced some difficulties controlling the time correctly, as it is acquiring both analogue signals and digital signals with a changing frequency, so it varies how often there are values to write to the queue. This problem might be due to bad programming (probably is Smiley Wink ) but the watch solves this problem - it's definitely precise enough for me with the watch.

 

Again thank you all.

0 Kudos
Message 7 of 7
(2,520 Views)