Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

ND_COUNT - but for NI DAQmx?

Hi Hiren,

 

I believe you can accomplish that functionality with certain kinds of DAQmx tasks.  Specifically, there is a Two Edge Separation task and a Pulse Width measurement task you may want to look into.  You can find shipping examples (Help>>Find Examples) or search ni.com for them:

 

Let me know if you have any further questions.

 

Regards,

Andrew

National Instruments
0 Kudos
Message 11 of 13
(1,571 Views)

Hi Andrew,

 

Here is what I am trying to use. It is giving me an error saying I need to use the external source for the timing.

 

 DAQmxCreateTask ("", &ctr0Task);

 errorStatus = DAQmxCreateCIPulseWidthChan (ctr0Task, "Dev1/ctr0", "", 0.000001, 0.1, DAQmx_Val_Seconds, DAQmx_Val_Rising, NULL);
 if (errorStatus < 0)
 {
  DAQmxGetErrorString (errorStatus, errorString, 1024);
  printf("Error Create CTR0 Ch:%s\n", errorString);
 }

 errorStatus = DAQmxCfgSampClkTiming (ctr0Task, NULL, frequency, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 700);
 if (errorStatus < 0)
 {
  DAQmxGetErrorString (errorStatus, errorString, 1024);
  printf("Error Timing CTR0:%s\n", errorString);
 }

 

 errorStatus = DAQmxReadCounterF64 (ctr0Task, -1, 10.0, readCtr0Data, 700, &numReadCtr0, NULL);
 if (errorStatus < 0)
 {
  DAQmxGetErrorString (errorStatus, errorString, 1024);
  printf("Error Read CTR0:%s\n", errorString);
 }

 errorStatus = DAQmxStartTask (ctr0Task); 
 if (errorStatus < 0)
 {
  DAQmxGetErrorString (errorStatus, errorString, 1024);
  printf("Error Start CTR0:%s\n", errorString);
 }

I want to get the counter to get all the data in readCtr0Data array and use numReadCtr0 to find out how many points I have in the buffer.

 

Please let me know where I am making a mistake.

 

Thank you,

Hiren Patel
0 Kudos
Message 12 of 13
(1,556 Views)

Hiren,

 

I'm not able to debug your application for you.  What is the error code you are receiving?  Usually it helps to type the error code without the minus sign into the search bar at ni.com.  (For instance, if you have error "-20598" then you should type in "20598".)  There may be others who have run into the same error as you, or there may be a knowledgebase (KB) article that explains the error in more depth.  You can sort by KB articles by clicking on the "KnowledgeBase" link at the top left of the search results page.

 

Another thing you may want to try is to step through your program to see which function call returns the error.  If you look up that function in the DAQmx Help, you can get more information about what the requirements of that function are, and it may give you clues as to why it's saying you need to wire in an external source.

 

Hope this helps,

-Andrew

National Instruments
0 Kudos
Message 13 of 13
(1,548 Views)