Docsity

Understanding Interrupt Control Systems in PIC16F87X: Microcontroller Interrupts & Timers, Lecture notes of Microcontrollers

Partial preview of the text

Download Understanding Interrupt Control Systems in PIC16F87X: Microcontroller Interrupts & Timers and more Lecture notes Microcontrollers in PDF only on Docsity!

BEEZ 2404

Microcontroller Technology

Chapter 3: Interrupt Control Systems

At the end of the class, you will be able:

To understand the concept of interrupt.

to setup timers.

to application of interrupt.

Source of Interrupt

Internal peripheral sources

◦ Timers (TMR0, TMR1, TMR2, …)

◦ A/D Converter

◦ Serial I/O

External sources

◦ RB0/INTO (in case of PIC16F877A)

◦ Can be used to connect external interrupting sources i.e. Keypads or switches

◦ PORTB Interrupt (RBI)Change in logic levels of pins RB4‐RB

Source of Interrupt

In total, The PIC16F87X family has up to 17 sources of interrupt

Interrupt vs Polling

Polling

◦ Ask the device if it has any data

◦ All intelligence is in the CPU

◦ CPU controls interaction with the device

Interrupts

◦ Device tells the CPU that is ready with/for data or needs service by

interrupting the CPU

◦ Intelligence is moved to the device

◦ Device informs the CPU when it needs service

Interrupt vs Polling

Which is better/faster?
◦ Polling is simple
◦ Query each device via pointers and do whatever is required
◦ Very little setup required
◦ Interrupts are faster
◦ Interrupts are more complicated
◦ Difficult to debug due to asynchronous behavior
◦ Debugging can alter the behavior of the interrupt
◦ More setup involved to write IS
◦ All code called by ISR must be re-entrant, i.e., callable while it is
already being executed

Interrupt Process

The location from where the program proceeds with execution is called an interrupt vector. For PIC16F877A, this address is 0004h

PIC16F877A Interrupt Vector

The Reset vector is at 0000h and the

interrupt vector is at 0004h

Interrupt System Register

When an interrupt request arrives, it doesn’t mean that an interrupt

will automatically occur, because it must also be enabled by the user.

◦ there are special bits used to enable or disable interrupts which is IE (Interrupt Enable). ◦ each interrupt is associated with another bit called the flag which indicates that an interrupt request has arrived which is IF ( Interrupt Flag ).

Interrupt System Register (HOW?)

14 Enable? Set to “1” “0” Ignore Internal Interrupt External Interrupt

PIC16F877A Interrupt Instruction Enabler

The INTCON register contains various enable and flag bits for TMR 0

register overflow, PORTB change and external INT pin interrupts.

  • INTCON – Int errupt Con trol Register
  • Function – to allow or disallowed interrupts

PIC16F877A Interrupt Instruction Enabler

GIE - Global Interrupt Enable bit - controls all possible interrupt sources simultaneously. ◦ 1 - Enables all unmasked interrupts. ◦ 0 - Disables all interrupts.

PIC16F877A Interrupt Instruction Enabler INTE - RB0/INT External Interrupt Enable bit controls interrupt caused by changing the logic state of the RB0/INT input pin (external interrupt). ◦ 1 - Enables the INT external interrupt. ◦ 0 - Disables the INT external interrupt.

PIC16F877A Interrupt Instruction Enabler RBIE - RB Port Change Interrupt Enable bit. When configured as inputs, PORTB pins may cause an interrupt by changing their logic state (no matter whether it is high-to-low transition or vice versa, the fact that something is changed only matters). This bit determines whether an interrupt is to occur or not. ◦ 1 - Enables the port B change interrupt. ◦ 0 - Disables the port B change interrupt.