0% found this document useful (0 votes)
112 views

2017 DAQ LV Online ParticipantGuide

Uploaded by

Ara Rosario
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views

2017 DAQ LV Online ParticipantGuide

Uploaded by

Ara Rosario
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 176

Data Acquisition Using

NI-DAQ mx and
TM

LabVIEW TM

Online Participant Guide


Course Software Version 2016
January 2017 Edition

Data Acquisition Using NI-DAQmx and LabVIEW

Copyright
© 2017 National Instruments. All rights reserved.
Under the copyright laws, this publication may not be reproduced or transmitted in any form,
electronic or mechanical, including photocopying, recording, storing in an information retrieval
system, or translating, in whole or in part, without the prior written consent of National
Instruments Corporation.
National Instruments respects the intellectual property of others, and we ask our users to do the
same. NI software is protected by copyright and other intellectual property laws. Where NI
software may be used to reproduce software or other materials belonging to others, you may
use NI software only to reproduce materials that you may reproduce in accordance with the
terms of any applicable license or other legal restriction.

End-User License Agreements and Third-Party Legal Notices


You can find end-user license agreements (EULAs) and third-party legal notices in the following
locations:
• Notices are located in the <National Instruments>\_Legal Information and
<National Instruments> directories.
• EULAs are located in the <National Instruments>\Shared\MDF\Legal\License
directory.
• Review <National Instruments>\_Legal Information.txt for more information on
including legal information in installers built with NI products.
Trademarks
Refer to the NI Trademarks and Logo Guidelines at ni.com/trademarks for more information
on National Instruments trademarks.
ARM, Keil, and µVision are trademarks or registered of ARM Ltd or its subsidiaries.
LEGO, the LEGO logo, WEDO, and MINDSTORMS are trademarks of the LEGO Group.
TETRIX by Pitsco is a trademark of Pitsco, Inc.
FIELDBUS FOUNDATION™ and FOUNDATION™ are trademarks of the Fieldbus Foundation.
EtherCAT® is a registered trademark of and licensed by Beckhoff Automation GmbH.
CANopen® is a registered Community Trademark of CAN in Automation e.V.
DeviceNet™ and EtherNet/IP™ are trademarks of ODVA.
Go!, SensorDAQ, and Vernier are registered trademarks of Vernier Software & Technology.
Vernier Software & Technology and vernier.com are trademarks or trade dress.
Xilinx is the registered trademark of Xilinx, Inc.
Taptite and Trilobular are registered trademarks of Research Engineering & Manufacturing Inc.
FireWire® is the registered trademark of Apple Inc.
Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.
Handle Graphics®, MATLAB®, Real-Time Workshop®, Simulink®, Stateflow®, and xPC
TargetBox® are registered trademarks, and TargetBox™ and Target Language Compiler™ are
trademarks of The MathWorks, Inc.
Tektronix®, Tek, and Tektronix, Enabling Technology are registered trademarks of Tektronix,
Inc.
The Bluetooth® word mark is a registered trademark owned by the Bluetooth SIG, Inc.
The ExpressCard™ word mark and logos are owned by PCMCIA and any use of such marks by
National Instruments is under license.
The mark LabWindows is used under a license from Microsoft Corporation. Windows is a
registered trademark of Microsoft Corporation in the United States and other countries.
Other product and company names mentioned herein are trademarks or trade names of their
respective companies.
Members of the National Instruments Alliance Partner Program are business entities independent
from National Instruments and have no agency, partnership, or joint-venture relationship with
National Instruments.

Patents
For patents covering National Instruments products/technology, refer to the appropriate
location: Help»Patents in your software, the patents.txt file on your media, or the National
Instruments Patent Notice at ni.com/patents.

Support
Worldwide Technical Support and Product Information
ni.com

Worldwide Offices
Visit ni.com/niglobal to access the branch office websites, which provide up-to-date
contact information, support phone numbers, email addresses, and current events.

National Instruments Corporate Headquarters


11500 North Mopac Expressway Austin, Texas 78759-3504 USA Tel: 512 683 0100

For further support information, refer to the Additional Information and Resources appendix.
To comment on National Instruments documentation, refer to the National Instruments website
at ni.com/info and enter the Info Code feedback.
Table of Contents
Student Guide
A. What You Need To Get Started .................................................. 5
B. Installing the Course Software.................................................... 5
C. Course Lesson Icons ................................................................. 5

Lesson 1
Measuring Voltage or Current (Analog Input)
Exercise 1-1 Sample Rate and Aliasing .......................................... 1-5
Exercise 1-2 Calculating Range, Resolution, and Accuracy ............... 1-11
Exercise 1-3 Connecting Signal Sources with Measurement Systems 1-17
Exercise 1-4 Using NI-DAQmx to Measure Voltage.......................... 1-20

Lesson 2
Generating an Analog Signal (Analog Output)
Exercise 2-1 Using NI-DAQmx to Generate a Voltage ...................... 2-4

Lesson 3
Generating or Reading a Digital Signal
Exercise 3-1 Using NI-DAQmx to Generate a Digital Signal............... 3-4

Lesson 4
Choose a Signal to Explore
A. List of Signals .......................................................................... 4-3

Lesson 5
Programming with the NI-DAQmx API
Exercise 5-1 Using Digital Lines to Control Multiple Devices ............. 5-5
Exercise 5-2 Acquire Finite Data from a Light Sensor ...................... 5-8
Exercise 5-3 Continuously Monitoring Fan Status............................ 5-11
Exercise 5-4 Continuously Controlling Fan Speed ............................ 5-14

Lesson 6
Programming Multiple Channels
Exercise 6-1 Measuring Voltage and Temperature in a Single Task .... 6-4

Lesson 7
Triggering on a Specific Condition
Exercise 7-1 Adding Hardware Triggers ......................................... 7-4

© National Instruments | 1
Table of Contents

Lesson 8
Advanced Timing and Synchronization Methods
Exercise 8-1 Simultaneously Started Analog Input and Output...........8-4
Exercise 8-2 Sharing a Sample Clock .............................................8-8
Exercise 8-3 Synchronizing with a Master Timebase ........................8-14

Lesson 9
Logging Measurement Data to Disk
Exercise 9-1 Streaming Fan Acceleration Data to Disk......................9-4

Lesson 10
System Considerations

Appendix A
NI compactDAQ Measurements Demo Box Information
A. NI CompactDAQ Measurements Demo Box Overview ....................A-3
B. Light Sensor Information ............................................................A-5
C. Thermocouple Information ..........................................................A-6
D. Strain Gage Information .............................................................A-7
E. Speaker Information...................................................................A-9
F. Sound and Vibration Signal Simulator Box Information ...................A-10
G. LEDs Information.......................................................................A-12

Appendix B
Measuring Temperature
Exercise B-1 Using NI-DAQmx to Measure Temperature with a Thermocou-
ple B-4

Appendix C
Measuring Sound, Vibration, and Acceleration (IEPE Measurements)
Exercise C-1 Using NI-DAQmx to Measure Vibration ........................C-4

Appendix D
Measuring Strain, Force, or Pressure (Bridge-Based Measurements)
Exercise D-1 Using NI-DAQmx to Measure Strain.............................D-4

Appendix E
Measuring Position with Encoders (Counter Input)
Exercise E-1 Exploring an Encoder Application ................................E-4

Appendix F
Measuring Edges, Frequency, Pulse Width, and Duty Cycle
Exercise F-1 Simple Edge Counting................................................F-4

Appendix G
Additional Information and Resources
NI Services 2
Services and Resources 2
Other National Instruments Training Courses 3
National Instruments Certification 3

2 | ni.com
Student Guide

In this student guide, you will learn about the course


description and the items you need to get started in this
course.

Topics
+ What You Need To Get Started
+ Installing the Course Software
+ Course Lesson Icons
Data Acquisition Using NI-DAQmx and LabVIEW

A. What You Need To Get Started


Before you use take this course, make sure you have all of the following items:

 Computer running Windows 7 or later

 LabVIEW 2016 (32-bit) and NI-DAQmx 2016

 Data Acquisition Using NI-DAQmx and LabVIEW course exercise and solution files
copied to the following folders:

Directory Table Head

Exercises\DAQ\ Contains files used in the course

Solutions\DAQ\ Contains completed course exercises

B. Installing the Course Software


File Locations
Exercise files are located in the <Exercises>\ folder where <Exercises> refers to
C:\Exercises\ assuming that you installed the files on your root directory.

Solution files are located in the <Solutions>\ folder where <Solutions> refers to
C:\Solution\ assuming that you installed the files on your root directory.

C. Course Lesson Icons


The lessons in this course are binned into hardware-focused and programming-focused
tasks using the following icons.

• Analog Input • DAQmx API • Other System


• Analog Output • Multiple Channels Considerations
• Digital I/O • Triggers
• Specific Sensors and • Advanced Timing and
Signals Synchronization
• Data Logging

© National Instruments | 5
1 Measuring
Voltage or
Current
(Analog Input)

Exercises
Exercise 1-1 Sample Rate and Aliasing
Exercise 1-2 Calculating Range, Resolution, and Accuracy
Exercise 1-3 Connecting Signal Sources with Measurement Systems
Exercise 1-4 Using NI-DAQmx to Measure Voltage
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Sample Rate

Article Location

Acquiring an Analog Signal: Bandwidth, Info code: nyquist


Nyquist Sampling Theorem, and Aliasing

Different Types of ADCs

Article Location

Benefits of Delta-Sigma Analog-to-Digital Info code: deltasigma


Conversion

Simultaneous Sampling Data Acquisition Info code: sampledata


Architectures

Isolation

Article Location

Isolation Types and Considerations Info code: isolationtype


when Taking a Measurement

Isolation Technologies for Reliable Info code: isolationtech


Industrial Measurements

Article Location

High Voltage Measurement and Isolation Info code: voltageisolation

Isolation and Safety Standards for Electronic Info code: isolationsafety


Instruments

Filtering

Article Location

Median and Nth Order Filtering Info code: median

Digital Filtering Info code: filtering

© National Instruments | 1-3


Lesson 1 Measuring Voltage or Current (Analog Input)

Field Wiring and Grounding

Article Location

Field Wiring and Noise Considerations for Info code: fieldwiring


Analog Signals

Using Test Panels

Article Location

Using Test Panels in Measurement & Automation Info code: testpanels


Explorer for Devices Supported by NI-DAQmx

Meausring current

Article Location

How to Measure Voltage, Current, and Power Info code: currentpower

Fundamentals, System Design, and Setup for the 4 Info code: currentloop
to 20 mA Current Loop

Article Location

Current Measurements: How-To Guide Info code: currenthowto

How to Minimize Errors for Low-Current Measurements Info code: currenterrors

Determining the Accuracy of a System

Article Location

Measurement Accuracy of a Data Acquisition Board Info code: ma101

How Do I Calculate Absolute Accuracy or System Info code: sysacc


Accuracy?

Understanding Instrument Specifications -- How to Info code: instrumspecs


Make Sense Out of the Jargon

Absolute Accuracy of Dynamic Signal Acquisition Info code: accdsa


Devices

Understanding Frequency Performance Info code: performspecs


Specifications

Specifications Explained Info code: specexplain

1-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Exercise 1-1 Sample Rate and Aliasing


Goal
Explore the effects of sample rate on an input signal.

Scenario
The Nyquist Theorem states that you must sample at greater than two times the
maximum frequency component of your signal to accurately represent the frequency
of the signal. However, the Nyquist Theorem only deals with accurately representing
the frequency of the signal. In order to properly represent the shape of your signal,
you must sample between 5 to 10 times greater than the maximum frequency
component of your signal.

Nyquist Frequency (fn) is fn = ½ fs. Below is an example of a 100 Hz sine wave


sampled at different frequencies.

Aliased signal

100 Hz Sine Wave Sampled at 100 Hz

Adequately sampled
signal for frequency only

100 Hz Sine Wave Sampled at 200 Hz

Adequately sampled
signal for frequency and
shape

100 Hz Sine Wave Sampled at 1 kHz

In this exercise, you use the Sample Rate Example VI to demonstrate aliasing and the
effects of sample rate on an input signal.

© National Instruments | 1-5


Lesson 1 Measuring Voltage or Current (Analog Input)

Implementation
1. Open the Sample Rate Example VI located in the <Exercises>\DAQ\Aliasing\
directory. The front panel in Figure 1-1 appears.
Figure 1-1. SampleRate Example VI Front Panel

This VI acquires a sine wave that is generated by the analog output circuitry on a
DAQ device. The VI graphs both the time domain and frequency domain of the
acquired signal.

1-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

2. Using wires, connect an analog output channel to an analog input channel in the
demo box.

a. Locate the pins for generating the analog output signal.

The CompactDAQ Measurements Demo Box contains modules of various


capabilities. Refer to Figure A-1 in Appendix A, for the location of these modules.

Signal Type Module Options

Analog output NI 9263

Figure 1-2. Device Pinout for the NI 9263

b. Locate the pins for measuring the analog input signal.

Signal Type Module Options

Analog input NI 9215

Figure 1-3. Device Pinouts for NI 9215

c. Using a wire and screwdriver, connect AO2 on the NI 9263 module to AI2+
on the NI 9215 module.

d. Using a different wire, connect COM on the NI 9263 module to AI2- on the
NI 9215 modules.

© National Instruments | 1-7


Lesson 1 Measuring Voltage or Current (Analog Input)

3. Set the front panel controls with the following values, where cDAQx is the identity
of your chassis.

• Analog Output Channel: cDAQxMod4/ao2

• Analog Input Channel: cDAQxMod8/ai2

• Analog Output Frequency (Hz): 500

• Analog Input Frequency (Hz): 1500

4. Run the VI. The x coordinate of the peak you see on the Frequency plot represents
the frequency of the sine wave the DAQ device generates.

Remember that the Nyquist Frequency (fn) is fn = ½ fs.

With a sample rate of 1,500 Hz, the Nyquist frequency is 750 Hz. This implies that
the sample rate is sufficient to measure a sine wave up to 750 Hz. When you run
the VI, you see a peak at 500 Hz, which is the analog output frequency that the
DAQ device generates.

5. Stop the VI. Click the Zoom button, as shown in Figure 1-4, and drag on the Time
Domain Data graph to zoom in on the data.

1-8 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Figure 1-4. Graph Palette - Zoom Button

The data looks like a triangular wave. Because you are sampling three times faster
than the analog output frequency, you are satisfying the Nyquist Theorem, but you
are not capturing the shape of the signal. Notice on the Frequency Domain Data
graph that you have captured the correct frequency of the signal.

6. Run the VI.

a. Increase the Analog Input Frequency to 5,000 Hz.

b. Stop the VI and zoom in on the Time Domain Data graph. The shape of the
time domain signal looks like a smooth sine wave.

Increasing the sample rate ten times faster than the signal you are trying to acquire
more accurately represents the shape of the signal.

Tip In general, try to acquire a signal 5 to 10 times faster than the highest
frequency in the signal you are trying to capture.

7. Run the VI to explore aliasing of a 500 Hz signal.

a. What is the Nyquist frequency for sampling frequency of 750 Hz?__________

b. Decrease the Analog Input Frequency to 750 Hz but keep the


Analog Output Frequency at 500 Hz.

c. What is the Frequency displayed on the Frequency Domain Data graph?______

© National Instruments | 1-9


Lesson 1 Measuring Voltage or Current (Analog Input)

d. Does the frequency displayed on the graph match the Analog Output
Frequency control value?_________________________________________________

The Nyquist frequency, fn, is equal to 375 Hz, which is lower than the analog
output signal frequency. Although the time-domain data waveform appears
sinusoidal in nature, the signal measured has the incorrect frequency, as displayed
on the frequency domain chart.

The alias frequency is determined by the following formula:

Alias freq. = | (closest integer multiple of the sampling freq. – signal freq.) |

Therefore, | 750 – 500 | = 250 Hz, which is what you see on the Frequency
Domain Data graph.

The Frequency Domain Data graph displays the incorrect frequency because the
frequency has been aliased between 0 and 375 Hz. The 500 Hz signal has been
aliased to 250 Hz.

