09-09-2011 04:31 PM
Hi,
I am trying to do buffered data acquisition of a quadrature encoder using the cDAQ-9188 counters with the 9401 C Series module. I want to sample the counter at the same rate that my analog inputs are being sampled at, so I have set the tasks sample clock source to the AI sample clock. The AI sample clock is sampling at a rate of 25KHz, but for some reason when I do the DAQmx Read (N Samples) of my counter task I am only getting one data point. What is even more confusing is that if I set the number of samples to read to almost anything other than -1, it works but I get buffer overflow errors.
Can anybody relate to this? Have you found a solution? I have been trying to figure this out for a while now and I don't understand what is preventing me from reading more than one data point from my counter task.
Also does anyone know how the averaging works for the CI tasks? Is it just something that you enable? I can't get that to work, and it seems like it is related.
Thanks and Best Regards,
Ryan
Solved! Go to Solution.
09-12-2011 06:00 PM
Hello rehelmin,
The 9401 C Series Module is a Digital I/O module, how are you reading analog values? Do you have another module in the 9188? The counters cannot use the analog sample clock, if you want to sync up an analog input with counters you need to use an external clock.
To do this, you must generate a pulse using one of the counters, then send that pulse to the gate of another counter. You can then use this counter's gate as your timebase for everything. So you will use two counters to setup this external clock. The other two counters can be used to read encoders. If you open up example finder and open the example called "Meas Angular Position-Buffered-Cont-Ext Clk.vi", this will show you how to setup a counter to read an encoder based off of an external clock. The "Sample Clock Source" is just the gate of whatever counter you are using. (For example: On the 9401, if you generate a pulse on counter 0 (output on PFI3), and send that to the gate of counter 1 (PFI 5), and use counter 2 for your encoder, just remember to set all the Sample Clock Source to PFI5).
To generate the Pulses, you can refer to the example called "Gen Dig Pulse Train-Continuous.vi". Use the "DAQmx Connect Terminals.vi" to connect the internal terminals if you don't want to use a wire to connect the output of one counter to the gate of another counter.
For your analog input, you can open up "Cont Acq&Graph Voltage-Ext Clk.vi" from example finder and set the "Clock Source" to the same source as your counter's source. You can combine these examples into one VI once you get a feel for how it will work. Good luck!
-Nathan H
09-15-2011 02:52 PM
Thanks for the help! Unfortunately I don't think the method you mentioned will work. I am already using three of my four counters for other tasks.
Plan B:
What are my options for setting the sample rate of my counters using a different sample clock? If I set the sample rate to 200KHz for one of my counters and leave the sample clock unwired then I get errors saying I must specify a sample clock. Right now it seems like I can only use the 20MHz timebase which is much too high for what I'm measuring.
Thanks for the help!
Ryan
P.S. To clarify I am using a NI 9211 module for my analog input.
09-16-2011 01:40 PM
Hello rehelmin,
What are you doing with your counters? Are the gate pins of counters being used? Are you just trying to count digital events? You can find synchronization examples here NI example finder --> browse tab --> Hardware Input and Output --> DAQmx --> Synchronization --> Multi-Function (or Multi-Device), if you would like to browse other options you may have for synchronization.
One good option for this is to send the analog sample clock through your PFI lines on the 9188 from your 9211 to your 9401. (I'm sorry I didn't recommend the earlier, I didn't realize you had two separate modules). I've attached a .zip file with 2 VIs in it. One VI acquires analog signals, and sends it's sample clock and trigger the PFI lines. The other VI reads counter events, and uses the PFI lines as it's clock source and trigger. You can combine these into one VI if you want. Basically, you use the Export Signal VI to export the analog sample clock to the PFI lines, and then set that same PFI line as your external clock for the counters. Make sure to start the counter one first, and then the analog one second (so that the counter starts, and then waits for the analog trigger to start). Hopefully this should get you started.
-Nathan H
09-17-2011 10:25 AM
Hi Nathan,
I'm trying to do two things, the first is measure angular velocity and the second is measure angular postion, both from a single encoder. The counter VI that you sent me won't work because the counters on the cDAQ chassis only support the Arm Start trigger.
I was able to get triggering to work for the counter that is measuring angular position and the analog inputs (using just a regular start trigger), but for some reason when I do the same setup for the velocity tach it won't arm. Do you have any idea why that might be? I know when you do frequency measurements it is somewhat different than most other measurements because of the fact that you need to collect two data points in order to calculate the frequency, but I don't know if that has any relevance.
You've been really helpful.
Thanks,
Ryan
09-17-2011 01:37 PM
Nevermind it was something dumb. I have everything working now.
Thanks for the help!
Best Regards,
Ryan
09-19-2011 05:10 PM
Ryan,
I am glad things are working. Thanks for letting us know.
Jacob K
01-13-2012 01:25 PM
I am working on doing this exact same thing, but am having a lot of trouble figuring out how to route my signals. My hardware consists of:
- cDAQ-9179 (called "cDAQ1") with
- NI 9234 Accelerometer AI in Slot 1
- NI 9402 Digital IO in Slot 2
I am using the same two VI's as posted above (copied here with my hardware names). I tried to use cDAQ1/di/StartTrigger as the trigger terminal in both VIs and cDAQ1/di/SampleClock as the Sample Clock. I am able to run the AI VI and acquire analog data, however, when I run the counter input VI I get an error message:
Error -200452 occurred at Property Node DAQmx Trigger (arg 1) in DAQmx Start Trigger (Digital Edge).vi1 -> Count Digital Events-Buffered-Continuous-Ext Clk_mod.vi
Possible Reasons:
Specified property is not supported by the device or is not applicable to the task.
Property: Start.TrigType
I read that this can be because I am using too many DMA lines and I had tried making my AI VI use the "Interrrupts" data transfer method but I am still having trouble. I am sure that it is because I am routing my triggers and sample clocks wrong, but I don't understand how to make them right. Any help would be appreciated.
01-16-2012 05:06 PM
Hi JBradway,
I think your problem is due to the "Start Trigger" VI that you're using in your counter input task. There's a really good section in Chapter 5 of the cDAQ-917x manual that goes over counter triggering and it's definitely worth taking a look at. Basically, to begin any counter input or output function you have to "arm" the counter. This puts the counter into a ready state so that when an event is received, counting can begin. For counter output operations, this can be used in conjunction with a "Start Trigger" VI, however counter input operations use the arm start trigger to have start trigger-like behavior.
I've attached your VI, but with the start trigger replaced with an arm trigger. You'll probably have to change your inputs back to your device names, etc. Let me know if this fixes the error!
Regards,
Courtney L.
Applications Engineer
National Instruments
01-17-2012 02:40 PM
Courtney,
Thank you for the help. Would you be able to save this VI in 2010 format? I probably won't be upgrading any time this week. I am looking into the arming sugestion now.
Thanks,
Jeff