Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx non-cumulative buffered edge counting (like the PMT TTL problem) with PCI6221 in C program environment

I have a PCI-6221. I am programming in C/C++ and DAQmx. My application is much like the previous thread counting the number of asynchronous TTL pulses from a PMT in some user specified time interval. The time interval is typically around 1 msec and the signal rates are around 1-10 kHz. So I expect to count 0 to 10 pulses per timebin. In traditional DAQ this was called Non-cumulative buffered edge counting.

To get a clock at about 1kHz, I first create an "analogue in" task that samples at 1kHz. The only thing I use this task for is to route its sample clock to the gate of the counter. This defines my time interval as 1 msec.

I then create the counter task. I am using count edges. So I think counter0 gate = PFI9 and source = PFI8.
DAQmxCreateCICountEdgesChan(*taskHandle,chan,"",edge,initialCount,countDirection);
DAQmxCfgSampClkTiming(*taskHandle,clockSource,rate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,samplesPerChan);
where clockSource="/Dev1/ai/SampleClock"

I apply my signal to PFI8.
After starting the task, I read an array of values with

DAQmxReadCounterU32(taskHandle,samplesToRead,10.0,data,samplesToRead,read,NULL);

I expect the array data to have values ranging from 0-10 for PMT input with an average rate of about 10 kHz. The trouble is that the array data does not seem to make sense. I get constantly increasing values. For very low input frequency, it just increments by one per array member.

More troublesome, when I hold PFI8 at ground, so that I expect zero pulses to be counted at the source for each edge at the gate that occur 1 per msec, I get a timeout error. I really must be able to count zero events per bin.

Am I doing something obviously wrong?
0 Kudos
Message 1 of 4
(4,473 Views)
Hello,

The behavior of non-cumulative event counting is equivalent to period measurement. Additionally, the timeouts when no edges occur on your event counting terminal are the result of duplicate count prevention. In DAQ 7.4, the default behavior of duplicate count behavior should take care of this for you, but if you cannot upgrade to DAQ 7.4, I'd do a search of the discussion forums for "duplicate count prevention". There are a number of previous posts about this attribute, including this one.

If you aren't using the second counter on your device, you should be able to use the Period Measurement 2 Counter High Frequency measurement method to get your desired values. The "Measurement Time" attribute in this case would be the "sample clock" (1 kHz in your example). Then just raed the data raw to get counts rather than scaled.

If you'd like to do it using the AI timing engine. Configure a 1 counter period measurement task, use "clockSource" as your input terminal and use your PMT TTL pulses as the "Counter Timebase Source". Then read the data raw, since the scaling will not be appropriate for your needs.

I hope this helps!
gus....
0 Kudos
Message 2 of 4
(4,459 Views)
Gus,
Thanks for the advice. I just upgraded to DAQmx 7.4.0. I was previously using 7.3.0. Now the timeout errors are gone as you predicted would happen with the different default settings of the duplicate count prevention feature.

I eventually need this application to be a two channel counter. I will be using both counters for signals. That is why I am trying to use the AI clock for the kHz timebase.

I will implement the changes you suggest in the next day or so, I have other things going too. I will post any success or failure for others who may be interested.

Keith
0 Kudos
Message 3 of 4
(4,448 Views)

Hi everyone,

I know this is an old thread but I hope someone can help me out.  It is recommended above by gus:

 

"If you'd like to do it using the AI timing engine. Configure a 1 counter period measurement task, use "clockSource" as your input terminal and use your PMT TTL pulses as the "Counter Timebase Source". Then read the data raw, since the scaling will not be appropriate for your needs."

 

The "Counter Timebase Source" is one of the Properties of the Counter Channel.  But what is "clockSource" referring to?

Thanks.

0 Kudos
Message 4 of 4
(3,774 Views)