NI-DAQmx: Using Counters to Time Program Execution

Publish Date: Sep 06, 2006 | 5 Ratings | 4.80 out of 5 | Print | Submit your review
Tick Count (ms) VI in LabVIEW uses the Windows clock to get a millisecond time reading. In cases where you need a more precise and NIST-traceable method for timing a portion of your LabVIEW code, use the Time with Counters VI (below). These VIs use two counters on an E Series device for timing program execution.

This VI measures the time it takes for a particular segment of code to execute by using the counters on an E-Series board. The example in the code is a for loop that executes for a user-definable number of iterations. This is marked as "EVENT TO TIME". You can delete this for loop and replace it with whatever you want to time, but be sure to wire the error cluster and task ID "through" your code or sub-vi so that it properly enforces order of execution.

Since the DAQ-STC has a 24-bit counter and a 20 MHz timebase, the 24-bit counter will overflow more than once per second. This 20 MHz timebase is highly stable internal clock that is used as the time reference for this example so we must accomodate for the rollover. The rollover calculation looks like this: 2^24 = 16,777,216 (maximum count) and with a 20 MHz timebase, we get 20,000,000 edges per second. We then monitor this rollover (terminal count or output pulse) and keep track of how many times it has occurred using a second event counter. This gives us effectively a 48-bit (DAQ-STC) counter to count the events. On the DAQ-STC with a 20 MHz timebase it will be 160 days before timer roll-over (20 MHz resolution).

Back to Top

Bookmark & Share





Rate this document

Answered Your Question?
Yes No