8. Stop and close the VI. Do not save changes.

Note When you select a sample rate to obtain time-domain information


such as the shape of the waveform, you must oversample at a rate of at
least 5x greater than the highest frequency component in the waveform. If
you want to obtain only the frequency information, oversample at least 2x
greater than the highest frequency component in the waveform, according
to the Nyquist Theorem.

End of Exercise 1-1

1-10 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Exercise 1-2 Calculating Range, Resolution, and


Accuracy
Goal
Determine the optimal configuration for a data acquisition measurement system.

Scenario
In this exercise, you will review the specifications for a project and determine the most
appropriate DAQ device and input range for that device.

When choosing a DAQ device, consider performance against cost. A higher resolution
DAQ device costs more but provides a more accurate representation of the acquired
signal.
1. First determine if the DAQ device offers an input range that meets the
requirements of the project.
2. Next, determine if the desired code width is within the capability of the DAQ
device.
3. Finally, determine if the absolute accuracy of the DAQ device meets the
measurement requirements of the project.

Tip Use the code width equation.

Device Input Range


code width = -------------------------------------------------------
resolution in bits
-
2

In this exercise you will have two project scenarios. For each scenario, select the
appropriate DAQ hardware and optimum input range to maximize accuracy.
Tables 1-1, 1-2, and 1-3 list the three DAQ devices you can use for the project and
their resolution, input ranges, and accuracy.

© National Instruments | 1-11


Lesson 1 Measuring Voltage or Current (Analog Input)

Tables 1-1, 1-2, and 1-3 display the values for the analog input (AI) absolute accuracy
of each nominal range for each DAQ device.

Table 1-1. DAQ Device 1 AI Absolute Accuracy

Nominal Range (V)

Negative Full Absolute Accuracy


Resolution Positive Full Scale Scale at Full Scale (μV)

10 –10 3,100

5 –5 1,620
DAQ Device 16 Bit
1 1 –1 360

0.2 –0.2 112

Table 1-2. DAQ Device 2 AI Absolute Accuracy

Nominal Range (V)


Absolute Accuracy
Resolution Positive Full Scale Negative Full Scale at Full Scale (μV)

10 –10 1,920

5 –5 1,010

2 –2 410
DAQ Device 16 Bit
2 1 –1 220

0.5 –0.5 130

0.2 –0.2 74

0.1 –0.1 52

Table 1-3. DAQ Device 3 AI Absolute Accuracy

Nominal Range (V)


Absolute Accuracy
Resolution Positive Full Scale Negative Full Scale at Full Scale (μV)

10 –10 980

5 –5 510

2 –2 210
DAQ Device 18 Bit
3 1 –1 120

0.5 –0.5 70

0.2 –0.2 39

0.1 –0.1 28

1-12 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Practice—Project 1 (Answers on page 1-15.)


1. A thermocouple is attached to the steam drum output of a high-pressure boiler
system. The thermocouple can measure a temperature range of –270 ºC to
1,372 ºC. With this temperature range, the thermocouple returns a voltage of
–6.548 mV to 54.874 mV. Which DAQ devices offer an acceptable input range
for this application?

a. DAQ Device 1

b. DAQ Device 2

c. DAQ Device 3

2. To detect a change of 3.74 μV, which DAQ devices offer an acceptable code
width for the project?

a. DAQ Device 1

b. DAQ Device 2

c. DAQ Device 3

3. The measurements need to be within 37.4 μV of their true value. Which DAQ
devices offer an acceptable analog input absolute accuracy for the project?

a. DAQ Device 1

b. DAQ Device 2

c. DAQ Device 3

Practice—Project 2
1. A pressure transducer is placed on the intake manifold of an engine.
The transducer outputs a voltage between –2 V and 2 V for a linear
pressure range of 20 kPa to 105 kPa. Which DAQ devices offer an acceptable
input range for this application?

a. DAQ Device 1

b. DAQ Device 2

c. DAQ Device 3

2. This project needs to detect a change of 1.5 Pa, which would be a voltage change
of 70 μV. Which DAQ devices and corresponding input ranges offer an acceptable
code width for the project?

a. DAQ Device 1

b. DAQ Device 2

c. DAQ Device 3

© National Instruments | 1-13


Lesson 1 Measuring Voltage or Current (Analog Input)

3. The measurements need to be within 5 Pa, which would be within 235 μV, of their
true value. Which DAQ devices offer an acceptable analog input absolute accuracy
for the project?

a. DAQ Device 1

b. DAQ Device 2

c. DAQ Device 3

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

1-14 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Answers from page 1-13

Project 1
1. In this project, the thermocouple outputs a voltage ranging from –6.548 mV to
54.874 mV. All three DAQ devices have a maximum input range of ±10 V, which
more than covers the voltage range of this project.

2. Using the code width equation, if you select:

• DAQ Device 1 using an input range of ±0.2 V, the code width is 6.10 μV, so
this DAQ device cannot detect a change of 3.74 μV.

• DAQ Device 2 using an input range of ±0.1 V, the code width is 3.05 μV.

• DAQ Device 3 using an input range of ±0.1 V, the code width is 0.76 μV.

DAQ Device 2 and DAQ Device 3 are both able to detect a change of 3.74 μV.

3. AI absolute accuracy by device:

• DAQ Device 1: 112 μV using a ±0.2 V input range

• DAQ Device 2: 52 μV using a ±0.1 V input range

• DAQ Device 3: 28 μV using a ±0.1 V input range

Only DAQ Device 3 is accurate enough to acquire measurements within 37.4 μV


of their true value.

Therefore, DAQ Device 3, using an input range of ±0.1 V, is the best DAQ device
for this project.

Project 2
1. In this project, the transducer is linear and outputs a voltage ranging from –2 V to
2 V. All three DAQ devices have a maximum input range of ±10 V, which more
than meets the ±2 V range of this project.

2. Using the code width equation:

• DAQ Device 1 can detect a change of 152 μV using an input range of ±5 V.

• DAQ Device 2 can detect a change of 61 μV using an input range of ±2 V.

• DAQ Device 3 can detect a change of 15 μV using an input range of ±2 V.

DAQ Device 2 and DAQ Device 3 are both able to detect a change of 70 μV.

© National Instruments | 1-15


Lesson 1 Measuring Voltage or Current (Analog Input)

3. AI absolute accuracy by device:

• DAQ Device 1: 1620 μV using a ±5 V input range

• DAQ Device 2: 410 μV using a ±2 V input range

• DAQ Device 3: 210 μV using a ±2 V input range

Only DAQ Device 3 is accurate enough to acquire measurements within 235 μV


of their true value.

Therefore, DAQ Device 3, using an input range of ±2 V, is the best DAQ device
for this project.

End of Exercise 1-2

1-16 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Exercise 1-3 Connecting Signal Sources with


Measurement Systems
Goal
Choose a grounding mode for a measurement system and properly connect signals to
that measurement system.

Scenario
In this two-part exercise, you practice determining a correct grounding mode
configuration.

Part I (Answers on page 1-19.)


Assume you have an instrument that plugs into a standard wall outlet. The outputs of
the instrument are referenced to the same ground as the instrument. Cross out any
measurement system you could not use to connect the outputs of the instrument to
a DAQ device. Which system would be the most desirable to use and why?

Differential RSE NRSE

Figure 1-5 shows the instrument and a 68-pin layout for a PCI-6221. Based on your
choice for the grounding mode of the measurement system, draw the connections for
the following:
• voltage source 1 to analog input channel 0
• voltage source 2 to analog input channel 1
• voltage source 3 to analog input channel 2

Figure 1-5. PCI-6221 68-pin Layout

AI 0 68 34 AI 8
AI GND 67 33 AI 1
AI 9 66 32 AI GND
AI 2 65 31 AI 10
AI GND 64 30 AI 3
+ AI 11 63 29 AI GND
AI SENSE 62 28 AI 4
AI 12 61 27 AI GND
VS 1 AI 5 60 26 AI 13
– AI GND 59 25 AI 6
AI 14 58 24 AI GND
AI 7 57 23 AI 15
AI GND 56 22 AO 0
+ AO GND 55 21 AO 1
AO GND 54 20 NC
D GND 53 19 P0.4
VS 2 P0.0 52 18 D GND
– P0.5 51 17 P0.1
D GND 50 16 P0.6
P0.2 49 15 D GND
P0.7 48 14 +5 V
+ P0.3 47 13 D GND
PFI 11/P2.3 46 12 D GND
PFI 10/P2.2 45 11 PFI 0/P1.0
VS 3 D GND 44 10 PFI 1/P1.1
– PFI 2/P1.2 43 9 D GND
PFI 3/P1.3 42 8 +5 V
PFI 4/P1.4 41 7 D GND
PFI 13/P2.5 40 6 PFI 5/P1.5
PFI 15/P2.7 39 5 PFI 6/P1.6
PFI 7/P1.7 38 4 D GND
PFI 8/P2.0 37 3 PFI 9/P2.1
D GND 36 2 PFI 12/P2.4
D GND 35 1 PFI 14/P2.6

Find the solution on page 1-19.

© National Instruments | 1-17


Lesson 1 Measuring Voltage or Current (Analog Input)

Part II
Assume you have three batteries. Cross out any measurement system you could not
use to connect the outputs of the batteries to a DAQ device. Which system would be
the most desirable to use and why?

Differential RSE NRSE

Figure 1-6 shows the batteries and a 50-pin layout for a PCI-MIO-16E-4. Based on
your choice for the grounding mode of the measurement system, draw the
connections for the following:
• battery 1 to analog input channel 5
• battery 2 to analog input channel 6
• battery 3 to analog input channel 7

Figure 1-6. PCI-MIO-16E-4 50-pin Layout

AI 0 68 34 AI 8
AI GND 67 33 AI 1
AI 9 66 32 AI GND
AI 2 65 31 AI 10
AI GND 64 30 AI 3
AI 11 63 29 AI GND
+ 62 28
AI SENSE AI 4
AI 12 61 27 AI GND
1 AI 5 60 26 AI 13
AI GND 59 25 AI 6
AI 14 58 24 AI GND
– AI 7 57 23 AI 15
AI GND 56 22 AO 0
AO GND 55 21 AO 1
AO GND 54 20 NC
+ D GND 53 19 P0.4
P0.0 52 18 D GND
P0.5 51 17 P0.1
2 D GND 50 16 P0.6
P0.2 49 15 D GND
P0.7 48 14 +5 V
– P0.3 47 13 D GND
PFI 11/P2.3 46 12 D GND
PFI 10/P2.2 45 11 PFI 0/P1.0
D GND 44 10 PFI 1/P1.1
+ PFI 2/P1.2 43 9 D GND
PFI 3/P1.3 42 8 +5 V
PFI 4/P1.4 41 7 D GND
3
PFI 13/P2.5 40 6 PFI 5/P1.5
PFI 15/P2.7 39 5 PFI 6/P1.6
– PFI 7/P1.7 38 4 D GND
PFI 8/P2.0 37 3 PFI 9/P2.1
D GND 36 2 PFI 12/P2.4
D GND 35 1 PFI 14/P2.6

Find the solution on page 1-19.

1-18 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Answers from page 1-17.


Solution to Part I
The signal source is grounded, so you cannot choose RSE. The ideal choice is
differential because you do not have more than eight signals to measure. If you have
more than eight signals to measure, the ideal choice is NRSE. If you chose differential,
wire the positive lead from voltage source 1 to pin 68 and wire the negative lead to
pin 34. Wire the positive lead from voltage source 2 to pin 33 and wire the negative
lead to pin 66. Finally, wire the positive lead from voltage source 3 to pin 65 and wire
the negative lead to pin 31. If you chose NRSE, wire the positive leads in the same
way, but wire the negative leads to AI SENSE.

Solution to Part II
The signal source is floating, so you could choose any of the three measurement
systems. Both RSE and NRSE allows you to use 16 channels, but NRSE requires you
to use bias resistors, so eliminate NRSE. Because you have fewer than eight signals
to measure, the best choice for a good measurement is differential. However, with
differential you would need bias resistors, so the simplest choice is RSE. Assuming
you chose differential, wire the positive lead from battery 1 to pin 60 and wire the
negative lead to pin 26. Wire the positive lead from battery 2 to pin 25 and wire the
negative lead to pin 58. Finally, wire the positive lead from battery 3 to pin 57 and
wire the negative lead to pin 23. You also need bias resistors from the positive and
negative terminals of each battery to AI GND. If you chose RSE, wire the positive leads
in the same way, but wire all the negative terminals to AI GND. RSE does not require
bias resistors.

End of Exercise 1-3

© National Instruments | 1-19


Lesson 1 Measuring Voltage or Current (Analog Input)

Exercise 1-4 Using NI-DAQmx to Measure Voltage


Goal
Open and run an example program to take a software-timed, analog input
measurement.

Scenario
You need to make sure a solar panel is functioning properly before deploying it to the
field.

In this exercise, you use the specifications of a solar panel and the NI 9215 C Series
module to verify a voltage reading. Instead of building a VI from scratch, you take
advantage of an NI-DAQmx shipping example to take a software-timed measurement.

Implementation
Note Make sure that all NI MAX test panels are stopped before completing
this exercise.

1. Refer to Light Sensor Information in Appendix A, NI compactDAQ Measurements


Demo Box Information to answer questions about the wiring of this sensor.
(Answers on page 1-23.)

a. Is the source sensor floating or grounded? ________________________________

b. What kind of terminal configuration is this wiring setup?

c. Which device pins are wired to the solar panel?

2. Open the Example Finder. (Select Help»Find Examples in LabVIEW.)

3. Select Directory Structure on the Browse tab and locate the DAQmx folder.

1-20 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

4. Open Voltage – SW-Timed Input.vi located in the DAQmx»Analog Input folder.

Notice that the front panel of the VI offers many of the same options that the test
panel in MAX offered.

5. Update the front panel so that the VI uses the NI 9215 to read a voltage from the
solar panel.

Parameter Hint Value

Physical Which slot of the cDAQ chassis contains the


Channel NI 9215 module?
What answer did you have for step 1c on
page 1-20?

Max Voltage, According to the solar panel specification,


Min Voltage what is the maximum voltage generated?

Terminal What answers did you have for step 1a


Configuration and 1b on page 1-20?

6. Review the block diagram to see how the VI is implemented.

a. Right-click the Physical Channel control and select Find Terminal from the
shortcut menu.

© National Instruments | 1-21


Lesson 1 Measuring Voltage or Current (Analog Input)

b. Review the components of the block diagram. For a software-timed acquisition


application, you see the basic DAQ API structure: Create, Configure, Start,
Read/Write, Stop/Clear.

1 2

1 DAQmx Create Virtual Channel—Using the Context Help for this VI, you see that only the
Physical Channel input is required. However, because we know the maximum and
minimum values we can program them. The Terminal Configuration has a default value
depending on the DAQ device, but it is important to verify that you are using the correct
terminal configuration for the grounding situation you have between the sensor and the
DAQ device. Because this is a simple acquisition, no further configuration is needed.
2 DAQmx Start Task—Starting the task means that the device is ready to take a
measurement.
3 The While Loop contains the DAQmx Read VI and controls the timing of the acquisition
using the Wait (ms) function. This means that the timing of the acquisition is dependent
on the OS.
4 DAQmx Stop Task VI and DAQmx Clear Task—This example VI uses both for
completeness, but the DAQmx Clear Task VI will stop the task if necessary.

Test
1. Run the VI. Because the y-axis on the Acquired Data graph is set to AutoScale,
you see a very jagged graph.

2. Stop the VI and change the y-axis so that it does not autoscale and has a minimum
value of 0 and a maximum value of .5.

Tip Right-click the y-axis and select Y Scale»Autoscale Y to remove the


checkmark and disable the autoscaling.

Click a value on the axis and type in the desired value to specify the new
scale. Editing the axis values can be tricky. Make sure nothing is selected
and the cursor becomes the text tool, as shown below, before trying to
click the value.

1-22 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

3. Run the VI again.

4. Place your hand over the light sensor to make sure the voltage drops to zero.

