Synched DAQmx AO/AI Loopback Returns Odd First Sample on the First AI Channel

Updated Dec 9, 2024

Issue Details

I am creating a loopback code to test AO/AI synchronization. In order to acquire 3 analog input channels synchronously with the generation of analog output voltage, I have ai0, ai1, and ai2 inputs connected directly to ao0 output.

When running the code, I end up with one element shift on the first AI channel (in this case ai0). Through experimentation, I learned that whichever channel is first in the task, it will have one sample shifted.

Solution

This is a behavior that can be expected, primarily resulting from two features of the Analog Output port: the Slew Rate and the Settling Time. Both the slew rate and settling time can impact the accuracy of the first sample reading from an Analog Input (AI) connected to an Analog Output (AO) port when both are initiated concurrently (synchronized tasks). Here’s how:

  • Slew Rate: An inadequate slew rate at the AO port can cause the output voltage to change at a slower rate than desired. This means that when the AI port takes its first measurement, the output voltage may not yet have reached the correct value, leading to a potential misreading.

  • Settling Time: Once the AO port alters its output, there is a delay before the voltage stabilizes within an acceptable error range. If the AI port captures the signal prior to the completion of this settling period, the measurement could be affected by ongoing voltage fluctuations, leading to inaccuracies.

When a synchronized AO/AI scenario occurs, the moment the common start trigger is engaged, the interval between obtaining a stable initial AO sample and capturing the first sample is almost immediate, making this behavior expected in such situations. To achieve precise readings in such cases, it is important to provide enough time for the AO to stabilize at the desired voltage before the AI takes its first sample. This could involve implementing a delay between setting the AO and the AI's sampling to account for both the slew rate and settling time.

If your using a Multifunction DAQ, such as a PXIe-636, you can set the Delay From Sample Clock:Delay value to a value that allows this distortion to disappear.

In LabVIEW:

LabVIEW Code Setting a DAQmx Timing Property DelayFromSamClk.Delay to 50

 

In C:

DAQmxSetTimingAttribute(AItaskHandle, DAQmx_DelayFromSampClk_Delay, 50.0);