Download presentation
Presentation is loading. Please wait.
Published byAndra Cunningham Modified over 9 years ago
1
Interrupts An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services the interrupt When the CPU finishes servicing the interrupt, it returns to the original execution stream at the point where it left off.
2
Interrupts can be requested from any of the following sources: hardware devices software interrupts (programmed interrupt requests (PIRs)) exceptions, such as page faults
3
Overview of PIC Interrupts An interrupt is an event which forces a call to a subroutine which is usually referred to as an interrupt service routine Typical sources of interrupts on the PIC include a positive or negative transition on the RB.0/INT input, a change on any of the inputs RB4 - RB7 or a timer / counter overflow from a value of FFH to 00H.
4
Overview of PIC Interrupts the processor saves the return address on the stack and program control is redirected to the interrupt service routine aside from the return address no registers are saved However the user may save such important registers as W and STATUS
5
Overview of PIC Interrupts On interrupt, program flow is directed to program location 004H As a reset directs program flow to 000H On interrupt, a flag bit associated with the type of interrupt is set by the processor
6
Overview of PIC Interrupts On interrupt, a flag bit associated with the type of interrupt is set by the processor flag bits may be used to determine the source of the interrupt and perform the appropriate action
7
Overview of PIC Interrupts a program using interrupts is usually structured as follows ORG 000H ; a reset redirects program to this point GOTO MAIN ORG 004H ; an interrupt redirects the program to here GOTO INT_SERV
8
Overview of PIC Interrupts The user may control the sources of interrupts. For example BSF INTCON, INTE ; enable interrupts on RB0/INT BSF INTCON, RBIE ; enable change in RB4 - RB7 interrupt BSF INTCON, TOIE ; enable timer interrupt Any of these may be used alone
9
Overview of PIC Interrupts At any time in the program, the user may turn any of the sources off by clearing these mask bits BCF INTCON, INTE BCF INTCON, RBIE BCF INTCON, TOIE several sources may be enabled, depending on your application
10
Overview of PIC Interrupts you are ready to accept interrupts. Set the appropriate mask bit (INTE, RBIE or TOIE) and set GIE When no further interrupts are desired, either clear GIE or the mask bits or both
11
Overview of PIC Interrupts If an event then occurs, a flag bit assocociated with that interrupt is automatically set allows you to determine the source of the interrupt
12
Overview of PIC Interrupts On interrupt, the processor clears the GIE bit, inhibiting any further interrupts The bit is set on execution of the return from interrupts (RETFIE) programmer need not perform this book keeping
13
Overview of PIC Interrupts Note that the occurrence of an interrupt event sets the flag bit It is the user's responsibility to clear the flag bit Failure to clear the flag bit is interpreted by the processor as "a previous interrupt occurred "
14
PIC Timers Available in all PICs 14+bit may generate interrupts on timer overflow Some 8 bits some 16 bits some have prescalers
15
PIC Timers Can use external pin as clock in / clock out (ie for counting events) Warning: Some Peripherals shares timer resources.
16
PIC Timers The device has three readable and writeable hardware timers that can increment automatically each instruction cycle (if no prescaler is used). All timers can cause an interrupt on overflow, and then restart from zero
17
PIC Timers / Timer 0 8 bit timer/counter with prescaler Readable and writeable 8-bit software programmable prescaler Internal or external clock set Interrupt on overflow from 0xFF to 0x00 Edge Select for external clock
18
PIC Timers / Timer 1 16-bit timer/counter with prescaler Readable and writeable 1, 2, 4, 8 programmable prescaler Internal or external clock select External clock can be syn. or asyn. Interrupt on overflow Second crystal permitted
19
PIC Timers / Timer 2 8-bit timer/counter with prescaler and postscaler Readable and writeable 1,4 or 16 programmable prescaler 4-bit programmable postscaler Interrupt on overflow Output to port pin
20
PIC Timers Timer 0 timer/counter with prescale Timer 1 timer/counter with prescale Timer 2 timer only with prescale and postscale Watch Dog Timer (discussed later)
21
Timers TIMER0 is an 8-bit timer with an eight bit prescaler, which can make the timer run 2 to 256 times slower than normal TIMER1 is a 16-bit timer (two 8-bit registers) with a 1:1 to 1:8 prescaler and some other features. Used by given C code to generate soft timer and sound TIMER2 is an 8-bit timer with 1:1 to 1:16 prescaler and a 1:1 to 1:16 postscaler It also has a period register.Used by given C code for PWM motor control
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.