Page 1 of 1

Interrupt vector numbers

Posted: Wed Aug 17, 2016 12:44 am
by dwculp
I think I might have answered my own question via experimentation but I wanted to ask just to make sure.

I am building robots with the MicroPython board and wrote a quadrature encoder class.

It is initialized as follows:

Code: Select all

    def __init__(self, pinA, pinB, pullups=True):
        #configure the two pins and set the callback function
        if pullups == True:
            self.encoderACB = pyb.ExtInt(pinA, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_UP, self.encoderCallback)
            self.encoderBCB = pyb.ExtInt(pinB, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_UP, self.encoderCallback)
            self.encoderACB = pyb.ExtInt(pinA, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_NONE, callback=self.encoderCallback)
            self.encoderBCB = pyb.ExtInt(pinB, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_NONE, callback=self.encoderCallback)
Inside my I import the encoders,py file and later setup the quad encoder as follows:

Code: Select all

#Setup our encoder
encAPin = pyb.Pin(pyb.Pin.board.Y11)
encBPin = pyb.Pin(pyb.Pin.board.Y10)
encoder = encoders.QuadEncoder(encAPin, encBPin, pullups=False)
A few lines down I also setup a leaf switch and an ISR to fire when it is pressed:

Code: Select all

#setup our leaf switch and start our ISR
leafPin = pyb.Pin(pyb.Pin.board.X19)
leafInt = pyb.ExtInt(leafPin, pyb.ExtInt.IRQ_RISING_FALLING, pyb.Pin.PULL_DOWN, leafCallback)
It doesn't work. I was getting the following error when the code to setup the leaf switch ran:

Code: Select all

Traceback (most recent call last):
  File "", line 152, in <module>
ValueError: ExtInt vector 0 is already in use
MicroPython v1.8.2-11-gbe313ea on 2016-07-13; PYBv1.1 with STM32F405RG
Type "help()" for more information.
I knew what the problem was, two interrupts trying to use the same int vector. I dug through the documentation here: ... xtInt.html and and few others places and didnt see anything that helped me (it may be that I missed it).

In looking at the pinout here: I noticed a few things:

1. The encoder was using Y10 and Y 11 which correspond to B0 and B11. Printing the "lines" variable inside the encoder ISR yields 0 and 11.
2. The leaf switch was using X19 which coresponds to C0 and happens to also be int vector 0.
3. Changing the leaf switch to X20 (C1) makes everything work perfectly.

So, does the number in the CPU name of each pin also correspond to the vector interrupt number it is assigned to?

Re: Interrupt vector numbers

Posted: Wed Aug 17, 2016 3:32 am
by dhylands
It isn't really that you're trying to share 2 vectors, it's that the stm32 EXTINT hardware only has 16 lines.

PA0, PB0, PC0, PD0, etc all connect to line 0.
PA1, PB1, PC1, PD1, etc all connect to line 1.
PA15, PB15, PC15, PD15 all connect to line 15.

And you can only connect each line to one port (i.e. A, B, C, D, etc). So once you've configured line 0 to use Port A (so PA0) you can't also configure line 0 to use Port B.

That's just a hardware limitation.

Re: Interrupt vector numbers

Posted: Wed Aug 17, 2016 7:31 am
by pythoncoder
@dwculp Are you aware that two of the timers support decoding quadrature encoders in hardware? ... or-a-timer see modes.

Re: Interrupt vector numbers

Posted: Sat Nov 02, 2019 7:41 am
by lnsri22
Thanks for the useful information. Encountered such a scenario, just now!!