Other data acquisition devices, such as E Series, do not offer a reference clock for synchronization purposes. A common way to synchronize these devices, which will also work for M Series devices, is to share a common sample clock across all devices in the acquisition. This can be done by routing the master sample clock over RTSI to be used as the sample clock for all slave devices. There are slight disadvantages with using this method. One is that small propagation delays are introduced between the master and slave by routing the sample clock over RTSI that do not exist when using a reference clock for synchronization. The second is that although a common AI Sample Clock is shared between all boards, the AI Convert Clocks that actually cause the A/D conversions on each channel for devices with multiplexed architectures (such as E Series and M Series) are still generated from each onboard oscillator, which will not be synchronized to each other. However, these errors are small and negligible for most E and M Series applications.
The example shown in Figure 1 demonstrates how to synchronize an acquisition between two M series devices by sharing a sample clock. With NI-DAQmx, the master sample clock will automatically be routed to the slave over RTSI bus or the PXI trigger lines by setting the source of the slave sample clock to be the master sample clock. Below are the descriptions of each of the steps labeled by the numbers on the figure.
Figure 1 Synchronization of Two M Series Devices Using the Sample Clock
In step 1, virtual channels are created. Each of the virtual channels is used to acquire an analog voltage signal. Notice that they are from independent devices – M Series Master and M Series Slave.
In this step, the timing information is entered. Both channels are set for finite acquisition of 1000 samples/channel at a rate of 1000 samples/s. This time, the SampleClock source of the slave is chosen to be the AI Sample Clock of the master device. NI-DAQmx will automatically make the necessary route to the slave over RTSI. The source of the master SampleClock is left to the default, which will be the internal analog input SampleClock.
As it was done previously, the Get Terminal Name with Device Prefix is used to programmatically extract the Start Trigger signal of the master device and route it to be used to start the slave device. This step is the second phase of the synchronization – making sure that they start at the same time.
The task from the slave is started first, but has to wait to receive a trigger signal from the master Start Trigger that was routed in the previous step. When the master is started, the Start Trigger signal is generated and triggers both tasks at the same time. The sequence structure is used to ensure that the slave is started before the master and to avoid race conditions.
At this step, the samples are read by both tasks. Each task will provide 1000 samples and display them on a waveform graph.
After the acquisition is done, the tasks are cleaned in this step. This step ensures that the resource is freed and can be used by another task.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.