Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
What is Developer Zone?
United States

Document TypeTutorial
NI Supported: Yes
Publish Date: Aug 20, 2010


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links -Products and Services

Timing and Synchronization Features of NI-DAQmx

41 Ratings | 4.10 out of 5
Read in  |  Print |  PDF

Table of Contents

  1. Overview
  2. Why Timing and Synchronization?
  3. A Behind-the-Scenes API
  4. Mixed-Mode Measurements
  5. Synchronized Analog Input/Output
  6. Synchronization Beyond Analog
  7. Signal Routing Options
  8. Advanced Functionality
  9. Multi-Device Synchronization
  10. The Bottom Line

 The National Instruments Getting Started with NI-DAQmx Series is aimed at helping you learn NI-DAQmx programming fundamentals. Through video and text tutorials, this series will take you from verifying your device's operation in Measurement & Automation Explorer (MAX) to programming data acquisition applications using LabVIEW. It is intended for both the beginner who wants to learn how to use the DAQ Assistant, as well as the experienced user who wishes to take advantage of advanced NI-DAQmx functionality.

Overview

This document covers the basics of timing and synchronization in NI-DAQmx with LabVIEW 7.  In particular, topics discussed include taking mixed-mode measurements, synchronizing beyond only analog functionality, and sharing timing signals between data acquisition (DAQ) devices.

Why Timing and Synchronization?

There are many applications that require precise control of timing and the ability to synchronize operations. For example, when you’re in charge of measuring and analyzing a large number of highly dynamic signals, any amount of phase mismatch may be unacceptable. There needs to be an understanding that a measurement of one signal at one point in time can be evaluated based on another signal at the same point in time, and thus, these acquisitions need some type of synchronization scheme. NI-DAQmx and the LabVIEW graphical programming environment give you the tools to easily construct these types of data acquisition systems.

A Behind-the-Scenes API

NI-DAQmx provides many powerful solutions for your timing and synchronization needs. Its native functionality in LabVIEW demonstrates the next generation of data acquisition programming. Gone are the days of specifically defining wiring paths of signals between devices--NI-DAQmx automatically finds a way to get the signals where you need them. All you have to do is specify the destination. In this sense, the driver intelligently operates behind the scenes to eliminate a complex configuration operation. This, however, is only the tip of the timing and synchronization iceberg...

Mixed-Mode Measurements

Since most E Series data acquisition devices have analog input, analog output, counter/timer, and digital input/output functionality, the challenge is often to program the device in such a way as to take advantage of each type of measurement with some amount of certainty that they are synchronized with each other. Some use cases include:

1) Simultaneously Started Analog Input and Analog Output

Operations start simultaneously but are not synchronizedSynchronized Analog Input and Analog Output

Operations can be simultaneously started and set to run at the same rate

Operations can share the sample clock

2) Synchronized Analog Input and Analog Output with a Trigger

Share hardware trigger and sample clock

3) Synchronized Analog and Counter Operations

4) Counter creates pulse train as clock for analog operation

5) Analog clock gates counter operation

In the NI-DAQmx API, you can use a very small number of VIs to accomplish most of your timing and synchronization needs. In particular, the DAQmx Timing.vi and DAQmx Trigger.vi allow you to specify at what interval your channels should be scanned and when they should start (or stop). By taking advantage of LabVIEW’s polymorphism, these two VIs are capable of defining the timing and triggering of not only analog input signals, but also the aforementioned analog output, counter/timer, and digital input/output (see Figure 1).



Figure 1

A common use case that demonstrates synchronization concerns is the situation where you would like an analog input and analog output operation to occur using the same clock. In this case, you would need two chains of code: one for analog input and one for analog output. In each, use the DAQmx Timing VI to specify the continuous operation desired. For the analog output timing, leave the “source” input as default – this means your analog output operation will function according to the default analog output clock, which is the internal clock. On the analog input DAQmx Timing VI, all you have to do is specify the “source” to be the analog output sample clock. This sets both analog input and analog output operations to operate on the analog output’s timing signal (see Figure 2).


The previous example demonstrated how you can tie analog timing signals together. What happens when you want to deal with mixed analog and digital signals together? Can you still expect the same amount of seamless integration? The answer is yes.

