How to Make Your Measurement System More Flexible With Counter/Timers

Publish Date: Sep 28, 2012 | 6 Ratings | 3.00 out of 5 | 0 Customer Reviews | Submit your review

Table of Contents

  1. Counter/Timer Overview
  2. Input Applications
  3. Output Applications
  4. Features to Make Your Life Easier
  5. Conclusion

1. Counter/Timer Overview

Counter/timers (or counters) are an extremely useful feature of many National Instruments multifunction DAQ devices and NI CompactDAQ chassis. You can use counters for many different applications, such as event counting and reading or writing digital pulse trains. You can easily develop counter applications using NI LabVIEW software and the NI-DAQmx API, which is also used for other measurement types, such as analog and digital I/O.

Most NI multifunction DAQ devices and NI CompactDAQ chassis contain two or four 32-bit counters, and NI also provides dedicated counter/timer cards with up to eight 32-bit counters. A 32-bit counter can count to 232-1 before rolling over to 0. Each counter contains multiple input and output lines, giving you additional flexibility in a variety of applications. Each application generally requires connecting a few specific terminals to accomplish your goal.

Figure 1. Counters can be used for many applications, including counting digital signals.

Back to Top

2. Input Applications

There are four main categories of counter input applications:

1. Digital Event Counting

Many applications require simple event counting. Whether it’s counting photons hitting a screen or how many times a button is pushed, counters provide this functionality. You can configure the counter to count up or down on either the rising or falling edge of the digital signal.

2. Encoders and Position Measurements

Encoders are sensors that measure angles or position changes. They generate two sets of pulses based on a known angle or change in position. When using a quadrature encoder to measure angular position, the rotational direction of the encoder determines how the pulses are generated. As shown in Figure 2, if the rising edge on Ch A occurs before the rising edge on Ch B, the counter counts up. If the opposite is true, the counter counts down. You can measure angular position with X1, X2, and X4 angular encoders.

X1 Encoding.JPG

Figure 2. This is an example of X1 encoding; the counter counts only one edge per period of the two signals.

When taking linear position measurements, you also have two sets of pulses. In this case, one set counts up, while the other counts down. You can measure linear position with two-pulse encoders.

3. Determining the Frequency or Period of a Digital Signal

Determining the frequency or period of a digital signal can also be important in your application. For instance, you can determine the revolutions per minute (RPM) of a motor from the frequency of an encoder. There are numerous ways you can measure the frequency or period of a signal. Your method largely depends on the frequency of the signal that you’re measuring. These methods involve one or two counters.

Figure 3. You can use multiple counters to get better accuracy when measuring a signal with a large range or high frequency.

4. Pulse Measurements

You can also take several measurements on the pulses themselves. For example, to determine the duration of an event or the time between two events, you use a pulse width measurement. Similarly, you can perform these measurements on two sets of signals using a two-signal edge-separation measurement, where your chosen edge of one signal starts the timing and your chosen edge of the other signal stops it.

Back to Top

3. Output Applications

There are two main categories of counter output applications:

1. Frequency Generation

Analog and digital tasks often use a frequency or a sample clock to dictate when a sample is acquired or generated. You can use a counter to generate continuous or finite pulse trains at a constant frequency to use in those tasks. The counter divides down an onboard or an external clock by an integer multiple, which means that not every frequency can be generated.

2. Pulse Width Modulation (PWM)

Pulse width modulation (PWM) is a technique in which a device outputs a digital pulse train, where you modify the proportion of “on” time to “off” time. The length and frequency of these pulses determines the total power delivered to the circuit. The ratio of the pulse width to the period is referred to as the duty cycle of the signal. PWM signals are most commonly used to control DC motors, but can also be used to control a variety of other devices.

http:/zone.ni.com/cms/images/devzone/tut/a/dadc74b4230.jpg

Figure 4. You can use the duty cycle and frequency of a PWM to control the power for many applications, such as a DC motor or pump.

Back to Top

4. Features to Make Your Life Easier

1. Filtering

You can perform lowpass filtering on the digital lines fed into NI counter/timers to remove glitches in the signal. The filter operates off a filter clock, which samples the signal on the programmable function interface (PFI) line on each rising edge of the sampling clock. A change in your signal is propagated only if it maintains its new state for at least the duration between two consecutive rising edges of the filter clock. There are a few different filter clocks you can use, ranging from nanoseconds to milliseconds.

2. Buffering

With the addition of a 127-sample first in, first out (FIFO) memory buffer on NI X Series multifunction DAQ devices and newer NI CompactDAQ chassis, counter input and output tasks can be buffered. For output tasks, this means that you can now preload multiple pulse specifications into an onboard buffer or memory, allowing you to bypass software and increase speed. For input tasks, this buffer helps achieve counter rates of up to 10 MHz on PCI Express and PXI Express.

3. Sample Clock

Another feature that was added to X Series and newer NI CompactDAQ chassis is the use of a sample clock on most tasks. Ordinarily, for frequency/period measurements, implicit timing is used. When using implicit timing, you inform the NI-DAQmx driver that the measured period or frequency value should be latched into a buffer at the end of each incoming signal cycle. Alternatively, you can perform these measurements at periodic intervals with a sample clock. Sample clock timing also brings an increase in accuracy for frequency/period measurements (see Figure 5). You get this accuracy because the frequency of the input signal has been decoupled from the steady sample clock, as opposed to implicit timing.

Figure 5. Using a one counter sample clock task to take frequency measurements can greatly improve your measurement accuracy.

4. Retriggerable

You can use counters to output a single pulse or multiple pulses in response to each pulse on a Start Trigger input signal, which is known as making a task retriggerable. This retriggering works as long as the counter is not in the middle of generating pulses from the last trigger. You can also specify a delay and a pulse width for the generated signal, which is beneficial in stimulus-response applications where you need a precise delay. You can use this feature for applications that require a quick turnaround time because the pulse generation response is done in hardware and eliminates any latency that host PC software might cause.

5. Synchronization

You can use counters to easily synchronize multiple analog and digital tasks together. You accomplish this by creating a pulse train from a counter output, and then exporting that signal to your other tasks, such as analog output. You can also use a single counter pulse as a trigger to start multiple measurement tasks at the same time.

Back to Top

5. Conclusion

You can use counters to easily create measurement and generation applications that were previously difficult or impossible to create. Whether you are counting digital signals, performing PWM, or generating pulse trains, counters provide useful features to accommodate your needs. Counters that are included on multifunction DAQ devices and NI CompactDAQ chassis are easily integrated into larger and more complex applications, making your test, measurement, and control applications more powerful.

Brian Phillippi  

Brian Phillippi is an applications engineer at National Instruments. He currently supports DMMs, SMUs, switches, DSAs, and multifunction DAQ devices. Brian received his bachelor’s in mechanical engineering from Brigham Young University.  

For more in-depth documentation and information on counters, view the NI X Series User Manual.

Back to Top

Customer Reviews

Bookmark & Share

Ratings

Rate this document

Answered Your Question?
Yes No

Submit