12-10-2015 03:48 PM
I'm using a USB-6221. I want to count TTL pulses coming from an external device. I want to start/stop counting using an external signal (trigger?).
The following function statements seem logical to me, but they don't work. Can you help?
DAQmxCreateTask ("pulseCnt", &cntTask);
DAQmxCreateCICountEdgesChan (cntTask, "Dev1/ctr0", "", DAQmx_Val_Rising, 0, DAQmx_Val_CountUp);
// The following statement gives this error, "Specified property is not supported by the device or is not applicable to the task".
// Property: "DAQmx_StartTrig_type"
DAQmxCfgDigEdgeStartTrig (cntTask, "/Dev1/PFI10", DAQmx_Val_Rising); // start counting when the TTL count start/stop signal is high
DAQmxCfgDigEdgeRefTrig (cntTask, "/Dev1/PFI0", DAQmx_Val_Falling, 0); // stop counting when TTL count start/stop signal is low.
DAQmxStartTask (cntTask);
How would I know if my device is capable of doing what I described above? What function calls should I use?
Do I need a statement to connect an internal clock to the counter? What statement specifies that?
How do find out where to physically connect the input signal to the USB-6221?
Sorry to ask these seemingly elementary questions but I don't understand in detail how counters work and I can't seem to find a good explaination. Documentation is either too simple or too complicated.
thanks!
12-11-2015 04:31 AM - edited 12-11-2015 04:33 AM
You should use different inputs and different instructions: basically you should connect the signal to be counted to the source terminal and the trigger to the gate terminal of the counter, next configure the task to use an arm start trigger and a pause signal. This way the counter will count only when the gate signal is high.
I modified a CVI sample some time ago and I am attaching it here: it should be correct but I cannot test at the moment as I don't have a similar device at hand; at least it compiles and runs without problems on a simulated 6221 device, even if it doesn't count of course.
You can check in Max which terminals to use and set in the program: this is the pinout for the 68-pin device, if you are using the 37-pin version the pinout is different.
12-14-2015 04:35 PM
Roberto, thanks for taking the time to provide an excellent response to my question.
Unfortunately I've been trying for days but I can't get it to work. Responses from my counter program are not correct. It seems to be counting something but I don't know what. I'm using signal generators for inputs as a debugging tool. They're sending TTL pulses to the source and gate terminals, so I know what the counts should be. (At least I think I know.) But the program responses are not very close to what I expect.
I hoped to see your program in action. But I haven't been able to run it because of version incompatiblity between your CVI and mine. Your code seems clear but I'm just not getting good responses when I plug your statements into my program.
How do I know if I'm specifying input terminal strings correctly? You stated that I can get terminal designations from MAX. But MAX just says to use Counter SRC 0 is PFI8, for example. How do I put that into a string that the function calls understand? Is it "dev1/pfi8", or "/dev1/pfi8", or /Dev1/PFI8", just "pfi8", or what? I'm not sure what the format is. Are the strings case sensitive?
Your program uses special controls to get channel and terminal information. What's special about those controls? Do they communicate with the device to create a list of valid channels and controls for a specific device?
I apologize for running on and on but I really have no idea where to look for the problem at this time.
12-15-2015 04:31 AM - edited 12-15-2015 04:33 AM
Hello,
I created the sample program modifying an existing example that you can find with the Example finder: browse in the tree up to Hardware Input and Output >> DAQmx >> Counter Measurements >> Count Digital Events, the example is the basic one CntDigEv.prj.
Based on this, I updated the user interface and the code for the new functions, relying on NIDAQmx I/O Controls instrument already used in the project (which is the one in charge of those special controls you are finding): both elements should have been installed on your system by DAQmx install.
Terminal names should be in the form "/Dev1/PFI8", it seems to me that they are case-insensitive.
I am attaching a slightly modified project that automatically loads the instrument: in the zip file you'll find also a .UIR file downgraded for use in CVI2009, which you may use to replace the original CVI2012 UIR file. Let me know if you need an older release.