Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

ai0 has a one sample offset when reading DAQmxReadAnalogF64

When reading three channels by DAQmxReadAnalogF64  the first channel appears to have an offset of one sample. I'm feeding the same signal to all three channels.
- trigger rate: 1kHz
- software version: LabWindows 8.1.1
- same behavior for GroupByScanNumber


source code:

int a=100;

DAQmxCreateTask ("", &readOutHandle);
DAQmxCreateAIVoltageChan (readOutHandle, "Dev1/ai0, Dev1/ai1, Dev1/ai2", "", DAQmx_Val_Diff, -10, 10, DAQmx_Val_Volts, "");
DAQmxCfgSampClkTiming (readOutHandle, "PFI0", 100, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 3*a);
DAQmxGetTaskAttribute(readOutHandle,DAQmx_Task_NumChans,&numChannels);
    
data = malloc((a*numChannels)*sizeof(float64));
DAQmxStartTask (readOutHandle);
    
DAQmxReadAnalogF64 (readOutHandle, -1, 1000.0, DAQmx_Val_GroupByChannel, data, a*numChannels, &numRead, 0);


when applying a sinosodial signal ai1 and ai2 are in phase, but ai0 is one sample behind.
0 Kudos
Message 1 of 9
(4,442 Views)
Hello,

what DAQ device do you use to sample the signal?

Most NI DAQ devices use multiplexing to sample the channels one after the other with a single ADC.

As you set a sampling rate of 100 Hz, it is possible that the signal value changes while the driver switches from one channel to the next.

Regards,
Johannes

NI Germany
0 Kudos
Message 2 of 9
(4,423 Views)
I use a PCI-6221 with a BNC-2090 terminal.

the input signals are constant for one ms. Changes are indicated via the external trigger (1kHz).

Is it correct to set the sampling rate to 1000Hz?
0 Kudos
Message 3 of 9
(4,415 Views)
First of all, the PCI-6221 is an M-Series board and does indeed do multiplexing for the AI channels.

The code fragment you used does not set the sample rate to 1000 Hz, but to 100. The DAQmx C reference (which can be found at
Programs > National Instruments > NI-DAQ) specifies for the "rate" parameter:

The sampling rate in samples per second per channel. If you use an external source for the Sample Clock, set this value to the maximum expected rate of that clock.

So, you would have to set this parameter to 1000.

The numSampsPerChan parameter of the DAQmxReadAnalogF64 function specifies how many samples are read from the buffer of the board.

Regards,
Johannes

NI Germany   627996


Message Edited by JoBa on 02-04-2008 11:39 AM
0 Kudos
Message 4 of 9
(4,400 Views)
Thank  you for your reply.

I changed the sampling rate to 1000.0 which is right anyway. Unfortunatly this does not solve the above problem.
0 Kudos
Message 5 of 9
(4,375 Views)
obviously it is a timing problem. The trigger is about 10µs early so that the convert clock samples ai0 still at the previous signal.

Is there a software possibility to delay the reading of samples with respect to the external trigger or do I have to delay the trigger by extra electronics?
0 Kudos
Message 6 of 9
(4,354 Views)
The external trigger signal is processed directly on the DAQ board and therefore can not be delayed by software.
You will have to do signal conditioning externally.

Regards,
Johannes

NI Germany
0 Kudos
Message 7 of 9
(4,334 Views)
Hi hoffmann@hiskp,

You can have the M Series hardware insert a 10
µs delay between the external sample clock edge and the first convert clock pulse for that sample. Set the delay from sample clock properties before you start your task:

DAQmxSetDelayFromSampClkDelay(taskHandle, 10e-6);
DAQmxSetDelayFromSampClkDelayUnits(taskHandle, DAQmx_Val_Seconds);


Also note that there are similar properties (DAQmxSetStartTrigDelay and DAQmxSetStartTrigDelayUnits) for setting the delay between an external start trigger and the first sample clock pulse for that task.

Brad
---
Brad Keryan
NI R&D
0 Kudos
Message 8 of 9
(4,315 Views)
DAQmxSetDelayFromSampClkDelay solves the problem.

Thank you!
0 Kudos
Message 9 of 9
(4,289 Views)