From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Encoders in PCIe-6251

Hi,
I need to connect three quadrature encoders in my PCIe-6251, which only has two internal counters.
Since I know the spinning direction from another source, I just need to count the pulse of one of the channels.
My idea is to read the values from the digital I/O and process it.
I tried this with one encoder and worked fine.
I tried with three and is much slower which make me loose some pulses.
The question would be which will be the fastest way to sample the channels.
Using an interrupt approach?
Read in a thread at maximum speed one sample at a time?
Read in a thread multiple samples at once?

 

Appreciate any help.

 

PS: Im working with Windows 7 64 bit and programming in c++ using the NIDAQmx API.

0 Kudos
Message 1 of 4
(5,270 Views)

Hello Mestor, 

 

I have a few questions about this issue.  What do you mean you tried it with one encoder and it worked fine?  Could you describe exactly what you did?  If it worked fine with one counter in digital I/O, try measuring one encoder in each counter with the final encoder in the digital I/O port.

 

One option would be to read in all the samples in digital I/O and do the change detection in software, but that would only work if your signal frequency was quite slow.  A good white paper on that is located here: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000PAn9SAG&l=en-US

 

If you have a fast signal, you may need to upgrade your card to one with 4 counters.  I suggest the NI PCIe-6320: https://www.ni.com/en-us/shop/model/pcie-6320.html

Patrick W.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(5,242 Views)

Hi Patrick,

Thank for the quick response.

 

Basically what i Did was:

Open the line, and create a thread to perform the read:

 

DAQmxCreateDIChan(encoderHandle,"Dev1/port0/line2","",DAQmx_Val_ChanForAllLines)
pthread_create( &this->encoderThread, NULL, funcEncoderThread, (void*) (this))

 Where the trhead function is basically:

void* funcEncoderThread(void* in){
	int32 read=3;
	uInt32 size=1;
	uInt32 data;
	while(true){
		if(DAQmxReadDigitalU32(encoderHandle,1,10.0,DAQmx_Val_GroupByChannel,data,size,&read,NULL)<0)procError();
		MyFunctionToProccesEncoderData(data);
	}
	return 0;
}

Later I tried

 

DAQmxCreateDIChan(encoderHandle,"Dev1/port0/line2,Dev1/port0/line3,Dev1/port0/line7 ","",DAQmx_Val_ChanForAllLines)

And use the same thread function, the result is much more slower.

 

I need to read the encoders roughly at  30 Khz.

 

try measuring one encoder in each counter with the final encoder in the digital I/O port.

 I will try that and let you know if is fast enough.

 

One option would be to read in all the samples in digital I/O and do the change detection in software, but that would only work if your signal frequency was quite slow.  A good white paper on that is located here: http://www.ni.com/white-paper/4102/en

 Do you think this could work at 35 Khz (windows 7 and core i5).

 

Thank for all your help.

 

0 Kudos
Message 3 of 4
(5,238 Views)

Mestor, 

 

Unfortunately, digital change detection will not be possible at those speeds.  Though the 6251 is capable of reading at that speed (Max clock speed of approximately 10 MHz), your loop will not be able to process that quickly enough.

 

Patrick W

Applications Engineer

National Instruments

Patrick W.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 4
(5,227 Views)