Go Down

Topic: Change Interrupt on all pins (Read 5241 times) previous topic - next topic

TGG3

Aug 30, 2016, 11:59 am Last Edit: Aug 30, 2016, 12:04 pm by TGG3
http://playground.arduino.cc/Main/PinChangeInterrupt

I want to change the pins of the interrupts of my Arduino micro to D2-D7.
The Standard Interrupt pins are D0, D1,  D2, D3 and D7

But I myself am not experienced enough In this topic so could someone please tell me how to perform this?

PaulS

Quote
But I myself am not experienced enough In this topic so could someone please tell me how to perform this?
You can't. The external interrupts are hardwired to those pins by the manufacturer.

J-M-L

#2
Aug 30, 2016, 12:17 pm Last Edit: Aug 30, 2016, 12:48 pm by J-M-L
there is an example sketch in the link you have

what else do you need?

(unless there is a confusion -  Change Interrupt Requests are different than specific interrupts you can attach to special hard wired pins)

Board Digital Pins Usable For Interrupts
Uno, Nano, Mini, other 328-based 2, 3
Mega, Mega2560, MegaADK 2, 3, 18, 19, 20, 21
Micro, Leonardo, other 32u4-based            0, 1, 2, 3, 7
Zero all digital pins, except 4
MKR1000 Rev.1 0 1, 4, 5, 6, 7, 8, 9, A1, A2
Due all digital pins
101 all digital pins

Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

MorganS

TGG3, you linked to the correct page. Are you having difficulty understanding it? Did you follow the link to Nick Gammon's page which explains it all?

The pin-change interrupts have only one interrupt for each "port" of 8 pins. It is up to you to then read the pins and find out which one changed.

It may also help to read www.xyproblem.info
"The problem is in the code you didn't post."

TGG3

TGG3, you linked to the correct page. Are you having difficulty understanding it? Did you follow the link to Nick Gammon's page which explains it all?

The pin-change interrupts have only one interrupt for each "port" of 8 pins. It is up to you to then read the pins and find out which one changed.

It may also help to read www.xyproblem.info
As for the XY Problem solution u referred to i may present my problem: I am building a fan controll for my PC with a Arduino Micro.
To read the RPM`s of the Fans i would like to use Interrupts becaue of the higher accuracy compared to simple polling the pins.

And the Problem is that the Micro only has 5 Interrupt pins 2 of which are for the Serial port which i wish to use.

And so i hope to find a software solution to my problem

Regards Thomas

J-M-L

#5
Sep 01, 2016, 11:25 am Last Edit: Sep 01, 2016, 11:33 am by J-M-L
So you have a Micro, Leonardo or other 32u4-based arduino - with 5 interrupts.

You say you are using 2 for Serial? on a Micro for example the hardware Serial pins are 0 (RX) and 1 (TX). so indeed part of your 5. but you are still left with 3 interrupt pins available (2,3,7).

isn't that enough? (if you use SPI/Wire library then 2 and 3 are gone but you still have 7)



Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

TGG3

You say you are using 2 for Serial? on a Micro for example the hardware Serial pins are 0 (RX) and 1 (TX). so indeed part of your 5. but you are still left with 3 interrupt pins available (2,3,7).

isn't that enough? (if you use SPI/Wire library then 2 and 3 are gone but you still have 7)
What I am saying is that i need the possibility of having 5 pins fire an interrupt so I can count the rpm`s for every fan individualy.

 

J-M-L

#7
Sep 01, 2016, 02:28 pm Last Edit: Sep 01, 2016, 02:31 pm by J-M-L
Right - so you have 5 fans to monitor. that's an important information :)

So 3 answers:

Software solution: do use change interrupt. you need to understand that you won't get differentiated ISR for each pin, if there is a change on any of the pins in a group, then the ISR will fire.

--> can you let us know which Arduino you use?

Try to group them on the same PORT and in the ISR code do read the PORT (that's fast and reads all of them in one go) and check what bits have changed from last read => you'll know which fan sent a RISING or FALLING signal and modify the appropriate counter accordingly. that could be multiple changes at the same time.

 

Hardware + Software:

using a Programmable Interrupt Controller. A programmable interrupt controller is used to combine several sources of interrupt onto one or more CPU lines, allowing priority levels to be assigned to its interrupt outputs. The Intel 82C59A is pretty simple to use.

Look at an General Purpose parallel Input/Output (GPIO) expanders like the MCP23017 or MCP23008  for which interrupts can be configured to be edge or level-sensitive for each input and offer SPI or I2C versions -- or those from Semtech (the SX1501-SX1506 family).



Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

TGG3

#8
Sep 01, 2016, 02:39 pm Last Edit: Sep 01, 2016, 02:51 pm by TGG3
Right - so you have 5 fans to monitor. that's an important information :)

So 3 answers:

Software solution: do use change interrupt. you need to understand that you won't get differentiated ISR for each pin, if there is a change on any of the pins in a group, then the ISR will fire.

--> can you let us know which Arduino you use?
I use the Arduino Micro with the MEGA32U4 chip.

Could it be that you mean something like that:

PinChangeInterrupt-Arduino


And concerning the additional hardware I would like it to be in a very small 2.5" SSD sized case.


J-M-L

#9
Sep 01, 2016, 03:20 pm Last Edit: Sep 01, 2016, 03:21 pm by J-M-L
I use the Arduino micro with the MEGA32U4 chip.
OK so you should read chapter 11 of the documentation (page 88)

"The Pin change interrupt PCI0 will trigger if any enabled PCINT7:0 pin toggles. PCMSK0 Register control which pins contribute to the pin change interrupts." (see page 91 for Pin Change Mask Register 0)

Read also the chapter 10.3.1 Alternate Functions of Port B page 74




Could it be that you mean something like that:
http://playground.arduino.cc/Main/PinChangeInterrupt
Yes I mean something like that :) BUT as you read in the chapter 10 and 11 above, you don't have 3 interrupt vectors in your hardware. You just have one. The ATmega32u4 has only portB (8 pins) pin change interrupts (including PB7 pin which can serve as an external interrupt source on top).

So you would need to connect your 5 fans to PORTB pins for this approach to work.

the pinout for the micro is

so look for PB0 to PB7 and careful on other use of some pins (for example if you use SPI pins MISO, MOSI, ...) (better image here)


Then proceed as discussed above - set up pin change interrupt for your 5 pins (PCMSK0 - Pin Change Mask Register 0) and your unique ISR will be triggered whatever change happens on one of the 5 pins. it's up to your code to handle that in the right way (and efficiently - so use PORT B registers to decide which fans pins changed, don't do 5 digital reads, that will be way too slow).


You might want to have a look as well at this library. it's maintained and handle your micro and offers a good abstraction level.
 
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

Go Up