# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Specific Questions: How to use a series of predetermined values to calculate a stepwise increase in sediment levels

I have an experimental setup consisting of two connected water tanks where I can measure and control the turbidity (sediment) levels in each to see how fish behave and when they leave their preferred environment for more clear water. I want the sediment level to increase from clean water to a series of set levels of sediment that increase by 20% each time. Between each level of sediment increase, I have a 2 min wait period where I observe the fish (i.e. Clean water -> 20% turbidity increase -> 2 min observation period -> 20% turbidity increase -> 2 min observation... etc.). I measure the sediment levels by the voltage input of a turbidity probe inserted in the tank and I use a pump in a sump of dirty water to pump sediment loaded water into my fish tank and I have calibrated it so I know exactly how much sediment is added per second the pump is on (on average). My problem is this: even tho I have calibrated how much sediment is added per second with my current setup it does vary sometimes, so instead of adding 20% sometimes it adds less or more and I want my program to adjust for the inaccuracy of the last turbidity increase in the next turbidity increase. e.g. if I wanna go from 1 NTU to 1.2 NTU but it goes up to 1.3 NTU, after the 2 min observation period here I want my program to try to increase the sediment to 1.44 (1.2 + 20%) and not 1.56 (1.3 + 20%). I am pretty much blanking on how to get it to aim for these predetermined increases instead of just adding 20% to the current sediment level. Is there a way to have these predetermined values in some sort of table and after each observation period it uses the next number in the line to calculate how long the pump should be on to hit the desired sediment level?

I hope it makes sense and I really appreciate any help!

Thank you.

Message 1 of 6
(198 Views)

## Re: Specific Questions: How to use a series of predetermined values to calculate a stepwise increase in sediment levels

Hi Math,

@Math808 wrote:

if I wanna go from 1 NTU to 1.2 NTU but it goes up to 1.3 NTU, after the 2 min observation period here I want my program to try to increase the sediment to 1.44 (1.2 + 20%) and not 1.56 (1.3 + 20%). I am pretty much blanking on how to get it to aim for these predetermined increases instead of just adding 20% to the current sediment level. Is there a way to have these predetermined values in some sort of table and after each observation period it uses the next number in the line to calculate how long the pump should be on to hit the desired sediment level?

So in the 1st iteration you start with a setpoint of 1=1*1.2^(1-1).

In the 2nd iteration you go to sp=1*1.2=1*1.2^(2-1).

In the 3rd iteration you want  a sp of 1*1.2*1.2=1*1.2^(3-1).

What's your problem to implement that simple math?

Message 2 of 6
(181 Views)

## Re: Specific Questions: How to use a series of predetermined values to calculate a stepwise increase in sediment levels

I assume you are referring to the use of a for loop. That would only work if I can control the progression of iterations in accordance with my different periods (sediment increase and wait periods) and only go to the next iteration when I have to increase the sediment and I am not sure how that would be possible.

I have attached my program. I don't know if it will help, there is quite a lot going on but where I need to insert this would be in the lower left corner (I added some text to indicate where). Right now I can only add 20% to the current value when the wait period is over.

Message 3 of 6
(165 Views)

## Re: Specific Questions: How to use a series of predetermined values to calculate a stepwise increase in sediment levels

Hi Math,

@Math808 wrote:

I assume you are referring to the use of a for loop. That would only work if I can control the progression of iterations in accordance with my different periods (sediment increase and wait periods) and only go to the next iteration when I have to increase the sediment and I am not sure how that would be possible.

No, I'm not referring to FOR loops. I'm referring to statemachines!

@Math808 wrote:

I have attached my program. I don't know if it will help, there is quite a lot going on but where I need to insert this would be in the lower left corner (I added some text to indicate where).

You don't need to "insert something in the lower left corner", you REALLY need to implement some thoughtful program schemes and CLEANUP that monster!

(There is so much wrong in your VI I'm forced to suggest to start over from scratch…)

@Math808 wrote:

Right now I can only add 20% to the current value when the wait period is over.

Why do you insist in multiplying the "current value" by 1.2 when you can also multiply the active setpoint with 1.2?

Message 4 of 6
(159 Views)

## Re: Specific Questions: How to use a series of predetermined values to calculate a stepwise increase in sediment levels

I know it is an absolute mess, but it does work. I started building this program when I knew nothing about labview and only, later on, became slightly familiar with state machines. This is the last thing I need to implement to make it work and then I can collect some data which I need within the next 3 weeks. After that, I definitely plan on starting over and program it much more thoughtfully.

I am not sure what you mean by active setpoint.

Do you think I would be able to implement a state machine in my current program just with the purpose of calculating how much time the pump needs to be on every time I need to increase the sediment to hit those 20% interval levels?

Message 5 of 6
(150 Views)
Solution
Accepted by topic author Math808

## Re: Specific Questions: How to use a series of predetermined values to calculate a stepwise increase in sediment levels

Hi Math,

@Math808 wrote:

I am not sure what you mean by active setpoint.

You want to increase the "sediment" setpoint by 20% for each measurement point: so you know the current setpoint and you can easily calculate the next setpoint!

I don't understand why you are fixed on the current measurement value (aka "process variable" in control loop speak)!?

@Math808 wrote:

Do you think I would be able to implement a state machine in my current program just with the purpose of calculating how much time the pump needs to be on every time I need to increase the sediment to hit those 20% interval levels?

Why do you need to rely on some "fixed time delay" to drive the pump?

In your statemachine there could be states like

1. switch on pump
2. get sediment measurement value
3. switch off pump

To progress from step 2 to step 3 you just need to compare the "process variable" to your "setpoint" (again control loop speak)! No need to rely on some predetermined time delays…

@Math808 wrote:

I know it is an absolute mess, but it does work. I started building this program when I knew nothing about labview and only, later on, became slightly familiar with state machines.

I got the impression

• you don't even use a LabVIEW project to organize your project…
• you don't use subVIs to put related code into their own VIs (like all those calculations to scale measurement values)
• you haven't even tried to learn from all those example VIs coming with LabVIEW: no single DAQmx example VI shows your approach of creating a DAQmx task for just a single sample measurement and immediatly killing this task after that single measurement - in each iteration of your loop!
• Why do you need all those DAQAssistents to output scalar boolean values?
• so much more…
Message 6 of 6
(110 Views)