05-30-2017 05:19 PM
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.
05-31-2017 12:43 AM
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.
05-31-2017 12:34 PM
How about something like this?
05-31-2017 07:14 PM
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.
05-31-2017 08:44 PM
This ?
05-31-2017 09:37 PM - edited 05-31-2017 09:39 PM
@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.
06-01-2017 07:17 AM
@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?
06-01-2017 07:33 AM - edited 06-01-2017 07:34 AM
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.
06-01-2017 09:36 AM
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.
06-01-2017 10:25 AM - edited 06-01-2017 10:26 AM
@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.