Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Counter in PCI-6229 to count edges

Hi,

 

Can anyone explain me how to use counter in 6229 to count the number of edges (I am new to MIO)

 

I have chosen "Dev1/ctr0" and called the following functions:

 

DAQmxErrChk (DAQmxCreateTask("",&gTaskHandle));
DAQmxErrChk (DAQmxCreateCICountEdgesChan(gTaskHandle,chan,"",edge,initialCount,countDirection));

DAQmxErrChk (DAQmxCfgSampClkTiming (gCITaskHandle, ClkSource, Clkrate, edge, mode,numSamplesPerChan))

DAQmxErrChk (DAQmxStartTask(gTaskHandle));

DAQmxErrChk (DAQmxReadCounterU32(gTaskHandle,numSamplesPerChan,timeout,data,arraySize,&sampsPerChanRead,NULL));

 

where ClkSource = "/Dev1/10MHzRefClock",

           Clkrate=1000,edge=DAQmx_Val_Rising,mode=DAQmx_Val_ContSamps,initialCount=0, countDirection=DAQmx_Val_CountUp,

           numSamplesPerChan= -1,timeout= -1,arraySize=10

and data is an array of size 10.

 

I am displaying the values of "data" and i get only one value which is 0 always. The "sampsPerChanRead" is always 1.

How is it that the Test Panel in NI MAX is able to generate the counter values wherase the NI example program at National Instruments\CVI81\samples\DAQmx\Counter\Count Digital Events\Cnt Dig Events is not generating any counter values?

 

One more thing, in the NI example, if i choose ClkSource = "/Dev1/10MHzRefClock" and Clkrate=10000000 then i am getting a "General protection error" and the application is failing.

 

Kindly let me know how to solve this. Do i need to do some external connection or routing? Can i do them programmatically using some functions?

 

Thanks in advance,

Priya.

0 Kudos
Message 1 of 4
(5,343 Views)

Hi Priya,

 

Based on your explanation, it appears that you are trying to do buffered edge counting, meaning that you are interested in the count of your source signal only at certain times, specified by the gate signal. In your case, you are configuring this gate signal to be a 10MHz clock. What kind of signal are you trying to count the edges of, and why are you interested in using a 10MHz signal as the gate? I am guessing that you may actually be trying to count the 10MHz clock rather than use it as the gate, since when you use the MAX test panels, the source is the signal you are able to select as opposed to the gate. If this is the case, then you will not want to configure the sample clock timing, as this only configures the gate. Instead, you will simply create the count edges channel and then set the input terminal of the count edges task with the following property:

 

DAQmxErrChk (DAQmxCreateTask("",&gTaskHandle));
DAQmxErrChk (DAQmxCreateCICountEdgesChan(gTaskHandle,chan,"",edge,initialCount,countDirection));

DAQmxErrChk (DAQmxSetCICountEdgesTerm(gTaskHandle,"Dev1/ctr0", "10MHzRefClock" ));

DAQmxErrChk (DAQmxStartTask(gTaskHandle));

 

In the above example, we have specified the source of the counter to be the 10MHz Reference Clock. By default (such as if you do not call the DAQmxSetCICountEdgesTerm property), the source of the counter (ie- what is actually being counted) will be  PFI8. More information on the DAQmxSetCICountEdgesTerm property may be found in the NI-DAQmx C Reference Help document, as well as the online KnowledgeBase article linked here. Hopefully this helps in accomplishing what you need, but if not, or if you have additional questions, please let me know.

 

Best Regards,

Daniel S.
National Instruments
Message 2 of 4
(5,318 Views)

Hi Daniel,

 

Thanks for the explanation. Actually i was looking for buffered counter for counting edges (with Gate signal).

I have some more questions:

 

1. How does on-demand counter (using DAQmxReadCounterU32) for counting edges differ from using the DAQmxReadCounterScalarU32?  

 

When do we have to use either of these methods?

 

2. How to use counter to measure frequency? I understand we can use DAQmxReadCounterF64 or  DAQmxReadCounterScalarF64 methods. Also do we need to use a Gate signal here which has to be configured using DAQmxCfgImplicitTiming ?

 

Kindly provide me an insite into these functions and the scenarios in which we need to use them.

 

Thanks,

Priya.

 

0 Kudos
Message 3 of 4
(5,271 Views)

Hi Priya,

 

Let me see if I can clarify the following differences with the Counter Read functions:

 


 1. How does on-demand counter (using DAQmxReadCounterU32) for counting edges differ from using the DAQmxReadCounterScalarU32?  

 

When do we have to use either of these methods?


The DAQmxReadCounterU32 function will return multiple samples when it is called (the count at each gate pulse) and so it should be used when performing buffered edge counting. The DAQmxReadCounterScalarU32 function would be used when performing a simple edge counting task, as it will return a single value when called (the current count).

 

 


2. How to use counter to measure frequency? I understand we can use DAQmxReadCounterF64 or  DAQmxReadCounterScalarF64 methods. Also do we need to use a Gate signal here which has to be configured using DAQmxCfgImplicitTiming ?

 

Kindly provide me an insite into these functions and the scenarios in which we need to use them. 


To measure frequency, you will want to call the DAQmxCreateCIFreqChan function to create a frequency task. Using this function, you will need to specify the measurement method as one of three different types: Low Frequency with 1 Counter, High Frequency with 2 Counters, or Large Range with 2 Counters. As with counting edges, you can perform a single measurement using the DAQmxReadCounterScalarF64 function, or a buffered measurement which will use the DAQmxReadCounterF64 to return multiple values. If you do wish to perform a buffered measurement, you will need to call the DAQmxCfgImplicitTiming function and specify if you are going to use finite or continuous sample mode.

 

For more information about each of these different types of frequency measurements and when to use each one, please refer to the Frequency Measurements: How-To Guide. Depending on which method you use, your signal which you will actually be measuring may be input as the gate of the counter or the source. All of the other signals required by the measurement will be automatically routed by DAQmx and so you will not need to explicitly specify any of these signals. In the case of the Low Frequency method, your signal will be the gate of the counter and the internal timebase will be the source. For the High Frequency method, another counter generates a pulse train which is used to gate the counter doing the measurement. In this case, your signal to be measured will be the source of the counter doing the measurement. Finally, in the Large Range method, your signal will be the source of the counter generating the pulse train, and this counter will divide your signal down and output it to the counter performing the measurement. The counter doing the measurement will use the internal timebase as its source and the divided down pulse train from the other counter will be used as the gate. One good method that I find to use when determining which pin to connect the signal to is to create a Counter Input Frequency task in Measurement & Automation Explorer. When you configure the task and specify which method to use, it will tell you which pin to connect your signal to. Hope this helps,

Daniel S.
National Instruments
Message 4 of 4
(5,248 Views)