LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Force a boolean to stay true for ever after an event ?

Hello,

My code is complicated and my problem simple so I don't want you to lose time understanding my code so I prefer not to give it for the moment,

So here is the problem that would be awesome if someone has an idea how to fix that :

 

I have an oscillator that goes from -100 to 100 (so it goes through 0) then it goes from 100 to -100 then again from -100 to 100 etc...

 

A part of my code should calculate the time between the first -100 to 0. So this part of the code works if the value is less than 0. Otherwise it doesn't work (with a case structure).

 

So here is what happen :

 

from -100 to 0 it calculates the time it takes : this works fine

from 0 to 100 then 100 to 0 it is greater than 0, so the part of the code stop working and the indicator display the time it has taken : it still works fine

from 0 to -100 again, now it adds the time to the previous time : this is wrong !

 

So I need a way to disable for ever the part of the code (that calculates the time) when the value is greater than zero for the first time

 

So basically I am trying to have a boolean that stay true for ever if it become true one time

Any idea ? event structure maybe ? (I dont know them)

 

thanks so much

0 Kudos
Message 1 of 5
(2,812 Views)

There are many ways to do this.  If you had attached your code, we could look at it and come up with a "teachable moment" (by understanding what you "didn't understand", explain it, and, we would hope, show you how to analyze and "fix" similar problems yourself).

 

Here's something to try (with pencil and paper) -- create a block with two inputs, call one "Boolean" and the other "Lock".  If Lock is false, the output is the same as Boolean.  If Lock is True, the output stays True.

 

Two questions:

  • What two-input, one output function can you think of that will do this?
  • Can you figure out how to derive Lock?

Bob Schor

0 Kudos
Message 2 of 5
(2,786 Views)

Your example is easy to do with a case structure linked with "Lock"

"If "Lock" is false, the output is the same as "Boolean""

=> so case structure, you just pass with no change with the "Boolean" value

"If Lock is True, the output stays True."

=> you return a true boolean constant value if "Lock" is true

 

I don't see the link with my situation. "Lock" is always linked with a boolean that can be false

 

Here is my code with 2 subvis

 

First press "Tester le PID"

when the pressure reached the setpoint, "trmax" indicator stops and gives you the time it needed to reach the setpoint

problem is : it will restart again if you wait a certain time 😕

0 Kudos
Message 3 of 5
(2,746 Views)

This not code you should even be attempting at your stage or learning. Who wrote it?

 

How should it be operated? Do all controls have good defaults? What should we click in what order, what should we see that's wrong, and what should see instead?

 

There are serious race conditions (e.g. writing to the "Tester le PID" local variable occurs in parallel to reading from the terminal. There is no way to tell what happens first, etc, etc. Then you have terminals without labels and thus several local variables that look indistinguishable. That's like herding cats. Look inside the case structure wired to "change l'ordre". There is no reason to place terminals in one case and local variables of the same terminals in the other case. Just place the terminals after the case structure. No locals needed!) What do you think "delete from array" does if you set the length to the length of the input?? Couldn't you just use leave the output tunnel unwired to output an empty array?

0 Kudos
Message 4 of 5
(2,735 Views)

If you want a LED to remain true after an input turns true, then stays true forever, use a shift register or feedback node, e.g. as follows.

 

 

altenbach_0-1596693632198.png

 

You can add more code to reset  on demand, etc.

0 Kudos
Message 5 of 5
(2,732 Views)