Mbed Encoder Limit

16 Apr 2013

Hey everyone, first post here take it easy on me!

I have been experimenting with the official QEI library (LPC11U24) but I can only get 4 encoders working at once.

Attempt 1 works as expected:

Attempt 1

#include "mbed.h"
#include "USBSerial.h"
#include "QEI.h"
 
int main() {
 
    //Virtual serial port over USB
    USBSerial serial;
    
    //Initialize encoders
    //24 Positions per revelution
    QEI encoder0(p5, p6, NC, 96, QEI::X4_ENCODING);
    QEI encoder1(p7, p8, NC, 96, QEI::X4_ENCODING);
    QEI encoder2(p9, p10, NC, 96, QEI::X4_ENCODING);
    QEI encoder3(p11, p12, NC, 96, QEI::X4_ENCODING);
    
    //Display Encoder Pulse count
    while(1) {
    serial.printf("Pulse Count=> e0:%d, e1:%d, e2:%d, e3:%d        \r",encoder0.getPulses(),encoder1.getPulses(),encoder2.getPulses(),encoder3.getPulses());
    }
}

Attempt 2 also works as expected:

Attempt 2

#include "mbed.h"
#include "USBSerial.h"
#include "QEI.h"
 
int main() {
 
    //Virtual serial port over USB
    USBSerial serial;
    
    //Initialize encoders
    //24 Positions per revelution
    QEI encoder4(p13, p14, NC, 96, QEI::X4_ENCODING);
    QEI encoder5(p15, p16, NC, 96, QEI::X4_ENCODING);
    QEI encoder6(p17, p18, NC, 96, QEI::X4_ENCODING);
    QEI encoder7(p19, p20, NC, 96, QEI::X4_ENCODING);
    
    //Display Encoder Pulse count
    while(1) {
    serial.printf("Pulse Count=> e4:%d, e5:%d, e6:%d, e7:%d        \r",encoder4.getPulses(),encoder5.getPulses(),encoder6.getPulses(),encoder7.getPulses());
    }
}

Attempt 3 compiles and connects, but only encoders 0,1,2 & 3 are working:

Attempt 3

#include "mbed.h"
#include "USBSerial.h"
#include "QEI.h"

int main() {

    //Virtual serial port over USB
    USBSerial serial;
    
    //Initialize encoders
    //24 Positions per revelution
    QEI encoder0(p5, p6, NC, 96, QEI::X4_ENCODING);
    QEI encoder1(p7, p8, NC, 96, QEI::X4_ENCODING);
    QEI encoder2(p9, p10, NC, 96, QEI::X4_ENCODING);
    QEI encoder3(p11, p12, NC, 96, QEI::X4_ENCODING);
    QEI encoder4(p13, p14, NC, 96, QEI::X4_ENCODING);
    QEI encoder5(p15, p16, NC, 96, QEI::X4_ENCODING);
    
    //Display Encoder Pulse count
    while(1) {
    serial.printf("Pulse Count=> e0:%d, e1:%d, e2:%d, e3:%d, e4:%d, e5:%d        \r",encoder0.getPulses(),encoder1.getPulses(),encoder2.getPulses(),encoder3.getPulses(),encoder4.getPulses(),encoder5.getPulses());
    }
}

Using X2 Encoding similarly only has encoders 0,1,2 &3 working:

Attempt 4

#include "mbed.h"
#include "USBSerial.h"
#include "QEI.h"

int main() {

    //Virtual serial port over USB
    USBSerial serial;
    
    //Initialize encoders
    //24 Positions per revelution
    QEI encoder0(p5, p6, NC, 96, QEI::X2_ENCODING);
    QEI encoder1(p7, p8, NC, 96, QEI::X2_ENCODING);
    QEI encoder2(p9, p10, NC, 96, QEI::X2_ENCODING);
    QEI encoder3(p11, p12, NC, 96, QEI::X2_ENCODING);
    QEI encoder4(p13, p14, NC, 96, QEI::X2_ENCODING);
    QEI encoder5(p15, p16, NC, 96, QEI::X2_ENCODING);
    
    //Display Encoder Pulse count
    while(1) {
    serial.printf("Pulse Count=> e0:%d, e1:%d, e2:%d, e3:%d, e4:%d, e5:%d        \r",encoder0.getPulses(),encoder1.getPulses(),encoder2.getPulses(),encoder3.getPulses(),encoder4.getPulses(),encoder5.getPulses());
    }
}

Now, am I missing something really obvious, if not, is there a way to get around this limitation? Otherwise what is the best way to interface a large number of encoders?

Any help would be greatly appreciated!

Bart

16 Apr 2013

The way you are using the library uses two InterruptIns per QEI instance (if you used the index pin then it would use 3).

In the QEI library you can see the interruptins on line 231 and 232 in http://mbed.org/users/aberk/code/QEI/file/5c2ad81551aa/QEI.h

http://mbed.org/users/mbed_official/code/mbed-NXP/file/db45fac3c573/capi/gpio_irq_api.c

Here you can see that in the mbed SDK you can see that the number of channels is defined. For the LPC11U24 it is 8.

Because each QEI uses two that means you're limited to 4 QEI instances. You'll notice the LPC1768 has 48 channels, so theoretically you could have 12 QEIs.

17 Apr 2013

Thanks for your reply Stephen, saved me a lot of time!

Bart

08 Feb 2014

"Because each QEI uses two that means you're limited to 4 QEI instances. You'll notice the LPC1768 has 48 channels, so theoretically you could have 12 QEIs."

And the LPC4088 has 64 channels so from, you can use 16 QEIs

24 Jul 2018

What is the channel means in here? can you let me know about that? interrupt pins?