interrupts an interrupt is any service request that causes the cpu to stop its current execution...

21
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.

Upload: andra-cunningham

Post on 18-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 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

InterruptsAn 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.

Page 2: 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

Interrupts can be requested from any of the following sources:

•hardware devices

•software interrupts (programmed interrupt requests (PIRs))

•exceptions, such as page faults

Page 3: 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

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.

Page 4: 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

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

Page 5: 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

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

Page 6: 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

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

Page 7: 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

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

Page 8: 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

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

Page 9: 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

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

Page 10: 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

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

Page 11: 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

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

Page 12: 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

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

Page 13: 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

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 "

Page 14: 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

PIC Timers

• Available in all PICs

• 14+bit may generate interrupts on timer overflow

• Some 8 bits some 16 bits some have prescalers

Page 15: 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

PIC Timers

• Can use external pin as clock in / clock out (ie for counting events)

• Warning: Some Peripherals shares timer resources.

Page 16: 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

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

Page 17: 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

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

Page 18: 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

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

Page 19: 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

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

Page 20: 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

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)

Page 21: 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

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