Period Measurement with a Counter
Description
One potential use for counters is to measure the period, or the length of time between successive rising edges, of an incoming signal. A faster signal with a known frequency, usually an internal clock, is used as a reference. The counter starts counting at a rising or falling edge, which is user-configurable, and stops counting at its successive edge. The pulse period is the number of counts between rising edges divided by the number of counts expected in one second (frequency of the known clock), that is, period = counts / frequency.As an illustration, assume that you want to verify the period of a one millisecond pulse train which should be sent to the counter's gate. You now need a known frequency to count against, so you can connect the internal clock to the source. Suppose that this internal clock is 100 kHz. After starting the measurement, you check the counter's value and find that is 112. Therefore, the period of the incoming pulse is 112 counts / 100000 counts per sec = .00112 seconds (1.12 msec).

Single-Period Measurement
Multiple Period Measurements
To do multiple period measurements, you can either stop, reconfigure, and restart the counter in software (and therefore slower and subject to software delays), or you can use buffered counting. Buffered counting latches the counter value on each rising edge of the gate pulse. This gate signal can be provided by an external device or can be generated by using another available counter. The measurement continues to count exactly as before regardless of the gate signal, except that an array is returned with the number of counts between each gate edge. You can then perform the same calculation from above to extract the time information.

Buffered Period Measurement
Period measurement is useful when the frequency of the unknown signal is much smaller than the frequency of the source signal, so that a high accuracy is achieved. Assuming that the counter may miss or over count one pulse, the uncertainty of the measurement (in percent) is count uncertainty / total number of counts. Thus, in the example above, the uncertainty would be 1 / 105 = .95 %. If the source frequency were decreased to 10000, then only 10.5 = 10 counts would be received, so the uncertainty would 1 / 10 = 10 %.
Common Applications
You should not connect the same signal to both the gate and the source when doing pulse width measurement. Doing so yields incorrect readings because the transitions are occurring the same time.
When using buffered counter operations, the first acquired points may represent bad data in pulse measurements and thus should be ignored. The first data point is the measured interval between the instant when the counter is armed and when the first edge transition takes place on the counter GATE. Since there is no deterministic way of specifying when the counter is actually armed, the first value may be incorrect. Subsequent data points acquired will not have this problem.
Reader Comments | Submit a comment »
Without the example code...
Could it be possible to give us an
example VI for the case of buffered
counts? Thanks.
- Claude Wang, INI ETHZ/UNIZH. cwang@ini.phys.ethz.ch - Jul 8, 2007
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
