By s.achterop
Hello list,
I need to control 2 motors with encoders on a bluno m0. The adafruit dc-motor-shield works fine, but there are no interrupt pins available for the encoder signals.
D0 and D1 are used for the ble connection and the adafruit shield uses i2c on D2 and D3.

But luckely interrupts can be used on all digital pins in a Cortex-m0.
So I adapted the attachInterrupt function in cores/NUC123/WInterrupt.cpp.
I extended the intFunct table (in interrupt.h) and added the code, mostly by copying/adapting from the other entries. For example one extra case in attachInterrupt looks like this
Code: Select all
   case 4://PC2                                                                                                                                                                 
           GPIO_SetMode(PC, BIT2, GPIO_PMD_INPUT);
           GPIO_EnableInt(PC, 2, modeArray[mode]);
           NVIC_SetPriority(GPCDF_IRQn, 2);
The other changes are trivial.
Note that PC2 is D7 on the connector. It can also be used for i2s, but I don't use that.
If I turn on the motor I can see, with an oscilloscope, the encoder signals changing, say, every 0.5msec.
The problem is, that only roughly ONE interrupt per second occurs.

What am I doing wrong? I think that this should work.
Is there something in the arduino-compatibility-layer that prevents this?
I would be very grateful for any hints or help.

Regards, Sietse
By s.achterop
I found a way around this and now have working interrupts on D7 and D8 pins. I just removed the 2 debounce statements shown above!
I don't understand why, but it works now.
By the way, interrupts did work when they came not too quick, say 100 times a second.