Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Does PCI 6229 support DAQmxReadCtrFreq function?

Hi

         In my application I am using DAQmxReadCtrFreq function. But I am getting the error number -200525

( Read cannot be performed because this version of DAQmx read doesnt match the type of channels in the task).

I am trying to read the frequency in the range 100-1000Hz. I tried acquiring both continous samples and N number of samples.
For both the cases I am getting the same error number.
Any example program using DAQmxReadCtrFreq function will be a great helpful.
I am interested in reading the both frequency and duty cycle. Please  anyone help me on this?

 

Regards

NB

0 Kudos
Message 1 of 11
(4,639 Views)

Hi Nagraj B,

 

DAQmxReadCtrFreq() is designed to work with DAQmxCreateCIPulseChanFreq(). These functions are used for "pulse measurement", a new hardware feature that is supported on X Series and newer CompactDAQ chassis (cDAQ-9174/78/88) but not on older devices like your PCI-6229. This feature acquires both the frequency and duty cycle, as opposed to just the frequency.

 

Did you manage to find the examples that shipped with NI-DAQmx? If not, check here: Location of ANSI C NI-DAQmx Shipping Examples and DAQmx Library File for Windows

Then take a look at the example in the Counter/Measure Digital Frequency/Dig Freq-Low Freq 1 Ctr directory. It uses DAQmxCreateCIFreqChan() with DAQmxReadCounterScalarF64(). However, it doesn't measure the duty cycle--to do that with an M Series, Counter/Measure Period or Pulse Width/Buff Semi-Period-Finite might be closer to what you need.

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 2 of 11
(4,629 Views)

Hi Brad K,

            So for PCI 6229 I should use two seperate counters for measuring frequency and duty cycle.
In my application I am creating many tasks and starting and stopping the tasks in seperate function.

In other functions I am doing reading and writing operation.

 

           Without stopping the Frequency measurement task, is it to possible to use the same counter which

I have used for Frequency measurement task to measure period???

            Is there any solution to measure both frequency and dutycycle using single counter in my

application as DAQmxReadCtrFreq function does?

 

Regards

NB

 

0 Kudos
Message 3 of 11
(4,614 Views)

Hi Nagraj B,

 

You don't need two separate counter tasks. Did you try the semi-period example that I mentioned in my previous post? The M Series manual explains semi-period on page 114.

 

Once you measure the high and low times using semi-period, calculate the frequency and duty cycle:

freq = 1/(high + low)

duty = high/(high + low)

 

The semi-period example uses finite mode, so it uses both counters under the hood, but if you switch to continuous mode then it will use only one counter.

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 4 of 11
(4,604 Views)

You asked: Is there any solution to measure both frequency and dutycycle using single counter in my

application as DAQmxReadCtrFreq function does?

 

Yes, probably.  You can perform a buffered semi-period measurement and then figure out frequency and

(probably) duty cycle with some simple post-processing in software.  The only possible catch relates to

knowing the polarity of the alternating semi-period data.  Once upon a time (E-series), this could not be

specified.  The 660x counter-timer boards allowed polarity to be specified.  I don't recall needing to do this

measurement on an M-series like the 6229, but I would pretty strongly suspect that it would allow polarity

to be specified.

 

Here's a snippet of what I'd try.  I only have a simulated device, so I can't fully vouch for this code, but it

should at least be pretty close.  Note that a single counter will capture high and low times and you can

use this set of high/low times to calculate your freq and duty cycle info.

 

freq_duty.png

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 5 of 11
(4,602 Views)

Hi All,

 

         Using the formula I am able to calculate both dutycycle and frequency. Without stopping the task, If I change the value of frequency and dutycycle of the signal which I am generating and try to call the semiperiod function then the the first read value only updated in the array of DAQmxReadCounterF64 function.Its not updating the current value which I set. Pls help me to solve this issue

 

Regards

NB

0 Kudos
Message 6 of 11
(4,587 Views)

1. Sorry, I left something out of the code snippet.  I intended to show a buffered measurement but I forgot to include the needed call to DAQmx Timing.vi to set that up.  Here's another try:

 

freq and duty cycle.png

 

2. I'm not sure I understand the problem you're having.  Please try the following and see if things behave like you want:

A. Let the snippet above be its own separate vi that you run when you choose by clicking the run arrow.  (Add the freq &

duty cycle calcs as needed, of course).

B. Run it to measure your original freq/duty cycle signal.

C. Change your freq/duty cycle signal.

D. Run it again for a new measurement.

 

In this mode, you *should* see distinct and correct results from steps B and D.  If you get the right results from this mode but are having trouble with a different mode of operation, write back.  On the other hand, maybe it'll all be fine and my incomplete snippet last time was the whole problem all along.

 

-Kevin P

 

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 7 of 11
(4,579 Views)

Hi Kevin,

             I dont know much on LabVIEW. But in your vi you are first starting the task, measuring the semiperiod and clearing the task.           

I am using CVI for my application. In my application I am starting and stopping the task seperately in function. In Read Freqency function I am calling DAQmxReadCounterF64 function. When I call the function first time it measure the proper high period and low period value.

1. Call Start Function

2. Call Read Freq function.(Result for eg : High = 0.0006 and Low = 0.0004 for freq=1kHz and 60% duty)

 

But When I change the frequency and duty cycle and I follow the below steps then the value which I got in the previous measurement only updated in the array. (I already started the task in the previous measurement So I am directly calling the read function)

1. Call Read Freq function(Though I changed the value of freq and duty, Result is: High = 0.0006 and Low = 0.0004 for freq=2kHz and 30% duty)

 

So I am mot understanding why its not updating the new values???

 

Regards

NB

 

 

0 Kudos
Message 8 of 11
(4,569 Views)

1. I made the example to configure and clear the task on purpose to help isolate the source of the problem.  I don't know the CVI syntax, but try to make yourself an example where you clear the measurement task, then change the freq/duty cycle, then reconfigure & run the measurement task again.

 

2.  That said, here's what I *think* is happening.  You mentioned an array so I'm supposing you're doing a buffered measurement.  When you do that, the data acq hardware and driver will begin accumulating an array of measurements.  However, the standard behavior of the "Read" function (in LabVIEW at least, likely also in CVI) is to keep track of which data you've read out of the buffer and to give you the oldest data that wasn't previously read.

   In your case, your 2nd attempt to read is probably giving you old data that was accumulated back before you changed the freq/duty cycle.  If instead you were to stop and restart the measurement task *after* changing the freq/duty cycle, then only new data would be in the buffer for you to read.

 

3. To avoid "getting behind" on your reads this way, you may want to read all available data from the buffer each time you call the Read function.  Under LabVIEW, this is done by specifying -1 as the # samples to read which is interpreted to mean, "read all available samples."

 

-Kevin P

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 9 of 11
(4,565 Views)

Hi Kevin,

             I am using bufferred semi period measuremnt. As you mentioned instead of reading the specified number of samples it reads extra samples and store all the values in the buffer. So when I change the frequency and try to read again I will get the old values which was stored in buffer.

             So I mentioning the size of buffer by using DAQmxSetBufferAttribute()  function. It solved my problem. But the disadvantage is that I need to stop the counter task, Set the buffer size and start the task again.

             I feel starting and stopping the task again and again reduces the performance.

 

Regards

NB

0 Kudos
Message 10 of 11
(4,555 Views)