Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Continous buffered event counting.

Hello,

We are trying to create an application for counting TTL pulses (similar to PMT pulse counting discussed on the forum several times). We want the counter to return a number of samples read since the last read into the buffer array (obviously filled to different amount depending on the time since last read).

SRC |__|__|__|__|__|__|__

GATE ____|_____|_____|__

                0       N        N

                         0        N

                                   0

We use PCI-6220 card, under Suse Linux 9.3 with kernel 2.6.11.4-20a-smp,with DAQmxBase version 1.5 for Linux patched with the kernel patch made by uav-steve that's available on this forum. When trying to implement continuous buffered counting resulted in complete fiasko - the output of the counter does not make sense at all. Here is some diagnostics. We create a clock/source pulse at a relatively low frequency F (10 Hz, 50 Hz or 100 Hz), and feed it to the source of the counter, and a sample/gate pulse at F/13. The counting is set up to be triggerred by rising edges of the sample/gate signal on PFI4, and it is the falling edges of the clock/source we are counting:

DAQmxBaseCreateCICountEdgesChan(*myTaskHandle,CNT1_CHAN,"",DAQmx_Val_Falling,0,DAQmx_Val_CountUp);

DAQmxBaseCfgSampClkTiming(*myTaskHandle,"/Dev1/PFI4",1000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);

The counter is then read out in a loop with the following command:

while (1) {

isDAQerror(DAQmxBaseReadCounterU32(taskHandleCnt,DAQmx_Val_Auto

,10,buff_data,100,&read,NULL) , taskHandleCnt);

for(k=0; k<read; k++)

printf("%d\n", buff_data[k]);

printf("\nread: %d\n",read);

// sleep(1);

}

We should get is N=13 counts in each sample.

Here are the options we have tried:

1. reading a requested number of samples (Setting second argument of DAQmxBaseReadCounterU32 to numSampsPerChan as in the example cntBuffCont.c).

It always returns 10 samples read, which start at a value of 25 (which is accidentally 2*N - 1 ), and increments by N each sample.

The next batch of 10 samples starts at 25 again, and runs incrementally. With the schematic diagram this looks in the following way:

SRC |__|__|__|__|__|__|__|__

GATE ____|_____|_____|__

             2N-1.. ? .. 2N-1

             3N-1        3N-1

Always returns 10 samples, never fewer! Apparently wait for 10 samples to be collected, before returning.

2. description of DAQmxBaseReadCounterU32 says that the number of samples to read should be DAQmx_Val_Auto in order to read all available samples. What happens is that it returns values of 25 on each time when it is called, returning just one element in the array. Setting it to sleep for 1 second in the loop should have made the buffer longer (new samples would have accumulated in that time), but it does not, and returns the same value each time, different for different frequencies (14 counts for 50 Hz clock,16 for 100 Hz, and 15 counts for 10 Hz). With the schematic diagram:

NO SLEEP

SRC |__|__|__|__|__|__|__|__

GATE ____|_____|_____|__

            2N-1     2N-1 

SLEEP

SRC |__|__|__|__|__|__|__|__

GATE ____|_____|_____|__

               X    ??   X

Always returns 1 sample, even if the elapsed time forced to be multiple sample/gate periods! The value is wrong either way.

3. Trying to read it on the fly (with DAQmxBaseReadCounterScalarU32) gives 2N-1 samples as well. This is not a solution in the long run, since we cannot allow to miss any samples, and with on-demand read one cannot be sure no samples are lost (even at couple hundred hz sampling).

SRC |__|__|__|__|__|__|__

GATE ____|_____|__

            2N-1 ?? 2N-1

The number of lost samples is not known, the value is wrong!

cheers,

Nickolay Ivchenko & Josef Höök

0 Kudos
Message 1 of 1
(3,361 Views)