LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

synchronizing AI and quadrature encoder

Hello,

 

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.

 

B.Williot

0 Kudos
Message 1 of 3
(2,801 Views)

I am adding a stripped down version of my code.

Here under a screen capture of output window.

 

Capture.PNG

 

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

 

B.Williot.

Download All
0 Kudos
Message 2 of 3
(2,792 Views)

I've found a modification that works.

 

I changed

 

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

 

by

 

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 ?

 

B.Williot.

0 Kudos
Message 3 of 3
(2,721 Views)