5. Use a flashlight or camera flash to see if you can get the voltage to reach its
maximum, .5 V.

6. Stop and close the VI without saving it.

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

Answers from page 1-20.


1. Refer to Light Sensor Information in Appendix A, NI compactDAQ Measurements
Demo Box Information to answer questions about the wiring of this sensor.

a. Is the source sensor floating or grounded? Floating

b. What kind of terminal configuration is this wiring setup? Differential

c. Which device pins are wired to the solar panel? 0 and 1

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

End of Exercise 1-4

© National Instruments | 1-23


Lesson 1 Measuring Voltage or Current (Analog Input)

1-24 | ni.com
2 Generating an
Analog Signal
(Analog Output)

At the end of this lesson, you will be able to select and


connect to hardware, configure the task appropriately, and
validate the measurement.

Topics
+ Resources

Exercises
Exercise 2-1 Using NI-DAQmx to Generate a Voltage
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Article Location

M-series: External AO Reference Info code: mseriesextref

Outputting a Voltage Using an External Voltage Info code: aoextref


Reference

How Can I Maximize the Resolution of My Analog Info code: aoresolution


Output Signal?

Signal Conditioning: Isolation and Amplification

Article Location

Isolation Technologies for Reliable Industrial Info code: isolationtech


Measurements

Output Terminal Configuration

Article Location

Default Input/Output Terminal Configurations Info code: defaultioterm

Field Wiring and Noise Considerations for Analog Info code: fieldwiring
Signals

Reading the Pinout

Article Location

Connect Analog Output Signals to a DAQ Device Info code: connectao

Data Transfer Mechanism for an Output Operation

Article Location

Data Transfer Mechanisms Info code: datatransfermech

© National Instruments | 2-3


Lesson 2 Generating an Analog Signal (Analog Output)

Exercise 2-1 Using NI-DAQmx to Generate a Voltage


Goal
Open and run an example program to generate a software-timed, analog output signal.

Scenario
In this exercise, you use the NI 9263 C Series module to generate a tone through the
speaker in the demo box. Instead of building a VI from scratch, you take advantage of
a NI-DAQmx shipping example to make an on-demand, software-timed measurement.

Implementation
Note Make sure that all NI MAX test panels are stopped before completing
this exercise.

1. Refer to Appendix A, section E, Speaker Information, and section F, Sound and


Vibration Signal Simulator Box Information, to answer questions about the wiring
of the NI 9263 module to components in the Demo Box.

a. Which device pins are wired to the speaker?______________________________

b. What device pins connect the NI 9263 to the fan control of the Sound and
Vibration Signal Simulator?______________________________________________

2. Open <Exercises>\DAQ\Analog Output\Analog Output Voltage – Fan


Control.vi.

Note This VI is based on the Example program


Voltage - On Demand Output.vi located in the <LabVIEW>\examples\
DAQmx\Analog Output folder.

2-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Notice that the front panel of the VI has similar options that the test panel in MAX
offered but is missing something called Mode.

3. Update the front panel so that the VI uses the NI 9263 to generate a voltage.

Parameter Hint Value

Physical Which slot of the cDAQ chassis contains the


Channel NI 9263 module?
What answer did you have for step 1b on
page 2-4?

4. Review the block diagram to see how the VI is implemented.

a. Right-click the Physical Channel(s) control and select Find Terminal from the
shortcut menu.

© National Instruments | 2-5


Lesson 2 Generating an Analog Signal (Analog Output)

b. Review the components of the block diagram. For a software-timed acquisition


application, you see the basic DAQ API structure: Create, Configure, Start,
Read/Write, Stop/Clear.

2 5
1
3 4

1 DAQmx Create Virtual Channel—Using the Context Help for this VI, you see that only the Physical Channels input
is required. However, because we know the maximum and minimum values we can program them. The output
terminal configuration has a default value depending on the DAQ device, but it is important to verify that you are
using the correct terminal configuration for the grounding situation you have between the actuator and the DAQ
device. Because this is a simple voltage generation, no further configuration is needed.
2 DAQmx Start Task—Starting the task means that the device is ready to generate a signal. Because this task is
software-timed, you do not need to write data to the buffer before starting the task.
3 DAQmx Write VI—The While Loop contains the NI-DAQmx Write VI and controls the timing of the generation of a
signal using the Wait Until Next ms Multiple function. This means that the timing of the signal generation is
dependent on the OS.
4 Turning off the fan—By writing 0 voltage to the fan control you make sure the fan isn’t still running after you stop
the VI.
5 DAQmx Stop Task VI and DAQmx Clear Task VI—This example VI uses both for completeness, but the NI-DAQmx
Clear Task VI will stop the task if necessary.

Test
1. Run the VI.

2. Change the Analog Output Voltage (V) slider on the front panel of the VI to change
the speed of the fan.

3. Stop the VI.

4. Change the Max Voltage to a value less than 5 and run the VI again.

 What happens when you specify an Analog Output Voltage greater than the
Max Voltage?__________________________________________________________

Note If the fan continues to run after you stop the VI, you can go to NI
MAX and reset the hardware.

5. Stop and close the VI without saving it.

End of Exercise 2-1

2-6 | ni.com
3 Generating or
Reading a
Digital Signal

After this lesson you will be able to connect hardware,


configure a task appropriately, and validate a measurement
or generation of a digital signal.

Topics
+ Resources

Exercises
Exercise 3-1 Using NI-DAQmx to Generate a Digital Signal
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Digital I/O

Article Location

Choosing the Right Industrial Digital I/O Info code: industrialdio


Module for Your Digital Output Sensor

Article Location

Digital I/O Sinking and Sourcing Info code: diosinksource

Isolation

Article Location

Isolation Types and Considerations Info code: isolationtype


when Taking a Measurement

Common Hardware Connections for Info code: dioconnect


Digital I/O and Counter/Timer Boards

Reducing Measurement Noise in Digital Signals

Article Location

Five Tips to Reduce Measurement Noise Info code: noisetips

High-Speed Digital I/O Logic Families Info code: diologicfam

3 Types of Digital Input Configurations

Article Location

Connecting Digital Input Signals to a DAQ Device Info code: connectdio

4 Types of Digital Output Configurations

Article Location

Connecting Digital Output Signals to a DAQ Device Info code: connectdout

© National Instruments | 3-3


Lesson 3 Generating or Reading a Digital Signal

Exercise 3-1 Using NI-DAQmx to Generate a Digital


Signal
Goal
Open and run an example program to generate a digital signal.

Scenario
In this exercise, you use the specifications LEDs and the NI 9472 C Series module to
generate the status of a digital line. Instead of building a VI from scratch, you take
advantage of a NI-DAQmx shipping example to take a software-timed measurement.

Implementation
Note Make sure that all NI MAX test panels are stopped before completing
this exercise.

1. Refer to LEDs Information in Appendix A, NI compactDAQ Measurements Demo


Box Information to answer questions about the wiring of the LEDs.

a. Which lines from the 9472 is wired to the red LEDs?________________________

b. Which lines pins are wired to the green LEDs?_____________________________

c. Are the LEDs a sinking or sourcing device? ________________________________

2. Open the Example Finder. (Select Help»Find Examples in LabVIEW.)

3. Select Directory Structure on the Browse tab and locate the DAQmx folder.

3-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

4. Open Digital – SW-Timed Output.vi located in the DAQmx»Digital Output


folder.

1
2

1 Notice that the front panel of the VI has a Line(s) control to specify the port and line. Using the syntax
device/portx/line0:7 you are specifying every line in the port. On the other hand
device/portx/line0:1 only writes to the first two lines.
2 The example VI is set up to give you control of only two digital lines. If you specify more lines in the
Lines(s) control you must click the individual Boolean push button to activate it.

5. Right-click the Data to Write control and select Find Terminal.

1 Notice that the control is actually a one-dimensional array of Boolean elements.


2 The NI-DAQmx Write VI instance is configured to accept data that is a
one-dimensional array of data.

© National Instruments | 3-5


Lesson 3 Generating or Reading a Digital Signal

6. Review the rest of the block diagram to see how the VI is implemented.

For a software-timed acquisition application, you see the basic DAQ API structure:
Create, Configure, Start, Read/Write, Stop/Clear.

4
1 2

1 DAQmx Create Virtual Channel VI—Using the Context Help for this VI, you see that only the Physical Channel input
is required. However, because we know the maximum and minimum values we can program them. The Terminal
Configuration has a default value depending on the DAQ device, but it is important to verify that you are using the
correct terminal configuration for the grounding situation you have between the sensor and the DAQ device. Because
this is a simple acquisition, no further configuration is needed.
2 DAQmx Start Task VI—Starting the task means that the device is ready to take a measurement.
3 The While Loop contains the NI-DAQmx Write VI and controls the timing of the acquisition using the Wait (ms)
function. This means that the timing of the generation of the signal is dependent on the OS.
4 DAQmx Stop Task VI and DAQmx Clear Task VI—This example VI uses both for completeness, but the DAQmx Clear
Task VI will stop the task if necessary.

7. Update the front panel so that the VI uses the NI 9472 to generate a signal that
turns on example one green, one amber, and one red LED.

Parameter Hint Value

Lines(s) Which slot of the cDAQ chassis contains the


9472 module?
How many lines does the port on the 9472
contain?

Data to Write The demo box has eight LEDs, one for each
line in the port.
What answers did you have for step 1a and
1b on page 3-4?

3-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Test
1. Run the VI.

2. Update the front panel so that the VI uses the NI 9472 to generate a signal that
turn on example one green, one amber, and one red LED.

3. Update the front panel so that the VI only lights green and amber LEDs.

4. Stop the VI and change the Line(s) control such that you specify only five lines.
What happens when you run the VI?

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

The array of data input into the NI-DAQmx Write VI must match the number of
lines you specify.

5. Stop and close the VI without saving it.

Challenge
Change the instance of the NI-DAQmx Write VI to a U8 (port format). Delete the
broken wires and create a new control, data.

Run the VI and enter different values.

 Can you guess which LEDs light up before you enter the new value? For example,
if you enter the value 8, which LED lights up? Why?__________________________

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _l

 What happens when you enter 600 into the data control?______________________

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

Stop and close the VI without saving it.

End of Exercise 3-1

© National Instruments | 3-7


Lesson 3 Generating or Reading a Digital Signal

3-8 | ni.com
4 Choose a Signal
to Explore

In this lesson you choose a signal you would like to explore


more closely.

Topics
+ List of Signals
Data Acquisition Using NI-DAQmx and LabVIEW

A. List of Signals
Refer to the appropriate appendix for more information and exercise instructions.
• Measuring Temperature—Appendix B
• Measuring Sound, Vibration, and Acceleration (IEPE Measurements)—Appendix C
• Measuring Strain, Force, or Pressure (Bridge-Based Measurements)—Appendix D
• Measuring Position with Encoders (Counter Input)—Appendix E
• Measuring Edges, Frequency, Pulse Width, and Duty Cycle—Appendix F

© National Instruments | 4-3


5 Programming
with the
NI-DAQmx API

At the end of this lesson you will be able to use the


NI-DAQmx API in LabVIEW to automate data
communication with a DAQ device and computer.

Topics
+ Resources

Exercises
Exercise 5-1 Using Digital Lines to Control Multiple Devices
Exercise 5-2 Acquire Finite Data from a Light Sensor
Exercise 5-3 Continuously Monitoring Fan Status
Exercise 5-4 Continuously Controlling Fan Speed
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Article Location

Creating a Virtual Channel in NI-DAQmx and using Info code: createchannellv


it in LabVIEW

Getting Started with NI-DAQmx: Main Page Info code: daqmxgetstart

What types of task configuration are possible?

Article Location

Getting Started with NI-DAQmx: Basic Info code: basicdaqmx


Programming with NI-DAQmx

Getting Started with NI-DAQmx: Getting Started Info code: basicdaqmprog


with NI-DAQmx Programming in LabVIEW

10 Functions to Handle 80% of Your Data Acquisition


Applications

Article Location

Learn 10 Functions in NI-DAQmx and Handle 80 Info code: 10functions


Percent of Your Data Acquisition Applications

Starting and Stopping Tasks

Article Location

When to Use the DAQmx Start Task and DAQmx Info code: daqmxstartstop
Stop Task VIs

Stopping vs. Clearing Tasks

Article Location

What is the Difference between the DAQmx Stop Info code: diffstopclear
Task VI and the DAQmx Clear Task VI?

© National Instruments | 5-3


Lesson 5 Programming with the NI-DAQmx API

What if I want even MORE control over a task?

Article Location

Getting Started with DAQmx: Basics of DAQmx Info code: basicdaqmxprop


Property Nodes

5-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Exercise 5-1 Using Digital Lines to Control Multiple


Devices
Goal
Use a digital output device to write a finite amount of digital data across a digital port.

Scenario
You must develop an application that controls the power state of eight devices. Each
device can be turned on or off by connecting a digital line to its POWER input.

Design
To complete this task, you will write digital data to lines 0-7 of port 0 of the NI 9472
module in your cDAQ-9178 chassis. You do not yet have samples of the eight devices
that your VI needs to control. Therefore, the values of these lines are wired to the
LEDs on the NI CompactDAQ Measurements Demo Box to ensure that you are setting
the line values correctly.

When this application runs, each digital line will be set to the on or off state. The
application will write one value to each line that is included in as part of the digital
channel.

Because all eight digital lines are part of the same port on the same device, you can
create and use a single channel to handle writing data to all eight lines at once.

Implementation
Develop a project and VI that will use one channel to write digital data to multiple
digital output lines.

1. Open a blank project and save it as


<Exercises>\DAQ\Finite Output\Control Multiple Devices.lvproj.

2. Create a new VI for this project and save it as


<Exercises>\DAQ\Finite Output\Control Multiple Devices.vi.

© National Instruments | 5-5


Lesson 5 Programming with the NI-DAQmx API

3. Create the block diagram to perform a buffered acquisition of a finite number of


samples.

4 3

2
1 Line grouping constant—This constant configures the virtual channel to contain all of the digital lines
specified in the DO Lines control.
2 DAQmx Write VI—Configure this VI to write a single sample of a 1D digital data array to a single channel.
3 Reverse 1D Array—Rearranges the values in the Boolean array so that the orientation shown on the front
panel matches the orientation of the LEDs on the NI CompactDAQ Measurements Demo Box.
4 1D array of Boolean control—To create this 1D array, place a True Constant on the block diagram.
Right-click the constant and select Change to Control. Right-click the control and select Change to Array.

4. Arrange the items on the front panel and set the values.

1 2

1 DO Lines—Because you are using one channel to write to multiple digital lines on
the same device, you can use the format cDAQ1Mod3/port0/line0:7 to write data
to lines zero to seven of port0.
2 Device Power Status—Remove the Index Display from the Visible Items.
3 Labels—Add labels to make it more clear which device is being controlled by each
digital line.

5. Save the VI and the project.

5-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Test
Ensure that the VI is able to write digital data to LEDs zero to seven.

1. Ensure that you are able to turn on all eight LEDs.

 Set the Device Power Status for each device to ON.

 Run the VI. Each LED on the NI CompactDAQ Measurements Demo Box should
turn on.

2. Ensure that you are able to selectively turn on some LEDs and turn others off.

 Set the Device Power Status for several devices to OFF.

 Run the VI. The LEDs on the NI CompactDAQ Measurements Demo Box should
match the values that you specified for Device Power Status.

3. Ensure that you are able to turn off all eight LEDs.

 Set the Device Power Status for each device to OFF.

 Run the VI. Each LED on the NI CompactDAQ Measurements Demo Box should
turn off.

Note It is important to run this step to turn off all eight LEDs, otherwise
they will remain on.

End of Exercise 5-1

© National Instruments | 5-7


Lesson 5 Programming with the NI-DAQmx API

Exercise 5-2 Acquire Finite Data from a Light Sensor


Goal
Acquire data using finite buffered configuration and analyze this data for maximum
and minimum values.

Scenario
Your team is developing a camera that uses a light sensor to automatically determine
whether or not a flash is needed when taking photographs. You are responsible for
developing code that acquires a fixed number of samples under different lighting
conditions and then measures the minimum, maximum, and DC voltage levels that the
light sensor generates.

