GPIO interrupt programming help needed

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

Hello there I am a newbie trying to code my own ISR routine/handler for the incoming edge triggered interrupt on PIN - 0 of PORTA i.e Pin PA0 precisely.

The microcontroller I am using is ATmega64A - 8 bit MCU.
Can someone please let me know about any tutorials available for these I did try googling and then came across this link http://asf.atmel.com/docs/2.11.1/mega.applications.mega_gpio_example.mega64_stk600/html/files.html

I am referring the AVR-GCC manual but I couldn't find anything related to generation of interrupts for GPIO pins.

Thanking you

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

From a brief look at the ATmega128 data sheet, the 64/128 has INT0-INT7 interrupt vectors. These fire on pin-changes of PD0..PD7

All AVRs have INT0, INT1 and sometimes a few more INTn pins.
Modern AVRs have PCINTn functionality on every pin with associated interrupts.

So I suggest that you monitor one of the PORTD pins rather than the PA0 pin.
Or you change to a pin-compatible modern AVR.

Note that the PCINTn interrupts fire on every change.
The INTn interrupts can be configured for rising edge, falling edge, level, ...
This makes life a lot easier. The INT0 irq is normally the highest priority vector on an AVR.

David.

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

Don't look to the GCC manuals for that info; look at the spec sheet for your particular AVR. I presume you're talking about the PCINT0..7 interrupt signals. If you're only interested in precisely one of those eight pins, you're in luck: you can set the "changes on which pins of PortA should fire the PCI0 interrupt" mask to focus only on that pin. If you want to look for changes on more than one pin of PortA, your ISR would have to take care of identifying exactly which of the set of pins you cared about changed.

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

Caution is warranted with edge interrupts. Especially when generated by switches.

The reason for caution is a phenomenon called "switch bounce". A real switch will give you many interrupts every time it closes, and, again, when it opens. There are a number of techniques for dealing with it. The search term is "debounce". One of the best references is by Gannsle.

http://www.ganssle.com/debouncin...

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Hello david.prentice,Levenkay & ka7ehk sincere thanks for replying to my query ...can you please give some example code ... I am using ATMEL AVR Studio 5 ..I searched for some sample codes for GPIO Interrupt coding ..but couldn't find anything. Any links ,sources etc would be of more help ...Sincere thanks again

Last Edited: Thu. Jun 7, 2012 - 04:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is almost no "code" involved. You set bits in some control registers. YOU write the service routine that does what you want. You have to define what you want to happen in the ISR.

By the way, this has virtually nothing to do with Studio. It is a basic AVR programming task.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

AFIK, you can't interrupt on the mega64A's PA0 pin.
You could use the PD0 pin.

Say exactly what you want to do, and you may get an example.

If you must use the PA0 pin, you need to change to a different AVR.

David.

Last Edited: Thu. Jun 7, 2012 - 04:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok ka7ehk(Jim Wagner) ..I will do that once I get to the laptop ,I will read the datasheet thoroughly ..I will try this ..sincere thanks again

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

Ok David.Prentice here is what I would like to accomplish - I am getting an input signal - momentarily on the circuit on Pin - PA0 and also on the pin PD5 (XCK1) ..so I was thinking of some method where in these GPIO pins would be acting as INTERRUPTS.If I get a high to low pulse on these port pins then I would code ISR routines to handle them ... GPIO can be configured as interrupts ?? Am I correct .sorry if I sound too naive ...I am rereading to get myself corrected ....thanks for the help and input

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

Look at your data sheet. PD5 is INT5 and has its own interrupt vector (INT5_vect).
Likewise PD0 has INT0_vect.

Please take the time to read people's replies. The m64A does not have PCINTn_vect interrupts.

David.

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

Moderator: Please move to the AVR forum.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

david.prentice wrote:
Look at your data sheet. PD5 is INT5 and has its own interrupt vector (INT5_vect).
Likewise PD0 has INT0_vect.

Please take the time to read people's replies. The m64A does not have PCINTn_vect interrupts.

David.


Hi David.Prentice I have checked the datasheet and on page 83 PORTE'S PIN5 i.e PE5 has the dual functionality:-
PE5 INT5/OC3C
(1) (External Interrupt 5 Input or Output Compare and PWM Output C for Timer/Counter3)

So I guess I may not be able to code PCINTs for any of these pins - PA0 and PD5,now since ATmega64A doesn't provide this PCINTs concept I just need to rely on this bare method of checking for the transition for a few milliseconds and then move on to the next step in my code .... so in short I would be just checking for a low pulse (since the circuit that I am working on expects a low pulse on these pins) for few milliseconds and then take the appropriate action about what to do next...please correct me if I am wrong ..thanks for your help

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

If the pulse is stable (no bouncing) and last for milliseconds you can probably poll the state of the pin at a place in the code that suits you (MAIN?). Then you don't need to mess with interrupts. You can use any GPIO pin for this. In assembler it would look like this:

    sbis     pina,0      ;if pin A0 low
    rjmp     next        ;jump to next task in code
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My apologies. I must be losing my marbles !

I swear that I read INT2..INT7 were on PD2..PD7 directly from the mega64/128 TQFP pinout diagram.

You are quite correct. INT2..INT7 are on PE2..PE7
INT0, INT1 are on PD0, PD1

Using interrupts means that you can respond within microseconds.

If your pulse is several milliseconds long, you can simply 'look' every 500us or so and you will catch the 'long' pulse.

Sorry for my incorrect advice. Not only have I got to read a data sheet, but focus my eyes too.

David.