Interrupt vector numbers

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
dwculp
Posts: 9
Joined: Wed Jul 13, 2016 6:43 pm

Interrupt vector numbers

Post by dwculp » Wed Aug 17, 2016 12:44 am

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)
        else:
            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 main.py 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 "main.py", 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: https://docs.micropython.org/en/latest/ ... 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: http://micropython.org/resources/pybv10-pinout.jpg 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?

User avatar
dhylands
Posts: 3477
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Interrupt vector numbers

Post by dhylands » Wed Aug 17, 2016 3:32 am

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.
etc
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.

Online
User avatar
pythoncoder
Posts: 4641
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Interrupt vector numbers

Post by pythoncoder » Wed Aug 17, 2016 7:31 am

@dwculp Are you aware that two of the timers support decoding quadrature encoders in hardware? http://docs.micropython.org/en/latest/p ... or-a-timer see Timer.channel modes.
Peter Hinch

lnsri22
Posts: 75
Joined: Fri Aug 17, 2018 12:16 pm
Location: India

Re: Interrupt vector numbers

Post by lnsri22 » Sat Nov 02, 2019 7:41 am

Thanks for the useful information. Encountered such a scenario, just now!!
lnsri22 :)

Post Reply