NI-DAQmx: Measure Single Period - Low Frequency - One Counter in .NET
Overview
This example demonstrates how to measure the period using one counter on a Counter Input Channel. The Edge, Minimum Value and Maximum Value are all configurable. This example shows how to measure the period on the counter's default input terminal (refer to section IV, I/O Connections Overview, below for more information), but could easily be expanded to measure period on any PFI, RTSI, or internal signal. Additionally, this example could be extended to measure period with two counters for different frequency and quantization error requirements.
Instructions for running
- Enter the physical channel which corresponds to the counter you want to use to measure pulse width on the DAQ device.
- Enter the measurement Edge to specify the edge on which you want the counter to start measuring. Enter the Maximum and Minimum Value to specify the range or your unknown period. Additionally, you can change the input
terminal where the period is measured using the channel property node.
Note: It is important to set the Maximum and Minimum Values of your
unknown period as accurately as possible so the best internal timebase can be
chosen to minimize measurement error. The default values specify a range
that can be measured by the counter using the 20MhzTimebase. Use the Gen
Dig Pulse Train-Continuous example to verify that you are measuring correctly
on the DAQ device.
Steps
- Create a Task.
- Create a CIChannel object using CreatePeriodChannel. The edge parameter is used to determine if the counter will measure high or low pulses. It is important to set the maximum and minimum values of your unknown period as accurately as possible so the best internal timebase can be chosen to minimize measurement error. The default values specify a range that can be measured by the counter using the 20MHzTimebase.
- Create a CounterReader object by passing it a stream to the task created. Then use the ReadSingleSampleDouble method to return the next period measurement.The timeout is set to 10 seconds by default so an error is returned if a pulse is not returned in the specified time limit.
- Handle any DaqExceptions and display a message for errors
I/O Connections Overview
This example will perform a measurement on the default terminal(s) of the counter specified. The default counter terminal(s) depend on the type of measurement being taken. For more information on the default counter input and output terminals for your device, open the NI-DAQmx Help, and refer to Counter Signal Connections found under the Device Considerations book in the table of contents.
Requirements
Filename: meas_period_lowfreq_1ctr.zip
Software Requirements
Language(s): C#, Visual Studio .NET, Visual Basic .NET
Additional Software: Visual Studio 2005, Visual C#, Visual Basic .NET, Visual Studio .NET 2005
Hardware Requirements
Hardware Group: Multifunction DAQ (MIO), Counter/Timers (TIO)
Driver: NI-DAQmx 8.6
Reader Comments | Submit a comment »
Legal
This example program (this "program") was developed by a National Instruments ("NI") Applications Engineer. Although technical support of this program may be made available by National Instruments, this program 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 program with each new revision of related products and drivers. THIS EXAMPLE PROGRAM 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/).
