AVR > AVR Microcontroller Interrupts

TODAY5,527 TOTAL3,486,664
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | AVR | 외부인터럽트 | AVR Microcontroller Interrupts

페이지 정보

작성자 키트 작성일2017-08-29 09:16 조회3,926회 댓글0건

본문

 

AVR Tutorials
The Best AVR Microcontroller Tutorials on the Web










AVR Microcontroller Interrupts

What are interrupts?


Interrupts are basically events that require immediate attention by the microcontroller. When an interrupt event occurs the microcontroller pause its current task and attend to the interrupt by executing an Interrupt Service Routine (ISR) at the end of the ISR the microcontroller returns to the task it had pause and continue its normal operations.

In order for the microcontroller to respond to an interrupt event the interrupt feature of the microcontroller must be enabled along with the specific interrupt. This is done by setting the Global Interrupt Enabled bit and theInterrupt Enable bit of the specific interrupt.

Interrupt Service Routine or Interrupt Handler
An Interrupt Service Routine (ISR) or Interrupt Handler is a piece of code that should be execute when an interrupt is triggered. Usually each enabled interrupt has its own ISR. In AVR assembly language each ISR MUSTend with the RETI instruction which indicates the end of the ISR.

Interrupt Flags and Enabled bits
Each interrupt is associated with two (2) bits, an Interrupt Flag Bit and an Interrupt Enabled Bit. These bits are located in the I/O registers associated with the specific interrupt:

  • The interrupt flag bit is set whenever the interrupt event occur, whether or not the interrupt is enabled.
  • The interrupt enabled bit is used to enable or disable a specific interrupt. Basically is tells the microcontroller whether or not it should respond to the interrupt if it is triggered.

In summary basically both the Interrupt Flag and the Interrupt Enabled are required for an interrupt request to be generated as shown in the figure below.

 

3660040649_fnYy74JU_Interrupt2520Request.jpg

 

Global Interrupt Enabled Bit
Apart from the enabled bits for the specific interrupts the global interrupt enabled bit MUST be enabled for interrupts to be activated in the microcontoller.

For the AVR 8-bits microcontroller this bit is located in the Status I/O Register (SREG). The Global Interrupt Enabled is bit 7, the I bit, in the SREG.
AVR Microcontroller SREG

 

Interrupt sources provided with the AVR microcontroller


The AVR 8-bits microcontroller provide both internal and external interrupt sources. The internal interrupts are associated with the microcontroller's peripherals. That is the Timer/Counter, Analog Comparator, etc. The external interrupts are triggered via external pins. The figure below shows the pins, on which the external interrupts can be triggered, for an AVR 8-bit microcontroller. On this microcontroller there are four (4) external interrupts:
  1. The RESET interrupt - Triggered from pin 9.
  2. External Interrupt 0 (INT0) - Triggered from pin 16.
  3. External Interrupt 1 (INT1) - Triggered from pin 17.
  4. External Interrupt 2 (INT2) - Triggered from pin 3.

 

AVR Microcontroller External Interrupt Pins

 

Very Important
When writing assembly codes for your AVR microcontroller utilizing the interrupt feature the following MUST be observed:

  • The interrupt MUST be enabled by setting its enabled bit in the appropriate I/O register.
  • The Global Interrupt bit, the I bit, in the microcontroller's status register (SREG) MUST also be enabled.
  • The stack MUST be initialized. When an interrupt is being service the microcontroller need to store critical information on the stack and so it must be initialized.
  • The Interrupt Service Routine (ISR) MUST end with the RETI instruction, which indicates the end of the ISR. The microcontroller needs to know when it reaches the end of the ISR so it can return to its previous task.

 

Steps taken in servicing an interrupt


Upon the triggering of an interrupt the following sequence is followed by the microcontroller providing that the both the specific interrupt and global interrupts are enabled in the microcontroller:
  1. The microcontroller completes the execution of the current instruction, clears the I bit and stores the address of the next instruction that should have been executed (the content of the PC) on the stack.
  2. The interrupt vector of the triggered interrupt is then loaded in the PC and the microcontroller starts execution from that point up until is reaches a RETI instruction.
  3. Upon the the execution of the RETI instruction the address that was stored on the stack in step 1 is reloaded in the PC and the I bit is re-enabled.
  4. The microcontroller then start executing instructions from that point. That is the point that it left off when the interrupt was triggered.

Important Notes:
As it relates to AVR microcontrollers - An interrupt vector is the memory address of an interrupt handler. The interrupt vector for each interrupt provided by the AVR microcontrollers can be found in its datasheet. The table below is an extract from the interrupt section of the ATMega8515 datasheet and gives the interrupt vectors for the interrupts provided with this microcontroller.

Please note here that the interrupt vectors are apart of the microcontroller's program memory. As such when utilizing interrupts this section of memory should be reserved to store pointers to interrupt handlers and not to store regular programs. For the ATMega8515 microcontroller to ensure that regular programs are not stored in this section of program memory insert the following line is your AVR assembly code.

.org $11

 

ATMega8515 Interrupt Vector Table
Vector #Program Memory AddressSourceDefinition
1$000RESETALL Reset - External Pin Reset, Power Down Reset, Watchdog Reset, Brown-Out Reset
2$001INT0External Interrupt Request 0
3$002INT1External Interrupt Request 1
4$003TIMER1 CAPTTimer/Counter1 Capture Event
5$004TIMER1 COMPATimer/Counter1 Compare Match A
6$005TIMER1 COMPBTimer/Counter1 Compare Match B
7$006Timer1 OVFTimer/Counter1 Overflow
8$007Timer0 OVFTimer/Counter0 Overflow
9$008SPI STCSerial Transfer Complete
10$009USART RXCUSART Rx Complete
11$00AUSART UDREUSART Data Register Empty
12$00BUSART TXCUSART Tx Complete
13$00CANA_COMPAnalog Comparator
14$00DINT2External Interrupt Request 2
15$00ETIMER0 COMPTimer/Counter0 Compare Match
16$00FEE_RDYEEPROM Ready
17$010SPM_RDYStore Program Memory Ready

AVR Tutorials hope this AVR interrupt tutorial was benificial to you and looks forward to your continued visit for all your microcontroller tutorial needs.

댓글 0

조회수 3,926

등록된 댓글이 없습니다.

AVRHOME > AVR > 외부인터럽트 목록

게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기