Example Code

Stop and Start Timer for Boolean Control

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

The example demonstrates how to program a Boolean timer ('stop watch') with events.

 

Description

The example uses a Boolean control to start and stop a timer. The first time the Boolean changes to ON it turns the timer on. The next time it transitions from OFF to ON, it turns the timer off and records the time that was saved.

Also the example uses the timeout event to update the elapsed time. The timeout event is only activated when the timer has been started and is otherwise deactivated.

 

Requirements

 Software

  • LabVIEW 2012 Base Development System (or compatible)

 Hardware

  • No hardware is necessary to use this example VI

 

Steps to Implement or Execute Code

  1. Open the attached file
  2. Run the VI
  3. Click the Start Watch Button to start the timer
  4. The Current Timer indicator updates every 10 ms
  5. Click the same button again to stop the timer
  6. The time difference is displayed and the timer stops updating

 

Additional Information or References

Boolean Timer (Event) - Front Panel.png

 

Boolean Timer (Event) - Block Diagram.png

 

 

**The code for this example has been edited to meet the new Community Example Style Guidelines. The edited copy is marked with the text 'NIVerified'. Read here for more information about the new Example Guidelines and Community Platform.**

Jeff | LabVIEW Software Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
pollon
Member
Member
on

Hi, could you please save it in labView 8.6? Thanks

pollon
JeffL
NI Employee (retired)
on

Done.

Jeff | LabVIEW Software Engineer
nkrajoo
Member
Member
on

Hi,

I find this timer is interesting but I am new to labview. Can you briefly explain the block diagram?

Thanks.

NKR

JeffL
NI Employee (retired)
on

What about it specifically? It uses shift registers to remember the previous selections for each iteration of the loop.

Jeff | LabVIEW Software Engineer
nkrajoo
Member
Member
on

Hi,

1. I wanted to know what the timers with 50 are for and the 2 timers inside the loop.

2. Is this used for a simulation?

Rgds.

NKR

JeffL
NI Employee (retired)
on
  1. The timer with the 50 ms wired in is just so LabVIEW will take a break each iteration of the loop. It guarantees the loop will take at least 50 ms to process and therefore LV can work on some other process for the difference. If the loops takes only 10 ms to run, there will be 40 ms of downtime. This prevents your processor from being dominated and locking up your UI. The "timers" inside I believe you're referring to are for getting the current time. One of them is used to check what the time was at the beginning of the process (when you first start the timer) and the other is used to get the current time as the timer runs (to compare against the previous value).
  2. I just made it as a demonstration of shift registers and getting the current time.
Jeff | LabVIEW Software Engineer
nkrajoo
Member
Member
on

Hi Thanks for the explanation.

I wonder if I can use the same concept to a have Boolean controlled timer for other application. For e.g. can I have a timer which at the end of it's set time can produce a logic output (0,1) so that I can use it initiate other sequential events.

Thanks.

NKR

JeffL
NI Employee (retired)
on

Sounds like you want to use the Elapsed Time Express VI. It basically is this under the hood. Just drives a boolean line to TRUE when the timer has elapsed.

Jeff | LabVIEW Software Engineer
nkrajoo
Member
Member
on

Hi I think you have shed some light! Thank you and this looks more like what I am after. I have downloaded some examples and will play around with to develop a better understanding.   If I am stuck, I will contact you. Hope you don't mind.   Regards, NKR  P/S: If you have any examples or if you know where I can find one, please do let me know.

JeffL
NI Employee (retired)
on

I'd recommend posting over at http://forums.ni.com/ if you have further questions. These example threads aren't really intended for support. There is a huge community in the forums of people ready to answer your questions!

Jeff | LabVIEW Software Engineer
nkrajoo
Member
Member
on

Okay I will thank you.