Showing results for 
Search instead for 
Did you mean: 

synchronizing AI and quadrature encoder



I'm facing a problem.


With Ni USB 6343 I want to acquire synchronously some Ai chanels and two quadrature encoders


here under the flow of my program :


Create analog input task

Create counter task 1 for left position

Create counter task 2 for right position


Setup analog task (Sample rate, input voltage, …)

Setup counter task 1 & 2 with analog sampling clock as master clock


DAQmxRegisterEveryNSamplesEvent on analog input task


Start counter task 1 & 2

Start analog task as master task to synchronize the three task.



in callback :


DAQmxReadAnalogF64 to read analog samples,

DAQmxReadCounterU32 to read counter 1

DAQmxReadCounterU32 to read counter 2


Here is the issue :

On first (and sometime second) calling of the callback I get the right number of samples from analog task but 0 or 1 samples from counter tasks.



Any idea about this issue ?


Thanks by advance for your support.



0 Kudos
Message 1 of 3

I am adding a stripped down version of my code.

Here under a screen capture of output window.




You can see that the first call to EventAcquireCallback, there is no data from counters.



Download All
0 Kudos
Message 2 of 3

I've found a modification that works.


I changed


err = DAQmxReadCounterU32(g_TaskHandleCpt1,DAQmx_Val_Auto,60,ctr0Data,50,&nbCtr0,NULL);




err = DAQmxReadCounterU32(g_TaskHandleCpt1, nSamples,60,ctr0Data,50,&nbCtr0,NULL);


nSamples is the parameters from


int32 CVICALLBACKEventAcquireCallback(TaskHandle taskHandle,int32 everyNsamplesEventType,uInt32 nSamples,void*callbackDatas)


But I don't know why DAQmx_Val_Auto is not working !


Any idea ?



0 Kudos
Message 3 of 3