08-10-2012 08:10 PM - edited 08-10-2012 08:15 PM
Hi,
Hardware: USB 6251 Mass Term
Software: LabView 2011 SP1
I need to measure the angular position of a lever and the speed of a treadmill belt. I am using two quadrature encoders for this. To accurately calculate the velocity I would like to use buffered position measurements using one of the counters available on board. I understand that for this technique I need to provide a sample clock for the counter. I wonder whether it is possible to use the internal timebase for this. Note that both of my counters are used so I cannot generate a clock signal with them.
I found two contradictory pages relating to my problem:
1) http://digital.ni.com/public.nsf/allkb/EA7FFFEAFC3E1D85862572F700699530
2) http://digital.ni.com/public.nsf/allkb/775290A3121D1FFC862577140074D3B3
The first one says I can use the 100KHz internal clock, and the second one says I must have an external clock.
Any comments/solutions?
Javad
Solved! Go to Solution.
08-13-2012 12:21 PM - edited 08-13-2012 12:30 PM
Hi Javad,
If you are doing buffered position measurement you cannot use the internal clock since buffered counter tasks cannot divide down the internal or onboard clock as stated in Why do I Get Error -201002 or -200303 When Doing Buffered Event Counting?
Since both of your counters are already used, you can feed an external clock to a PFI line and use that as a sample clock for your buffered counter task. However, you will need an external clock source to accomplish that.
08-13-2012 12:25 PM - edited 08-13-2012 12:29 PM
Hi Javad,
On your particular device there is not a direct route from the 100 kHz timebase to the counter (according to the routing table found in MAX):
The yellow cell indicates that a route is possible but it is not direct (the "Gate" terminal is used as the sample clock for M Series counters). Mousing over the yellow cell reveals that making this route actually requires the use of a counter (so it isn't suitable for your application).
On the row above "100kHzTimebase" you'll notice there is something called "FrequencyOutput" which does have a direct route to the gate. This would be the way to go if you wanted to route 100 kHz (or some other frequency) as your counter sample clock--you can configure it similarly to a standard counter output task:
The frequency output does not have as many features as a counter output but it is capable of generating a stable continuous frequency. There are only 32 distinct frequencies that may be generated using Freq Out on the 6251:
{10 MHz, 100 kHz} / {1:16}
Keep in mind that the resolution of your frequency measurement using this method is going to be equal to how often you update the measurement (I hope that makes sense). That is, if at the end of every 1 second you take the total number of counts since the last second, you would have a 1 count per second resolution equal to the change in count. If you take the difference twice every second, you would end up with half the resolution. You will be sampling the count register rather quickly but you will need to only make the frequency calculation after every N samples in order to obtain a meaningful number.
Another method which will almost certainly give a higher resolution in less time at speeds typical of encoders is to configure a frequency measurement (the counter will count the internal 80 MHz timebase during one period of your external signal and the driver calculates frequency for you based on the result). This method only uses a single input--so you can just feed it the "A" signal of your quadrature encoder (the method won't work if you are interested in absolute position or direction). Without using the A and B signals together you will be susceptible to noise (which is common to have from a quadrature encoder) which you would want to remove (perhaps by configuring a digital filter). Finally, you will want to configure a reasonable timeout on your read calls (which will block until a period of your external signal occurs) and handle error -200284 to simply report back "0 Hz" to make sure your program is still responsive even without an external signal present.
Best Regards,
08-14-2012 01:14 PM
Thanks John for the very detailed answer and soloution.
- Javad
08-14-2012 01:15 PM
Thanks Mikhail for your reply. I wanted to avoid using an external clock, but it seems that I have no other choice. Now I am using a function generator as the external clock.
- Javad