LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Check if number within one of many ranges

Solved!
Go to solution

I need a system that continuously checks if my analog input is within 1 of 30 different ranges starting at 0-0.5 and then increasing the upper value by 20% (e.g. 0-0.5, 0.5-0.6, 0.6-0.72, etc.). I am able to do so by using a case structure with 30 different cases, however, is there an easier way to do it where I would need so many different cases? It is super time-consuming to make and if small changes have to be made in the program.

 

Thank you for your help.

Message 1 of 3
(1,771 Views)
Solution
Accepted by topic author Math808

Look at Threshold 1D Array.  You can give it an array for your ranges and your value and it will give you a fractional index of where your number would fit in the array.  You can round it towards -Inf to get an index of which range it was in.  Your array will want additional points in your array for -Infinity and +Infinity.  This will make the first valid range index 1.

 

EDIT:  Ok, some of my advice was slightly off.  Here is what I came up with with some tweaks as I played around.



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
Message 2 of 3
(1,744 Views)
Solution
Accepted by topic author Math808

Another variation is to check the range in a 30 iteration loop, changing the upper and lower limit on each iteration. If the value is within a range, stop the loop.

 

30-case-in-range.png

 

A stacked shift register is used to track the upper and lower limits, which allows the previous iteration's upper limit to be used as this iteration's lower limit.




Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
Message 3 of 3
(1,735 Views)