Professional Documents
Culture Documents
Lect 12-PIC Architecture
Lect 12-PIC Architecture
1
PIC Architecture
Will now look at another architecture
Look at the microcontroller company
Step 1 – The programmers model
2
Philosophy of PIC Architecture
Embedded processing is pervasive
Electronic intelligence in is everyday products
Company Philosophy
Have products that fit the problem
Many systems can be automated using 8-bit
microcontrollers
Much of product line is 8-bit
3
Reasons for pervasiveness?
Competitive pressure
Expanded functionality of products
Provide differentiation in product from that of
competitor
Cost competitive integrated solution
Allow creation of new classes of products
4
Microcontroller Solution
Microcontroller features
CPU – processing unit
Non-volatile program memory
Re-settable non-volatile data memory
(EEPROM)
RAM for data storage
Direct support for various input/output
5
Typical automotive use
Engine control – 32-bit microcontroller
Fuel flow, fuel mixture, valve timing, throttle body
opening, spark timing
Transmission control –16-bit microcontroller
Audio system – 16-bit
Antilock braking – 16-bit
Up to fifty 8-bit microcontrollers for functions of
Wiper control
Electric Mirrors
Air Bags
6
Automotive today continued
Up to fifty 8-bit microcontrollers for functions of
Wiper control
Electric Mirrors
Air Bags
Fuel pump
Speedometer
Security system
Climate control system
Power windows …..
7
Microchip’s position
8
Microcontroller choice parameters
Number of I/O pins
Amount of program and data memory
Speed
Timer Resources
Interrupt control
Robustness
Error recovery – watchdog timers
Power, I/O expansion, math support
9
Block Diagram
10
PIC architecture is a “Harvard”
architecture
The Harvard Architecture
11
Feature of Harvard architecture
Near all instructions are single instruction
word instructions
Only one fetch per instruction
Instruction fetch and execute are pipelined so
you can operate at near clock rate instructions
per second
2 separate buses
One for instructions and one for data
12
PIC Instruction pipelining
What % of
time does 1st
flow of
execution
occur??
13
Frequency of Branches
On architectures such as the HP during the
normal flow of a program’s execution on 8 to
12 instructions are executed before a branch
occurs.
(aside) Modern architectures can easily
achieve above 90% correct branch prediction.
This can be factored into actual “speed” of the
processor.
14
The PIC 18F4550
15
Pin Diagram
16
17
Device Features Conti…
Supply Voltage
Most microcontrollers operate with the standard logic voltage
of 5V.
Some microcontrollers can operate at as low as low 2.7V, and
some will tolerate 6V without any problem.
The manufacturer’s data sheet will have information about the
allowed limits of the power supply voltage.
Usually, a voltage regulator circuit is used to obtain the
required power supply voltage
when the device is operated from a mains adapter or batteries.
For example, a 5V regulator is required if the microcontroller is
operated from a 5V supply using a 9V battery. 18
THE CLOCK
All microcontrollers require a clock (or an oscillator) to operate, usually
provided by external timing devices connected to the microcontroller.
In most cases, these external timing devices are a crystal plus two small
capacitors.
In some cases they are resonators or an external resistor-capacitor pair.
Some microcontrollers have built-in timing circuits and do not require external
timing components.
If an application is not time sensitive, external or internal (if available)
resistor-capacitor timing components are the best option for their simplicity
and low cost.
An instruction is executed by fetching it from the memory and then decoding
it. This usually takes several clock cycles and is known as the instruction
cycle.
In PIC microcontrollers, an instruction cycle takes four clock periods. Thus
the microcontroller operates at a clock rate that is one-quarter of the actual
oscillator frequency.
The PIC18F series of microcontrollers can operate with clock frequencies up to 40MHz.
19
Clock sources on the PIC18F microcontroller, selected by the
configuration register CONFIG1H.
These are:
Low-power crystal (LP)
Crystal or ceramic resonator (XT)
High-speed crystal or ceramic resonator (HS)
High-speed crystal or ceramic resonator with PLL (HSPLL)
External clock with FOSC/4on OSC2 (EC)
External clock with I/O on OSC2 (port RA6) (ECIO)
External resistor/capacitor with FOSC/4output on OSC2 (RC)
External resistor/capacitor with I/O on OSC2 (port RA6) (RCIO)
20
Crystal or Ceramic
The first several clock sources listed use an external crystal or ceramic
resonator that is connected to the OSC1 and OSC2 pins.
For applications where accuracy of timing is important, a crystal should
be used.
If a crystal is used, a parallel resonant crystal must be chosen, since series
resonant crystals do not oscillate when the system is first powered.
Resonators should be used in low-cost applications where high accuracy
in timing is not
required
21
22
Frequency ranges
31
Current Sink/Source Capability
Current sink/source capability is important if the
microcontroller is to be connected to an external device that
might draw a large amount of current to operate.
PIC microcontrollers can source and sink 25mA of current
from each output port pin.
This current is usually sufficient to drive LEDs, buzzers, etc.
The current capability can be increased by connecting
external transistor switching circuits or relays to the output
port pins
32
33
The Program Counter (PC) specifies the address of the instruction to fetch
for execution
The PC increments by 2 to address sequential instructions in the program
memory.
The return address stack allows any combination of up to 31 program
calls and interrupts to occur.
The PC is pushed onto the stack when a CALL or RCALL instruction is
executed or an interrupt is Acknowledged.
The PC value is pulled off the stack on a RETURN, RETLW or
a RETFIE instruction.
34
The Stack
The PIC18F microcontroller has a 31-entry stack that is used to hold the
return addresses for subroutine calls and interrupt processing.
The stack is not part of the program or the data memory space.
The stack is controlled by a 5-bit stack pointer which is initialized to
00000 after a reset.
During a subroutine call (or interrupt) the stack pointer is first
incremented, and the memory location it points to is written with
the contents of the program counter.
During the return from a subroutine call (or interrupt), the memory
location the stack pointer has pointed to is decremented.
he Stack Pointer is initialized to ‘00000’ after all
Resets.
35
36