11-02-2021 05:24 PM
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.
Solved! Go to Solution.
11-02-2021 08:08 PM - edited 11-02-2021 08:24 PM
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.

11-02-2021 09:15 PM
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.
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.