Download presentation
Presentation is loading. Please wait.
Published byMarjorie Harrington Modified over 9 years ago
1
1 © Unitec New Zealand Interrupt Lecture 6 Date: - 20 Sept, 2011 Embedded Hardware ETEC 6416
2
Two methods are used in microcontrollers to acquired external/internal information –Polling: - the microcontroller accesses the external/internal device at the exact time interval and gets the required information. The user is the one who determines the time intervals in which micro “contacts” the device. –Draw back of polling system is that micro wastes it time for the information to arrive. –Interrupt: - Interrupt is the signal sent to the micro to mark the event that requires immediate attention. 2 © Unitec New Zealand
3
Interrupt Request An interrupt request is an internal or external event that when serviced makes the microcontroller interrupt the execution of the current program and execute another program instead. Once the interrupt is serviced then the main program is executed. 3 © Unitec New Zealand
4
Sources of Interrupt Internal interrupts :- –I/O module –Memory –CPU External interrupts –External interrupt originates in peripherals and reach the microcontroller through one of its pins and associated ports. 4 © Unitec New Zealand
5
Resources for servicing of interrupts Each interrupt source has two associated bits. These bits may be in the same register or different registers One bit is a control bit, which enable and disable the interrupt of the source. The other bit is a flag, which is informative that interrupt is occurred. This bit can be checked by the program depending on the technique used to service the interrupt. Microcontrollers also have one bit for global control of interrupts. This must be enabled for any interrupt to be serviced. 5 © Unitec New Zealand
6
Interrupts type Mask-able interrupts –The control bits used to allow or disallow interrupt requests to reach the CPU. These bits are called mask bits. It is enabled or disabled by software. Non maskable interrupts –It has no masking bits and it can not be enabled or disabled from software. They are always enabled. 6 © Unitec New Zealand
7
Servicing Interrupt requests Servicing an interrupt request means to interrupt the execution of the current program and to move it to execute another program. Interrupt request servicing is different than normal subroutine as interrupt can occurred any time. 7 © Unitec New Zealand
8
Steps to service an interrupt request are 1.Microcontroller completes the execution of the current instruction. 2.The PC value is stored in the stack in order to execute the current program, once Microcontroller get back from the interrupt request. 3.Address of interrupt service subroutine is stored in the PC and program is executed at that address. 4.The interrupt service subroutine is executed and finishes with a return instruction. 5.When executing the return instruction, the microcontroller continues executing the program that was interrupted. 8 © Unitec New Zealand
9
Fixed and vectored interrupts Two ways to provide the CPU with the address for the interrupt service subroutine: 1.The interrupt service subroutine is stored in a fixed memory location that the CPU already knows called FIXED INTERRUPT request. 2.At the time of the interrupt being requested, the interrupt service subroutine address is given to the CPU called VECTORED INTERRUPT. 9 © Unitec New Zealand
10
Interrupts in PIC microcontrollers Interrupts in medium-end PIC microcontrollers are fixed, maskable interrupts. Interrupts can be disable or enabled globally and locally. For interrupt to be serviced both global and individual interrupts should be enabled. GIE (Global Interrupt Enable) bit is used for enabling the interrupts globally and it is INTCON special function register. 10 © Unitec New Zealand
11
Interrupts in PIC. Pic micro’s are fixed interrupts. Therefore, when an interrupt is serviced, the microcontroller execute instruction stored at address 4 in the program memory. Source of interrupt can be find out by reading the special function registers (INTCON, PIR1 and PIR2) associated with the interrupt system in PIC’s. 11 © Unitec New Zealand
12
When interrupt occurs then PIC completes the current instruction, stores the next instruction address in the stack and jumps to address 4 in program memory. The time elapsed between the moment the interrupt is requested and execution of the first interrupt in the interrupt service subroutine is in range of 3 to 3.75 machine cycles and is called latency time. When an interrupt request is being serviced, the global interrupt system is disabled (bit GIE set to 0). In C language, a special function take cares for all this… given in tutorial 12 © Unitec New Zealand
13
Possible interrupt request in PIC External Interrupt RA2/INT TMR0 Overflow Interrupt PORTA/PORTB Change Interrupts 2 Comparator Interrupts A/D Interrupt Timer1 Overflow Interrupt Timer2 Match Interrupt EEPROM Data Write Interrupt Fail-Safe Clock Monitor Interrupt Enhanced CCP Interrupt EUSART Receive and Transmit interrupts 13 © Unitec New Zealand
14
Special function registers for Interrupts The following interrupt flags are contained in the INTCON register: –INT Pin Interrupt –PORTA/PORTB Change Interrupts –TMR0 Overflow Interrupt The peripheral interrupt flags are contained in the PIR1 and PIR2 registers. The corresponding interrupt enable bits are contained in PIE1 and PIE2 registers. 14 © Unitec New Zealand
15
15 © Unitec New Zealand Pic16f877a data sheet pg 24
16
16 © Unitec New Zealand Pic16f877a data sheet pg 25
17
17 © Unitec New Zealand Pic16f877a data sheet pp26
18
PIR1 Interrupt flags The following interrupt flags are contained in the PIR1 register: –A/D Interrupt –EUSART Receive and Transmit Interrupts –Timer1 Overflow Interrupt –Synchronous Serial Port (SSP) Interrupt –Enhanced CCP1 Interrupt –Timer1 Overflow Interrupt –Timer2 Match Interrupt 18 © Unitec New Zealand
19
19 © Unitec New Zealand Pic16f877a data sheet pp 27
20
PIR2 flags The following interrupt flags are contained in the PIR2 register: –Fail-Safe Clock Monitor Interrupt –2 Comparator Interrupts –EEPROM Data Write Interrupt 20 © Unitec New Zealand
21
21 © Unitec New Zealand Pic16f877a data sheet pp 28
22
Interrupt service subroutine structure As interrupt can occurred any time, so the contents of the most commonly used register should be stored as during execution of interrupt service routine, every thing will be lost. PUSH and POP instructions are used in microprocessor for saving the contents of the registers in stack. PIC can only store the contents of PC in stack In PIC, contents of WORKING and STATUS register should be stored in the stack. This can be done in software by the programmer. 22 © Unitec New Zealand
23
Steps involved in servicing interrupt request 1.Microcontroller completes the execution of current instruction. 2.Value of PC is stored in the stack. 3.PC is set to 0004 and it causes MC to jump to interrupt routine. 4.Values of W and STATUS registers are stored. 5.Interrupt source are determined by checking the appropriate flag bits. 6.Once the source is identified, its flag is set to 0. 7.After execution of interrupt subroutine, W and STATUS registers are restored. 8.Retfie is used to return to the main program. This retrieves the value of PC from stack and Global Interrupt system (GIE=1) is enabled 23 © Unitec New Zealand
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.