06-02-2015 04:10 PM
Hello,
I am using a NI cDAQ-9178 with the NI-9205 (in slot 1) and NI-9402 (in slot 2). I have a (Keysight 33220A) function generator generating a square wave at 100Hz (@5Vpp) and is connected to the ci0 of the NI-9402 module. The output of the function generator has been verified with an oscilloscope.
I am having trouble reading the frequency using a counter input channel. I am executing the DAQmx ANSI C example that shipped with NI-DAQmx version 14.5 named "Dig Freq-Low Freq 1 Ctr". Below is the error message that I observe when I attempt to execute the code:
DAQmx Error: Specified operation did not complete, because the specified timeout expired. Task Name: _unnamedTask<0> Status Code: -200474 End of program, press Enter key to quit
I have attached the corresponding C file to this post. I have NIDAQmx driver version 14.5 installed on my machine.
Is this a regression in the driver or a limitation in the NI hardware modules? If this is a bug in the driver, can you please provide a CAR # related to the bug.
PS: I am able to use the NI tool to count edges using the exact same setup.
Thanks,
Varun Hariharan
The MathWorks
06-02-2015 04:50 PM - edited 06-02-2015 04:51 PM
You didn't specify which input terminal (you can use DAQmxSetCIFreqTerm) so the driver will use the default:
Counter/Timer Signal | Default Pin Number | Signal Name |
---|---|---|
CTR 0 SRC | 0 | PFI 0 |
CTR 0 GATE | 1 | PFI 1 |
CTR 0 AUX | 2 | PFI 2 |
CTR 0 OUT | 0 | PFI 0 |
CTR 1 SRC | 3 | PFI 3 |
CTR 1 GATE | 2 | PFI 2 |
CTR 1 AUX | 1 | PFI 1 |
CTR 1 OUT | 3 | PFI 3 |
CTR 2 SRC | 1 | PFI 1 |
CTR 2 GATE | 3 | PFI 3 |
CTR 2 AUX | 0 | PFI 0 |
CTR 2 OUT | 1 | PFI 1 |
CTR 3 SRC | 2 | PFI 2 |
CTR 3 GATE | 0 | PFI 0 |
CTR 3 AUX | 3 | PFI 3 |
CTR 3 OUT | 2 | PFI 2 |
FREQ OUT | 1 | PFI 1 |
The frequency measurement takes its input signal on the gate of the counter. CTR 0 GATE uses pin 1 by default. If you connected your signal to pin 0 of the 9402 this would explain the problem. It also makes sense that you can count edges with the same setup, since this would use the SRC terminal which is in fact pin 0 for ctr0.
To avoid issues like this, I pretty much always define my input terminals when possible rather than use defaults.
Best Regards,
06-03-2015 10:31 AM
Hello John,
Thank you for that. I was able to modify the example to give me a frequency reading.
This example, however, used to work with the 9.x version of the driver. Is this a deliberate change in 14.x of the driver? Is this behavior expected going forward?
Regards,
Varun Hariharan
The MathWorks
06-03-2015 11:21 AM
It's been ~3 years since I last worked at NI so I can't double-check this for you, but the behavior should be the same--as far as I'm aware the frequency measurement has always used the default gate terminal in DAQmx (the high frequency 2 counter method uses the source terminal though).
Looking at the C Example... I realize the documentation at the top could probably be a bit more specific, but it does point in the right direction:
/********************************************************************* * I/O Connections Overview: * The counter will measure frequency on the input terminal of the * counter specified in the Physical Channel I/O control. * * This example uses the default source (or gate) terminal for the * counter of your device. To determine what the default counter * pins for your device are or to set a different source (or gate) * pin, refer to the Connecting Counter Signals topic in the * NI-DAQmx Help (search for "Connecting Counter Signals"). * *********************************************************************/
Following the instructions, I found this in the DAQmx Help:
Measurement | Ctr0 | Ctr1 | Ctr2 | Ctr3 |
---|---|---|---|---|
Count Edges |
|
|
|
|
Pulse Width Measurement | PFI 1 | PFI 2 | PFI 3 | PFI 0 |
Period/Frequency Measurement (Low Frequency with One Counter) | PFI 1 | PFI 2 | PFI 3 | PFI 0 |
Period/Frequency Measurement (High Frequency with Two Counters) | PFI 0 | PFI 3 | PFI 1 | PFI 2 |
Period/Frequency Measurement (Large Range with Two Counters) | PFI 0 | PFI 3 | PFI 1 | PFI 2 |
Semiperiod Measurement | PFI 1 | PFI 2 | PFI 3 | PFI 0 |
Two-Edge Separation Measurement |
|
|
|
|
Position Measurement |
|
|
|
|
Best Regards,