Semantic issue. C++

Hi, I use QEI library to work with encoder. Everything works fine. But when try to create my own class like it’s shown below, it compiles fine but doesn’t work. What do I do wrong?

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

        class Encoder{
        private:
                QEI enc;
                float ppr;

               Encoder(PinName chA, PinName chB, float pulses):enc(chA, chB, NC, 5000, QEI::X4_ENCODING){
                ppr = pulses;
               }
        public:        
               float getSensedVal(){
                   return (float)enc.getPulses() / ppr;             
               }

               void reset(){
                   enc.reset();
               }

    };
RawSerial pc(PD_5, PD_6);
Encoder encBottom(PA_6, PB_5, 2796.03f);
int main(){
    while(1){
wait(0.1);
pc.printf("%.3f\n", encBottom.getSensedVal());
}
}

The problem appears only when using QEI inside my own class, otherwise it works.

Hello Alex,

The sample does not compile because the Encoder’s constructor is private. I did not run a full test but the InterrupIn callbacks seem to be triggered. So after making the constructor public it should work.

Hi, Zoltan, thank you for your answer. I found another problem. At my project I use 4 different encoders, so I have to create 4 QEI objects. And it seems like there is a conflict between two of them:

QEI encBottom(PA_6, PB_5, NC, 5000, QEI::X4_ENCODING);

QEI encMiddle(PB_6, PB_7, NC, 5000, QEI::X4_ENCODING);

The program doesn’t work if I initialize both of them, but according to the documentation those pins are connected to different timers: TIM3 and TIM4.
I use BlackBoard STM32F407VET6.

Also I noticed, that they probably share some common resources, because encoder that works is the last one I initialize. So the first encoder in the code always doesn’t work.
Do you know where can be the problem?

The number of interrupt-in channels (lines) is usually less than the number of GPIO pins. In order to have interrupt-in capability on each GPIO pin the pins are grouped and each group is connected to different interrupt-in channel (line). If it happens that you configure two on more pins as interrupt-in and they belong to the same group (it means that they are connected to the same interrupt-in channel (line)) then only the latest pin will work as interrupt-in. Check the datasheet of your MCU for grouping of GPIOs to interrupt-in channels. Most likely PA_6 and PB_6 are connected to the same interrupt-in channel (they belong to the same group) that’s why only PB_6 (configured for interrupt-in as last) works as interrupt-in.

Thank you, that’s probably it.