LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect how long a boolean is true

Solved!
Go to solution

Dears,

I apologize for the simple question but I need help.

 

I would like to know how is possibile to determine how long a boolean is true. In other words, I would like to know after a boolean come true for how much time it is stil true.

 

I am trying with Time Elapsed but I do not really understand how to use it.

 

Thank you so much for the help!

0 Kudos
Message 1 of 19
(3,955 Views)

Hi mb,

 

you need the timestamp for the rising edge and the timestamp for the falling edge. Then subtract both.

To easily detect boolean edges you can use the BooleanCrossing (PtByPt) function…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 19
(3,952 Views)

@GerdW wrote:

Hi mb,

 

you need the timestamp for the rising edge and the timestamp for the falling edge. Then subtract both.

To easily detect boolean edges you can use the BooleanCrossing (PtByPt) function…



Is there an example to learn how to use it?? I am really a beginner about VI, can you help me?

0 Kudos
Message 3 of 19
(3,949 Views)

Hi mb,

 

the simplest example you can get, realized in less than 60s:

check.png

How long do you need to recreate it?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 19
(3,945 Views)

@GerdW wrote:

Hi mb,

 

the simplest example you can get, realized in less than 60s:

check.png

How long do you need to recreate it?


Thank you so much! I will let you better understand my problem.

I would like to know if a boolean become true and after how long it is true. If it is for 2 seconds then another bolean become true.  

0 Kudos
Message 5 of 19
(3,937 Views)

LabVIEW has functions that return the time.  Your situation is how to call this when you Boolean variable changes.  I'm guessing you have not taken advantage of all of the Tutorial Material mentioned on the first page of this Forum, which would discuss things like how to recognize changes to variables.  You also haven't put this question "in context" by saying what else will be going on and how you intend to use this information.

 

I urge you to take advantage of the tutorials.  You need to get the "LabVIEW Model" of programming into your head, particularly the Principle of Data Flow, which if done right, can allow you to ask (and answer) the question you raised.

 

Bob Schor

0 Kudos
Message 6 of 19
(3,922 Views)

okay thanks..

0 Kudos
Message 7 of 19
(3,919 Views)

What makes the boolean change? Is this from a DIO measurement, from some computations, or from user interactions on the front panel? What kind of time resolution do you need? (nanoseconds? days?)

 

You basically have a state machine with three states:

 

  1. No change from the previous iteration
  2. Changed from FALSE to TRUE
  3. Changed from TRUE to FALSE

So you need a case structure with three states inside a while loop that polls the boolean. You also need a shift register or feedback node to retain the boolean value for the next iteration so you have something to compare it with. You were told how to detect state changes already.

You need a second shift register to keep track of the elapsed time. You can use "tick count" (millisecond units, U32 integer) or "high resolution relative seconds" (unit in seconds, but high resolution), both in the timing palette.

In the three mentioned states do:

 

  1. nothing, just wire the tick across. You can still do the subtraction to show the updated  elapsed time in the current true state (or zero if the state is false).
  2. Place the current tick into the shift register as new time reference
  3. Subtract the current tick from the one in the shift register to display the elapsed TRUE time.

There are plenty of examples posted in the forum to do just that.

Message 8 of 19
(3,906 Views)

@altenbach wrote:

What makes the boolean change? Is this from a DIO measurement, from some computations, or from user interactions on the front panel? What kind of time resolution do you need? (nanoseconds? days?)

 

You basically have a state machine with three states:

 

  1. No change from the previous iteration
  2. Changed from FALSE to TRUE
  3. Changed from TRUE to FALSE

So you need a case structure with three states inside a while loop that polls the boolean. You also need a shift register or feedback node to retain the boolean value for the next iteration so you have something to compare it with. You were told how to detect state changes already.

You need a second shift register to keep track of the elapsed time. You can use "tick count" (millisecond units, U32 integer) or "high resolution relative seconds" (unit in seconds, but high resolution), both in the timing palette.

In the three mentioned states do:

 

  1. nothing, just wire the tick across. You can still do the subtraction to show the updated  elapsed time in the current true state (or zero if the state is false).
  2. Place the current tick into the shift register as new time reference
  3. Subtract the current tick from the one in the shift register to display the elapsed TRUE time.

There are plenty of examples posted in the forum to do just that.


Thank you so much for all the help! It seems clear now, but not having a good knowledge of LabVIEW it is not simple to undarstand quikly. Could you be so kind to link me some of these examples, because I am trying to find them but without success.

 

The boolean represents an error and change the state of the clutch of a motor, engaging it. I would like to engage it only after 2 seconds in which the boolean come true. 

0 Kudos
Message 9 of 19
(3,901 Views)

I guess this might help you. 

rise fall delta difference.PNG


CLD Using LabVIEW since 2013
0 Kudos
Message 10 of 19
(3,856 Views)