LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How would I increment by one each time a sensor's indicator reaches a specific value range?

Hello -

In my Labview vi, I need to count the number of times a range of sensor values are reached. I am using the +1 incriment element but becuase the vi's loop is sampled so frequently, it continues to incriment because the loop starts over - and also because the sensor hasn't had a chance to change state yet. I need to just count when something is fully compressed and after the it is expanded, and again compressed - add one.
Thanks!
0 Kudos
Message 1 of 3
(3,188 Views)
Hi,
I would utilise a state machine approach. It seems to me you have two states - compressed and expanded. And you want to record everytime it is compressed. So I would do the following:

1. Set the state (any integer) to zero when inside the compressed range. If it is outside this range set it to 1. Utilise an IF loop here.
2. Independent of all this, check for any state changes. Using a shift register in your while loop, check for old state vs the new state. IF the old state was expanded (ie 1) and the new state is compressed (ie 0), increment COUNTER.

Hope this helps.

Regards,
Setu.
Message 2 of 3
(3,188 Views)
Hello,

Setu's answer was great, and I wanted to provide you with a simple VI showing an example of a state machine. This VI simply uses a boolean switch to change between the expansion and compression states (you would replace this with your code that indicates which state the process is in), and it adds one to the shift register value for each time that the compression occurs. (I added a half-second wait so that the effects can be seen slowly).

I hope this helps! Have a great day.

Liz Fausak
Applications Engineer
National Instruments
Download All
Message 3 of 3
(3,188 Views)