Design
To complete this task, you will read data from Channel 0 of the NI 9215 module in
your cDAQ-9178 chassis.

You want to acquire 1000 points of data to ensure that your maximum, minimum and
DC measurements are statistically valid. You want for the acquisition to occur over
the course of 2 seconds.

What sample rate should you use for this acquisition? ____________________________

Implementation: Finite Buffered Acquisition


First, you will create a VI to ensure that you are able to acquire light sensor data and
display it in a VI.

1. Open a blank project and save it as


<Exercises>\DAQ\Finite Input\Light Sensor Acquisition.lvproj.

2. Create a new VI for this project and save it as


<Exercises>\DAQ\Finite Input\Light Sensor Acquisition.vi.

3. Create the block diagram to perform a buffered acquisition of a finite number of


samples.

1 DAQmx Timing VI—This VI configures the number of samples to acquire or generate and creates a buffer.

5-8 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

4. Arrange the items on the front panel and set the values.

1 Replace the Acquired Data indicator with a waveform graph.

5. Save the VI.

Test
Ensure that the VI is able to acquire and display light sensor data from your NI 9215.

1. Run the VI.

 While the VI is running, place your hand over the light sensor to ensure that
the sensor detects the change in light level.

 Verify that the VI takes approximately two seconds to run.

Note If your data does not appear, troubleshoot the VI. If that doesn’t
reveal the problem, then try to build a task in MAX. If you still have trouble,
ask for additional assistance.

© National Instruments | 5-9


Lesson 5 Programming with the NI-DAQmx API

Implementation: Light Sensor Data Analysis


After ensuring that your VI is working properly, it is time to analyze the data that you
acquire. In order to develop the code that controls the flash functionality, you need to
characterize the voltage values acquired at different light levels. You have determined
that you need to calculate the minimum, maximum, and average voltage values at
each light level.

1. Save a copy of the Light Sensor Acquisition VI as Light Sensor Acquisition


with Analysis.vi in the <Exercises>\DAQ\Finite Input directory.

2. Add waveform analysis to the finite acquisition by analyzing the data after it has
been acquired, as shown below.

1 2

1 Mean VI—This VI calculates the average voltage value for the waveform read from the light sensor.
2 Waveform Min Max VI—This VI determines the maximum and minimum values in the light sensor signal.

3. Save the VI.

Test
1. From the front panel, run the VI and observe the resulting values.

 What is the average voltage value? ______________________

 What is the maximum voltage value? ______________________

 What is the minimum voltage value? ______________________

2. Place your hand over the light sensor, run the VI and observe the resulting values.

 What is the average voltage value? ______________________

 What is the maximum voltage value? ______________________

 What is the minimum voltage value? ______________________

3. Save and close the VI.

End of Exercise 5-2

5-10 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Exercise 5-3 Continuously Monitoring Fan Status


Goal
Continuously monitor an analog input channel.

Scenario
You must develop an application that can read acceleration data for the X and Y axes
of a fan and determine whether it has become unbalanced as a result of a broken fan
blade.

The first step in developing this type of application is to first ensure that you are able
to continuously read data from accelerometers. You can then compare the results from
a known good fan with those from an unbalanced fan to determine the test limits that
you could use for a pass/fail test.

Design
To complete this task you will read data from Channels 0 and 1 of the NI 9234 module
in your cDAQ-9178 chassis. These channels are connected to accelerometers that
generate X and Y acceleration data for the balanced and unbalanced fans within the
Sound and Vibration Signal Simulator.

As the fan speed increases, the differences in the acceleration data for the balanced
and unbalanced fans will become more pronounced.

The Sound and Vibration Signal Simulator has two switches that you will use in this
exercise:

 The Balanced Fan / Unbalanced Fan switch determines which fan is active and
generating acceleration data.

 The BNC/DIAL switch determines whether the knob or BNC input terminal
controls the speed of the selected fan.

Implementation
1. Create a blank project and save it as
<Exercises>\DAQ\Continuous Input\Read Fan Acceleration.lvproj.

2. Use the NI Example Finder to open Voltage - Continuous Input.vi shipping


example.

 To locate this example, open the NI Example Finder and navigate to


Hardware Input and Output»DAQmx»Analog Input.

3. Save a copy of the Voltage - Continuous Input VI as


<Exercises>\DAQ\Continuous Input\Read Fan Acceleration.vi. so that you
can modify the without affecting the source files for the example program.

 In the Save As dialog box, create a copy on disk and substitute the copy for
the original, closing the original.

4. Add Read Fan Acceleration.vi. to Read Fan Acceleration.lvproj.

© National Instruments | 5-11


Lesson 5 Programming with the NI-DAQmx API

5. Modify the block diagram of the VI.

1 Delete the Trigger Settings and Logging Settings sections and wire the task and error wires from the
DAQmx Timing VI to the NI-DAQmx Start Task VI.

6. Modify the front panel.

1 Change the Physical Channel input to read from ai0 and ai1 of the NI 9234
(cDAQ1Mod7).
2 Show the plot legend for the waveform graph. Once you run the VI, the labels
will map to the physical channels.

7. Save the VI.

Test
Generate data for both the balanced fan and the unbalanced fan. Note the difference
in the data generated when the fan is at maximum speed.

1. Configure the Sound and Vibration Signal Simulator to begin testing the balanced
fan.

 Ensure that the Fan Speed Control switch is set to Dial.

5-12 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

 Ensure that the switch between the fans is set to Balanced Fan.

 Ensure that the Fan Speed Control dial is turned all the way counterclockwise.

2. Run the VI.

3. Turn the Fan Speed Control knob clockwise and observe the impact on the X and
Y acceleration plots.

 Note that the magnitude of the X and Y acceleration did not change
significantly.

4. Configure the Sound and Vibration Signal Simulator to begin testing the
unbalanced fan.

 Turn the Fan Speed Control dial is turned all the way counterclockwise.

 Set the switch between the fans to Unbalanced Fan.

5. Slowly turn the Fans Speed Control knob clockwise and observe the impact on the
X and Y acceleration plots.

 What shape do the waveforms take on? _________________________________

 What is the approximate amplitude of the resulting waveforms?

– ai0 (X-Acceleration): ______________________________

– ai1 (Y-Acceleration): ______________________________

End of Exercise 5-3

© National Instruments | 5-13


Lesson 5 Programming with the NI-DAQmx API

Exercise 5-4 Continuously Controlling Fan Speed


Goal
Continuously write analog data to a device.

Scenario
In the previous exercise, you developed an application that can be used to determine
whether or not a fan is unbalanced. Now you must develop an application that can
control the speed of a balanced fan.

Design
To complete this task, you will write analog data to channel 1of the NI 9263 analog
output module in your cDAQ-9178 chassis.

This channel is wired to the Fan Speed Control BNC on the Sound and Vibration Signal
Simulator.

For this application, we can use software timing to write new fan speed values to the
virtual channel when they become available. Hardware timing requires that you create
a buffer of values. If a number of values reside in the buffer, that could result in a delay
when you change the fan speed value on your front panel.

Implementation
1. Create a blank project and save it as
<Exercises>\DAQ\Continuous Output\Fan Speed Control.lvproj.

2. Use the NI Example Finder to open Voltage - On Demand Output.vi shipping


example.

 To locate this example, open the NI Example Finder and navigate to Hardware
Input and Output»DAQmx»Analog Output.

3. Save a copy of the Voltage - On Demand Output VI as


<Exercises>\DAQ\Continuous Output\Fan Speed Control.vi. so that you can
modify it without affecting the source files for the example.

 In the Save As dialog box, create a copy on disk and substitute the copy for
the original, closing the original.

4. Add Fan Speed Control.vi. to Fan Speed Control.lvproj.

5-14 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

5. Modify the block diagram of the VI.

2
3
1 4

1 DAQmx Write VI—Configure this VI to write a single double precision sample to a single channel.
2 Fan Speed input—Rename the Output Array control to Fan Speed. Right-click this control and change it
to contain a single element instead of an array.
3 Wait Until Next ms Multiple VI—For this example, we use software timing because there is no need to
create a buffer of Fan Speed values.
4 DAQmx Write VI—Insert another DAQmx Write VI after the loop to turn off the fan when you stop the VI.

6. Modify the front panel.

1 The Max Voltage and Min Voltage values correspond to the highest and lowest
voltage values that you expect to measure. 0 to 5 corresponds to the voltage
range that the fan uses to set the fan speed.
2 Replace the Fan Speed numeric with a Horizontal Fill Slide (Silver). Set the
maximum value to 5, since that value corresponds to the top speed for the fan.

7. Save the VI.

© National Instruments | 5-15


Lesson 5 Programming with the NI-DAQmx API

Test
Verify that you are able to control the speed of the fan on the Sound and Vibration
Signal Simulator.

1. Configure the Sound and Vibration Signal Simulator so that your VI will be able to
control the fan speed.

 Ensure that the Fan Speed Control switch is set to BNC.

 Ensure that the switch between the fans is set to Balanced Fan.

2. Run the VI.

3. Adjust the value of Fan Speed on the FP. Observe that the fan speed on the Sound
and Vibration Signal Simulator changes accordingly.

4. If you completed Exercise 5-3, open Read Fan Acceleration.vi and modify it to
read tachometer values as you adjust the fan speed from Fan Speed Control.vi.

 Modify Read Fan Acceleration.vi to measure the current fan speed.

– Instead of reading accelerometer values from AI0 and AI1 for the NI 9234,
read data from AI2.

AI2 is connected to the Tach Out terminal on the Sound and Vibration Signal
Simulator. That terminal outputs data from a tachometer that reads the fan
speed from the selected fan.

 Run Read Fan Acceleration.vi.

 Calculate the fan speed at max speed.

– Set Fan Speed to 5.

– Stop the VI.

Beneath the Tach Out terminal on the Sound and Vibration Signal Simulator,
there is a label that indicates that the tachometer generates two pulses per
revolution of the fan.

– Show the Graph Palette for the waveform graph and use the Zoom tool to
view approximately two cycles of tachometer data.

– How long does it take for two cycles to complete?______________________

– Given that two pulses correspond to one revolution of the fan, how fast is
the fan spinning?_______________________

End of Exercise 5-4

5-16 | ni.com
6 Programming
Multiple
Channels

At the end of this lesson you will be able to describe the


different ways you can create multi-channel tasks and
when you can use them.

Topics
+ Resources

Exercises
Exercise 6-1 Measuring Voltage and Temperature in a Single Task
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Selecting More than One Channel on a Device

Article Location

Physical Channel Syntax Info code: channelsyntax

Use Different Modules in Same Task

Article Location

Channel Expansion Explained Info code: channelexp

When to Use Channel Expansion

Article Location

Multidevice Tasks— Info code: multitask


• C Series
• S Series
• DSA, SC Express, and X Series

© National Instruments | 6-3


Lesson 6 Programming Multiple Channels

Exercise 6-1 Measuring Voltage and Temperature in a


Single Task
Goal
Create a VI that communicates over multiple channels of the same type.

Scenario
You need to make sure that the solar panel controller does not overheat while testing
the solar panels under maximum voltage. You want to write an application to measure
the temperature and voltage generation.

In this exercise, you create a VI that measures both temperature and voltage using
two different C Series modules but only one task.

Requirements
• The solar panel temperature shall not exceed 30 °C.
• A J-type thermocouple is placed over the solar panel to measure the temperature.
• Solar panel wiring information is located in Appendix A.

Implementation
1. Create a project LabVIEW project containing an analog input VI.

a. Open the LabVIEW NI-DAQmx example VI named


Voltage - SW-Timed Input.vi.

b. Save the VI as Solar Panel Test.vi in the <Exercises>\DAQ\


Solar Panel Test folder.

c. Create a new LabVIEW project by selecting Project»Create Project from the


LabVIEW menu.

d. Click Blank Project from the Create Project dialog box and click the Finish
button.

e. When prompted, click Add to add the Solar Panel Test VI to the project.

f. Save the project as Solar Panel Test.lvproj.

6-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

2. Make room between the DAQmx Create Virtual Channel VI and the DAQmx Start
Task VI.

Tip Press the <Ctrl> key while dragging the cursor from right to left to
easily make room.

3. Change the timing of the VI from software to hardware by removing the Wait (ms)
function and Loop Time control and adding a NI-DAQmx Timing VI.

4. Update the block diagram to take a voltage measurement from the solar panel and
display the value on a waveform chart.

a. Add or update the controls and indicators as shown in the following block
diagram.

b. Run the VI to make sure it is taking proper voltage values from the solar panel.

 On the front panel, enter the values for Voltage Channel, Max Voltage,
Min Voltage, and Terminal Configuration.

 Turn off auto-scaling on the y-axis for the waveform chart and set the min and
max voltages according to your specifications for the solar panel.

 Change the Sample rate to 10 Hz.

© National Instruments | 6-5


Lesson 6 Programming Multiple Channels

5. Now that your task can take a voltage measurement, add a virtual channel to the
task to measure temperature.

a. Which instance of the DAQmx Create Virtual Channel VI should you select to
take a temperature measurement from your hardware kit?__________________

b. From the specs for the NI 9213, what cjc source should you use?____________

c. You do not have to create constants or controls for all of the input to the
DAQmx Create Virtual Channel VI, but make sure your block diagram contains
the following controls and constants.

d. Clean up the front panel to accommodate the new controls.

6-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

6. Update the block diagram to include a second chart to map the temperature
reading.

a. You’ll need to include an Index Array to split the output. Make sure you adjust
the Write VI to NChan 1Samp.

1 DAQmx Write VI—Change to Analog 1D DBL NChan 1Samp.


2 Index Array—Splits the output from the two sensors.

b. Clean up the front panel to see the new graph.

© National Instruments | 6-7


Lesson 6 Programming Multiple Channels

7. Run the VI to make sure it is taking proper temperature values from the
thermocouple.

 On the front panel, enter the values for Temperature, Thermocouple Type, and
Temperature Units.

 Turn off auto-scaling on the y-axis of the Thermocouple waveform chart and
set the min and max amplitude according to your estimate of the range of
temperature values.

 Change the Sample rate to 10 Hz, if necessary.

Test
Verify the VI can acquire both temperature and voltage data.

1. Verify that the input values on the front panel are correct and run the VI.

Tip Refer to Appendix A, Section C,Thermocouple Information for


information about the wiring of the thermocouple.

2. Hold the thermocouple between your fingers to increase the temperature.

3. Cover the light sensor or use a flash to decrease and increase the sensor lighting.

4. Stop the VI after acquiring some data.

Now you want to see the data values in a spreadsheet like Excel.

1. Right-click in either the Solar Panel Data or Thermocouple graphs and select
Export»Export Data To Clipboard.

2. Open a spreadsheet application, like Excel, or a text editor.

3. Paste the data into a blank spreadsheet or document.

4. What do you notice about the formatting of the data?_________________________

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

5. What do you notice about the data collected?_________________________________

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

Challenge
You want modify your application to measure the temperature and voltage generation
and notify the technician of an overheating situation. Update your Solar Panel Test VI
according to the following requirements.
• Add a control that allows the user to set the temperature at which a warning
notification displays.
• Display an indicator the easily communicates the status of the solar panel
temperature. For example, the indicator could be green during normal operation
and red when the temperature exceeds the limit set by the user.

End of Exercise 6-1

6-8 | ni.com
7 Triggering on a
Specific
Condition

At the end of this lesson you will be able to modify a DAQ


VI to begin data acquisition on a specific condition and
understand how to use hardware sources as triggers.

Topics
+ Resources

Exercises
Exercise 7-1 Adding Hardware Triggers
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Triggering to Synchronize

Article Location

Synchronizing Analog Input C Series Modules with Info code: synchcseries


NI-DAQmx

Implementing a Pause Trigger

Article Location

Tips and Techniques in Data Acquisition Triggering Info code: techniqdaqmx

Analog vs Digital Triggering

Article Location

Tips and Techniques in Data Acquisition Info code: techniqdaqmx


Triggering - NI-DAQmx

© National Instruments | 7-3


