LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Acquiring data from encoders using NI 9401

Greetings,

 

I am working on a project which acquires data from two encoders to measure position and velocity. My system is a NI-cDAQ 9191 chassis with NI 9401 Digital I/O. I am using a model 260 encoder from the encoders products company which has 360 CPR. Since the cDAQ-9191 has up to four counters, I selected to acquire data from two counters (0 & 1). From the counts, I can get position and velocity. Now the problem is when using DAQmx commands in labview, I could not acquire data for both counters 0 and 1 at the same time which also means that I cannot acquire digital data from both at the same time. In other words, the DAQmx subview called "Start Task" only works with one channel being used at a time. My question is: is there any way to get the data from the two encoders at the same exact time to find the position and velocity?

 

An early reply would be appreciated.

 

Thanks for the help.

 

P.S. you can find the VI attached and also the datasheet for the encoders

 

Encoders datasheet: http://www.encoder.com/literature/datasheet-260.pdf

Mechanical Engineer
0 Kudos
Message 1 of 7
(4,843 Views)

Hi Marwan-S,

 

I would suggest that you take a look at this example:

https://decibel.ni.com/content/docs/DOC-17346

 

Try copying the daqMX code from this example and pasting in the same block diagram so you have two counter input tasks. Make sure to select Counter 0 and 1 with your AB lines from the encoder one hooked up to CTR 0 AB and CTR 1 AB for your second encoder.

 

Default NI-DAQmx Counter Terminals

Counter/Timer SignalDefault Pin NumberSignal Name
CTR 0 SRC 14 PFI 0
CTR 0 GATE 16 PFI 1
CTR 0 AUX 17 PFI 2
CTR 0 OUT 19 PFI 3
CTR 0 A 14 PFI 0
CTR 0 Z 16 PFI 1
CTR 0 B 17 PFI 2
CTR 1 SRC 20 PFI 4
CTR 1 GATE 22 PFI 5
CTR 1 AUX 23 PFI 6
CTR 1 OUT 25 PFI 7
CTR 1 A 20 PFI 4
CTR 1 Z 22 PFI 5
CTR 1 B 23 PFI 6
CTR 2 SRC 19 PFI 3
CTR 2 GATE 17 PFI 2
CTR 2 AUX 14 PFI 0
CTR 2 OUT 16 PFI 1
CTR 2 A 19 PFI 3
CTR 2 Z 17 PFI 2
CTR 2 B 14 PFI 0
CTR 3 SRC 25 PFI 7
CTR 3 GATE 23 PFI 6
CTR 3 AUX 20 PFI 4
CTR 3 OUT 22 PFI 5
CTR 3 A 25 PFI 7
CTR 3 Z 23 PFI 6
CTR 3 B 20 PFI 4
FREQ OUT 17

PFI 2

0 Kudos
Message 2 of 7
(4,825 Views)

I already tried this example before, I am using two counters. The problem is, I cannot find what is the trigger source and sample clock source for the NI 9401 in a cDAQ - 9191 chassis.

 

Thanks.

Mechanical Engineer
0 Kudos
Message 3 of 7
(4,809 Views)

Hi Marwan-S,

 

If you note from the example, it doesn't use a trigger or a specified sample clock. If you would like to synchronize your counter reads (not software timed like the example) you can use something to this effect:

 

https://decibel.ni.com/content/docs/DOC-14643

 

If you would like to implement a trigger, the source would be up to you, and most likely be a PFI line. Here is where you can find a great example from LabVIEW's example finder, although this uses an external clock and you will need to remove one of the counter channels:

 

example.PNG

 

DylanC

0 Kudos
Message 4 of 7
(4,799 Views)

I have tried the example and I removed one counter but it gives an error:

 

Possible reason(s):

Specified route cannot be satisfied, because the hardware does not support it.

Property: SampClk.Src

Property: SampClk.ActiveEdge

Source Device: cDAQ9191-16C68FE

Source Terminal: ao/SampleClockTimebase

 

I don't know where to connect the sample clock source.

 

Thanks.

Mechanical Engineer
0 Kudos
Message 5 of 7
(4,785 Views)

Hi Marwan-S,

 

Are you trying to synchronize the reading of your counter with an analog output? Is there a reason you selected ao/SampleClockTimebase for the source of your counter sample clock? As noted in the first example I linked:

 

https://decibel.ni.com/content/docs/DOC-17346

 

you don't need to specify a sample clock. If you would like to synchronize your reading using a buffered counter read, you need to specify a sample clock source that your hardware supports. Here is a link to a forum post which should help:

 

http://forums.ni.com/t5/LabVIEW/9401-buffered-digital-output-sample-clock-source/td-p/865670 

 

with the corrected 1st link that S_Hong posted:

 

http://digital.ni.com/public.nsf/allkb/ADFC4DD8C9690232862575B70079FBD4?OpenDocument

 

DylanC

0 Kudos
Message 6 of 7
(4,778 Views)

I don't think you understood what I meant. Please look at the VI attached in the first post. As you willl notice, there is two start task and two counters to read from. Again, I have two counters that I want to read from at the same time. Imagine that one of them is wheel A and the other is Wheel B. Now how are you going to read data from both wheels at the same time?

 

 

Mechanical Engineer
0 Kudos
Message 7 of 7
(4,750 Views)