06-08-2010 04:19 AM
Hi Folks,
I am trying to access counter using ANSI C (python wrapper actually). Now I am able to read number of counts with sets of commands:
DAQmxCreateTask("", &task);
DAQmxCreateCICountEdges(task, "Dev1/ctr0", "", DAQmx_Val_Rising, 0, DAQmx_Val_CountUp);
DAQmxSetCICountEdgesTerm(task, "Dev/ctr0", "Dev1/PFI11");
DAQmxStartTask(task);
DAQmxReadCounterScalarU32(task, 10, &data, NULL)
This example cumulates all counts since task was started, so I can get all counts from begining of task or from previous call (using internal software buffer).
But what I want to do is count non-periodical series of 'events' represented with TTL/NIM pulses. So I want to set up measurement (integration) time for one single shot (let say 1000 ms) and then in loop read number of counts (=events) in this window (i.e. frequency in Hz). I probably need to trigger the 'counting function' in some way, probably something like DAQmxCfgSampClkTiming...
Can you please show me short, simple piece of code, how to do this?
Thanks a lot.
Radek
06-09-2010 03:07 AM
Hi Radek,
I'm not sure if understand what exactly do you need to do, but it really sounds like period (or frequency) measurement. There, you actually perform edge counting for exactly specified period of time.
Notice here, that you need another signal of known frequency. To get this signal, you can use for example 2nd counter. If you need to measure edge count continuously, meening read edge count on each rising edge of the Gate (known) signal and then restart counting, then you might consider buffered operation.
I strongly recomend to read manual for your DAQ board. Assuming you are using M Series, use M Series User Manual, and check chapter 7 - Counters.
There are actualy couple of examples shipped with DAQ driver itself. Chceck NI-DAQ™mx C Reference Help (Windows Start -> Programs -> National Instruments -> NI DAQ -> Documentation -> Text based Support) for information on exact location of the examples. By default, they are in public Documents\National Instruments\NI-DAQ\Examples.
In my case, on Windows 7 they can by found in C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter
As I mentioned, the best would be to clarify with manual mentioned above what is the best counter mode for your application, and I'm sure you can find this implemented in shipped examples.
Hope it helped.
Stefo
06-16-2010 02:00 PM
So I spent a lot of time reading manuals and examples, googling and experimenting with our devices, but I am still not able to get a simple piece of code, which is doing what I want.
Can you please anybody show me the code which do what is on that picture one post ago (fig. 7-8), also with description how/where to connect all signals? With preinstaled examples there is one problem, that I am not sure what are they doing, so I can not follow them.
Yes, and we have several 6601 and 6602 cards and one 6229, if it matters...
Thanks a lot.
Radek
06-17-2010 02:10 AM
Hi Radek,
To measure period, it is pretty the same as when you configure let say pulse width (there is example on pulse width), just change the functions to measure Counter Input -> Period Measurement (DAQmxCreateCIPeriodChan). This should be pretty much everythink you have to do:
1. Create a task. (DAQmxCreateTask)
2. Create a Counter Input channel to measure Period (DAQmxCreateCIPeriodChan).
3. Call the Start function to arm the counter and begin measuring. (DAQmxStartTask)
4. Call the Read function to return the next pulse width measurement. Set a timeout so an error is returned if a pulse is not returned in the specified time limit. (DAQmxReadCounterScalarF64)
5. Call the Clear Task function to clear the task. (DAQmxStopTask; DAQmxClearTask)
6. Display an error if any.
If you want to get information on what should be connected, you can see M Series User Manual, as I mentioned earlier. Connection and functionality of period measurement is described in chapter 7, Counters -> Counter Input applications -> Period Measurement. You need to connect your measured signal into Counter Source. Counters IOs are actualy PFI lines, and you can pick which one to be used. See page 7-30 to get Default Counter/Timer Pinouts. For example, for M Series devices CTR 0 Source is connected to PFI8 by default. Consult pinout of 6601 and 6602 with 660x User Manual.
If you need to know the pins where to connect the signal, see device pinout in particular manual (for example for 6229, see page 219, PCI/PXI-6229 Pinout of M Series User Manual manual).
Hope this will lead you to solution
Regards / S pozdravom
Stefo
06-25-2010 10:38 AM
Hi Stefo,
Thanks for trying to help me.
I tried to use DAQmxCreateCIPeriodChan and it works fine, but it just not what I was looking for. In our application, we have to read counts from multiple counters (usually 3) in the same time window and the signal is NOT periodic (if it matters). Also it blocks one more counter for each one in the task, so if I need 3 Inputs, the 6601 cards with just 4 counters is not enough. Maybe if it is be possible to share that "gate" counter, I will need just 4 and also it will be maybe possible to count corresponding events in the same time window.
But I found a solution. This "code" (seems to) do exactly what I need:
(this is just important part of Python code, but I guess it is very easy to read, so...)