Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 36

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

Higher capacitance increases the oscillator stability but


also increases the start-up time. 23
24
25
26
RESISTOR CAPACITOR MODE
Timers
 A timer is basically a counter which is driven from either an external clock
pulse or the microcontroller’s internal oscillator.
 A timer can be 8 bits or 16 bits wide. Data can be loaded into a timer under
program control, and the timer can be stopped or started by program control.
 Most timers can be configured to generate an interrupt when they reach a
certain count (usually when they overflow).
 The user program can use an interrupt to carry out accurate timing-related
 operations inside the microcontroller.
 Microcontrollers in the PIC18F series have at least three timers.
 Some microcontrollers offer capture and compare facilities, where a timer
value can be read when an external event occurs, or the timer value can be
compared to a preset value, and an interrupt is generated when this value is
reached.
 Most PIC18Fmicrocontrollers have at least two capture and compare
27
modules.
Watchdog
 Most microcontrollers have at least one watchdog facility.
 The watchdog is basically a timer that is refreshed by the user
program.
 Whenever the program fails to refresh the watchdog, a reset
occurs.
 The watchdog timer is used to detect a system problem, such as
the program being in an endless loop.
 This safety feature prevents runaway software and stops the
microcontroller from executing meaningless and unwanted code.
 Watchdog facilities are commonly used in real-time systems
where the successful termination of one or more activities must
be checked regularly 28
The Reset
 The reset action puts the microcontroller into a known state.
 Resetting a PIC18F microcontroller starts execution of the program from
address 0000H of the program memory.
 The microcontroller can be reset during one of the following operations:
 Power-on reset (POR)
 MCLR reset
 Watchdog timer (WDT) reset
 Brown-out reset (BOR)
 Reset instruction
 Stack full reset
 Stack underflow reset
 Two types of resets are commonly used: power-on reset and external reset
using the MCLR pin. 29
30
Interrupts
 Interrupts are an important concept in microcontrollers.
 An interrupt causes the microcontroller to respond to
external and internal (e.g., a timer) events very quickly.
 When an interrupt occurs, the microcontroller leaves its
normal flow of program execution and jumps to a special part
of the program known as the interrupt service
 routine (ISR).
 The program code inside the ISR is executed, and upon return
from the ISR the program resumes its normal flow of
execution.

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

You might also like