Example Code

Simple Stopwatch

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

Download All

Overview

This example implements a stopwatch using a state machine architecture.

 

 

Description

This example is a perfect example for those that are looking for ways to simplify complicated code.  The example utilizes state machine architecture, functional global variables and subVIs.  The best part about this code is that is can be easily ported to a Real-Time target, an embedded system or FPGA.  This can also be used on any OS that runs LabVIEW.  The Stopwatch can do this because it uses low level code that can be used on any platform.

 

 

Requirements

LabVIEW 2012 (or compatible)

 

 

Steps to Implement or Execute Code

1. Open the project

2. Run the Stop Watch (Main) VI. The Stop Watch Window will open
3. In the Stop Watch Window, click on Start/Stop to initiate the timer
4. Click again on Start/Stop to stop counting
5. Click on Reset to reinitialize the timer to 0
6. Click on start/Stop again to restart the timer
7. Stop the simulation

 

 

Additional Information or References

 

User Interface

User Interface.PNG

 

Block Diagram

BD.PNG 

 

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

National Instruments
Applications Engineer

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

Comments
davekorpi
Member
Member
on

CounterTimerSR2243863.pngAWESOME! When I get this thing to work with real clock timers, like 9513's or STC timers, or whatever I will put the answer in with this one.

This is a BRILLIANTLY simple solution! GREAT JOB! LOVE IT!

Got a strategy to deal with when it wraps around??? Would LOVE to see your elegant solution for that one!! A hardware timer, running at 20 MHz, and using 1/1000 second will wrap around at 20,000 seconds... This software timer wraps from (2^32)–1 to 0.

davekorpi
Member
Member
on

The solution above deals with the issue of wrapping. It also has a 1 KHZ counter but I do not know how accurate that is and it is not NIST Traceable. I can not put a traceable Freq Counter and measure the time base and certify it and have a valid error analysys.

BELOW is the solution using a SINGLE HARDWARE timer from a PCI-6221 using it's INTERNAL 20 MHz Crystal, taht you can CERTIFY BY NIST, and have a TRQACEABLE timer!


Where is the place to attach a doggone sample file??

If you need it let me know the path and pop me an email at dave.korpi@gmail.com

Here is the path. (I saved it in LV 2011 so you can easily upgrade to any version of LV folks will likely use..)

\\DMK-DISKSTA\Data\Vato Dave Rodriquez Dropbox\CounterTimerLV2011\LV2011\Counter - Count Edges-lv2011.vi

You can close this SR as it was brilliantly answered by Robert on SR Reference#2243863

The solution to this SR is to use the following settings:

http://www.screencast.com/t/mSmaW2tUqS

The VI looks like this:

http://www.screencast.com/t/XrKrnOP18mGV

The 6221 has the onboard clock at 20 MHz and we selected this. The Trigger Settings tabs on the bottom must be set to NO TRIGGER... The timer WRAPS at 20,000 seconds.

THis is a PERFECT and BRILLIANT solution!

Here is a video: http://www.screencast.com/t/WKFiYuj7D

The attached file is PRE LOADED with defaults to support the PCI-6221 device on Ctr 0.

Thanks Robert!

You are a champ!