02-27-2020 08:23 PM
Hi, all,
I am trying to test the example code at
Examples\DAQmx ANSI C\Counter\Measure Digital Frequency\Dig Freq-Buff-Cont-Large Range 2 Ctr
I changed the original code
DAQmxErrChk (DAQmxCreateCIFreqChan(taskHandle,"Dev1/ctr0","",100000,1000000,DAQmx_Val_Hz,DAQmx_Val_Rising,DAQmx_Val_LargeRng2Ctr,0.001,10,""));
to
DAQmxErrChk (DAQmxCreateCIFreqChan(taskHandle,"Dev1/ctr0","",100000,1000000,DAQmx_Val_Hz,DAQmx_Val_Rising,DAQmx_Val_HighFreq2Ctr,0.001,10,""));
I found that, the time to execute the following command is very slow (~8 second) if my input signal frequency is low (~20 Hz).
DAQmxErrChk(DAQmxReadCounterF64(taskHandle, 1000, 10.0, data, 1000, &read, 0));
Since I use the 0.001 second in the measTime, I supposed it should be very fast. It should be around 1000 * 0.001 s = 1 second.
It behavior normal if my input signal frequency is high.
Thanks for help from anyone first!
03-04-2020 04:20 PM
As a LabVIEW guy, I don't really know any of the text API's. But this question's been hanging around a long time, so I'll take a shot.
First, virtually all my frequency measurement experience with counters has used the 1-counter method. I'd bet you'd be fine using it too, considering that your nominal frequency is only in the realm of ~20 Hz. Virtually any device with counters could measure that with a timebase of at least 20 MHz, giving you a quantization error of only 1 part per million.
I could give more definitive advice and statements if you switched over and started working with 1-counter freq measurements.
Nevertheless, I looked up your API functions and will tentatively comment thusly:
1. Have *you* looked up those functions? Some of the arguments you supply don't really make much sense when measuring a ~20 Hz signal.
2. When creating the task, you indicate Min and Max expected freqs of 100 kHz and 1 MHz. You also designate a desired measurement time of 0.001 sec. But your signal is expected to be ~20 Hz, so its period is ~0.05 sec.
3. When you attempt to read your measurements, you ask for 1000 measurements of a 0.050 sec interval while designation a 10 second timeout.
4. This combination of #'s isn't self-consistent and I simply don't know how DAQmx handles it. If the measurement time parameter is honored, 1000 measurements would need 1 second. If the input signal period is honored, 1000 measurements would need 50 seconds. But the function won't wait that long because your timeout is 10 seconds.
So from where I sit, your observation of ~8 sec seems most likely to be a timeout.
5. If you were to change to a 1-counter freq method, you could easily just read 1 value at a time in a loop. Then you could get a fresh new measurement every 50 msec, and it would have only a 1 part-per-million quantization error. Tough to beat that!
-Kevin P