10-27-2016 10:38 AM
I am using a PXI-6221 DAQ card and LabVIEW 2012.
I have linear encoder that gives a quadrature signal and I have four proximity sensors that give a digital output.
I have successfully implemented example code that runs a while-loop and updates a display of the encoder position and digital inputs at regular interals.
I would like to capture the exact encoder value when each of the four digital inputs changes state. The simplest method might be to have the loop compare the previous state of the digital inputs via a shift-register and save the encoder value if there is a change. I would prefer to use hardware-triggering to get a more acurate measurement. Is there any example code that does something like this?
10-27-2016 02:47 PM
Your board supports digital change detection as one of its hw-timed sampling modes. You need to set up a DI task based on change detection, and then set up an encoder task that uses an internal "change detection event" signal as a sample clock.
I've attached a LV2013 snippet to illustrate main points, you may need to wire up some other inputs for encoder scaling, etc. Since DI samples are only taken when there's a transition on one of them, I do a quick sneak preview of the DI lines before doing the main config. Then you'll have something to compare to when the first transition happens to let you know which sensor changed state and in which direction. This assumes that you'll start this program before starting motion on the system you're characterizing. Also note that the encoder task is started before the DI change detection task, making sure both are running when the first ChangeDetectEvent occurs.
Hope this helps you get started...
-Kevin P
10-28-2016 12:16 PM
Thank you Kevin, this was exactly the start I needed. I had a chance to try it today and got quite close to what I needed. Here is my code so far:
I had to change "Digital 1D Bool 1Chan 1Samp" to "Digital 1D Bool NChan 1Samp". I also found that "nominal transition rate" needs to be the maximum transition rate expected otherwise I was getting Error 200284 'Some or all of the samples have not yet been acquired.'
I have managed to run this code with my test system and the data that comes back looks like what I expect. My only problem is that the number of samples "DI Samples" and "Counter" samples don't always match.
Thanks again.
10-28-2016 07:01 PM
Only time for quick comments:
1. Looking at the way you're waiting for a while and then doing a one-time bulk read of samples, you might be better off doing Finite Sampling.
2. Your error was likely caused by waiting too long before hitting the stop button that initiated the Reads, not directly by estimating too low a nominal sample rate. (In an indirect way, the claimed sample rate can affect the auto-sizing of the Continuous Sampling buffer when you leave the input unwired. With Finite Sampling, you aren't allowed to leave the size unwired.
3. Also, when you leave the '# samples to read' input to DAQmx Read unwired, it has a specific meaning. For Continuous Sampling, it means "read all available samples". This explains why you don't always get the same # of samples from your two tasks -- you're asking for "all available" at two slightly different times. The 2nd task to be read might have collected some extras after the 1st task was read. A good workaround would be to read all available from the AI task, take the array size and request that same # samples from the DI task.
When doing Finite Sampling, the meaning would be "read the entire buffer size worth of samples". If you define both buffer sizes to be equal and do Finite Sampling, you'd get the same # of samples from both tasks. Well, as long as you don't time out. That's another Read input you may need to wire.
-Kevin P
11-02-2016 04:34 AM
Thank you for your comments Kevin. Finite sampling does work out better. I now have a piece of code that captures exactly the data that I need. I include it here for the benefit of anyone reading this thread in the future.
Thank you for you help.