Lesson 7 Triggering on a Specific Condition

Exercise 7-1 Adding Hardware Triggers


Goal
Use the DAQ modules in your suitcase to generate a tone when a digital trigger is
received on PFI0. 

Scenario
You have a VI that generates a tone at a given frequency through a speaker.

In this exercise, you add a hardware trigger to the VI so that the tone only occurs after
you push the trigger button on the cDAQ Measurements Demo Box.

Implementation
1. Open the Tone Generation VI, located in the <Exercises>\DAQ\Tone Generation
folder and display the block diagram.

1 2

1 For buffered write operations, the DAQmx Write VI must run before the DAQmx Start Task VI to ensure
that the buffer has data to write when the task starts.
2 DAQmx Wait Until Done VI—This VI ensures that the tasks is not accidentally cleared before all samples
are written.

2. Explore the block diagram.

a. Which module should you specify to generate the signal?__________________

b. Is this a finite or continuous signal generation?____________________________

c. How long will the tone last?_____________________________________________

d. Why does the DAQmx Write VI come before the DAQmx Start VI in this task?
_______________________________________________________________________
_______________________________________________________________________
_______________________________________________________________________

e. Which DAQmx VI ensures that the specified operation is complete before


stopping the task?______________________________________________________

7-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

3. Update the block diagram so that the signal generation waits until you trigger it
with the Trigger button on the cDAQ Measurements Demo Box.

a. Insert the DAQmx Trigger VI between the DAQmx Timing VI and the
DAQmx Write VI.

b. Select the correct instance of the DAQmx Trigger VI. Consider the following
questions to determine the correct instance.

• Is the Trigger button an analog or digital control?_____________________

• Do you want the tone to sound before or after you push the Trigger
button? ___________________________________________________________

4. Create a constant or control to specify the source of the DAQmx Start Trigger.

5. Enter an appropriate value for the source of the trigger.

Tip What line is the Trigger button on the demo box connected to?
___________
(Refer to Table A-1, Connections in the NI CompactDAQ Measurements
Demo Box, in Appendix A, to determine which channel is connected to the
Trigger button.)

Test
1. Verify that all controls and constants refer to valid channel in the demo box.

2. Click the run button on the VI and verify that no sound is generated.

3. Press the Trigger button on the demo box to hear the generated sound.

End of Exercise 7-1

© National Instruments | 7-5


Lesson 7 Triggering on a Specific Condition

7-6 | ni.com
8 Advanced
Timing and
Synchronization
Methods

At the end of this lesson you will be able to use an


appropriate method for synchronizing multiple DAQ tasks
using the DAQmx API, hardware triggers, and shared
timing source.

Topics
+ Resources

Exercises
Exercise 8-1 Simultaneously Started Analog Input and Output
Exercise 8-2 Sharing a Sample Clock
Exercise 8-3 Synchronizing with a Master Timebase
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

What clocks does your device have?

Article Location

Clocks Info code: clocks

Jitter

Article Location

Digital Timing: Clock Signals, Jitter, Hysteresis, and Eye Info code: jitter
Diagrams

Using External Clock Signals

Article Location

Reference Clock Synchronization Info code: clocksynch

Master Timebase Implementation

Article Location

Master Timebase Synchronization Info code: synchtimebase

Synchronizing Specific Hardware Series

Article Location

Synchronizing Analog Input C Series Modules with Info code: synchcseries


NI-DAQmx

M Series Synchronization with LabVIEW and Info code: synchmseries


NI-DAQmx

Synchronization Explained Info code: synchexplain

Timing and Synchronization Systems Info code: synchsystems

© National Instruments | 8-3


Lesson 8 Advanced Timing and Synchronization Methods

Exercise 8-1 Simultaneously Started Analog Input


and Output
Goal
Compare simultaneous data acquisition tasks with tasks using different triggers.

Scenario
In this exercise you explore the problems with using software to trigger different tasks
and you create VIs using different methods to simultaneously generate and measure
analog signals.
• Part A: Relying on Software to Trigger Tasks
• Part B: Using the Start Trigger to Trigger Tasks
• Part C: Using a Hardware Trigger to Trigger Tasks

Hardware Configuration
Using two wires, connect an analog output channel from the NI 9263 to an analog
input channel of the NI 9215. Be sure to note which channel you use for output and
which channel you use for input.

Part A: Relying on Software to Trigger Tasks


1. Open the Start Trigger Synchronization project in the
<Exercises>\DAQ\Start Trigger Synchronization directory.

2. From the Project Explorer window, open Simultaneous Start (1).vi.

3. Examine the block diagram.

1 The top row is a task that measures a finite, buffered analog input acquisition and displays the acquired
data on the 1st samples waveform graph.
2 The bottom row is a task that generates a finite, buffered analog output signal. The output waveform is
generated by the Sine Waveform VI and is displayed on the signal out waveform graph.
3 Note that the signal out graph displays the waveform before the waveform is generated on the analog
output device.

8-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

4. Set the front panel controls for the Simultaneous Start VI.
• AI Channel: Specify the channel you wired in Hardware Configuration.
• Input Rate: 1000
• AO Channel: Specify the channel you wired in Hardware Configuration.
• Output Rate: 1000

5. Run the VI several times and compare what you see in the two graphs.

 Does the 1st samples graph display the same waveform every time it runs?

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

 What causes the flat line at the beginning or end of the 1st samples plot?

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

What’s Happening
Because the VI is using the Flat Sequence Structure and the two NI-DAQmx Start Task
VIs to trigger and begin the data acquisition, the OS is controlling when the analog
output and analog input tasks begin. As you see from the graphs, the analog input
often begins before the analog output. This causes the analog input signal measured
(shown in the 1st sample graph) to finish before all of the output signal has generated.
The flat line at the end of the graph indicates that the buffer was empty when the
analog input task tried to read the samples.

Part B: Using the Start Trigger to Trigger Tasks


1. Modify the VI to start two tasks at the same time by using the implicit
StartTrigger signal which the NI-DAQmx Start VI calls.

a. Save the VI as Simultaneous Start (2).vi and add it to the project.


• Select File»Save As and select Open additional copy
• Make sure that the Add copy to Start Trigger synchronization.lvproj
checkbox has a checkmark.

b. Before updating the block diagram, answer the following questions:

 Which task, analog input (top row) or analog output (bottom row), is the
master task and which task is the slave task? Why?

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

 Because you must complete the configuration of all slave tasks before starting
the master task, which Start Trigger should you use in this VI?
ai/StartTrigger or ao/StartTrigger?
________________________________________________________________________

Tip From the NI-DAQmx Help: To perform Start Trigger synchronization,


configure the start triggering on all slave tasks by setting the trigger source
to the internal Start Trigger terminal of the master task, such as
ao/StartTrigger.

© National Instruments | 8-5


c. Complete the block diagram as shown below.
8-6

Lesson 8
|
ni.com

Advanced Timing and Synchronization Methods


3

1 NI-DAQmx Trigger VI—Select the Start»Digital Edge instance from the pull-down menu.
2 /cDAQ1/ao/StartTrigger—By specifying the ao/StartTrigger as the trigger source, you ensure that the acquisition does not begin
before the output task begins generation because the analog input task is dependent on the analog output trigger. cDAQ1 refers to your
device.
3 Merge Errors VI—Merging the analog input task data flow with the analog output task data flow ensures that the analog input task does
not start before the analog output task is ready.

2. Save the VI.

Test
1. Set the front panel controls for the Simultaneous Start (2) VI.
• AI Channel: Specify the channel you wired in Hardware Configuration.
• Input Rate: 1000
• AO Channel: Specify the channel you wired in Hardware Configuration.
• Output Rate: 1000

2. Run the VI.


Data Acquisition Using NI-DAQmx and LabVIEW

3. Run the VI several times and compare what you see in the two graphs.

 Does the 1st samples graph display the same waveform every time it runs?

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

 Is the 1st samples plot the same as the signal out plot?

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

What’s Happening
By specifying the ao/starttrigger for the analog input task, you guarantee that both
tasks begin at the same time because the analog output NI-DAQmx Start Task VI
implicitly calls the ao/starttrigger if no other trigger is specified. In other words, on
a hardware level, both tasks begin on the exact same clock pulse.

Part C: Using a Hardware Trigger to Trigger Tasks


1. Add a hardware trigger to start two tasks simultaneously, as shown below.

1 NI-DAQmx Trigger VI—Select the Start»Digital Edge instance.


2 source constant—Right-click the source input, select Create»Constant and
specify /cDAQ1/PFI0 as the value.
3 edge constant—Right-click the edge input, set the edge constant to Falling so
that it triggers when the trigger button on the demo box is pushed.

2. Save the VI as a Copy and Substitute the copy for the original.

Name the VI as Simultaneous Start with Hardware Trigger.vi in the


<Exercises>\DAQ\Synchronization directory.

Test
1. Run the VI.

2. Press the TRIGGER button on the demo box.

When you press the TRIGGER button, it produces a falling edge on the PFI 0 line
of the cDAQ-9178 chassis. The falling edge received on the PFI 0 line triggers the
analog output task to begin. The analog input task is configured to begin on the
first edge of the analog output sample clock, so both analog input and analog
output tasks will start simultaneously.

3. Stop the VI.

End of Exercise 8-1

© National Instruments | 8-7


Lesson 8 Advanced Timing and Synchronization Methods

Exercise 8-2 Sharing a Sample Clock


Goal
Synchronize the analog input acquisition on a cDAQ device to the analog output
generation on a separate DAQ device using a shared sample clock and hardware
trigger.

Hardware Configuration
Make sure that the NI 9263 (analog output) module is directly wired to the NI 9215
(analog input) module. You can use the same configuration you used in Exercise 8-1
on page 8-4.

Scenario
In this exercise, you modify the Simultaneous Start (3) VI from the previous exercise
to synchronize the analog output and analog input by sharing the same sample clock.

Implementation
1. Create a copy of the Simultaneous Start (3) VI you created in Exercise 8-1 and add
it to a new project, Shared Sample Clock.

a. Open the Simultaneous Start (3) VI and save as


Multidevice AO AI Synchronization.vi in a new directory,
<Exercises>\DAQ\Sample Clock Sharing.

Tip In the Save As dialog box, select Open additional copy and make sure
there is no checkmark in the Add copy to... checkbox.

b. Select Project»Create Project and create a new project named


Shared Sample Clock.lvproj in the <Exercises>\DAQ\Sample Clock
Sharing folder.

c. Add the Multidevice AO AI Synchronization VI to the Shared Sample Clock


project.

8-8 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

2. Open the block diagram of Multidevice AO AI Synchronization.vi and answer


the following questions.

a. What is the syntax for specifying that the analog input task use the start
trigger from the analog output device?____________________________________

b. Using the same syntax, how do you think you specify the source of the analog
input DAQmx Timing VI to use the analog output sample
clock?__________________________________________________________________

__ ___ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

c. Modify the block diagram as shown below to share the analog output sample
clock.

1 Right-click the source input of the analog input DAQmx Timing VI and select
Create»Constant. Use the drop down list to select the analog output sample
clock, cDAQ1/ao/SampleClock.
2 Sine Waveform VI—Note that by default, this VI generates a sine wave of 1000
samples at 1 S/s (samples per second).

3. Update the DAQmx Read VI to output data in a waveform data type so that the
data contains a timestamp.

© National Instruments | 8-9


Lesson 8 Advanced Timing and Synchronization Methods

4. Complete the following steps to change the 1st samples chart on the front panel
into a waveform graph and adjust the display to match the image below.

a. Right-click the 1st samples chart and select Properties.

b. On the Scales tab click the Minor grid box in the Grid Style and Colors section
and select T to make the x-axis minor grid lines transparent.

8-10 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

c. Select Amplitude (Y-Axis) from the drop-down menu on the Scales tab and
make the Minor grid lines transparent.

5. Save the VI.

Test
1. Set the front panel controls for the analog input and analog output channels you
used in Exercise 8-1.

2. Make sure the input rate and output rate are 1000.

Tip Right-click a chart on the front panel and select Data Operations»
Clear Graph to reset the chart.

© National Instruments | 8-11


Lesson 8 Advanced Timing and Synchronization Methods

3. Run the VI. After pressing the trigger on the demo box, the front panel updates.

Note that the 1st samples graph updates one second after pressing the trigger
button on the demo box. The graph updates in one second because the analog
output is generating 1000 samples at 1000 samples per second. (Refer to the
block diagram notes in step 2 on page 8-9.)

4. Change the input rate to 500 and run the VI again.

1 Note that the 1st samples graph updates at the same rate as before, but the time
stamp displays 2 seconds instead of 1. Sharing a sample clock does not allow you
to run the acquisition at different rates.

8-12 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

5. Change the input rate to 1000, change the output rate to 250, and run the VI again.
Count the number of seconds it takes to update the 1st samples chart after you
press the trigger button the demo box.

1 Note that the 1st samples graph time displays 1 second. However, by counting
seconds after pressing the trigger button on the demo box, you know that the
acquisition actually took four seconds. This chart is displaying inaccurately
synchronized data.

6. What happens to the graphs when you change the output rate to 1000 and the
input rate to 2000? Write your guess here before running the VI to find out.

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

7. Save and close the VI and project.

End of Exercise 8-2

© National Instruments | 8-13


Lesson 8 Advanced Timing and Synchronization Methods

Exercise 8-3 Synchronizing with a Master Timebase


Goal
Synchronize two operations the acquire data at different rates by using a reference
clock as a clock source.

Scenario
You are monitoring how hot a solar panel gets as it is generating voltage over the
course of an afternoon. Because temperature does not change as quickly as the
voltage generated, you want to sample at a slower rate to save storage space.

In this exercise you synchronize two C Series modules using a master timebase on the
backplane of the cDAQ chassis.
• NI 9213—Delta-Sigma ADC using a scanning sampling mode (slow sample device)
• NI 9215—SAR ADC using successive approximation

Implementation
1. Open the Timebase Synchronization project in the <Exercises>\DAQ\Timebase
Synchronization directory.

2. From the Project Explorer window, open Timebase Synchronization.vi.

8-14 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

3. Examine the block diagram. Part of the VI is already coded for you.

1 2 3

1 Channel settings—The DAQmx Create Virtual Channel VIs are already set up to accept a channel for the
light sensor task and the thermocouple task.
2 Timing settings—The DAQmx Timing VIs are set up to take continuous samples at a specified sample
rate.
3 Trigger settings—The DAQmx Start Trigger VIs still need a trigger source defined.
4 While Loop—The While Loop already contains code to read data from the light sensor and thermocouple
tasks and display that data on a graph on the front panel. The number of samples per channel input
should match the sample rate specified in the DAQmx Timing VI.

4. Update the trigger settings portion of the application so that both tasks start when
the trigger button on the demo box is pressed.

1 Right-click the terminal and select Create»Constant from the shortcut menu to create a constant.
2 Click the constant and specify the PFI0 line for the cDAQ chassis. Refer to Table A-1 to confirm which
PFI line is wired to the physical trigger on the box.

Note Because both tasks are using the same external hardware trigger to
begin the task, so you do not have to designate one task as slave and one
as master.

© National Instruments | 8-15


Lesson 8 Advanced Timing and Synchronization Methods

5. Place a DAQmx Timing property node on the block diagram by right-clicking the
block diagram and selecting Measurement I/O»NI DAQmx»Timing Node from the
palette.

6. Update the node to use the sample clock timebase source property.

Click the terminal and select Sample Clock»Timebase»Source to specify the


property.

7. Expand the node to display the SampClk.Timebase.Rate property using the cursor
to drag the top handle of the node, as shown below.

Note Whenever you specify an external source for a timebase, you must
also specify the rate of the source.

8. Copy and paste the configured timing node so that you have two nodes on the
block diagram.

8-16 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

9. Wire one timing node in between the DAQmx Timing VI and


DAQmx Start Trigger VI for each task, as shown below.

10. Create a constant for both SampClk.Timebase.Rate and SampClk.Timebase.Src


properties and wire them to each node, as shown below.

Tip Right-click the property terminal and select Create»Constant from the
shortcut menu to create a constant.

