Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

usage of quadrature encoder with M-series DAQ

Hi, I have a problem which I hope a standard M series DAQ card can solve using the DAQmx drivers:

I need to sample some analog inputs with each tick on a quadrature encoder from a servo (running on max 5kHz). However sometimes the servo will reverse its direction temporarily. I need to know what analog value is assoicated with what encoder value, so what I would like to get after a measurement sweep in the buffer is something like this:

position      value
0                  4.2
1                  4.6
2                  4.1
3                  4.6
4                  5.6         
3                  4.6  <-- reverses direction
2                  4.1

Is there any simple way to do this, that is placing the encoder value in the buffer beside each analog value? Note that I must know when the direction is reserved so I can't just count the number of ticks or the number of samples. Thanks in advance!

0 Kudos
Message 1 of 15
(4,726 Views)
This is how I solved this exact measurement :
  • Run simultaneously an AI (one sample of every input at a time with external trigger) and a CI task (position measurement in X4 mode).
  • Trigger the AI task with the output of the encoder. Use an external interface circuit (like LS7184 from LSI) if you need the rising and falling edges of both signals of the quadrature encoder. This will give you a for times better resolution of the position measurement. The advantage of this circuit is that it will also filter the outputs of the encoder.
  • Use the internal ai/SampleClock of the DAQ board to trigger the CI task. By using ai/SampleClock, you only need to start the CI task before the AI task to guarantee that the AI and the CI samples will be aquired at the same time. Without this precaution, one of the tasks may start before the other leading to a phase error.
  • You will then get two arrays : one with the AI samples (2D) and one with the CI samples (AI). These arrays can then be combined into an XY array (X = position / Y = analog inputs).
  • With some math you can then delete the samples of the wrong direction. Eg for increasing position :
    • for every sample, check if sample[i] > max
      • yes --> expected direction, max = sample [i]
      • no --> wrong direction, delete sample [i] from the X and Y arrays

An alternative solution just went to my mind. It wouldn't need a CI task. Use a LS7184. Like for the first solution, its Pulse output is used to trigger the AI samples. But you only need to add its Direction output to the AI samples to be able to locate and delete the undesired samples.

Let me know if you need further help.

0 Kudos
Message 2 of 15
(4,719 Views)
JB, thanks a lot for the fast reply! I have never used NIDAQmx or the NI cards and was unsure after all the different posts on this forum regarding similar tasks, but this seems to be exactly what I want.

Another question, in the proposed solution, is there a way to stop the measurement at a specific encoder value and fetch the whole run? I would like to wait until a full sweep is complete before I fetch the data, as I do not want to poll the data continously and be dependent on real-time attributes of the OS (Windows will be used). From what I understood in the product description, all M series DAQs can buffer the data into the RAM using the DMA, so that the measurement operation do not clog down the CPU. I assume this is possible in this case as well? Thanks again!

/ Roland
0 Kudos
Message 3 of 15
(4,699 Views)
Set sample mode for the AI and the CI tasks to Finite Samples and samples per channel according to the CPR of the encoder. Add a multiplying factor to take the pulses in the wrong direction into account. For example samples per channel = CPR*1.2. Without this factor, the measurement will not cover the desired angle in case of vibrations.
0 Kudos
Message 4 of 15
(4,686 Views)

Sounds like JB's answers are helping you, but I just wanted to mentio

In your original question, you mentioned wanting to sample an analog signal on every quadrature encoder tick.  The M-series boards have a "change detection" capability you can use for this.

1. Wire the quad encoder A,B both to a counter's inputs AND to 2 digital input lines on port 0.

2. Configure a digital input task using "change detection" as the timing type.  Make it sensitive to both rising and falling edges of the encoder A,B signals.

3. Configure your encoder and analog tasks to use the "change detect event" as their sample clock source signal.

4. Now, on every quadrature state change of your encoder, you'll capture both a position sample and an analog sample.  They will be in sync because they use a common sample clock.

5. If you need accurate time information, you can configure your 2nd counter to do freq measurement on the "change detect event", and later calculate your actual cumulative time from the array of freqs.

-Kevin P.

 

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 5 of 15
(4,670 Views)
Hi Kevin,

Your solution sounds very interesting ! I must admit that I have never used this event.

Thank you for sharing your tremendous knowledge one more time !

0 Kudos
Message 6 of 15
(4,666 Views)
Ok that also sound like a good idea 🙂 Is this possible even if I use a clock converter as JB recommended and have the Up/Down signal connected to B?
0 Kudos
Message 7 of 15
(4,646 Views)
Hi again,
JBs idea worked well, except I forgot to mention I am doing to parallell measurements on the board, so I can't use the ai/SampleClock as I must keep the two ai/ctr tasks separate, and the ai/SampleClock will (to my knowledge) generate a pulse whenever any of the AI tasks samples. But your idea Kevin, I understand how to setup the measurement except stage 3. How do I setup the analog and encoder tasks to time on the digital task? Thanks a lot again,

Roland
0 Kudos
Message 8 of 15
(4,516 Views)

Both the analog and encoder tasks should include a call to DAQmx Timing.  One of its inputs lets you wire in a programmer-specified source for the task's sample clock.  Create a control or constant by right-clicking on one of those inputs.  Then right-click on the resulting control (or constant) and choose to show advanced terminals.  Now you should get a longer list of options and somewhere in that list is something like "dev1/ChangeDetectEvent".  That's the internal timing signal generated by your digital change-detection task.  Wire this control/constant to the DAQmx Timing vi for both the analog and encoder tasks.

-Kevin P.

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 9 of 15
(4,494 Views)
Ok. But I still have the same problem, that I can only generate one event per card that is common to all change events on a card, right? That is, it won't be possible to know for which of my 2 separate  measurements the change came? I guess that I should probably go with two cards for this task...
0 Kudos
Message 10 of 15
(4,445 Views)