06-17-2010 03:51 PM
I am trying to upgrade a VI from the traditional DAQ to DAQmx. This VI perform buffered event counting on 4 channels of a PCI-6602 board. Although I found some information scattered throughout this forum and on the rest of the NI website, I havent solved all my problems yet.
Specific questions that I keep running into:
1) With the traditional DAQ it is very simple to assign custom PFIs as source and gate of each counter. This terminology seems to have changed in DAQmx, but there are contradicting explanations in this forum. What are the new terms and how do I set them with DAQmx?
2) It seems that the finite buffer is set with the sample clock VI in DAQmx. A required input there is a sample rate. I do not understand this. In our application, the gate pulses advancing the counting buffer are not periodic. I dont know what number to put there.
3) In the traditional DAQ it doesnt seem to matter if you dont fill a buffer to its specified size. This happens in our application as the number of gate pulses is not fixed from run to run. In DAQmx I get an error message if I read out before the buffer is full. While I can ignore this error, is there a way to avoid this and still work with buffers of unknown size?
I am attaching the VI using the tradional DAQ as well as the new DAQmx version I made based on the information I found. Hopefully someone can explain to me where they differ in functionality and how to modifiy the mx VI to reproduce the old behaviour.
Thanks a lot
Sebastian
06-18-2010 05:24 PM
Hi Sebastian,
You are correct that things have changed a little. You have the basic idea down for the example. The basic idea is that you use your sample clock to segment the samples into buffered chunks at your desired rate.
However, you have a timeout set for 0 on your DAQmx reads, and you have varying sizes for your number of samples per channel. Everytime that your counter is "gated" and latches a value, in your situation every 1 msec, the number of pulses counted will be stored onto your FIFO. When sampling in continuous mode, rather than finite, everytime you call the Counter Read in DAQmx, you will pull off "n" number of samples, as specified by number of samples per channel. I recommend using 1/10th of your sample rate, so in your case 100. Because you are sampling all of your counter at the same rate, I also recommend using the same number of samples per channel for each counter.
Your error is most likely coming form your timeout stopping your acquisition. There is a good example that ships with DAQmx for LabVIEW that can be found by searching for "buffered" in the Example Finder (Help»Find Examples... in LabVIEW) and then selecting "Count Digital Events-Buffered-Finite-Ext Clk.vi"
Best,
06-18-2010 08:51 PM
Hi Adam
Thanks for the answer. I have a few remaining questions, though.
In our application there are no regular intervals in which we want to count events. Instead, the pulse train on each counters gate channel is very irregular. In the traditional DAQ, this is no problem. In the buffered event counting, each counter produces a number for edges on the source channel between each pair of edges on the gate channel, no matter how irregular they are. What we care about are these numbers, i.e. counts per gate edge, not counts per real time (i.e. sometimes these numbers correspond to N counts per ms, sometimes N counts per us, as I said the gates are very irregular).
Also in the traditional DAQ, it is ok to specify a finite buffer size which is not reached. I.e. when the number is set to 400, but only 350 gate edges happen in one measurement, this is no problem.
Thats also related to why 2 channels have their buffer set to 3. In this particular case, one these channels only two edges are expected, so only one number is produced. We change this as needed.
I want to reproduce this behaviour with DAQmx. As far as I understand it, here I have to specify a rate on the sample clock (what used to be gate?). This doesnt seem to make sense for our application, as I am not interested in events per fixed time. I think the program actually already does what I want, i.e. puts a number of counts into a buffer with each edge on the sample clock PFI. I just dont understand what meaning the sample rate has in my case and what value I should use.
The second thing I havent figures out is how to change the counter input (what used to be source) PFI. In the channel name I specify something like deviceX/ctr0, but I never specify an actual PFI.
I hope this all is somewhat understandable. Thanks for your time helping me!
Sebastian
06-21-2010 07:37 PM
Hi Sebastian,
You should set the rate to be the fastest rate you expect, DAQmx uses this value to determine how large a buffer to allocate in your ram. Also, you can specify what terminal to count on directly by using a DAQmx Channel property node. Under Counter Input, then Count Edges, you’ll find an Input Terminal Property that you can use to specify other input terminal besides the default. As Adam mentioned, if you want to read an unknown number of sample you may want to read continuous and use other logic to end your loop. Take a loop in the example finder at: Count Digital Events-Buffered-Continuous-Ext Clk. Alternatively you can specify a timeout and handle that error appropriately. Does that help?
06-22-2010 03:41 PM
Hi
Thanks again for the reply. It all seems to work as desired now, although I have to handle an error at the end because the buffer is bigger than the actual number of gate (sample clock) edges.
I still have a follow-up question about the buffer size determination works in DAQmx. The sample clock VI gets an explicit number "samples per channel". What exactly is the rate required for, then?
Also, for buffered event counting the definition of a rate seems somewhat unclear. For example in my particular application, I am expecting roughly 400 gate events. The first 300 of these are at a rate of 1MHz, then I am counting 50 at a rate of 1kHz and the last 50 at 500kHz. I now run my program with a rate of 1MHz, but I dont see what this actually does and why it is required for buffered event counting. I would greatly appreciate if you cleared this up for me before I finish this project.
06-23-2010 06:11 PM
The “Samples per channel” input is primarily used for finite acquisition to configure the acquisition buffer. In continuous acquisition mode the buffer size is the larger of the specified samples per channel or a corresponding buffer size dependent on that rate you specify. The rate you should specify is the fast rate you expect, so 1 MHz. This way the buffer allocated by DAQmx by default should be large enough for that task.