From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Level change indicators

Solved!
Go to solution

Hi.

 

My VI is measuring Ing the level of water in a tank, and want I LED indicators to tell me if the level is  Increasing, decreasing or stable.

There's 1 indicator for each case.

 

How do I compare the current waterlevel to the level 1 sec ago?

 

So far I've made at sequence structure (in a while loop) that's is comparing the value in seq.2 to the one of seq. 1.

It only works once.

 

Any ideas to a solution?

 

Regards

Kat

1. year engineering student

0 Kudos
Message 1 of 10
(3,801 Views)

I can't see your code (I have LV 2014), but for that kind of timing you may consider putting the time and water level into a shift register. Put your code which compares the water levels into a case structure, and only update if 1 second has elapsed from the shift register value. If it has, make sure to update the shift register with the current time. You can use things like tick count (ms), high resolution (sec), and time stamp to keep track of time.

0 Kudos
Message 2 of 10
(3,794 Views)

You should get rid of the sequence structure and the local variables. Both are unnecessary and make it much more difficult to do what you want. 

 

While you can meet your stated goals without, it might be a good time to learn about state machines.  Your states could be "Increasing," Decreasing," and "Stable." You might also have states for empty and overflow.

 

To get a decreasing value, Input will need to include negative values.

 

Consider what should happen if Tank2 has a negative value or a value greater than 100.

 

Lynn

0 Kudos
Message 3 of 10
(3,785 Views)
Solution
Accepted by topic author KatrineRav

Use that Feedback Node to store the previous level.  From there, just subtract the new and the old and use the Sign function.  This will give you a -1 (decreasing), a 0 (stable), or a 1 (increasing).  Just use a case structure to interpret this into your boolean indicators.


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 10
(3,779 Views)

Nevermind my post. The one above is a cleaner solution




Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 5 of 10
(3,767 Views)

Thanks a lot!

0 Kudos
Message 6 of 10
(3,740 Views)

@crossrulz wrote:

Use that Feedback Node to store the previous level.  From there, just subtract the new and the old and use the Sign function.  This will give you a -1 (decreasing), a 0 (stable), or a 1 (increasing).  Just use a case structure to interpret this into your boolean indicators.


Is the 1 to infinity needed on the case structure? It seems like that function only has 3 output possibilities.

0 Kudos
Message 7 of 10
(3,729 Views)

@Gregory wrote:

@crossrulz wrote:

Use that Feedback Node to store the previous level.  From there, just subtract the new and the old and use the Sign function.  This will give you a -1 (decreasing), a 0 (stable), or a 1 (increasing).  Just use a case structure to interpret this into your boolean indicators.


Is the 1 to infinity needed on the case structure? It seems like that function only has 3 output possibilities.


Yes it is.  The case structure just sees a numeric.  You therefore must cover ALL numerics.  So the 3 cases here are "..-1", "0", and "1..".


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
Message 8 of 10
(3,715 Views)

Thank you, I see now. That is nicer than having a default case.

0 Kudos
Message 9 of 10
(3,707 Views)

@crossrulz wrote:

Just use a case structure to interpret this into your boolean indicators.


I would recommend to just us an array of three boolean indicators (And use the array caption for labels). It is much cleaner code if you don't need to use a case structure and you only need exactly one indicator.

 

 

 

 

 

 

I changed the input to I32. If the Value is really a DBL coming from a real instrument with noise, you most likely never get an equal. You probably should introduce some deadband such that very small changes are ignored (Not shown).

 

Also note that you have a hidden race condition, because the tank indicator lags behind by one iteration and does not show the current level. You need to wire it to the output of the addition, not the output of the shift feedback node. You are also comparing the input with the tank, which is logically incorrect.

 

 

0 Kudos
Message 10 of 10
(3,679 Views)