2017 DAQ LV Online ParticipantGuide
2017 DAQ LV Online ParticipantGuide
NI-DAQ mx and
TM
LabVIEW TM
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.
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.
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
Topics
+ What You Need To Get Started
+ Installing the Course Software
+ Course Lesson Icons
Data Acquisition Using NI-DAQmx and LabVIEW
Data Acquisition Using NI-DAQmx and LabVIEW course exercise and solution files
copied to the following folders:
Solution files are located in the <Solutions>\ folder where <Solutions> refers to
C:\Solution\ assuming that you installed the files on your root directory.
© 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
Article Location
Isolation
Article Location
Article Location
Filtering
Article Location
Article Location
Article Location
Meausring current
Article Location
Fundamentals, System Design, and Setup for the 4 Info code: currentloop
to 20 mA Current Loop
Article Location
Article Location
1-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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.
Aliased signal
Adequately sampled
signal for frequency only
Adequately sampled
signal for frequency and
shape
In this exercise, you use the Sample Rate Example VI to demonstrate aliasing and the
effects of sample rate on an input signal.
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.
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.
3. Set the front panel controls with the following values, where cDAQx is the identity
of your chassis.
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.
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
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.
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.
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.
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.
1-10 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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.
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.
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.
10 –10 3,100
5 –5 1,620
DAQ Device 16 Bit
1 1 –1 360
10 –10 1,920
5 –5 1,010
2 –2 410
DAQ Device 16 Bit
2 1 –1 220
0.2 –0.2 74
0.1 –0.1 52
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
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
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
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.
• 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.
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.
DAQ Device 2 and DAQ Device 3 are both able to detect a change of 70 μV.
Therefore, DAQ Device 3, using an input range of ±2 V, is the best DAQ device
for this project.
1-16 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
Scenario
In this two-part exercise, you practice determining a correct grounding mode
configuration.
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
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
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?
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
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
1-18 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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.
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.
3. Select Directory Structure on the Browse tab and locate the DAQmx folder.
1-20 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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.
a. Right-click the Physical Channel control and select Find Terminal from the
shortcut menu.
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.
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
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.
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
1-24 | ni.com
2 Generating an
Analog Signal
(Analog Output)
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
Article Location
Article Location
Field Wiring and Noise Considerations for Analog Info code: fieldwiring
Signals
Article Location
Article Location
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.
b. What device pins connect the NI 9263 to the fan control of the Sound and
Vibration Signal Simulator?______________________________________________
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.
a. Right-click the Physical Channel(s) control and select Find Terminal from the
shortcut menu.
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.
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.
2-6 | ni.com
3 Generating or
Reading 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
Article Location
Isolation
Article Location
Article Location
Article Location
Article Location
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.
3. Select Directory Structure on the Browse tab and locate the DAQmx folder.
3-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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.
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.
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.
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.
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?______________________
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
3-8 | ni.com
4 Choose a Signal
to Explore
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
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
Article Location
Article Location
Article Location
When to Use the DAQmx Start Task and DAQmx Info code: daqmxstartstop
Stop Task VIs
Article Location
What is the Difference between the DAQmx Stop Info code: diffstopclear
Task VI and the DAQmx Clear Task VI?
Article Location
5-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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.
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-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.
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.
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.
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.
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? ____________________________
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.
Test
Ensure that the VI is able to acquire and display light sensor data from your NI 9215.
While the VI is running, place your hand over the light sensor to ensure that
the sensor detects the change in light level.
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.
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.
Test
1. From the front panel, run the VI and observe the resulting values.
2. Place your hand over the light sensor, run the VI and observe the resulting values.
5-10 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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.
In the Save As dialog box, create a copy on disk and substitute the copy for
the original, closing the original.
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.
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.
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.
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.
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.
5. Slowly turn the Fans Speed Control knob clockwise and observe the impact on the
X and Y acceleration plots.
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.
To locate this example, open the NI Example Finder and navigate to Hardware
Input and Output»DAQmx»Analog Output.
In the Save As dialog box, create a copy on disk and substitute the copy for
the original, closing the original.
5-14 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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.
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.
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 switch between the fans is set to Balanced Fan.
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.
– 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.
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.
– Given that two pulses correspond to one revolution of the fan, how fast is
the fan spinning?_______________________
5-16 | ni.com
6 Programming
Multiple
Channels
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.
Article Location
Article Location
Article Location
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.
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.
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.
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.
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.
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.
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.
3. Cover the light sensor or use a flash to decrease and increase the sensor lighting.
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.
__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __
__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __
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.
6-8 | ni.com
7 Triggering on a
Specific
Condition
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
Article Location
Article Location
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.
d. Why does the DAQmx Write VI come before the DAQmx Start VI in this 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.
• 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.
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.
7-6 | ni.com
8 Advanced
Timing and
Synchronization
Methods
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.
Article Location
Jitter
Article Location
Digital Timing: Clock Signals, Jitter, Hysteresis, and Eye Info code: jitter
Diagrams
Article Location
Article Location
Article Location
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.
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.
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?
________________________________________________________________________
Lesson 8
|
ni.com
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.
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
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.
2. Save the VI as a Copy and Substitute the copy for the original.
Test
1. Run the VI.
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.
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.
Tip In the Save As dialog box, select Open additional copy and make sure
there is no checkmark in the Add copy to... checkbox.
8-8 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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.
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.
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.
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.
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.)
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.
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
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.
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.
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.
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
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.
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.
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.
Control Value
Physical channel - light sensor Channel connected to solar panel in demo box
Sample rate - light sensor 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.
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.
___________________________________________________________________________
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
a. Right-click the Light Sensor graph and select Export»Export Data to Clipboard.
d. Paste the data into a column next to the light sensor data.
a. How many data points are in the Light Sensor 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.
8-22 | ni.com
9 Logging
Measurement
Data to Disk
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.
Article Location
Article Location
Article Location
Offline Processing
Article Location
TDM Excel Add-In for Microsoft Excel Download Info code: exceladdin
Article Location
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.
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
Test
1. Acquire and log data for a balanced fan.
– Turn the Fan Speed Control Knob clockwise to the maximum speed for the
fan.
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.
– 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 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.
9-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
– 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.
9-8 | ni.com
10 System
Considerations
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
Article Location
10-4 | ni.com
A NI compactDAQ
Measurements
Demo Box
Information
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
PFI 0 Trigger
VDC Power
Ch 0 X Accelerometer
NI 9234 Ch 1 Y Accelerometer
Ch 2 Tachometer Out
AO 0 Speaker
NI 9263
AO 1 Fan Speed Control
A-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
Voltage 0.5 V
Current 100 mA
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.
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.
A-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
Based on the image in the specification, you can see that the strain gage is a
Quarter Bridge 1 type.
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.
Accelerometer Specifications
The following information is provided by the manufacturer.
A-10 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
G. LEDs Information
The eight LEDs are located on the left side of the demo box and are connected to the
NI 9472 module.
Dimmable Yes
IP Rating IP20
Weight 13 grams
Housing Aluminum
Diameter 8mm
Green 525 4 3
Amber 590 3 3
Red 625 3 3
A-12 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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
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.
3. Select Directory Structure on the Browse tab and locate the DAQmx folder.
B-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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 9213 to read a voltage from the
thermocouple.
CJC Value If the CJC source is Constant Value then you must
specify the value.
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
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.
B-8 | ni.com
C Measuring
Sound,
Vibration, and
Acceleration
(IEPE
Measurements)
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
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.
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-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
4. Select Directory Structure on the Browse tab and locate the DAQmx folder.
Notice that the front panel of the VI offers many of the same options that the test
panel in MAX offered.
6. Update the front panel so that the VI uses the following values.
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.
C-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
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-8 | ni.com
D Measuring
Strain, Force, or
Pressure
(Bridge-Based
Measurements)
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
Article Location
Article Location
Article Location
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.
b. Which bridge configuration type is the strain gage installed in the demo box?
________________________________________________________________________
c. What is the minimum and maximum values, in volts, that the device can read?
________________________________________________________________________
D-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
4. Select Directory Structure on the Browse tab and locate the DAQmx folder.
Notice that the front panel of the VI offers many of the same options that the test
panel in MAX offered.
6. Update the front panel so that the VI uses the NI 9236 to read a voltage from the
strain gage.
Minimum Value and What are the answers to step 2, page D-4?
Maximum Value
Lead Wire Resistance For now, assume that both of these are 0
and Initial Bridge nominal.
Voltage
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.
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?_________________________________________
__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __
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
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
__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __
D-8 | ni.com
E Measuring
Position with
Encoders
(Counter Input)
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
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.)
• Z Index availability
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).
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
4.You will be working in an environment with some noise and vibration. Which
decoding type should you use?
__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __
__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __
__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __
E-6 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
5. Select Directory Structure on the Browse tab and locate the DAQmx 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.
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
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.
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.
_ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ _____ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
E-10 | ni.com
F Measuring
Edges,
Frequency,
Pulse Width,
and Duty Cycle
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
Article Location
Article Location
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.
F-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
a. Right-click the Counter control and select Find Terminal from the shortcut
menu.
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.)
__ _ ___ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __
(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.)
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.)
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
a. Right-click the Counter control and select Find Terminal from the shortcut
menu.
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.
Test
1. Run the VI.
__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __
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?_____
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
__ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ __ _ _ __ _ ___ __ _ ___ __ _ ___ __
F-8 | ni.com
G Additional
Information and
Resources
A. NI Services
To get started, register your product at ni.com/myproducts.
Log in to your National Instruments ni.com User Profile to get personalized access to
your services.
G-2 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
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.
Notes
G-4 | ni.com
Data Acquisition Using NI-DAQmx and LabVIEW
Notes
G-6 | ni.com