03-10-2012 08:12 PM
Hi guys,
I've been searching these forums for about 20 hours now but I still can't seem to get this to work.
I have a NI cDAQ-9172 with a NI-9402 digital I/O module hooked up to an 360 count/rev optical encoder. The encoder produces square wave pulses equal to the input voltage. I am attempting to use the encoder as a speed sensor for my final year engineering design project. I can easily get pulse counts from the encoder into LabView (v8.5) using both DAQmx functions or the DAQ assistant. I'm pretty new to LabView but I believe I've done all I can with the program itself to make this work.
The problem I get is whenever I try to get a period or frequency output from the DAQ nothing happens. The data output stays at zero. I know the encoder is working because LabView can count the pulses. It's as if the module doesn't have any sample for time at all.
Note: When useing the "Measurements & Automation Explorer" and setting up a Task for frequency measurement, in the Timing Settings section I only have 3 options: 1 Sample (On Demand), N Samples, and Continuous Samples
Should there maybe be more?
03-10-2012 08:59 PM
I've stumbled upon some information that leads me to belive the NI cDAQ 9172 dosen't support buffers. Might this be the issue?
03-12-2012 11:32 AM - edited 03-12-2012 11:34 AM
Hi Frontball,
If the behavior you are seeing is the read timing out, then most likely you have your signal connected to the wrong input. Frequency measurements require the input signal to be connected to the gate of the counter--this has a different default input than the counter source which is used for edge count tasks. On your 9402, the default source lines are PFI 0 and PFI 3 (for counters 0 and 1 respectively) and the default gate lines are PFI 1 and PFI 2 (again, for counters 0 and 1 respectively). The input lines can be programmatically changed via a DAQmx Channel Property node.
As far as the timing goes, the underlying idea is that the counter will count a known timebase (80 MHz) during one period of your external signal--the driver can determine the period from this and thus can calculate the frequency by inverting. So, each period of your signal should generate a single sample. If you specify 1 Sample (On Demand), you will get the very first measured value after you call the read. If you specify either of the other cases, you will receive back a buffer of consecutive periods that have been inverted to measure frequency (if you are using the lower-level DAQmx API, you should use "Implicit" timing, meaning that the signal itself is what acts as the clock).
It's true that the 9172 doesn't have on-board FIFOs for buffered counter tasks, but the consequences of this are likely unrelated to your problem:
1. The 9172 cannot perform buffered counter output tasks (where you write a series of pulse characteristics to be clocked out deterministically).
2. The 9172 cannot sustain "high-frequency" buffered counter input tasks (high being in the 100s of kHz in this case).
Best Regards,
03-12-2012 01:30 PM
Alright,
So the two inputs on the Ni 9402 are Digital I/O 0 and 1, but the PFI inputs in order to obtain frequency are the gated ones (PFI 2 for input 0, ie cDAQ1MOD5/ctr0, and PRI 3, ie cDAQ1MOD5/ctr1). So with the attached .vi I should simply plug my optical encoder into BNC input 0 (with 5v source or course, one square-pulse waveform output) and set my timing sample clock to cDAQ1MOD5/PFI2 in order to obtain a frequency that I can then changed to RPM (360 pulses per rev) and write vs. time into excel?
I'm probably missing something... Maybe more step by step? I'm only 40 hours new to the program and hardware.
Thanks for the reply,
Evan
03-12-2012 07:06 PM - edited 03-12-2012 07:09 PM
Hi Evan,
The default gate terminals should actually be PFI1 (for ctr0) and PFI2 (for ctr1). However, these are just defaults and can be changed if you're using the DAQmx functions (but not the DAQ Assistant).
You don't actually use sample clock timing for frequency measurements (at least not on the 9172). What you could use is "Implicit Timing", meaning that the signal to be measured (which is connected to the gate) is also what is used to latch the sample in. However, in your case it might make more sense to start out using no timing at all--DAQmx Read will merely ask for data once it is called (if no signal is present it will timeout).
Here's a slightly modified version of your VI that should be a good starting point:
To avoid confusion, you can just specify any PFI line that you want for the Input Terminal (I usually do this with counters anyway). Implicit timing is an option that you can add in (before the task is started) but it didn't seem necessary based on what you have described so far.
Best Regards,
03-12-2012 08:18 PM
Hey John,
I've tried you're code (remade it using v8.5) and tried everything I could find for the input frequency. Every time, even though my sensor is spinning the entire time, the task times out before it recieves any information. When I select the 20 MHZ timebase my data output turns into 20000000.00 and when I select 80 MHZ timebase it goes to 26666666.67, but otherwise with any other input it stays at 0 and times out.
I've been able to see the pulses using a digital waveform measurement .vi that I've attached, but I have no idea how to make it into a usable form so I can monitor the rotational speed over a specified time period and write it to excel.
Could the counter frequency not be working because of my module or something else in its configurarion? I've got it set up as a sinking input, which it says the NI 9402 is capable of.
Could my module be hooped?
Thanks,
Evan
03-13-2012 12:17 PM - edited 03-13-2012 12:17 PM
Which slot of your chassis is the 9402 in? To do a digital waveform measurement requires the module to be in slot 1-4 of the 9172 chassis. To do a counter measurement requires the module to be in slot 5-6. I guess I hadn't thought about it because it sounded like you were successfully implementing an edge count task (i.e. with one of the counters), but perhaps it was a digital input task all along?
The name of the terminal should be of the form:
/MODULE_NAME/PFI0
Where MODULE_NAME is the name of your module (can be found in Measurement and Automation Explorer). For example, /cDAQ1Mod5/PFI0. If your module is not in the appropriate slot, you won't be able to see its PFI lines in the DAQmx Terminal Control.
If you are still having problems, take a screenshot of the inputs on your front panel as you have them configured (or save them as default values and re-post the VI). The measured values of the time bases are correct (you can't measure 80 MHz directly with the 1 counter method), so it still sounds like the problem is with referencing the correct input for your external signal. The fact that you can see the signal as part of a digital input task leads me to believe the logic levels are correct to be driving the 9402.
Best Regards,
03-13-2012 04:13 PM
Hey John,
I've found out about that stuff to do with the 9172 chassis and have since switched to a 9178 chassis just because I thought it might be the issue. Turns out it wasn't.
I've attached my VI with the inputs set as constants. I currently have my encoder (single pulse waveform) hooked up as a sinking source to bnc terminal 0 on my 9402. The 9402 is currently installed in position 5 or the 9178 chassis.
I just wanna say that I really appreciate all that you're doing to help.
Thanks,
Evan
03-14-2012 12:17 PM
Hi Evan,
Do you mean that the output of the encoder is open collector and that it cannot source any current? If that's the case then you need an external pull-up resistor to 5V to use this in conjunction with the 9402. The value of the pull-up will be dependant on how much current your output can sink. The 9402 is active-drive when used as an output module and thus can sink or source current, but as an input the lines are just tri-stated with a ~50 kOhm pull-down to ground.
This has me confused though because it sounded like you were successfully measuring data from the same encoder using a digital input task. I would expect either task type to have the same problem.
Best Regards,