AV-314
Digital Systems-Embedded Systems
Lecture No 06 & 07
“PIC16F887 Oscillators
Textbook (Bates) Section 1.2
PIC 16x Datasheet
PIC Microcontrollers (mikroElectronika) Chapter 08
Number of Slides: 36
1
Objective
• To learn about Oscillator types and
associated options and configurations
2
PIC 16Fx Overview
3
PIC16F887 Pinout
•
4
PIC16F887 OSCILLATOR
SFR 5
Types of Oscillator
• Internal Oscillator
• External Oscillator
• System Clock Select (SCS) bit of the OSCCON
register selects external or internal
6
INTERNAL OSCILLATOR
7
Internal Oscillator
• PIC16F887 consists of two separate, internal oscillators:
• HFINTOSC
– High-frequency internal oscillator which operates at 8MHz
– Factory calibrated
• LFINTOSC
– Low-frequency internal oscillator which operates at 31 kHz
– Watchdog timer, Powerup timer and Fail safe clock
monitor use the same timer
8
Clock Control
9
Oscillator Control (SFR)
• Contains
– Frequency Selection bits (IRCF2, IRCF1, IRCF0)
– Frequency Status bits (HTS, LTS)
– System Clock Control/Status Bits (SCS, OSTS)
10
Oscillator Control (SFR)
11
Oscillator Control (SFR)
12
Internal Oscillator Control
• HFINTOSC is connected to the post scaler (frequency divider)
• It is factory calibrated and operates at 8MHz
• HFINTOSC is enabled by selecting one of seven frequencies (between
8 MHz and 125 kHz) and setting the System Clock Source (SCS) bit of
the OSCCON register
• The low-frequency oscillator LFINTOSC is un-calibrated and operates
at 31 kHz
• It is enabled by selecting this frequency (bits of the OSCCON register)
and setting the SCS bit of the same register
13
Oscillator Control (SFR)
• OSTS – Oscillator Start-up Time-out Status bit indicates which
clock source is currently in use. This bit is read only
1 – External clock oscillator is in use; and
0 – One of internal clock oscillators is in use (HFINTOSC or
LFINTOSC)
• HTS – HFINTOSC Status bit (125 kHz - 8 MHz) indicates whether
high-frequency internal oscillator operates in a stable way.
1 – HFINTOSC is stable; and
0 – HFINTOSC is not stable
14
Oscillator Control (SFR)
• LTS – LFINTOSC Status bit (31 kHz) indicates whether low-frequency
internal oscillator operates in a stable way
1 – LFINTOSC is stable;
0 – LFINTOSC is not stable
• SCS – System Clock Select bit determines which oscillator is to be
used as a clock source
1 – Internal oscillator is used for system clock;
0 – External oscillator is used for system clock;
The oscillator mode is set by bits in Config Word which are written to
the microcontroller memory during programming
15
Oscillator Selection by Config Word
16
Internal Oscillator (INTOSC Mode)
• OSC1 Pin is available
as GPIO
• OSC2 Pin outputs
selected internal
oscillator frequency
divided by 4
17
Internal Oscillator (INTSCIO Mode)
• Both OSC(1 & 2) pins
are available as GPIOs
18
EXTERNAL OSCILLATOR
19
External Oscillator
• External oscillator is connected to the OSC1 and
OSC2 pins
• Relies on external circuitry for the clock signal and
frequency stabilization
-quarts crystal
-ceramic resonator
-resistor-capacitor circuit
• Oscillator mode is selected by FOSC<2:0> bits in
the Config Word
20
Oscillator Selection by Config Word
21
External Oscillator (RC &RCIO Mode)
F=1/T
T=R*C
•More flexible
•Cheapest
•Less Accurate
22
Oscillator Selection by Config Word
23
External Oscillator EC Mode (0-20 MHz)
EC=External Clock
•No delay required for
frequency stabilization
•Better reliability.
•Stopping clock will halt
the program while
keeping the data intact
24
Oscillator Selection by Config Word
25
External Oscillator in LP, XT or HS Modes
LP mode (Low Power) is used for low-frequency quartz
crystal only.This mode is designed to drive only 32.768 kHz
crystals. Current consumption is minimum.
XT mode is used for intermediate-frequency quartz crystals
up to 8 MHz. Current consumption is medium.
HS mode (High Speed) is used for high-frequency quartz
crystals over 8 MHz. Current consumption is maximum.
26
External Oscillator Modes
27
External Oscillator
Quarts Crystal Ceramic Resonator
28
Selecting Oscillator Modes: MikroC Pro
29
Fail Safe Monitor
T=?
30
Fail Safe Monitor
• Detects a failed oscillator by comparing the
internal and external clock sources
• In case it takes more than 2mS for the
external oscillator clock to come, the clock
source will be automatically switched
• The internal oscillator will thereby continue
operating controlled by the bits of the
OSCCON register
31
Enabling Fail Safe Monitor
32
SUMMARY
SFR 33
34
End of Lecture
35