Imagine that your analog measurements depend upon an external or nontraditional clock signal – ex: take a sample once every millisecond for 10 milliseconds, wait 3 milliseconds, repeat. In this case, you can use the counter functionality on an E Series device to generate the desired timing signal, but how do you tell the analog side to use it as a clock? The answer is, yet again, the DAQmx Timing VI. By specifying your “source” to be a counter’s internal output pin, the counter output will become the analog input clock without the use of an external wire to connect pins on a terminal block (see Figure 3).



Figure 3


The ease of use demonstrated with synchronization also extends to triggering. Using the DAQmx Trigger VI, you can easily set an operation to wait for either an internal or external trigger signal (analog or digital). A good example of this deals with event triggering. With event triggering, the device ignores the first N triggers before it starts an acquisition. To do this, a counter is used to create the single pulse to start the analog input acquisition. The counter uses the first N triggers to create the low part of the pulse and the valid trigger to start the high part of the pulse and trigger the actual acquisition. In the following example, there are two parallel rows of code; the top configures the analog input operation, and the bottom configures a counter. The source of the trigger is the output of Counter 0, and Counter 0 has been configured to output a trigger pulse after it has input its "nth" pulse. In this case, the 100 kHz internal timebase is selected as the input source, but you could also have specified an external location for the source, allowing you to set up a delayed trigger from an external pulse train (see Figure 4).


Figure 4



Note: In the last two examples, Ctr0InternalOutput and Crt0Out are referenced as the location of a clock or trigger signal. Ctr0Internal Out is a signal available for routes internal to the board. Crt0Out should be used when routing the counter output to PFI and RTSI. The example in Figure 4 could have used CtrOInternal Out instead of Ctr0Out.

Signal Routing Options


To route signals from one location on a device to another like the previous examples demonstrate, you need to take a few things into consideration. First, is NI-DAQmx configured to route these signals? Second, which signals are available for routing? Because the ability to pass these signals relies on an intermediate communication path, make use of the Real Time System Integration (RTSI) bus.

The RTSI bus (available on a PCI device as a 34-pin connector or included in the backplane connector on PXI) exposes 7 pins onto which you can send timing signals from one device to another (or internally on one device). Before you can use this communication path, let the driver know how the devices in the system are connected. For PCI devices, connect the appropriate devices with a RTSI cable and register this connection in Measurement & Automation Explorer (MAX). With MAX 3.0, this is done by right-clicking on NI-DAQmx Devices and choosing Create New NI-DAQmx Device >>RTSI Cable. This will add a RTSI cable to your NI-DAQmx Devices listing. For PXI systems, all you need to do is to identify the PXI system by right clicking on PXI System >> Identify As. The RTSI bus is referred to as the PXI Trigger bus in PXI systems. (Figure 5 shows a RTSI cable connected to one DAQ device.)




Figure 5


To see which signals can be routed where within a single DAQ device, you can view the Device Routes tab in MAX. When you click on the DAQ device in MAX, you will see the device attributes appear in the window to the right of the Configuration tree. If you choose the Device Routes tab at the bottom of that window, each available signal route is listed. The green squares indicate routes that can be made directly where the yellow squares indicate routes that must go through some type of subsystem on the device to be made. The intermediate subsystems are needed to complete the route are listed in the Subsystem Used box when you hover over a yellow square. This may be useful as indirect routes can sometimes interfere with other operations you are performing (Figure 6).


The DAQmx Timing and DAQmx Trigger VIs offer high-level functionality to set up your operation, but there are occasions when lower level information becomes important. Let’s say you need to know what timebase an analog output operation is updating on or for what level an analog edge trigger has been configured. This information is exposed through the DAQmx Timing and DAQmx Trigger Property Nodes (see Figure 7). From these property nodes, you can access all the relevantly configured values, either to set them or view them.



Figure 7



One example of where the DAQmx Trigger Property Node exposes complex functionality is the retriggerable option for counters. In previous APIs, making a counter retriggerable completely changed the code for the counter operation. With the NI-DAQmx API, the simple inclusion of a DAQmx Trigger Property Node, set to Start.Retriggerable, changes the counter from a single trigger to retriggerable operation (see Figure 8).

