03- introduction in Interrupts AndTimers.ppt

ssuser3cbb4c 25 views 19 slides Apr 27, 2024
Slide 1
Slide 1 of 19
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19

About This Presentation

Interrupts AndTimers


Slide Content

Working with time: interrupts,
counters and timers
Chapter 3
Dr. Gheith Abandah 1

Outline
•Interrupts
–Interrupt Structures
–Interrupt Demonstration Program
•Counters and Timers
•Watchdog Timer
•Sleep Mode
Dr. Gheith Abandah 2

Interrupt
Dr. Gheith Abandah 3
Interrupts are one of the most powerful features
of PIC microcontrollers interrupts make it
possible to create applications that can respond
to external stimulus in real time. An interrupt is
basically an event that requires the
microcontroller to stop normal program
execution and then to jump to execute a
program code related to the event causing the
interrupt.

The 16F84A Interrupt Sources
Dr. Gheith Abandah 4
1.External interrupt. It shares a pin with Port B,
bit 0. It is edge triggered.
2.Timer 0 overflow. It occurs when the timer’s
8-bit counter overflows.
3.Port B interrupt on change. This interrupts
when a change is detected on any of the
higher 4 bits of Port B.
4.EEPROM write complete.

The 16F84A Interrupt Structure
Dr. Gheith Abandah 5
INTCON:
SFR 0Bh

Dr. Gheith Abandah 6

Dr. Gheith Abandah 7

External interrupt
Dr. Gheith Abandah 8

Timer0interrupt
Dr. Gheith Abandah 9

Dr. Gheith Abandah 10

Counters and Timers
•A digital counter is
usually made of flip
flops and counts up or
down.
•When the triggering
event is a constant
frequency clock, we get
a timer.
Dr. Gheith Abandah 11

Timer Applications
(a)Measure the time
between two events
(b)Measure the time
between two pulses
(c)Measure a pulse
duration
Use interrupts
Dr. Gheith Abandah 12

PIC 16F84A Timer 0 Module
Dr. Gheith Abandah 13

PIC 16F84A Timer 0 Module
Dr. Gheith Abandah 14

Option Register
•T0CS: Clock source select
•T0SE: Source edge select
•PSA: Prescaler assignment bit
•PS2:PS0: Prescaler rate select
Dr. Gheith Abandah 15

Hardware-Generated Delays
•In software-generated delays, the CPU is tied
up during the delay time.
•Can use Timer 0 for delays.
•The timer overflow interrupt is used to inform
the CPU when the delay time is up.
•Example:
–Clock = 800 KHz → Fosc/4 = 200 KHz → T = 5 μs
–Preselect = 8 for 125 count → 125 x 8 x 5 μs = 5.00 ms
–Need to set T0 at 256-125 = 131 to get overflow after 5 ms
Dr. Gheith Abandah 16

The Watchdog Timer
•A big danger with any computer-based system
is that the software fails in some way and that
the system locks up or becomes unresponsive.
•The WDT continually counts up. If it ever
overflows, it forces the microcontroller into
reset.
•If the instruction clrwdtis not executed every
(18 ms * prescaler rate), overflow occurs.
Dr. Gheith Abandah 17

Sleep Mode
•When the sleepinstruction is executed, the
PIC halts execution and enters power saving
mode.
•It awakes at:
–External reset (MCLR)
–WDT wake-up
–Occurrence of an enabled interrupt
Dr. Gheith Abandah 18

Summary
•Interrupts and counter/timers are important
hardware features of almost all microcontrollers.
•They both carry a number of important hardware
and software concepts, which must be understood.
•The basic techniques of using interrupts and
counter/timers have been introduced in this
chapter. There is considerably increased
sophistication in their use in more advanced
applications.
Dr. Gheith Abandah 19