Interrupt vector numbers
Posted: 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:
Inside my main.py I import the encoders,py file and later setup the quad encoder as follows:
A few lines down I also setup a leaf switch and an ISR to fire when it is pressed:
It doesn't work. I was getting the following error when the code to setup the leaf switch ran:
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?
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)
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)
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)
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.
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?