Because you wire the same value to both nodes, each task will use the same
source to create its sample clock.

© National Instruments | 8-17


Lesson 8 Advanced Timing and Synchronization Methods

11. Click the I/O Name constant and select a timebase for the sample clock. In this
exercise, select the 20 MHz Timebase from the cDAQ chassis as shown below.

12. Update the constant for the SampClk.Timebase.Rate property to be 20000000.

Note Whenever you specify an external source for a timebase, you must
also specify the rate of the source.

13. Save the VI after confirming that the Run button is not broken.

8-18 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Test
In this test you compare measurements taken at the same sample rate and
measurements taken at different sample rates.

1. Set the controls to the following values:

Control Value

Physical channel - light sensor Channel connected to solar panel in demo box
Sample rate - light sensor 1000

Samples to read - light sensor 1000

Physical channel - temperature Channel connected to thermocouple in demo box


Sample rate - temperature 1000

Samples to read - temperature 1000

2. Run the VI and press the trigger button on the demo box when you are ready to
start your measurements.

3. Adjust the temperature and light reaching the light sensor and then press stop on
the front panel to stop the VI. Your graphs may be similar to the image below.

Notice that the Light Sensor data fluctuates rapidly, but the Temperature data
changes only approximately every 0.1 seconds.

© National Instruments | 8-19


Lesson 8 Advanced Timing and Synchronization Methods

Because the temperature does not change as quickly as the voltage from the light
sensor, you can save storage space by decreasing the sample rate for the temperature
analog input task.

4. Set the Sample rate - temperature control to 100 and leave the Samples to read -
temperature control at 1000.

Tip We select a sample rate of 100 because from the graph above we see
that the temperature samples change only 10 times. 1000 divided by 10
equals. 100.

5. Run the VI and press the trigger button on the demo box when you are ready to
start your measurements.

Why does the VI time out? __________________________________________________

___________________________________________________________________________

6. Set the Sample rate - temperature control to 100 and set the Samples to read -
temperature control to 100.

7. Run the VI and press the trigger button on the demo box when you are ready to
start your measurements.

8. Compare the look of the Temperature graph at a sample rate of 100 with the
Temperature graph at a sample rate of 1000 (step 3, page 8-19).

8-20 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

9. Export the data to a spreadsheet to compare the samples.

a. Right-click the Light Sensor graph and select Export»Export Data to Clipboard.

b. Open up Excel or another spreadsheet software and paste the data.

c. Right-click the Temperature graph and select Export»Export Data to Clipboard.

d. Paste the data into a column next to the light sensor data.

10. Compare the data in the spreadsheet.

a. How many data points are in the Light Sensor column? ____________________

b. How many data point are in the Temperature column?_____________________

Notice that the light sensor data column has nine data points between each
temperature data point, as shown below.

11. Close and VIs and spreadsheet program when you are done exploring.

End of Exercise 8-3

© National Instruments | 8-21


Lesson 8 Advanced Timing and Synchronization Methods

8-22 | ni.com
9 Logging
Measurement
Data to Disk

At the end of this lesson you will be able to log data to a


TDMS file to store and analyze post-acquisition.

Topics
+ Resources

Exercises
Exercise 9-1 Streaming Fan Acceleration Data to Disk
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

TDMS File I/O VIs vs. DAQmx TDMS VIs

Article Location

The NI TDMS File Format Info code: tdmsfileformat

Customize Logging Behavior With Property Nodes

Article Location

DAQmx Write Properties Info code: daqmxwriteprop

DAQmx Read Properties Info code: daqmxreadprop

Use TDMS Metadata to Avoid File Format Pitfalls

Article Location

Writing Data-Management-Ready TDMS Files Info code: datamanfiles

Offline Processing

Article Location

TDM Excel Add-In for Microsoft Excel Download Info code: exceladdin

Moving Beyond Microsoft Excel for Measurement Info code: datareport


Data Analysis and Reporting

Review: Data Best Practices for DAQ

Article Location

Best Practices for Saving Measurement Data Info code: loggingdata

© National Instruments | 9-3


Lesson 9 Logging Measurement Data to Disk

Exercise 9-1 Streaming Fan Acceleration Data to Disk


Goal
Open an existing data acquisition VI and modify it to write measurement data to a
TDMS file.

Scenario
Earlier in this course, you created a VI that read accelerometer data from a fan to assist
in determining whether or not the fan was damaged. The end-user has provided
feedback that they would like to be able to view that data independently of the
application.

In addition to the numeric data, they would like the file to also include header
information to provide context for that data.

Design
You decide to use the TDMS file format so that you can stream at high speeds and
use the benefits of the built-in file and channel attributes that come with that format.

Implementation
1. Open Read Fan Acceleration.lvproj.

 If you completed Exercise 5-3, navigate to


<Exercises>\DAQ\Continuous Input\ and open Read Fan
Acceleration.lvproj.

 If you did not complete Exercise 5-3, navigate to


<Solutions>\DAQ\Exercise 5-3\ and open Read Fan Acceleration.lvproj.

2. Create a copy of the project.

 In the project window, select File»Save As.

 Select Duplicate .lvproj file and contents. Click Continue.

 Save the project as <Exercises>\DAQ\Logging Data\Read and Log Fan


Acceleration.lvproj.

3. Open Read and Log Fan Acceleration.lvproj.

4. Rename Read Fan Acceleration.vi to Read and Log Fan Acceleration.vi.

9-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

5. Modify the block diagram to stream the acquired data to a TDMS file and view the
file at the end of the acquisition.

1 2

1 DAQmx Configure Logging VI—This VI modifies the NI-DAQmx task to write acquired data directly to
the specified TDMS File. Set the logging mode to Log and Read so that you can read data from the file
in this same VI. Group Name creates a common grouping in the TDMS file for both acceleration channels.
2 TDMS File Viewer—This method launches the TDMS File Viewer UI, enabling you to view the TDMS
attributes and data.

6. Modify the front panel to group the timing controls together and set the control
values.

2
3

1 If you right-clicked on inputs to the NI-DAQmx Configure Logging VI to create


these controls, they will be Modern controls. The controls shown here are Silver
controls. You can right-click a control and select Replace to change the
appearance of a control.
2 Set Group Name to Balanced Fan. The Group Name determines how the data will
be grouped within the TDMS file.
3 Set File Path to <Exercises>\DAQ\Logging Data\Fan Acceleration.tdms.

7. Save the VI.

© National Instruments | 9-5


Lesson 9 Logging Measurement Data to Disk

Test
1. Acquire and log data for a balanced fan.

 Configure the Sound and Vibration Signal Simulator.

– Set the Fan Speed Control to DIAL.

– Toggle the switch to acquire data for the BALANCED FAN.

– Turn the Fan Speed Control Knob clockwise to the maximum speed for the
fan.

 Run the VI.

 Acquire approximately five seconds of data and click Stop.

2. Review the data acquired and logged to the TDMS file.

 In the TDMS File Viewer window that appears, select Fan Acceleration.tdms.

– In the Properties tab, note that the property name is set to Fan
Acceleration. This is based on the name of the TDMS file.

– Switch to the Analog values (graph) tab. Here you can see all of the data
currently stored in the TDMS file.

 Navigate to Fan Acceleration.tdms»Balanced Fan.

– This corresponds to the Group Name that you specified on the front panel
of the VI.

– Here, you can see the data read from each channel during this acquisition.

 Switch to the Values (table) tab.

– Here you can see the data in table form.

 Navigate to Fan Acceleration.tdms»Balanced Fan»cDAQ1Mod7/ai0.

– Switch to the Properties tab. Here you can see the various attributes that
were recorded by default for that channel.

– Switch to the Analog values (graph) tab. Here you can view the data
acquired for just that channel.

 Click Quit.

3. Acquire and log data for an unbalanced fan.

 Configure the Sound and Vibration Signal Simulator.

– Toggle the switch to acquire data for the UNBALANCED FAN.

 Run the VI.

 Acquire approximately five seconds of data and click Stop.

9-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

4. Review the data acquired and logged to the TDMS file.

 Expand Fan Acceleration.tdms.

– Note that now there are two groups. You can view all of the data together
by selecting Analog Values (graph).

– You can use this view to quickly compare data sets. In this case, you can
clearly see the difference for both accelerometers when the fan is
unbalanced.

 To look at more specific data sets, navigate through the file contents tree to
select the group or specific channel that you are interested in viewing.

Challenge
Modify the Read and Log Fan Acceleration VI to write additional property data to the
TDMS file.

Tips:
• Use a property node to programmatically obtain information about a channel or
task.

• Use the TDMS functions to open, set properties, and close the file.

• You will need to write this property data before you call the NI-DAQmx Configure
Logging VI, because that function reserves the file for the duration of the
acquisition.

End of Exercise 9-1

© National Instruments | 9-7


Lesson 9 Logging Measurement Data to Disk

9-8 | ni.com
10 System
Considerations

At the end of this lesson you will be able to list other


considerations in building a data acquisition system,
including factors affecting the choice of hardware, bus,
and OS.

Topics
+ Resources
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Bus Comparison

Article Location

How to Choose the Right Bus Info code: choosebus

When Do You Need Real-Time OS?

Article Location

Do I Need a Real-Time System? Info code: needrt

© National Instruments | 10-3


Lesson 10 System Considerations

10-4 | ni.com
A NI compactDAQ
Measurements
Demo Box
Information

This section information about the components and wiring


of the NI CompactDAQ Measurements Demo Box used in
this course.

Topics
A. NI CompactDAQ Measurements Demo Box Overview
B. Light Sensor Information
C. Thermocouple Information
D. Strain Gage Information
E. Speaker Information
F. Sound and Vibration Signal Simulator Box Information
G. LEDs Information
Data Acquisition Using NI-DAQmx and LabVIEW

A. NI CompactDAQ Measurements Demo Box


Overview
The following figure and table describe the demo box contents and connections.
Figure A-1. Overview of CompactDAQ Measurements Demo Box Components

1 USB Input 7 NI 9472 (Digital I/O) 12 Sound and Vibration


2 Demo Kit Power 8 NI 9263 (Analog Signal Simulator Box
3 Speaker Output) 13 J-Type Thermocouple
4 NI cDAQ-9178 Chassis 9 NI 9234 (Analog 14 Trigger Button
5 NI 9236 (Analog Input—IEPE) 15 LEDs (0-7)
Input—Strain) 10 NI 9215 16 Strain Gauge Bar
6 NI 9213 (Analog Input—Voltage 17 Audio Input Port
(Analog Input—Temper )
ature) 11 Solar Panel

© National Instruments | A-3


Appendix A NI compactDAQ Measurements Demo Box Information

Table A-1. Connections in the NI CompactDAQ Measurements Demo Box

Module Channel I/O

PFI 0 Trigger

cDAQ-9178 USB Kit USB Port

VDC Power

NI 9213 AI 0 J-Type Thermocouple

AI 0 Solar Panel/Light sensor


NI 9215
AI 1 Audio In Aux Port

Ch 0 X Accelerometer

NI 9234 Ch 1 Y Accelerometer

Ch 2 Tachometer Out

NI 9236 AI 0 Strain bar

AO 0 Speaker
NI 9263
AO 1 Fan Speed Control

NI 9472 Port 0 LEDs 0:7

A-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

B. Light Sensor Information


The light sensor on the right side of the demo box is connected to the NI 9215 module
using one red and one black wire.

Solar Panel Description and Specification


The following information is provided by the manufacturer.

Type/Brand Solar Mini-Panel/Solar Made

Voltage 0.5 V

Current 100 mA

Dimensions 1.75 inches x 1 inch

Weight 1 inch

Encapsulated mini-panels utilize solar cells similar to those that power our
satellites in space. Mini-panels allow for handling without the normal breakage and
cell damage associated with fragile solar cells. Available in thirteen outputs with
four case sizes to fit your every need. 6" red/black lead wires attached. Modules
may be connected to create different outputs.
All mini panels are tested VOC (voltage open circuit), ISC (current short circuit),
using one full sun condition.
General helpful hints - Most applications require charging batteries (the solar
operating voltage must be higher than the battery voltage). Direct powering of
devices requires knowing the voltage and current of your device. Science Projects:
Light bulbs - use light emitting diodes (LED) which require 3 volts, plus 50mA per
LED. Motors - Most important for operating miniature motors is the "current",
most other motors will require at least 200mA to 500mA of current with the
voltage being less important.

Wiring Diagram for the Solar Panel and the NI 9215


The following figure illustrates how the solar panel is connected to the NI 9215.

© National Instruments | A-5


Appendix A NI compactDAQ Measurements Demo Box Information

C. Thermocouple Information
The thermocouple is attached to the NI 9236 module in the middle of the demo box
using one red and one white wire.

Thermocouple Description and Specification


The following information is provided by the manufacturer.

For cost-sensitive applications, NI offers ready-made thermocouples—individual


packets of thermocouple wire with the measuring junction provided at one end.
Ready-made thermocouples are ideal for starter or educational applications.

J-Type Thermocouples Wire, Fiberglass (32 deg F to 900 deg F) 1 m

Conductor Limits of Error

Calibration Positive Negative Temp Range (whichever greater)

J-type Iron Constantan 32 to 900 °F ±4.0°F (2.2 °C)


