Chapter 25 Measuring Pulse Width. NI LabVIEW Data Acquisition Basics

Add to My manuals
331 Pages

advertisement

Chapter 25 Measuring Pulse Width. NI LabVIEW Data Acquisition Basics | Manualzz

25

Measuring Pulse Width

This chapter describes how you can use a counter to measure pulse width.

There are several reasons you may need to determine pulse width. For example, to determine the duration of an event, set your application to measure the width of a pulse that occurs during that event. Another example is determining the interval between two events. In this case, you measure the pulse width between the two events. An example of when you might use this type of application is determining the time interval between two boxes on a conveyor belt or the time it takes one box to be processed through an operation. The event is an edge every time a box goes by a point, which prompts a digital signal to change in value.

Measuring a Pulse Width

You can measure an unknown pulse width by counting the number of pulses of a faster known frequency that occur during the pulse to be measured. Connect the pulse you want to measure to the GATE input pin and a signal of known frequency to the SOURCE (CLK) input pin, as

shown in Figure 25-1. The pulse of unknown width (T

pw

) gates the counter configured to count a timebase clock of known period (T s equals the timebase period times the count, or: T pw

= T s

). The pulse width

×

count. The

SOURCE (CLK) input can be an external or internal signal.

GATE OUT

T pw frequency source

SOURCE

(CLK)

Count Register

T s

Figure 25-1. Counting Input Signals to Determine Pulse Width

An internal signal is based upon the type of counter chip on your

DAQ device. With TIO-ASIC devices, you can choose internal timebases of 20 MHz, 100 kHz, and a device-specific maximum timebase. With

DAQ-STC devices, you have a choice between internal timebases of

© National Instruments Corporation 25-1

LabVIEW Data Acquisition Basics Manual

Chapter 25 Measuring Pulse Width

20 MHz and 100 kHz. With Am9513 devices, you can choose internal timebases of 1 MHz, 100 kHz, 10 kHz, 1 kHz, and 100 Hz. With 8253/54 devices, the internal timebase is either 2 MHz or 1 MHz, depending on which device you have.

Figure 25-2 shows how to physically connect the counter on your device to

measure pulse width.

your device counter source out gate

Figure 25-2. Physical Connections for Determining Pulse Width

Determining Pulse Width

How you determine a pulse width depends upon which counter chip is on your DAQ device. If you are uncertain of which counter chip your

DAQ device has, refer to your hardware documentation.

TIO-ASIC, DAQ-STC

Figure 25-3 shows the diagram of the Measure Pulse-Easy (DAQ-STC) VI

located in labview\examples\daq\counter\DAQ-STC.llb

, which uses the Easy VI, Measure Pulse Width or Period.

Figure 25-3. Diagram of Measure Pulse Width (DAQ-STC) VI

LabVIEW Data Acquisition Basics Manual

25-2 www.natinst.com

Chapter 25 Measuring Pulse Width

The Measure Pulse Width or Period VI counts the number of cycles of the specified timebase, depending on your choice from the type of

measurement menu located on the front panel of the VI.

The type of measurement menu choices for this VI are shown in

Figure 25-4.

Figure 25-4. Menu Choices for Type of Measurement for the Measure Pulse Width or Period (DAQ-STC) VI

Use the first two menu choices when you want to measure the width of a single pulse. In these cases, the GATE of the counter must start out in the opposite phase of the pulse you want to measure. For example, if you choose measure high pulse width of a single pulse, the GATE must start out low when you run the VI. If you attempt to measure a single high pulse, and the GATE is already high (such as in the middle of a pulse train) when you run the VI, an error will occur.

Use the last two menu choices when you want to measure the width of a single pulse within a train of multiple pulses. In these cases, it is the previous GATE transition that arms the counter to measure the next pulse.

For example, if you choose measure one high pulse width of multiple

pulses, the first high-to-low GATE transition from one pulse would arm the counter to measure the very next pulse.

The timebase you choose determines how long a pulse you can measure with the 24-bit counter. For example, the 100 kHz timebase allows you to measure a pulse up to 2 24

×

10

µ s = 167 seconds long. The 20 MHz timebase allows you to measure a pulse up to 838 ms long. For a complete description of this example, refer to the information found in

Windows»Show VI Info.