The previous examples have shown some of the ways you can tie operations together (either through triggering or timing) on the same device. But what if the functionality of one device does not allow the complete characterization of a system? There are certainly times when the sheer channel count of a system requires the combination of multiple devices. If each device contains RTSI connectivity, the same synchronization options are available to us as on a single device.



Figure 9


To show a connection between devices, right-click on the RTSI cable in MAX and select each of the appropriate devices under Add Device to Cable. Once each of the devices has been added, NI-DAQmx will now take advantage of all available routing paths between devices (synchronization will be seamless). If it is a PCI device, you will need to physically add the RTSI cable between the devices.

Now you can reference the appropriate timing or trigger pins from other devices as the "source" of your DAQmx Timing and Trigger VIs. (Management of the RTSI bus is hidden from the user by default, although the option exists to explicitly route certain signals to specific RTSI pins using the Export Signal.vi.) The following example demonstrates how you might share timing signals from one device to another for an analog input operation (see Figure 10).



Figure 10



Note that there are two separate operations taking place here on two separate devices. The sample clock for device one has been configured as the sample clock from device two simply by telling NI-DAQmx to use Dev1/ai/SampleClock as the sample clock for device two. NI-DAQmx figures out how to actually make that route happen to ensure that data will be taken at the same rate on both data acquisition devices.

The Bottom Line


Most of NI's DAQ devices contain functionality that enables you to share timing and triggering. To take advantage of this functionality, NI-DAQmx, with its characteristic ease of use, simplified analysis, and increased performance, gives you the tools to ensure your measurements occur in the same time domain.

 

Downloads

synchronization_code.zip

41 Ratings | 4.10 out of 5
Read in  |  Print |  PDF

Reader Comments | Submit a comment »

non-functional download
the diagram for figure 10 relies on a vi from an example in LabVIEW version 7.1... updating to make the example(s) functional would be helpful
- Nov 22, 2010

10ms-3ms-repeat not reachable?
The code in Figure 3 intends to clarify the sample 10ms stop 3 ms and repeat, but it can't do it. I have tried to accomplish that goal by configure the counter to produce pukses of 10ms High and 3ms Low, use the Ctr0InternalOutput to trigger the AI, the AI is configured as finite samples of 100 uses its default sampling clk at rate 1000S/s. After Start, a while loop is used to implement the Repeat reading. Unfortunately, ONLY the first reading successful, and it is found that the AI task has stopped automatically after the first finite reading, it can not be retriggered by the CO rising edge anaymore, although the CO is found to output as configured. But when the AI configured as Continuous, it runs OK, and the problem now is that it is not the intended triggering AI with CO as the time schedule. I suspect the feasibility as claimed in the article.
- Weimin Zhang,Petracarbon Pte Ltd. weimin@petracarbon.com - Feb 04, 2009

Print in Landscape Orientation
Click on the "print this page" link and then print in landscape orientation Worked for me.
- Nov 10, 2005

Still not printing
I'm still unable to print the right side of this document. Even with printer margins set to 0.2", the first line, for example, truncates in the middle of the word "include." Any advice? Thanks.
- wblythe@tcc.edu - Nov 09, 2005

Synchronized Counters' Operation?
It a great summary of Synchronization.I just wonder if there are several counters'operations, how to make them synchronized. for example three counters will measure "pulse width" of three-phase PWM signals seperately,how to make operation Synchronized.
- yc78@msstate.edu - Aug 10, 2005

Printing Problems Fixed
Thanks for all the feedback on this document. The printing issues should now be fixed. Enjoy!
- Nora Tucker,National Instruments. nora.tucker@ni.com - Apr 21, 2005

Cannot print properly
Unable to print this document properly, wither directly or through Acrobat writer. Right Hand side gets cut off.
- Mar 31, 2005

needs los of work
The page not formated to print correctly. Links to example vi's of each example would be nice. Examples of E-series to M-series would be nice. Examples of analog input and digital input would help.
- Bill Troyer,University of Oregon Dept of Psychology. troyer@darkwing.uoregon.edu - Sep 29, 2004

Layout
Marvellous content, but why are the page margins off the right side of my screen? I cannot see the entire text either in the browser window or when I print the right side is cut off. Is it my browser settings? I exported MSWord and the right margin is way past 10".
- Jim Henderson,Southern California Edison. henderjr@songs.sce.com - Feb 09, 2004

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).