(white) (Red) (0 to 482 °C or ±0.75%

Wiring Diagram for the Thermocouple and the NI 9213


The following figure illustrates how the solar panel is connected to the NI 9215.

A-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

D. Strain Gage Information


The strain gage is mounted on a metal bar on the left side of the demo box and is
connected to the NI 9236 module using one red, one white, and one black wire.

Strain Gage Description and Specification


The following information is provided by the manufacturer. The demo box uses the
CEA-XX-125UN-350 general purpose strain gage.
Universal general-purpose strain gages. Constantan grid completely encapsulated
in polyimide, with large, rugged copper-coated tabs. Primarily used for general
purpose static and dynamic stress analysis. Nominal gage factor for constantan is
2.10.

Based on the image in the specification, you can see that the strain gage is a
Quarter Bridge 1 type.

Quarter Bridge Type 1 Quarter Bridge Type 2

© National Instruments | A-7


Appendix A NI compactDAQ Measurements Demo Box Information

Wiring Diagram for the Strain Gage and the NI 9236


The following figure illustrates how the strain gage is connected to the NI 9236.

A-8 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

E. Speaker Information
The speaker is located on the left side of the demo box is connected to the NI 9263
module using one red and one black wire.

Speaker Description and Specifications


The following information is provided by the manufacturer.
The speaker measures only 2 1/8" in diameter and about 1 1/2" tall when closed
(about 2 1/8" tall when opened).The speaker comes with a combination
power/signal cable. Both the audio and power are carried to the speaker through
a USB mini-B connection.
Power Output ........................... 2.0W
AMP Freq Range ....................... 280Hz – 16KHz
Signal to Noise Ratio .................. ≥80dB
Charge voltage .......................... 5V±0.5V

Wiring Diagram for the Speaker and the NI 9263


The following figure illustrates how the NI 9263 module is connected to the
Sound and Vibration Signal Simulator box and the speaker.

© National Instruments | A-9


Appendix A NI compactDAQ Measurements Demo Box Information

F. Sound and Vibration Signal Simulator Box


Information
The Sound and Vibration Signal Simulator box is located in the front right side of the
demo box is connected to the NI 9263 module and the NI 9234 module using wires
and BNC connectors.

Sound and Vibration Signal Simulator Box Description and


Specifications
The following information is provided by the manufacturer.
The signal simulator box provides a basic rotor kit with two selectable vibration
sources, a balanced fan and an unbalanced fan, plus internal 2-axis
accelerometers. The signal accessory also includes a tachometer for the fans
which can be used in applications requiring order analysis and tracking.
Fan Speed Input (Analog Input)
Expected: .................................. 0 to 5 VDC
Absolute Rating:......................... ± 10V
Maximum fan speed.................... 6000 RPM
Analog Outputs:
Accelerometer Outputs ............... 2.5 V peak, 2.5V DC offset
Tachometer Output:.................... 0 to 5 V square wave, 2 pulses per revolution

Accelerometer Specifications
The following information is provided by the manufacturer.

A-10 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Wiring Diagrams for Sound and Vibration Signal Simulator


Box and the NI 9263 and NI 9234
The Sound and Vibration Signal Simulator box is wired to both the NI 9263 and the
NI 9234.

Wiring Diagram to the NI 9263


The following figure illustrates how the NI 9263 module is connected to the
Sound and Vibration Signal Simulator and the speaker.

Wiring Diagram to the NI 9234


The following figure illustrates how the NI 9234 module is connected to the
Sound and Vibration Signal Simulator. The accelerometer in the Sound and Vibration
Signal Simulator connects to channel 0 and channel 1.

© National Instruments | A-11


Appendix A NI compactDAQ Measurements Demo Box Information

G. LEDs Information
The eight LEDs are located on the left side of the demo box and are connected to the
NI 9472 module.

Aluminum LED Indicator Light Specifications


The following information is provided by the manufacturer.
An Indicator Light for flush mounting on a panel. Can be used to indicate that
status of a circuit.

Beam angle 25 degree

Connection Type 2 red/black wires

Dimmable Yes

IP Rating IP20

LED Type 3mm Super Bright LED

Polarity Sensitive Yes

Operating Voltage Range 12 VDC

Wire Gauge 22 AWG

Weight 13 grams

Housing Aluminum

Diameter 8mm

The demo box uses the following:

Color CCT(K)Wavelenth(nm) Lumen(lm) Current(mA)

Green 525 4 3

Amber 590 3 3

Red 625 3 3

A-12 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Wiring Diagram to the NI 9472


The following figure illustrates how the 9472 module is connected to the eight LEDs
in the demo box.

© National Instruments | A-13


B Measuring
Temperature

After this lesson you will be able to describe the basics of


temperature measurements and configure an NI-DAQmx
task to read them.

Topics
+ Resources

Exercises
Exercise B-1 Using NI-DAQmx to Measure Temperature with a
Thermocouple
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Article Location

Overview of Temperature Sensors Info code: tempsensors

Making a Thermocouple Measurement Info code: measurethermo


With NI LabVIEW

Temperature Measurements with Info code: measguide


Thermistors: How-To Guide

Taking Temperature Measurements with Info code: temperatureguide


RTDs: How-To Guide

© National Instruments | B-3


Lesson B Measuring Temperature

Exercise B-1 Using NI-DAQmx to Measure


Temperature with a Thermocouple
Goal
Open and run an example program to take a software-timed, temperature
measurement with the NI 9213 and a thermocouple.

Scenario
In this exercise, you use the specifications of a thermocouple and the NI 9213 C Series
module to verify a temperature reading. Instead of building a VI from scratch, you take
advantage of a NI-DAQmx shipping example to take a software-timed measurement.

Implementation
Note Make sure that all NI MAX test panels are stopped before completing
this exercise.

1. Refer to Thermocouple Information in Appendix A, NI compactDAQ


Measurements Demo Box Information to answer questions about the wiring of this
sensor.

a. Is the source sensor floating or grounded? ________________________________

b. What kind of terminal configuration is this wiring setup?

c. Which device pins are wired to the thermocouple?

2. Open the Example Finder. (Select Help»Find Examples in LabVIEW.)

3. Select Directory Structure on the Browse tab and locate the DAQmx folder.

B-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

4. Open Thermocouple - SW-Timed Input.vi located in the DAQmx»Analog Input


folder.

Notice that the front panel of the VI offers many of the same options that the test
panel in MAX offered.

© National Instruments | B-5


Lesson B Measuring Temperature

5. Update the front panel so that the VI uses the NI 9213 to read a voltage from the
thermocouple.

Parameter Hint Value

Physical Channel Which slot of the cDAQ chassis contains the


NI 9213 module? What is the answer to step 1c,
page B-4?

Max The thermocouple specification lists the maximum


Temperature, temperature. However, based on the temperature
Min Temperature of the room, what max or min values are practical?

Thermocouple Refer to the Thermocouple Information section of


Type Appendix A, NI compactDAQ Measurements Demo
Box Information.
CJC Source, CJC Refer to the NI 9213 DataSheet to determine if the
Channel NI 9213 has a built-in cold-junction compensation.
If the CJC Source is Channel, then you must
specify the channel.

CJC Value If the CJC source is Constant Value then you must
specify the value.

Auto Zero Mode Some hardware is capable of subtracting the None


measured ground voltage from every sample to
compensate for any offset errors. Use of the
autozero channel is optional.

6. Review the block diagram to see how the VI is implemented.

a. Right-click the Physical Channel control and select Find Terminal from the
shortcut menu.

B-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

b. Review the components of the block diagram. For a software-timed acquisition


application, you see the basic DAQ API structure: Create, Configure, Start,
Read/Write, Stop/Clear.

2 3 4

1 DAQmx Create Virtual Channel—Using the Context Help for this VI, you see that only the Physical
Channel input is required. However, the Thermocouple Type is important to specify to get accurate
readings. Because this is a simple acquisition, no further configuration is needed.
2 DAQmx Channel Property node—This node specifies whether to use the autozero channel of the NI 9213
module to calculate any offset error and subtract it from the measurement. The offset error reading from
the internal autozero channel is usually very small at room temperature, but if your testing environment
has a more extreme temperature condition, the offset error might be fairly significant.
3 DAQmx Start Task—Starting the task means that the device is ready to take a measurement.
4 The While Loop contains the DAQmx Read VI and controls the timing of the acquisition using the
Wait (ms) function. This means that the timing of the acquisition is dependent on the OS.
5 DAQmx Stop Task VI and DAQmx Clear Task VI—This example VI uses both for completeness, but the
NI-DAQmx Clear Task VI will stop the task if necessary.

Test
1. Run the VI.

2. Touch the thermocouple with your fingers to make the temperature rise.

3. Stop the VI.

4. Stop and close the VI without saving it.

End of Exercise B-1

© National Instruments | B-7


Lesson B Measuring Temperature

B-8 | ni.com
C Measuring
Sound,
Vibration, and
Acceleration
(IEPE
Measurements)

After this lesson you will be able to describe the basics of


IEPE measurements and configure an NI-DAQmx task to
read them.

Topics
+ Resources

Exercises
Exercise C-1 Using NI-DAQmx to Measure Vibration
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Article Location

AC and DC Coupling Info code: acdccoupling

Connecting Accelerometers to a DAQ Info code: connectaccel


Device

© National Instruments | C-3


Lesson C Measuring Sound, Vibration, and Acceleration (IEPE Measurements)

Exercise C-1 Using NI-DAQmx to Measure Vibration


Goal
Open and run an example program to take a vibration measurement.

Scenario
In this exercise, you use the NI 9234 and the Sound and Vibration Signal Simulator
hardware to validate a vibration measurement.

Implementation
Note Make sure that all NI MAX test panels are stopped before completing
this exercise.

1. Refer to in Appendix A, NI compactDAQ Measurements Demo Box Information to


answer questions about the wiring of this sensor. (Answers on page C-7.)

a. Which module pins are wired to the accelerometer in the Sound and Vibration
Signal Simulator box? ___________________________________________________

b. What is the minimum and maximum range, in g, that the sensor can read?
________________________________________________________________________
(Refer to the Accelerometer Specifications on page A-10.)

c. What is the sensitivity of the accelerometer?_______________________________

2. Refer to the NI 9234 Datasheet, located in


<Exercises>\DAQ\_Resources\Hardware Specifications, to answer questions
about the hardware connected to the sensor. (Answers on page C-7.)

a. Does the device have built-in voltage excitation?___________________________

b. How much excitation current, in Amps, does the NI 9234


provide?________________________________________________________________

3. Open the Example Finder. (Select Help»Find Examples in LabVIEW.)

C-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

4. Select Directory Structure on the Browse tab and locate the DAQmx folder.

5. Open IEPE - Continuous Input.vi located in the DAQmx»Analog Input folder.

Notice that the front panel of the VI offers many of the same options that the test
panel in MAX offered.

© National Instruments | C-5


Lesson C Measuring Sound, Vibration, and Acceleration (IEPE Measurements)

6. Update the front panel so that the VI uses the following values.

Parameter Hint Value

Physical Channel Which slot of the cDAQ chassis contains the NI


9234 module? What is the answer to step 1a,
page C-4?

Terminal Which configuration works with either source


Configuration reference?

IEPE Excitation Refer to the NI 9234 Datasheet or your answers


Source to questions in step 2, page C-4.

IEPE Current Refer to the NI 9234 Datasheet.


Value (A)

Max Refer to the accelerometer specs or your answers


Acceleration and to questions in step 1, page C-4.
Min Acceleration

Sensitivity Refer to the accelerometer specs or your answers


to questions in step 1, page C-4.

7. Review the block diagram to see how the VI is implemented.

1 DAQmx Create Virtual Channel—Using the Context Help for this VI, you see that
only the physical channels input is required.

Test
1. Run the VI.

2. Tap the side of the demo box and see how the signal changes.

Tip You might want to turn off the Y-axis autoscale to see the signal
better.

3. Stop the VI.

C-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

4. Change the Physical Channel input to a different channel on the NI 9234.

5. Run the VI and note any changes.

6. Stop and close the VI without saving it.

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

Answers from page C-4.


1. Refer to in Appendix A, NI compactDAQ Measurements Demo Box Information to
answer questions about the wiring of this sensor.

a. Which device pins are wired to the accelerometer in the Sound and Vibration
Signal Simulator box? AI0 and AI1

b. What is the minimum and maximum range, in g, that the sensor can read?
-5g to +5 g

c. What is the sensitivity of the accelerometer? 174 mV/g

2. Refer to the NI 9234 Datasheet, located in


<Exercises>\DAQ\_Resources\Hardware Specifications, to answer questions
about the hardware connected to the sensor.

a. Does the device have built-in voltage excitation? Yes

b. How much excitation current, in Amps, does the NI 9234 provide?


0.0021 Amps (typical)

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

End of Exercise C-1

© National Instruments | C-7


Lesson C Measuring Sound, Vibration, and Acceleration (IEPE Measurements)

C-8 | ni.com
D Measuring
Strain, Force, or
Pressure
(Bridge-Based
Measurements)

After this lesson you will be able to describe the basics of


bridge-based measurements and configure an NI-DAQmx
task to read them.

Topics
+ Resources

Exercises
Exercise D-1 Using NI-DAQmx to Measure Strain
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Article Location

Measuring Strain with Strain Gages Info code: measurestrain

Article Location

Load, Pressure, and Torque Measurements: How-To Info code: pressurehowto


Guide

Article Location

Connecting Strain Gages to a DAQ Device Info code: connectstrain

Article Location

Using Connection Diagrams for NI-DAQmx Tasks Info code: connectiontasks

© National Instruments | D-3


Lesson D Measuring Strain, Force, or Pressure (Bridge-Based Measurements)

Exercise D-1 Using NI-DAQmx to Measure Strain


Goal
Open and run an example program to take a software-timed, strain measurement with
the NI 9236 and a strain gage.

Scenario
In this exercise, you use the specifications of a strain gage and the NI 9236 C Series
module to verify a strain reading. Instead of building a VI from scratch, you take
advantage of an NI-DAQmx shipping example to take a software-timed measurement.

Implementation
Note Make sure that all NI MAX test panels are stopped before completing
this exercise.

1. Refer to Appendix A, NI compactDAQ Measurements Demo Box Information to


answer questions about the connection of this sensor. (Answers on page D-8.)

a. Which device pins are wired to the strain gage?___________________________


(Refer to the Wiring Diagram for the Strain Gage and the NI 9236 section in
Appendix A.)

b. Which bridge configuration type is the strain gage installed in the demo box?
________________________________________________________________________

c. What is the gage resistance, in ohms?_____________________________________

d. What is the gage factor?_________________________________________________

2. Refer to the NI 9236 Datasheet, located in


<Exercises>\DAQ\_Resources\Hardware Specifications, to answer questions
about the hardware connected to the sensor. (Answers on page D-8.

a. Does the device have built-in voltage excitation?___________________________

b. How much bridge excitation, in volts, does the NI 9236 provide?_____________

c. What is the minimum and maximum values, in volts, that the device can read?
________________________________________________________________________

3. Open the Example Finder. (Select Help»Find Examples in LabVIEW.)

D-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

4. Select Directory Structure on the Browse tab and locate the DAQmx folder.

5. Open Strain - Continuous Input.vi located in the DAQmx»Analog Input folder.

Notice that the front panel of the VI offers many of the same options that the test
panel in MAX offered.

© National Instruments | D-5


Lesson D Measuring Strain, Force, or Pressure (Bridge-Based Measurements)

6. Update the front panel so that the VI uses the NI 9236 to read a voltage from the
strain gage.

Parameter Hint Value

Physical Channel Which slot of the cDAQ chassis contains


the NI 9213 module? What is the answer to
step 1a, page D-4?

Minimum Value and What are the answers to step 2, page D-4?
Maximum Value

Strain Configuration What is the answer to step 1b, page D-4?

Lead Wire Resistance For now, assume that both of these are 0
and Initial Bridge nominal.
Voltage

Voltage Excitation What are the answers to step 2, page D-4?


Source and Voltage
Excitation Value

Gage Factor The gage factor for metallic strain gages is


usually around 2. The sensor
documentation may have more
information.

Nominal Gage What is the answer to step 1c, page D-4?


Resistance

Poisson Ratio The Poisson ratio for Constantan alloys .34


ranges between .34 and .35.

7. Review the components of the block diagram.

a. For a hardware-timed continuous acquisition application you begin on the left


of the block diagram with a basic DAQ API structure: create a virtual channel
and configure timing.

1
2

1 DAQmx Create Virtual Channel VI—Using the Context Help for this VI, you see that only the Physical
Channel input is required. However, the Bridge Information and Strain Gage Information is important to
specify to get accurate readings.
2 DAQmx Timing VI—This VI is necessary when you when to specify hardware-timed signal acquisition.

D-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

b. For strain gage applications, you might also need to configure additional signal
conditioning such as offset nulling or shunt calibration.

1 DAQmx Perform Bridge Offset Nulling Calibration—Performs a bridge offset


nulling calibration on the channels in the task.
2 DAQmx Perform Bridge Offset Nulling Calibration—Performs a bridge offset
nulling calibration on the channels in the task.

c. On the right of the block diagram you see the basic DAQ API structure: Start,
Read/Write, Stop/Clear.

1 3

1 DAQmx Start Task—Starting the task means that the device is ready to take a
measurement.
2 The While Loop contains the DAQmx Read VI. The Samples per Loop input
specifies the number of samples to read per loop iteration. For example, if the
sample rate is 100 Hz and the Samples per Loop is 100, the loop will execute
once per second.
3 DAQmx Stop Task VI and DAQmx Clear Task VI—This example VI uses both for
completeness, but the DAQmx Clear Task VI will stop the task if necessary.

Test
1. Run the VI.

2. What is the value generated by the gage before you press the strain bar?________

3. Press the strain bar and make sure that the VI registers a change on the Acquired
Data graph.

4. What is the maximum value you can generate? What is the smallest change you
can generate by pressing on the bar?_________________________________________

© National Instruments | D-7


Lesson D Measuring Strain, Force, or Pressure (Bridge-Based Measurements)

5. Stop and close the VI without saving it.

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

Answers from page D-4.


1. Refer to Appendix A, NI compactDAQ Measurements Demo Box Information to
answer questions about the connection of this sensor.

a. Which device pins are wired to the strain gage?

Pin Number Channel Name

Pin 1 EXC0

Pin 2 AIO

Pin 3 RC0

b. Which bridge configuration type is the strain gage installed in the demo box?
Quarter Bridge I

c. What is the gage resistance, in ohms? 350

d. What is the gage factor? 2.1

2. Refer to the NI 9236 Datasheet, located in


<Exercises>\DAQ\_Resources\Hardware Specifications, to answer questions
about the hardware connected to the sensor.

a. Does the device have built-in voltage excitation? Yes

b. How much bridge excitation, in volts, does the NI 9236 provide? 3.3 V

c. What is the minimum and maximum values, in volts, that the device can read?
-.0294 V and .0294 V

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

End of Exercise D-1

D-8 | ni.com
E Measuring
Position with
Encoders
(Counter Input)

After this lesson you will be able to describe the basics of


encoder measurements and how to configure a DAQmx
task to read them.

Topics
+ Resources

Exercises
Exercise E-1 Exploring an Encoder Application
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Article Location

Linear and Rotary Encoders Info code: encoders

© National Instruments | E-3


Lesson E Measuring Position with Encoders (Counter Input)

Exercise E-1 Exploring an Encoder Application


Goal
Open and explore an example program that uses counter to acquire an encoder signal.

Scenario
In this exercise, imagine that you are building an application that uses a quadrature
encoder to measure the position of a dial. You answer questions about how to set up
an encoder measurement and open a NI-DAQmx shipping example to review how to
program the measurement.

Implementation
1. Separate the following information into two categories depending on where the
information is specified. (Answers on page E-9.)

• Counter used in measurement

• Decoding type used

• Z Index availability

• Number of pulses per revolution

• Z index used in measurement

Specified in Encoder Documentation Specified by NI-DAQmx Task

Counter used in measurement

2. You are using an old encoder and can no longer find the specifications for it. How
might you find the pulses per revolution?

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

E-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

3. Below is the pinout for a USB-6363, an X-Series DAQ device. Where you would
connect your encoder's A, B, Z, +5VDC, and COM wires if you were connecting
to the default terminals of Counter 0. (Hint: The last two have multiple answers).

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

Default NI-DAQmx Counter Terminals


Counter/Timer Signal Terminal Name Counter/Timer Signal Terminal Name

CTR 0 SRC PFI 8 CTR 2 SRC PFI 0

CTR 0 GATE PFI 9 CTR 2 GATE PFI 1

CTR 0 AUX PFI 10 CTR 2 AUX PFI 2

CTR 0 OUT PFI 12 CTR 2 OUT PFI 14

CTR 0 A PFI 8 CTR 2 A PFI 0

CTR 0 Z PFI 9 CTR 2 Z PFI 1

CTR 0 B PFI 10 CTR 2 B PFI 2

CTR 1 SRC PFI 3 CTR 3 SRC PFI 5

CTR 1 GATE PFI 4 CTR 3 GATE PFI 6

CTR 1 AUX PFI 11 CTR 3 AUX PFI 7

CTR 1 OUT PFI 13 CTR 3 OUT PFI 15

CTR 1 A PFI 3 CTR 3 A PFI 5

CTR 1 Z PFI 4 CTR 3 Z PFI 6

CTR 1 B PFI 11 CTR 3 B PFI 7

FREQ OUT PFI 14

© National Instruments | E-5


Lesson E Measuring Position with Encoders (Counter Input)

4.You will be working in an environment with some noise and vibration. Which
decoding type should you use?

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

4. Open the Example Finder. (Select Help»Find Examples in LabVIEW.)

E-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

5. Select Directory Structure on the Browse tab and locate the DAQmx folder.

6. Open Counter - Read Encoder.vi located in the DAQmx»Analog Input folder.

Notice that the front panel of the VI asks for the channel A and channel B input
terminals. The VI also gives you the option to enable Z indexing.

1 Pulses Per Revolution—Specifies the number of pulses the encoder generates per
revolution. This value is the number of pulses on either channel A or channel B.
It is not the total number of pulses on both channel A and channel B.

© National Instruments | E-7


Lesson E Measuring Position with Encoders (Counter Input)

7. Review the block diagram to see how the VI is implemented.

a. For a software-timed acquisition application, you begin on the left of the block
diagram with a basic DAQ API structure: create a virtual channel and configure
timing.

1 DAQmx Create Virtual Channel—Using the Context Help for this VI, you see that
only the Physical Channel input is required.
2 DAQmx Channel Property Node—This property node is necessary to specify the
A, B, and Z channels unless you are using the default channels for the counter
you specify. Refer to the NI-DAQmx Help for more information about default
counter channels.

b. On the right of the block diagram you see the basic DAQ API structure: Start,
Read/Write, Stop/Clear.

1 2 3

1 DAQmx Start Task—Starting the task means that the device is ready to take a
measurement.
2 The While Loop contains a Counter instance of the DAQmx Read VI. The Loop
Time (ms) input controls the timing of the acquisition. This means that the timing
of the acquisition is dependent on the OS.
3 DAQmx Stop Task VI and DAQmx Clear Task VI—This example VI uses both for
completeness, but the DAQmx Clear Task VI will stop the task if necessary.

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

E-8 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Answers from page_E-4.


1. Separate the following information into two categories, depending on where this
information is specified.
• Counter used in measurement
• Decoding type used
• Z Index availability
• Number of pulses per revolution
• Z index used in measurement

Specified in Encoder Documentation Specified by NI-DAQmx Task

Counter used in measurement

Z index availability Decoding type used

Number of pulses per revolution —You Number of pulses per revolution —You
find this information in the encoder specify this in the DAQmx Create Virtual
documentation Channel VI and the value must match
the encoder specification.

Z index used in measurement

2. You are using an old encoder and can no longer find the specifications for it. How
might you find the pulses per revolution?
Use Counter test panel in MAX to count how many edges are output in one
revolution.

3. Below is the pinout for a USB-6363, an X-Series DAQ device. Label where you
would connect your encoder's A, B, Z, +5VDC, and COM wires if you were
connecting to the default terminals of Counter 0.
(Hint: the last two have multiple answers).
A connects to PFI 8
B connects to PFI 10
Z connects to PFI 9
Connect Com to any digital ground.
Connect the +VDC input to any digital line.

4.You will be working in an environment with some noise and vibration. Which
decoding type should you use?
X1 encoding, as it is the least sensitive to changes and noise.

_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __

End of Exercise E-1

© National Instruments | E-9


Lesson E Measuring Position with Encoders (Counter Input)

E-10 | ni.com
F Measuring
Edges,
Frequency,
Pulse Width,
and Duty Cycle

After this lesson you will be able to describe the basics of


event counting and configure NI-DAQmx tasks to analyze
a digital signal.

Topics
+ Resources

Exercises
Exercise F-1 Simple Edge Counting
Data Acquisition Using NI-DAQmx and LabVIEW

Resources
Resources Refer to the following resource for more information about topics in this
lesson. For locations with info codes, go to ni.com/info and enter the code
to access the article.

Article Location

Frequency Measurements: How-to Guide Info code: frequencyhowto

Article Location

High Frequency Two-Counter Measurement Method Info code: hifreq2count

Frequency Measurements: How-to Guide Info code: frequencyhowto

Article Location

Large-Range Two-Counter Measurement Method Info code: large2count

Frequency Measurements: How-to Guide Info code: frequencyhowto

© National Instruments | F-3


Lesson F Measuring Edges, Frequency, Pulse Width, and Duty Cycle

Exercise F-1 Simple Edge Counting


Goal
Open and explore an example program to count edges on a digital signal.

Scenario
In this exercise, you answer questions about how to set up an counter measurement
and open a NI-DAQmx shipping example to implement it.

Implementation
1. Open the Example Finder. (Select Help»Find Examples in LabVIEW.)

2. Select Directory Structure on the Browse tab and locate the DAQmx folder.

3. Open Counter - Count Edges.vi located in the DAQmx»Counter Input folder.

F-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

4. Review the block diagram to see how the VI is implemented.

a. Right-click the Counter control and select Find Terminal from the shortcut
menu.

b. Review the components of the block diagram. For a software-timed acquisition


application, you begin on the left of the block diagram with a basic DAQ API
structure: create a virtual channel and configure the channel.

1 2

1 DAQmx Create Virtual Channel—Using the Context Help for this VI, you see that
only the Counter input is required.
2 DAQmx Channel Property Node—This property node is necessary to specify the
terminal that contains the digital signal that you want to measure.

c. On the right of the block diagram you see the basic DAQ API structure: Start,
Read/Write, Stop/Clear.

1 2 3

1 DAQmx Start Task—Starting the task means that the device is ready to take a
measurement.
2 The While Loop contains a Counter instance of the DAQmx Read VI. The Loop
Time (ms) input controls the timing of the acquisition. This means that the timing
of the acquisition is dependent on the OS.
3 DAQmx Stop Task VI and DAQmx Clear Task VI—This example VI uses both for
completeness, but the DAQmx Clear Task VI will stop the task if necessary.

5. Answer the following questions about the built-in counter on the cDAQ-9178.
(Answers on page F-8.)

a. What is the resolution of the built-in counter for the cDAQ-9178?________

__ _ ___ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
(Hint: Refer to the NI cDAQ-9178 User Manual. A copy of the manual is
located in <Exercises>\DAQ\_Resources\Hardware Specifications.)

b. What is the highest number that the Count indicator will display?_________

__ _ ___ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
(Hint: Calculate the terminal count for the cDAQ-9178.)

© National Instruments | F-5


Lesson F Measuring Edges, Frequency, Pulse Width, and Duty Cycle

6. Open Counter - Count Edges.vi located in the DAQmx»Counter Input folder.

7. Update the front panel so that the VI uses the counter on the cDAQ-9178 to count
every time you push down the Trigger button on the demo box. (Answers on
page F-8.)

Parameter Hint Value

Counter What are the names of the counter lines for


the cDAQ-9178 chassis? Refer to the User
Manual or the NI-DAQmx Help, C Series
Physical Channels topic.

Input Terminal Refer to Table A-1, Connections in the NI


CompactDAQ Measurements Demo Box,
to see how the Trigger button on the demo
box is wired.

Active Edge Does the digital line go high when you push
the Trigger button or when you release the
Trigger button?

F-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

8. Review the block diagram to see how the VI is implemented.

a. Right-click the Counter control and select Find Terminal from the shortcut
menu.

b. Review the components of the block diagram. For a software-timed acquisition


application, you begin on the left of the block diagram with a basic DAQ API
structure: create a virtual channel and configure the channel.

1 2

1 DAQmx Create Virtual Channel—Using the Context Help for this VI, you see that
only the Counter input is required.
2 DAQmx Channel Property Node—This property node is necessary to specify the
terminal that contains the digital signal that you want to measure.

c. On the right of the block diagram you see the basic DAQ API structure: Start,
Read/Write, Stop/Clear.

1 2 3

1 DAQmx Start Task—Starting the task means that the device is ready to take a
measurement.
2 The While Loop contains a Counter instance of the DAQmx Read VI. The Loop
Time (ms) input controls the timing of the acquisition. This means that the timing
of the acquisition is dependent on the OS.
3 DAQmx Stop Task VI and DAQmx Clear Task VI—This example VI uses both for
completeness, but the DAQmx Clear Task VI will stop the task if necessary.

© National Instruments | F-7


Lesson F Measuring Edges, Frequency, Pulse Width, and Duty Cycle

Test
1. Run the VI.

2. Press the Trigger button on the NI CompactDAQ Measurements Demo Box


repeatedly to watch the Count indicator update.

3. Stop the VI.

4. Stop and close the VI without saving it.

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

Answers from page_F-5.


5. Answer the following questions about the built-in counter on the cDAQ-9178.

a. What is the resolution of the built-in counter for the cDAQ-9178?

The resolution of the built-in counter for the cDAQ-9178 chassis is 32 bits.

b. What is the highest number that will be output by the count indicator?_____

Terminal count = 2^(counter resolution) – 1


So the highest count displayed would be 2^(32) – 1, which equals 4294967295.

Answers from page_F-6.


7. Update the front panel so that the VI uses the counter on the cDAQ-9178 to count
rising edges.

Parameter Hint Value

Counter What are the names of the counter Any of the following will
lines for the cDAQ-9178 chassis? work:
Refer to the User Manual or the cDAQ1/_ctr0
NI-DAQmx Help, C Series Physical
Channels topic. cDAQ1/_ctr1
cDAQ1/_ctr2
cDAQ1/_ctr3

Input Terminal Refer to Table A-1, Connections in PFI 0


the NI CompactDAQ Measurements
Demo Box, to see how the Trigger
button on the demo box is wired.

Active Edge Does the digital line go high when Rising


you push the Trigger button or
when you release the Trigger
button?

__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __

End of Exercise F-1

F-8 | ni.com
G Additional
Information and
Resources

National Instruments provides global services and support


as part of our commitment to your success. Take
advantage of product services in addition to training and
certification programs that meet your needs during each
phase of the application life cycle; from planning and
development through deployment and ongoing
maintenance.
Appendix G

A. NI Services
To get started, register your product at ni.com/myproducts.

As a registered NI product user, you are entitled to the following benefits:


• Access to applicable product services.
• Easier product management with an online account.
• Receive critical part notifications, software updates, and service expirations.

Log in to your National Instruments ni.com User Profile to get personalized access to
your services.

B. Services and Resources


• Maintenance and Hardware Services—NI helps you identify your systems’
accuracy and reliability requirements and provides warranty, sparing, and
calibration services to help you maintain accuracy and minimize downtime over
the life of your system. Visit ni.com/services for more information.
– Warranty and Repair—All NI hardware features a one-year standard warranty
that is extendable up to five years. NI offers repair services performed in a
timely manner by highly trained factory technicians using only original parts at
a National Instruments service center.
– Calibration—Through regular calibration, you can quantify and improve the
measurement performance of an instrument. NI provides state-of-the-art
calibration services. If your product supports calibration, you can obtain the
calibration certificate for your product at ni.com/calibration.
• System Integration—If you have time constraints, limited in-house technical
resources, or other project challenges, National Instruments Alliance Partner
members can help. To learn more, call your local NI office or visit ni.com/alliance.
• Training and Certification—The NI training and certification program is the most
effective way to increase application development proficiency and productivity.
Visit ni.com/training for more information.
– The Skills Guide assists you in identifying the proficiency requirements of your
current application and gives you options for obtaining those skills consistent
with your time and budget constraints and personal learning preferences. Visit
ni.com/skills-guide to see these custom paths.
– NI offers courses in several languages and formats including instructor-led
classes at facilities worldwide, courses on-site at your facility, and online
courses to serve your individual needs.
• Technical Support—Support at ni.com/support includes the following resources:
– Self-Help Technical Resources—Visit ni.com/support for software drivers and
updates, a searchable KnowledgeBase, product manuals, step-by-step
troubleshooting wizards, thousands of example programs, tutorials,
application notes, instrument drivers, and so on. Registered users also receive
access to the NI Discussion Forums at ni.com/forums. NI Applications
Engineers make sure every question submitted online receives an answer.
– Software Support Service Membership—The Standard Service Program (SSP)
is a renewable one-year subscription included with almost every NI software
product, including NI Developer Suite. This program entitles members to direct
access to NI Applications Engineers through phone and email for one-to-one
technical support, as well as exclusive access to online training modules at

G-2 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

ni.com/self-paced-training. NI also offers flexible extended contract options


that guarantee your SSP benefits are available without interruption for as long
as you need them. Visit ni.com/ssp for more information.
• Declaration of Conformity (DoC)—A DoC is our claim of compliance with the
Council of the European Communities using the manufacturer’s declaration of
conformity. This system affords the user protection for electromagnetic
compatibility (EMC) and product safety. You can obtain the DoC for your product
by visiting ni.com/certification.

For information about other technical support options in your area, visit
ni.com/services, or contact your local office at ni.com/contact.

You also can visit the Worldwide Offices section of ni.com/niglobal to access the
branch office websites, which provide up-to-date contact information, support phone
numbers, email addresses, and current events.

C. Other National Instruments Training Courses


National Instruments offers several training courses for LabVIEW users. These courses
continue the training you received here and expand it to other areas. Visit
ni.com/training to purchase course materials or sign up for instructor-led, hands-on
courses at locations around the world.

D. National Instruments Certification


Earning an NI certification acknowledges your expertise in working with NI products
and technologies. The measurement and automation industry, your employer, clients,
and peers recognize your NI certification credential as a symbol of the skills and
knowledge you have gained through experience. Visit ni.com/training for more
information about the NI certification program.

© National Instruments | G-3


Appendix G

Notes

G-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW

Notes

© National Instruments | G-5


Appendix G

G-6 | ni.com

You might also like