Pages: [1]   Go Down
Author Topic: Building or use an interrupt controller.  (Read 1154 times)
0 Members and 1 Guest are viewing this topic.
Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys;

I notice the Arduino using the ATmega only have 2 external interupt. I wonder how, programs, parts, ideas to use / build an interrupt controller, just like the 8259 interrupt controller chip. ( It is use on 8085, 8086, 8088 system ) I will be usefull in some design using multiples inputs. Any idea ? Any examples ? Any Arduino program sample ?
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The AVR chip already has pin change interrupts which give a similar functionality.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The AVR chip already has pin change interrupts which give a similar functionality

I don't really understand, seem you are talking about changing the interrupt pin on the ATmega. <---From datasheet ? I will look it up.

But it still one or two interrupt pins, what I am talking about is to use multi inputs, use them as interrupts, just like the 8259 <--It an old chip. ( Multi inputs, one out, and it tell you which one input it is activate )
Logged

Bristol, UK
Offline Offline
Edison Member
*
Karma: 1
Posts: 1197
Exhibitor at UK Maker Faire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

On the newer AVR chips, every I/O pin can be set up to have a "pin change interrupt". This is an interrupt that is triggered when the pin changes state (LOW to HIGH, HIGH to LOW). But I'm not sure how such interrupts are configured via the Arduino IDE and libraries.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But I'm not sure how such interrupts are configured via the Arduino IDE and libraries.

The Arduino core and libraries provide no direct support for pin change interrupts, however the low level register commands are not all the difficult to set up. There have been examples posted around here and in the playground.

Lefty
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

PCIs can be used to cause an interrupt if any pin on a port changes. On the mega328 there are 3 PCIs giving a total of 23 (I think) pins that can be used for interrupts.

Not the same as a 8259 (although I admit I've forgotten how that works), you don't get an individual vector for all 23 pins, there are only 3 vectors so you have to decide for yourself which of the possible 8 pins caused the interrupt.

Not as good as the external ints, but usable.  

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Let me understand this...The ATmega can be configure to use any pins I want by using the Assembly Language of the ATmega. OK

And you can only use 3 interrupt vector. OK  ( I just explaining to myself, base on what I read in this subject posting )

The problem you have ONLY 3 PCI. So if someone want to use a multitude of inputs to be use as an interrupt... you are "out of luck"

OK...Mmmm...NOT so fast...

I "sleep" on that problem today, I look of one of my Digital books, I saw the chip 74LS145 a Decimal to BCD encoder chip, so what if I connect most of the inputs at the decimal section, OR gate the BCD output and use the BCD output. So when a switch activate, a signal from the BCD output goes into the OR gate and that single output is my interrupt signal...and the software in the interrupt subroutine will handle which switch that is, ( using digitalRead and Switch-Case ) and proceed the routine that represent the input switch. That way, it will extend the interrupts vector.  Unless I can buy a 8259 chip. 

Now that will work  smiley-wink

Sorry guys, I sometime find my own solution. I will provide a schematic.

Maybe other methods existed somewhere.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There's the 74xx147 as well, 9 inputs. These chips are often called "priority encoders".

That should work as long as you don't need the 0th input.

As you have to run the four lines to the processor anyway I don't think you need to OR them to get the interrupt. Set up the four pins to trigger a PCI then read the value in the ISR.

One possible issue with the ORing idea is what happens with two interrupts overlap?

Say 7 and 4 come in at the same time so you get an interrupt and handle 7. Then 7 goes away leaving 4 on the pins. BUT an OR gate will not change state so you don't get the second interrupt.

This may be an issue with PCI as well if you don't service the interrupt quickly (and in theory at any speed), but at least with PCI I think you will be OK as long as the second interrupt doesn't occur before you service the first.

BTW: No assembly language needed for any of this, just direct port manipulation in C.

______
Rob



« Last Edit: August 05, 2011, 10:43:14 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Say 7 and 4 come in at the same time so you get an interrupt and handle 7. Then 7 goes away leaving 4 on the pins. BUT an OR gate will not change state so you don't get the second interrupt.

I know what you mean. It look like a re-design of the circuit is needed. The encoder scheme is just a basic idea. But you are right.
Logged

Boston, MA
Offline Offline
Full Member
***
Karma: 0
Posts: 129
Batteries? We don't need no steenking batteries!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I recently found a couple libraries in the Playground for this, looks like someone has already done the dirty work and make pin-change interrupts pretty useful (e.g. allow you to assign per-pin interrupts and conditions, even though technically each 8-pin port shares a physical interrupt vector). Have a look at PcInt or PinChangeInt, depending on whether you value readability or speed more.

(I don't know enough about ATMega yet to say how simultaneous interrupts will be handled, and whether having them occur on different ports will make a difference.)
Logged

Offline Offline
Edison Member
*
Karma: 3
Posts: 1001
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you go back to the original request of using an 8259 controller, the AtMega PCI (pin-change-interrupts) will be the equivalent of three such devices already embedded in the microcontroller.

The 8088 (as used in the original IBM PC) had only one hardware IRQ pin and the 8259 multiplexed 8 additional inputs to this single IRQ. The interrupt service routine would then query the 8259 and channel the request to the appropriate handler (timer, keyboard, COM1, COM2, LPT1, …) based on which input triggered the interrupt. The AtMega 328P (as used in Uno/Duemillanove) can do the same with PCI three times over and trigger a total of 8*3 unique handlers without additional hardware.

If your request is about multiplexing dedicated (additional) inputs to a single IRQ, this will require additional external hardware and so PCI may not be the answer. Although it would be possible to interface an 8259, it is not really practical as it will require 8 I/O lines for data plus R/W. Port expanders with a serial interface (SPI/I2C) and pin change interrupt exist than can handle this. Another possibility would be adding an additional microcontroller as a DIY purpose built IC also using SPI or I2C plus a single interrupt line.
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

IO expanders like the MCP23017 will do this, 16 potential interrupts with latching.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
IO expanders like the MCP23017 will do this, 16 potential interrupts with latching.

That is an idea. A new "8259" I will look-it up, lean how to use it... ( that will take some hard learning curve )

@Drmn4ea

I will look it up. Thank. A bit comfusing right now, but I will learn it.

@BenF

I don't know if the 8259 still in production by the way.

My idea of using a priority encoder is OK unless I am sure that the inputs don't come at the same time.
I was thinking also using a "Parrallel to serial" an opposite of the 74HC595 Serial to Parralel < --- Hope I am right ? , What about I just ORing all the inputs, when a input or some at the same time, read the serial code, by software determine which input has the "right-of-way", and do the routine.

Anybody know a simple shift-register parrallel-to-serial chip ? And programs examples ?   
Logged

Pages: [1]   Go Up
Jump to: