Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

configuring a PFI pin as a counter source/gate

I have a NI 6229 M series DAQ. I would like to perform a pulse width measurement using the same. There are two counters (ctr0 and ctr1) in the board. I would like to know if i can configure any PFI pin as a patricular counter's source / gate input??...
 
0 Kudos
Message 1 of 12
(8,018 Views)
You should be able to route any PFI to a counter as long as it is not in use by another task.  You can view the available device routes in Measurement and Automation Explorer (MAX).  To find your device routes in MAX, expand Devices and Interfaces >> NI-DAQmx Devices and select your device then select the Device Routes tab.  I have attached a picture of my PCI-6251 device routes.

Regards,

Jesse O.
Applications Engineering
National Instruments
Jesse O. | National Instruments R&D
0 Kudos
Message 2 of 12
(7,995 Views)
Could you be more specific regarding how to make the connection using MAX or whatever?  I'm using LabWindows/CVI, and have a PXI-6229 device.  I'd like to connect PFI-15 to the Counter 0 source.  This is intended to use two counters to measure a 2MHz clock frequency.
0 Kudos
Message 3 of 12
(7,650 Views)

Hello Sandia,

First, follow the directions above to make sure the terminals are available for routing.  You can see in the above image, that for the device shown, PFI15 can be directly routed to Ctr0Source. After confirming that your device also supports this routing, you can use the following function to connect terminals in CVI.

You will find the following information in the DAQmx C Reference Help.

int32 DAQmxConnectTerms (const char sourceTerminal[], const char destinationTerminal[], int32 signalModifiers);

Simply specify the terminals you would like to connect for the source and destination.  Options for the signal modifier include:

DAQmx_Val_DoNotInvertPolarity (Do not invert the signal).
DAQmx_Val_InvertPolarity

(Invert the signal).

Alternatively, you can set terminals with property nodes for the channel you set up.  For example:

int32 __CFUNC DAQmxSetCIFreqTerm(TaskHandle taskHandle, const char channel[], const char *data);

Hope this helps,

Jennifer O.
Applications Engineer
National Instruments

0 Kudos
Message 4 of 12
(7,631 Views)
Still don't quite have it correct.  I get a non-fatal run-time error, shown below.  Is the sequence I'm using correct?  Or perhaps I can't re-route the connections when I'm trying to measure frequency?
 
Error message:
Specified route cannot be satisfied, because it requires resources that are currently in use by another route. 
Property: DAQmx_CI_Freq_Term
Property: DAQmx_CI_Freq_StartingEdge
Source Device: DAQBoard
Source Terminal: PFI8
 
Required Resources in use by
Source Device: DAQBoard
Source Terminal: PFI15
Destination Device: DAQBoard
Destination Terminal: Ctr0Source
 
The task creation routine for the frequency measurement is:
   DAQmxCreateTask("DAQClockFrequency", &taskOut);
 
  // Create a route between a source and destination terminal
  DAQmxConnectTerms ("/DAQBoard/PFI15", "/DAQBoard/Ctr0Source",
        DAQmx_Val_DoNotInvertPolarity);
 
  DAQmxCreateCIFreqChan(taskOut, "DAQBoard/ctr0",  // PFI8 is default Ctr0 Source
  "Frequency", 1000000, 3000000,
  DAQmx_Val_Hz, DAQmx_Val_Rising,
  DAQmx_Val_HighFreq2Ctr, 0.001,
  4, "");  
  DAQmxCfgImplicitTiming(taskOut, DAQmx_Val_FiniteSamps, NUM_SAMPLES);
0 Kudos
Message 5 of 12
(7,618 Views)
Try setting up your task, then use DAQmxSetCIFreqTerm(taskHandle,"", "DAQBoard/PFI15"); to use PFI15 for the counter source before starting the task.  You may need to reset your board to free up any resources previously reserved.  You can do this by selecting your board in Measurement and Automation Explorer (MAX) and clicking Reset Device. 
 
I set this up with an M-Series board using the DigFreq-Buff-Cont-LargeRange2Ctr.c shipping example found in your National Instruments directory under NI-DAQ/Examples/DAQmx ANSI C/Counter/Measure Digital Frequency.
 
Hope this helps,
 
Jennifer O.
0 Kudos
Message 6 of 12
(7,601 Views)

Just as a final note, this application works now.  The essential code lines are:

DAQmxCreateTask("DAQClockFrequency", &taskOut);

 

DAQmxCreateCIFreqChan(taskOut, "DAQBoard/ctr0", // PFI8 is default Ctr0 Source

   "Frequency", 1000000, 3000000, DAQmx_Val_Hz, DAQmx_Val_Rising,

   DAQmx_Val_HighFreq2Ctr, 0.001, 4, "");

 

// Layout error on circuit board, grounding PFI8. Reroute around error. The alternate function,

// DAQmxConnectTerms ("/DAQBoard/PFI15", "/DAQBoard/Ctr0Source", etc.

// does not seem to work here.

DAQmxSetCIFreqTerm(taskOut,"", "/DAQBoard/PFI15");  // the initial '/' was required

 

DAQmxCfgImplicitTiming(taskOut, DAQmx_Val_FiniteSamps, NUM_SAMPLES);

 

The measurement task is started and samples taken in a separate function call.  The only issue here is that the initial sample is incorrect.  The value of NUM_SAMPLES is 200, so I just set the Sample zero value to equal the Sample one value.

 

 

0 Kudos
Message 7 of 12
(7,593 Views)

Thanks Sandia for sharing your solution.

I thought for completeness I would add an explanation regarding the initial frequency measurement. Frequency measurement works by counting the number of unknown pulses that occur during a known time period or by counting the number of pulses of a known frequency which occur during the unknown period.  This determines the period of the signal and the frequency can be calculated as f=1/T. 

For the very first measurement, the counter will begin counting the pulses on the source and it is unlikely that this is starting exactly at the beginning of the gate pulse and therefore the first reading will be inaccurate (too few samples will be read).  The same applies to period measurement. This is expected behavior and is outlined well in the following knowledgebase: When Performing Buffered Period Measurement, Why Is the First Value in the Buffer Incorrect? .

Regards,

Jennifer O.

0 Kudos
Message 8 of 12
(7,573 Views)
Is there some manual for C# (.NET 2.0)? Because I have the same problem. I want to route the PFI0 channel to the counter gate and I know that it should work with my card (checked it in MAX). Thanks in advance.
0 Kudos
Message 9 of 12
(6,761 Views)
duplicate post
Rod T.
0 Kudos
Message 10 of 12
(6,731 Views)