I am trying to read digital encoder using USB-6001. Channel A and Channel B are being read by DI pins (1.1 and 2.0). Idea is to determine the phase difference between two channel. Based on its sign (positive phase or negative phase), direction of motion will be determined and counts will be incremented or decremented accordingly.
Challenge being faced: USB-6001 has only one counter pin but I require two of them to determine the position and the direction. Therefore, I decided to make use of its digital pins.
VI logic : Rising edges are being detected from each signal and rising edge index is stored in an array (as suggested in this post). Difference of first index can be thought of as phase difference. Positive value of the difference of index indicates positive phase (A leads B--> positive direction).
The VI(attached) is not outputting the result as expected. I seek help for figuring out flaw in logic and rectify it. Any alternate approach for reading a digital encoder using USB-6001 will also be helpful.
Thank you in anticipation.
The alternate approach for reading your encoder is NOT to try to do it with the counter or digital inputs of your USB-6001. It really isn't suitable for the job.
You *might* be able to use 2 AI channels and some post-processing if your encoder pulse rates are slow enough. Would it be an option to tie up your analog inputs for this task?
Yes, I do have 2 vacant AI Channels. The encoder I wish to read is a linear encoder with resolution of 50 pulses/mm . It may have to read maximum 20,000 pulses/sec at some point of our application.
Please explain the approach you are suggesting.
The approach would be very similar to what you planned with Digital inputs, just be careful how you define your transitions. It isn't always as clear-cut to identify them with analog values. I can only comment on your general description though, I can't open the code as I'm still on LV 2016.
However, your USB-6001 samples at 20 kHz max for a single channel so it'll be 10 kHz (or a bit less) for two channels. Nyquist theorem says you'd need a minimum sample rate of 40 kHz to capture all the transitions of a 20 kHz square wave. In real life you'd prefer an even higher sample rate.
So we're back to what I said before -- the 6001 is *not* a suitable DAQ device for your needs because your encoder pulse rates are too fast.
Hi Kevin P,
Thank you for your advice.
Also, I've attached the VI compatible with LV 2016 for your reference.