LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to create event driven timer



@altenbach wrote:
. For example you have 24 different comparison operations and 1/4 mile of wire for no real purpose.

Have you seen the price of copper lately? A 1/4 mile of wire costs twice as much as it did a year or so ago! Smiley Very Happy
0 Kudos
Message 21 of 56
(3,670 Views)
I'm struggling with a similar timer, I thought this would be simple .. to measure the time a signal spends over a set limit - the limit tester outputs a boolean high to start the clock, low to stop the clock, difference = elapsed time. I can do it if the outer while loop of my timer is deleted and replaced with the main program while loop, but I want half a dozen different timers within the main while loop. I'm sure I'll get it if I keep bashing away, but it's getting very late now ..   
0 Kudos
Message 22 of 56
(3,591 Views)
Here's a quick draft.
 
Basically, you trap yourself inside too many loops and local variables. Your inner loops prevent the outer loop from spinning. Here's one simple possibility with three timers inside a loop. Each counts how long a button is being currently pressed (switch until released). See if this can give you some ideas. 🙂
 
You should make sure that each inner loop correctly initializes at program start. Use the "first run" tool.
0 Kudos
Message 23 of 56
(3,580 Views)

Your upper structure has an outer while loop (not the largest program loop) that never stops because its stop node is wired with a false.  You never see the elapsed time because it is outside of that loop.  You may want to move the elapsed time indicator inside so you can see it update.

I think you may want to eliminate the inner while loop on the lower one.

Try the attachment.  I put two timers in there.  When the button is pressed true the first time, it resets the timer.  While true, it updates the indicator with the new elapsed time.  When false, the indicator stops.

0 Kudos
Message 24 of 56
(3,575 Views)

Hi Christian,

You got me beat 3 indicators to 2 and by a few minutes.  I think I had learned about the implies boolean function from one of your older posts.  I never knew what was a practical use for it until then.

0 Kudos
Message 25 of 56
(3,575 Views)
That's great guys, thanks! .. works well, I'll draw the line here and go to sleep now. 
0 Kudos
Message 26 of 56
(3,568 Views)

I think it could be made simpler, without the implies even needed. 🙂

Attached is a comparison of three versions. Do you see a fundamental functional difference?

(Also, since we take a tick count at each iteration, we can place it outside the loop. ;))

0 Kudos
Message 27 of 56
(3,558 Views)
Hi Christian,
 
I agree that your second option is definitely trimmer code than mine, and seems to functions the same.
 
I like the third option in that it uses the principle of an uninitialized shift register like a LV2 global or action engine would.  The only disadantage is that the false case uses the default for the tunnel, thus the indicator reverts back to zero when the button is unclicked.  I'm not sure if that is the action Graham wants or not.  But as you said, moving the terminal inside the case structure allows it to hold the value and function the same as the other two.
 
In the end, it probably comes down to which version would fit in better with the overall architecture of the program.  Option 3 adds an extra structure compared to 2, but you wouldn't have to string shift registers across the greater portion of the program.
 
Thanks for showing different variations.
 
-Bill
0 Kudos
Message 28 of 56
(3,546 Views)
I take this version elapsed_time_of_eventMOD.vi

The elapsed time countinues till the event trigger is TRUE and stops when the event trigger is FALSE.

Is it possible that the elapsed time is not continues but counts for 10 sec and reset, then counts again for 10 s and reset till the event trigger is FALSE.

example.

event trigger         elapsed time (sec)

TRUE                     0
TRUE                     1
TRUE                     2
TRUE                     3
TRUE                     4
TRUE                     5
TRUE                     6
TRUE                     7
TRUE                     8
TRUE                     9
TRUE                     10
TRUE                     0
TRUE                     1
TRUE                     2
TRUE                     3
TRUE                     4
TRUE                     5
TRUE                     6
TRUE                     7
TRUE                     8
TRUE                     9
TRUE                     10
TRUE                     0
TRUE                     1
TRUE                     2
TRUE                     3
TRUE                     4
TRUE                     5
FALSE                   0
FALSE                   0
FALSE                   0
FALSE                   0
FALSE                   0
FALSE                   0
FALSE                   0
FALSE                   0
FALSE                   0
FALSE                   0
TRUE                     0
TRUE                     1
TRUE                     2
TRUE                     3
TRUE                     4
FALSE                   0
FALSE                   0
FALSE                   0
FALSE                   0
TRUE                     0
TRUE                     1
TRUE                     2
TRUE                     3
TRUE                     4
TRUE                     5
TRUE                     6
TRUE                     7
TRUE                     8
TRUE                     9
TRUE                     10
TRUE                     0
TRUE                     1
TRUE                     2
TRUE                     3
FALSE                    0

and so on till I stop the vi.

Thanks in advance.


0 Kudos
Message 29 of 56
(3,509 Views)
Yes, just do a MOD 11 operation (using the Quotient and Remainder function) on the elapsed time and use the remainder as your output.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 30 of 56
(3,494 Views)