Sam
Sam

Reputation: 21

Seeking suggestion to count time inside the loop

I am trying to measure/count the time inside the while loop, I tried a couple of methods but couldn't find the solution yet.

Here is my current VI.

enter image description here

In short, I am trying to measure the time as long as the "Boolean is on/true" and once it's off/false the time must be displayed.

If something is not clear then please let me know.

Upvotes: 0

Views: 782

Answers (2)

srm
srm

Reputation: 3166

I may be repeating Fourier's answer, but typing it in two different forms may be helpful to you since I note you haven't accepted that answer yet.

  1. Remove the outer While Loop. It is superfluous.
  2. Then do this:

Turn on bool Turn off bool

In the "turn on" frame, you gather the current Tick Count and stash it in a shift register. In the "turn off" frame, you gather the Tick Count again and subtract. In all the other frames, make sure you wire the two tunnels together so you don't lose your Tick Count. Side note: you probably want Boolean to be an indicator, not a control, so your user cannot click on it and toggle it directly.

Upvotes: 1

Fourier
Fourier

Reputation: 111

You can reach your goal with simpler code. You should use one while loop only with the Event Structure:

  • When List of Conditions changes, intercept the event (as you are already doing) and register the time when this event happen (with the VI Tick count for example).

  • in two shift registers,"save" the time you registers in the previous point and the status of your count (a boolean should be enough: counting/not counting).

  • Then, in the Timeout event you calculate in real time the time passed with the following operation current time (Vi Tick count) - event time (save in the shift register). You should count time only if your boolean Counting/not counting is True.

  • When you detect another event List of Conditions Value Change, you should check if you should stop count time or not.

  • Finally, in the Timeout event or in the List of Conditions Value change event, evaluate the stop condition for your while loop.

Upvotes: 1

Related Questions