Interrupt on change

Go To Last Post
18 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I was suffering with PIC's, they had a cool feature that I miss on AVR's. That is interrupt on change for the I/O. Meaning that I can setup a mask for the pins I do not want to cause an interrupt, and the ones I do interrupt to the same location for service.

This was a very handy thing to have as there was no need for external circuitry that would trip one pin for several possible points. It was all done internally.

I currently use several pins on a CPLD that generates a single INT0, and the micro then polls the CPLD to find out what the deal is.

Does AVR have this feature in any of their devices? :?

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Most all of them do.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can anyone be more specific on part numbers?

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It would be harder to find a part number that doesn't have this ability...really :)
Do you have a specific part that you are wanting to use?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just got pin change interrupts working on a Tiny13 I was programming yesterday. They work fine.

However, it would have been nice to have the option to select positive, negative or both edges, rather than having any edge (change) be the only choice. I think you have to more or less keep the current state of every pin change interrupt pin in RAM so you can have something to compare to, to determine which of several pins changed. It would be nice to have an interrupt cause register to identify which pin caused the interrupt. (In my case it ended up not mattering.)

Does anybody have any better ideas on a strategy to manage several pin change interrupts? (Or please correct me if my understanding of PCIs is erroneous.)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tiny2313, Mega48/88/168//328/644 have intrrup on pin change ability.

I don't believe the Mega8535/16/32/64/128 have intrrupt on pin change ability. But, all of the newer models that have been released seem to incorporate the intrrupt on pin change capability.

Atmel provides a matrix showing what AVR controllers have what features at a quick glance but, I didn't see where the pin change intrrupt function was listed.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Does anybody have any better ideas on a strategy to manage several pin change interrupts? (Or please correct me if my understanding of PCIs is erroneous.)

In my Int routine I usually use something like this:
On initialization set InitialPinState to the state you want to act on. Here is some generic code. I have an assembler version if your iterested.

Interrupt Routine:
CurrentPinState = PINx & PinMask

PinsChanged = (PreviousPinState ^ CurrentPinState ) & (PreviousPinState ^ InitialPinState )

if (PinsChanged & PinValue1)
...
elseif (PinsChanged & PinValue2)
...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That's more or less what I had in mind for storing the pin(s) state on ISR exit so that next time the ISR executes it can compare the current state with the previous state. It's messy but I don't see any way to use the AVR's hardware to do it more efficiently.

In my case which input changed wasn't that important. I made a small state machine (4 states) and each state (switch statement) examined the current input values that were important to it, then did stuff and possibly changed the state variable. Some of the interrupts weren't important (wrong edge) but the state machine takes care of all possible situations.

It worked well but I wish the AVR had a pin change interrupt cause register. Not that I expect them to add it! :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also ATMega162 IIRC. Strange thing is, it's not supported by the dragon.

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, having only one interrupt for a group of 8 pins is a limitation, and so is not being able to select which edge interrupts, but I've not found the first to be a serious nuisance - I generally only use one or two PCINTs, and the one time I used a group of 8 I was logging all changes so reading them all at once of one interrupt was actually a bonus. As for not being able to select the edge, no problem. If you're looking for a low edge, the ISR starts with this:

     sbic   PINC,0        ; assuming port C,0 is the one
     rjmp   out_of_here   ; it went high, ignore

When I was using pin change recently to interface a PC keyboard, the double edge was a positive advantage. The keyboard produces the clock, which causes the interrupt, but when you're reading it you want to read on one state of the clock, and when you're writing to it you want to output the data on the other state. It would have been a lot more difficult to do it with a normal low- or high-edge triggered interrupt like INT0.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I remember on some AVRs you could trigger on both edges of an external interrupt line, but not all devices support it.

For example, Mega128 supports it on INT4..INT7, but not on INT0..INT3. Interesting..

But it is not that hard anyway to change edge as the first thing in the interrupt, I've gotten that to work too, on a 2313.

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Or use a Mega1281 and get your 8 external interrupts with complete edge selection, as well as 3 banks of 8 pin-change.

OP seems confused about this external interrupt/pin change thing. First, he wishes that AVRs had a mechanism to have multiple pins trigger an interrupt. When pin-change is pointed out to him, he bemoans the fact that then he doesn't know which pin triggered the change! Which do you want?!? Up to a reasonable number, there are several-to-many external interrupts on AVRs. And other pin functions can add more. Analog comparator, for one. ICP. Timer as counter.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
If you're looking for a low edge, the ISR starts with this:

Code:
sbic PINC,0 ; assuming port C,0 is the one
rjmp out_of_here ; it went high, ignore

The only problem with this method is that you can end up with double counts if you're using more than 1 pin.

Such that if PINC.0 changes and you respond as expected, but then if another PIN changes and PINC.0 is still low then you would end up responding to the same edge again. The simple assignment method I use above takes care of this automatically for 1 to 8 pins with just the 2 assignments.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
OP seems confused about this external interrupt/pin change thing.

I think that you are the one confused on this. The person "bemoaning" was not the OP.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Am I the bemoaner? :) I would call it more 'lamenting' than anything else. I'm a realist. I got my code working Friday, and no complaints. If the design were different maybe it would take less typing (code), but my typing is done and it doesn't matter now.

I enjoy discussing my trade and the tools used. The AVR is just one of my tools. I always get the job done in the end although I may have some tools I prefer and some I feel less happy about.

But I've always been paid! :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tiny26 has pin change interrupts, and it is not one of the "new" chips.

Embedded Dreams
One day, knowledge will replace money.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

The person "bemoaning" was not the OP.

I see that now.
Quote:

Am I the bemoaner?

Yes.

CirMicro gave the method for all but the most pathological of cases. Save New as Previous. Calculate new rising/falling edges. Process edges as needed.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not bemoaning. Rather, I'd call it musing. I've been designing microcontroller applications since the early '80s and always enjoy discussing the advantages and disadvantages of various microcontrollers, and what I would change if I could.

One reason I entered this discussion is that I've just completed my own Tiny design but I'm never entirely sure I didn't miss something in the spec, and figured out somebody would correct me if I was wrong. It appears that my understanding of the pin change interrupts is sound since nobody has pointed out any better way to accomplish my design. Thanks for the reality check! :)

BTW it was way cool that IIRC this is my shortest ever design cycle for a microcontroller, beginning with vague recollections of my AT90S2313 design several years ago, to completing my Tiny13 project in less than 40 hours! (Much of the time was spent reading the spec and finding/downloading/installing tools.) That's an amazingly short design cycle by all industry standards I'm familiar with.