© National Instruments Corporation 25-3

LabVIEW Data Acquisition Basics Manual

Chapter 25 Measuring Pulse Width

Am9513

Figure 25-5 shows the diagram of the Measure Pulse-Easy (9513) VI

located in labview\examples\daq\counter\Am9513.llb

, which uses the Easy VI, Measure Pulse Width or Period.

Figure 25-5. Diagram of Measure Pulse Width (9513) VI

The Measure Pulse Width or Period VI counts the number of cycles of the specified timebase, depending on your choice from the type of measurement menu located on the front panel of the VI. The type of

measurement menu choices for this VI are shown in Figure 25-6.

Figure 25-6. Menu Choices for Type of Measurement for the

Measure Pulse Width or Period (9513) VI

Either menu choice can be used to measure the width of a single pulse, or to measure a pulse within a train of multiple pulses. However, the pulse must occur after the counter starts. Because the counter uses high-level gating, it might be difficult to measure a pulse within a fast pulse train. If the counter is started in the middle of a pulse, it measures the remaining width of that pulse.

The timebase you choose determines how long a pulse you can measure with the 16-bit counter. For example, the 100 Hz timebase allows you to measure a pulse up to 2 16

×

10ms = 655 seconds long. The 1 MHz timebase allows you to measure a pulse up to 65 ms long. Because a faster timebase yields a more accurate pulse width measurement, it is best to use the fastest timebase possible without the counter reaching terminal count (TC).

LabVIEW Data Acquisition Basics Manual

25-4 www.natinst.com

8253/54

Chapter 25 Measuring Pulse Width

The valid? output of the example VI indicates whether the counter measured the pulse without overflowing (reaching TC). However, valid? does not tell you whether a whole pulse was measured when measuring a pulse within a pulse train. For a complete description of this example, refer to the information found in Windows»Show VI Info.

Figure 25-7 shows the diagram of the Measure Short Pulse Width

(8253) VI located in labview\examples\daq\counter\8253.llb

.

Figure 25-7. Diagram of Measure Short Pulse Width (8253) VI

This VI counts the number of cycles of the internal timebase of Counter 0 to measure a high pulse width. You can measure a single pulse or a pulse within a train of multiple pulses. However, the pulse must occur after the counter starts. This means it may be difficult to measure a pulse within a fast pulse train because the counter uses high-level gating. To measure a low pulse width, insert a 7404 inverter chip between your pulse source and the GATE input of counter 0.

On the example diagram, the first call to ICTR Control VI sets up counting mode 4, which tells the counter to count down while the gate input is high. The Get Timebase (8253) VI is used to get the timebase of your

DAQ device. A DAQ device with an 8253/54 counter has an internal timebase of either 1 MHz or 2 MHz, depending on the device. Inside the

© National Instruments Corporation 25-5

LabVIEW Data Acquisition Basics Manual

Chapter 25 Measuring Pulse Width

While Loop, ICTR Control VI is called to continually read the count register until one of four conditions are met:

• The count register value has decreased but is no longer changing.

It is finished measuring the pulse.

• The count register value is greater than the previously read value.

An overflow has occurred.

• An error has occurred.

• Your chosen time limit has been reached.

After the While Loop, the final count is subtracted from the originally loaded count of 65535 and multiplied by the timebase period to yield the pulse width. Finally, the last ICTR Control VI resets the counter. Notice that this VI uses only Counter 0. If Counter 0 has an internal timebase of

2 MHz, the maximum pulse width you can measure is 2 16

×

0.5

µ s = 32 ms.

For a complete description of this example, refer to the information found in Windows»Show VI Info.

Controlling Your Pulse Width Measurement

How you control your pulse width measurement depends upon which counter chip is on your DAQ device. If you are uncertain of which counter chip you DAQ device has, refer to your hardware documentation.

TIO-ASIC, DAQ-STC, or Am9513

Figure 25-8 shows one approach to measuring pulse width using the

Intermediate VIs Pulse Width or Period Meas Config, Counter Start,

Counter Read, and Counter Stop. You can use these VIs to control when the measurement of the pulse widths begins and ends. The Pulse Width or

Period Config VI configures a counter to count the number of cycles of a known internal timebase. The Counter Start VI begins the measurement.

The Counter Read VI determines if the measurement is complete and displays the count value. After the While Loop is stopped, the Counter

Stop VI stops the counter operation. Finally, the General Error Handler VI notifies you of any errors.

LabVIEW Data Acquisition Basics Manual

25-6 www.natinst.com

Chapter 25 Measuring Pulse Width

Figure 25-8. Measuring Pulse Width with Intermediate VIs

Buffered Pulse and Period Measurement

With the TIO-ASIC and DAQ-STC chips, LabVIEW provides a buffer for counter operations. You would typically use buffered counter operations

when you have a gate signal to trigger a counter several times. Figure 25-9

shows the diagram of the Meas Buffered Pulse-Period (DAQ-STC) VI located in labview\examples\daq\counter\DAQ-STC.llb

.

You also can refer to examples located in labview\examples\ daq\counter\NI-TIO.llb

.

© National Instruments Corporation

Figure 25-9. Diagram of Meas Buffered Pulse-Period (DAQ-STC) VI

25-7

LabVIEW Data Acquisition Basics Manual

Chapter 25 Measuring Pulse Width

With this example, you can perform four types of buffered measurements:

Buffered period measurement—Measures a number of periods in a pulse train.

Buffered semi-period measurement—Measures a number of high and low pulses in a pulse train.

Buffered pulse width measurement—Measures a number of high or low pulses in a pulse train.

Buffered counting—Each rising edge loads the current count into a finite buffer.

This example uses a single buffer. The block diagram uses the following

Advanced VIs: CTR Group Config, CTR Buffer Config, CTR Mode

Config, CTR Control, and CTR Buffer Read. CTR Group Config takes the counter and device and sets up a taskID. CTR Buffer Config sets up a finite buffer whose size is determined by the value you enter in counts per

buffer. CTR Mode Config determines what type of counting operation to perform based on your choices for gate parameters and config mode.

CTR Control starts the counting operation, but does not return until the counting has completed. CTR Buffer Read reads the buffer of data and returns the values to buffered counts. The buffered times are determined by dividing the counts by your chosen timebase. For a complete description of this example, refer to the information found in

Windows»Show VI Info.

Note Continuous buffered operations are supported by the new Advanced Counter VIs in

NI-DAQ 6.5 and higher.

Note If you are using NI-DAQ 6.5 or higher, National Instruments recommends you use the new Advanced Counter VIs, such as Counter Group Config, Counter Get Attribute,

Counter Set Attribute, Counter Buffer Read, and Counter Control. For more information, refer to the LabVIEW Online Reference.

LabVIEW Data Acquisition Basics Manual

25-8 www.natinst.com

Chapter 25 Measuring Pulse Width

Increasing Your Measurable Width Range

The maximum counting range of a counter and the chosen internal timebase determine how long of a pulse width can be measured. The internal timebase acts as the SOURCE. When measuring the pulse width of a signal, you count the number of source edges that occur during the pulse being measured. The counted number of SOURCE edges cannot exceed the counting range of the counter. Slower internal timebases allow you to measure longer pulse widths, but faster timebases give you a more accurate pulse width measurement. If you need a slower timebase than is available

on your counter as shown in Table 25-1, set up an additional counter for

pulse train generation and use the OUT of that counter as the SOURCE of the counter measuring pulse width.

Table 25-1. Internal Counter Timebases and Their Corresponding Maximum

Pulse Width, Period, or Time Measurements

Counter Type

TIO-ASIC

DAQ-STC

Am9513

Internal

Timebases

Maximum*

(depends on device)

20 MHz

100 kHz

20 MHz

100 kHz

1 MHz

100 kHz

10 kHz

1 kHz

100 Hz

Maximum Measurement

214.748 s

11 h 55 m 49.67 s

838 ms

167 s

65 ms

655 ms

6.5 s

65 s

655 s

8253/54 2 MHz**

1 MHz**

32 ms

65 ms

* You can obtain this timebase by calling the Counter Get Attribute VI.

** A DAQ device with an 8253/54 counter has one of these internal timebases available on counter 0, but not both.

© National Instruments Corporation 25-9

LabVIEW Data Acquisition Basics Manual

advertisement

Related manuals

Download PDF

advertisement

Table of contents