LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Time measurement in a case structure

Hi everyone!

 

I am measuring an analogal signal and I am using a Case Structure in order to compare this signal with a constant value. I need to know for how long my signal is greater than the constant value, in other words I need to know for how long my Case Structure is false or true. I need to use the value of time for real time calculations . Can anyone help me with that?

 

Thank you.

0 Kudos
Message 1 of 10
(5,278 Views)

Probably! If you posted your code, I'm sure you'd have had a response by now.

However, moving on, how are you measuring time? You mention a real time calculation - are you using a timed loop on a real-time system? Or do you instead mean simply that you need to know duration in seconds, rather than for example number of iterations?

 

In the simplest case, you can measure simply iterations. To do this, just add an increment function and a Shift Register to your For/While loop with a numeric constant 0 wired to the left side. It will increase on each true value due to the increment function inside the true case, and remain the same in the false case (wire it straight through - no changes).

 

To get a time, you should determine the duration of an iteration and use a similar scheme to cumulatively add values when the case is true, and just keep the old value for false. Take care because the simplest version of that which I can think of would actually add the duration of the previous step, which depending on your code might not be sufficiently accurate.

 

If you have a timed loop, then the iterations case is the same as the time case - now you know the loop iteration time (provided it never finishes late - you can check this!) and you can just multiply the iteration count with the iteration time.


GCentral
0 Kudos
Message 2 of 10
(5,221 Views)

How about something like this?

tmr.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 10
(5,192 Views)

I'm not certain, but I don't think that VI Snippet does what the OP really wanted.

 

I'm attaching a messy version of what I described in my first post with a shift register. Like I mentioned, it actually adds the time from the previous iteration, not the current iteration. You could work around this with a shift register for a boolean, if you wanted.


GCentral
Message 4 of 10
(5,179 Views)
0 Kudos
Message 5 of 10
(5,174 Views)

@ameni wrote:

This ?


Please don't post garbage code that only confuses and does not work. Once the case is true, the inner while loop will run forever and all dependent code will stall until the VI is aborted.

0 Kudos
Message 6 of 10
(5,165 Views)

@jleonqui wrote:

 

I am measuring an analogal signal and I am using a Case Structure in order to compare this signal with a constant value. I need to know for how long my signal is greater than the constant value,


A case structure cannot be used to compare anything, but it can select different code paths depending on a comparison.

Your question is a bit ambiguous. Do you want the time since the last false-true transition or the total true time of all earlier TRUE states? Both cases can be easily implemented. It would help if you could show us a simplified version of your code. What is the required time resolution? Seconds? Nanoseconds?

0 Kudos
Message 7 of 10
(5,145 Views)

Here's one way how to measure the total true time. It can easily be adapted to also measure FALSE and TOTAL time or even calculate the duty cycle in percent.

 

Download All
0 Kudos
Message 8 of 10
(5,142 Views)

Hi,

I'm not a champion Mr Altenbach i'm a Labview beginner hope to be like you but first you have to encourage people like me where i'm trying to help and i apologize for my "garbage code".

 

Thanks.

0 Kudos
Message 9 of 10
(5,130 Views)

@ameni wrote:

you but first you have to encourage people like me


I encourage you to actually run your code before posting to see if it works correctly. Your new code does NOT measure any elapsed time of the TRUE state, but just reports a random relative time that only depends on the time since the computer got booted up. Your time display is completely meaningless! Have you read the help on tick count?

 

Please do not post random code until you have verified that it actually works correctly. Your's does not! You are doing a disservice by distracting other new users and leading them down the wrong path.

0 Kudos
Message 10 of 10
(5,125 Views)