Author Topic: Hardware Interrupt help in Atmega 8!?!  (Read 3181 times)

0 Members and 1 Guest are viewing this topic.

Offline ramjam89Topic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Hardware Interrupt help in Atmega 8!?!
« on: September 28, 2009, 02:21:42 PM »
Hey guys, I am in dire need of a simple hardware interrupt example, i've done my research all to no avail. I know it isn't that difficult, but all i need is kick start... so please, if anyone of you can take the time and help me with my interrupt quandary, i'll appreciate it (BIG TIME). I am using the Atmega 8, using interrupt pin INT1 (aka PD3). Here's what i am trying to do, i have a switch connected to the PD3  pin, and i want to program the atmega8 in a way where when i press the switch (transition from 0 to 1), it turns the LED on (which is connected to an output pin). so far the LED is working perfectly with polling, however i want to learn how hardware interrupts work. i am not sure of the declaration of the interrupt per se, nor am i sure of the global declarations that need to be done. here's a sample of my program:

   ISR(INT1_vect)
   {
      while ((PIND & _BV(PD3))) == 1)
      LED_on();   
   }

Any help will be greatly appreciated.




Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: Hardware Interrupt help in Atmega 8!?!
« Reply #1 on: September 29, 2009, 10:28:44 AM »
You cannot connect a switch directly to a an external interrupt. Bouncing will cause many problems. If you don't know what bouncing is, take a look at http://www.ganssle.com/debouncing.pdf

Now for the software part, here is the main steps:

- configure INT1 (choose the type of trigger, ...)
- enable INT1
- enable interrupts

Your main source of information for this is the datasheet of your micro-controller.

Chelmi.

Offline ramjam89Topic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: Hardware Interrupt help in Atmega 8!?!
« Reply #2 on: September 29, 2009, 05:58:50 PM »
Hey Chelmi, thanks for the quick reply, much appreciated. I figured it out from the datasheet and it worked perfectly. of course to fix the debouncing problem i had to put a delay function, which worked quite well. Thanks anyway.

Cheers

 

SMF spam blocked by CleanTalk