LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Measure 2 counting rates with 2 counters

Solved!
Go to solution

I'm trying to measure counting rates (counts / second) for two devices using NI PXI 6224 and Labview 2012.
As far as I understand I need one counter for counting and one timer to define the counting interval.
The two cannot belong to the same general-purpose counter/timer or I get "resource reserved" error.
Is there a way to read out two counting rates simultaneously with the two counters on NI PXI 6224?

The example shows my current approach for one counting rate.

PS: The example is constantly creating and deleting tasks.
Can this be changed such that a single create task is followed by multiple reads and a single delete task?

0 Kudos
Message 1 of 11
(3,567 Views)

Since you just want frequency (counts/second), have the counters measure Period (seconds/count) and invert the measurement.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 11
(3,526 Views)

Thank you for that hint.

It works very well for periodic signals, but I forgot to mention that in my case the signals come from an ion detector and are not periodic.

Thus I do have to count each pulse in the time intervall to get the rate.

Are there other options?

 

0 Kudos
Message 3 of 11
(3,503 Views)

In that case, I would use a digital circuit.  Use a pulse circuit (like a 555 Timer) and AND that with the pulse output.  The result goes into your counter.  Then just use another digital line to enable the pulse timer, wait long enough for the pulse to end, and read the counts.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 11
(3,498 Views)

Hi,

 

If I got you correctly, you are trying to perform Edge Counting with your PXI 6224. If this is the case, I would advise you to have a look at LabVIEW examples; just search for "count".

 

For simultaneous measurement there are also lots of examples, if not directly for Edge Counting, for other tasks such as Continuous Voltage Acquisition. You can get the implementation idea for synchronization from such examples and program and adjust this code. It shouldn't be that complicated 😉

 

Let us know if you have further questions,

Bart

0 Kudos
Message 5 of 11
(3,485 Views)

Hi,

 

I'm familiar with the Edge counting examples but none of them adresses counting rates.

From "Counter - Count Edges.vi" I learned how to use a second counter/timer to determine when the first counter should start, pause or reset.

 

If I reset the counter periodically the count rate just before reset should be the total number of counts during the period.

However I was not able to synchronize reading out the counts to this event. I would be very interested in an example how to do this.

 

With the digital pause I can make sure the counter stops after a defined time and then read out the value.

In order to reset the counter I then have to restart the task as shown in the example attached in my original question.

 

I'm using multiple channels for voltage aquisition but when I try the same for counting I get the following error:

"There can not be multiple counters in the same task for input operations. Use a seperate task for each counter."

 

The 555 solution sounds reasonable but for now I will just read the rates alternating.

 

Best,

Tim

 

0 Kudos
Message 6 of 11
(3,472 Views)

Only have time for very brief summary right now...

1. One possible approach I've used is to "borrow" the AO subsystem for its sample clock if my app doesn't need to generate clocked AO.   You can just continuously regenerate 0 Volts on ao0.  Configure your two edge-counting tasks to use the AO Sample Clock as their own sample clock. 

2. Another possibility is to set up both counters for period measurement (as already suggested).  You can then post-process to calculate an average count rate over any interval you choose.  Note: this method offers a lot of flexibility for post-processing, but is also a little more prone to generating DAQmx errors during fast bursts of pulses.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 7 of 11
(3,454 Views)

1. I only have AI on the PXI 6224 but I guess it would work the same way.
Do you know of an example of how do this, since I'm new to DAQmx it takes a lot of time to figure it out.

2. Can you specify how to do the post processing?

Best, Tim

0 Kudos
Message 8 of 11
(3,436 Views)
Solution
Accepted by topic author tim.vi

Below is a decent starting point for method 1:

(This is a snippet.  You can save the image as a file, then drag it into an empty vi block diagram to get instant code.)

 

 

- Kevin P

 

count rate using dummy AI for clock.png

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 9 of 11
(3,429 Views)

Hi Kevin,

 

thank you so much, it worked instantly. Also the comments were very helpful.

However I do think the counts from the last iteration should be subtracted, not added.

I was worried about what happens if the counts reach the limit of U32, but appearently everything is wrapped correctly.

I also replaced your visually advantageous "Max" with the efficient "reverse 1D array" + "index array" to get the last element.

I then modified it so that I can read out my 32 AI channels while using both counters.

 

Best,

Tim

0 Kudos
Message 10 of 11
(3,390 Views)