Architecture - PICmicro Mid-Range MCU Family

M
Section 4. Architecture
HIGHLIGHTS
This section of the manual contains the following major topics:
4.1
4.2
4.3
4.4
4.5
4.6
4.7
Introduction ....................................................................................................................4-2
Clocking Scheme/Instruction Cycle ...............................................................................4-5
Instruction Flow/Pipelining .............................................................................................4-6
I/O Descriptions .............................................................................................................4-7
Design Tips ..................................................................................................................4-12
Related Application Notes............................................................................................4-13
Revision History ...........................................................................................................4-14
4
Architecture
 1997 Microchip Technology Inc.
DS31004A page 4-1
PICmicro MID-RANGE MCU FAMILY
4.1
Introduction
The high performance of the PICmicro™ devices can be attributed to a number of architectural
features commonly found in RISC microprocessors. These include:
•
•
•
•
•
•
•
•
Harvard architecture
Long Word Instructions
Single Word Instructions
Single Cycle Instructions
Instruction Pipelining
Reduced Instruction Set
Register File Architecture
Orthogonal (Symmetric) Instructions
Figure 4-2 shows a simple core memory bus arrangement for Mid-Range MCU devices.
Harvard Architecture:
Harvard architecture has the program memory and data memory as separate memories and are
accessed from separate buses. This improves bandwidth over traditional von Neumann architecture in which program and data are fetched from the same memory using the same bus. To execute an instruction, a von Neumann machine must make one or more (generally more) accesses
across the 8-bit bus to fetch the instruction. Then data may need to be fetched, operated on, and
possibly written. As can be seen from this description, that bus can be extremely conjested. While
with a Harvard architecture, the instruction is fetched in a single instruction cycle (all 14-bits).
While the program memory is being accessed, the data memory is on an independent bus and
can be read and written. These separated buses allow one instruction to execute while the next
instruction is fetched. A comparison of Harvard vs. von-Neumann architectures is shown in
Figure 4-1.
Figure 4-1: Harvard vs. von Neumann Block Architectures
von-Neumann
Harvard
Data
Memory
8
CPU
14
Program
Memory
CPU
8
Program
and
Data
Memory
Long Word Instructions:
Long word instructions have a wider (more bits) instruction bus than the 8-bit Data Memory Bus.
This is possible because the two buses are separate. This further allows instructions to be sized
differently than the 8-bit wide data word which allows a more efficient use of the program memory, since the program memory width is optimized to the architectural requirements.
Single Word Instructions:
Single Word instruction opcodes are 14-bits wide making it possible to have all single word
instructions. A 14-bit wide program memory access bus fetches a 14-bit instruction in a single
cycle. With single word instructions, the number of words of program memory locations equals
the number of instructions for the device. This means that all locations are valid instructions.
Typically in the von Neumann architecture, most instructions are multi-byte. In general, a device
with 4-KBytes of program memory would allow approximately 2K of instructions. This 2:1 ratio is
generalized and dependent on the application code. Since each instruction may take multiple
bytes, there is no assurance that each location is a valid instruction.
DS31004A-page 4-2
 1997 Microchip Technology Inc.
Section 4. Architecture
Instruction Pipeline:
The instruction pipeline is a two-stage pipeline which overlaps the fetch and execution of instructions. The fetch of the instruction takes one TCY, while the execution takes another TCY. However,
due to the overlap of the fetch of current instruction and execution of previous instruction, an
instruction is fetched and another instruction is executed every single TCY.
Single Cycle Instructions:
With the Program Memory bus being 14-bits wide, the entire instruction is fetched in a single
machine cycle (TCY). The instruction contains all the information required and is executed in a
single cycle. There may be a one cycle delay in execution if the result of the instruction modified
the contents of the Program Counter. This requires the pipeline to be flushed and a new instruction to be fetched.
Reduced Instruction Set:
When an instruction set is well designed and highly orthogonal (symmetric), fewer instructions
are required to perform all needed tasks. With fewer instructions, the whole set can be more rapidly learned.
Register File Architecture:
The register files/data memory can be directly or indirectly addressed. All special function registers, including the program counter, are mapped in the data memory.
Orthogonal (Symmetric) Instructions:
Orthogonal instructions make it possible to carry out any operation on any register using any
addressing mode. This symmetrical nature and lack of “special instructions” make programming
simple yet efficient. In addition, the learning curve is reduced significantly. The mid-range instruction set uses only two non-register oriented instructions, which are used for two of the cores features. One is the SLEEP instruction which places the device into the lowest power use mode. The
other is the CLRWDT instruction which verifies the chip is operating properly by preventing the
on-chip Watchdog Timer (WDT) from overflowing and resetting the device.
4
Architecture
 1997 Microchip Technology Inc.
DS31004A-page 4-3
PICmicro MID-RANGE MCU FAMILY
Figure 4-2:
General Mid-range PICmicro Block Diagram
13
Program
Bus
EPROM
Program Counter
Program
Memory
up to
8K x 14
8 Level Stack
(13-bit)
14
8
Data Bus
PORTA
RA0
RA1
RA2
RA3
RA4
RA5
RAM
File
Registers
up to
368 x 8
RAM Addr (1)
PORTB
9
Addr MUX
Instruction reg
Direct Addr
7
8
Indirect
Addr
FSR reg
STATUS reg
8
3
Power-up
Timer
Instruction
Decode &
Control
Timing
Generation
OSC1/CLKIN
OSC2/CLKOUT
Internal
RC clock (2)
Oscillator
Start-up Timer
Power-on
Reset
Watchdog
Timer
Brown-out
Reset (2)
MCLR
Timer0
Timer1
RC0
RC1
RC2
RC3
RC4
RC5
RC6
RC7
MUX
ALU
8
PORTD
W reg
PORTE
VDD, VSS
Timer2
PORTC
RB0/INT
RB1
RB2
RB3
RB4
RB5
RB6
RB7
RD0
RD1
RD2
RD3
RD4
RD5
RD6
RD7
RE0
RE1
RE2
RE3
RE4
RE5
RE6
RE7
A/D
PORTF
CCPs
Comparators
Other
Modules
Voltage
Reference
Peripheral Modules (Note 3)
Synchronous
Serial Port
USARTs
Parallel
Slave Port
LCD Drivers
Data EEPROM
up to
256 x 8
RF0
RF1
RF2
RF3
RF4
RF5
RF6
RF7
PORTG
RG0
RG1
RG2
RG3
RG4
RG5
RG6
RG7
General Purpose I/O
(Note 3)
Note 1: The high order bits of the Direct Address for the RAM are from the STATUS register.
2: Not all devices have this feature, please refer to device data sheet.
3: Many of the general purpose I/O pins are multiplexed with one or more peripheral module functions.
The multiplexing combinations are device dependent.
DS31004A-page 4-4
 1997 Microchip Technology Inc.
Section 4. Architecture
4.2
Clocking Scheme/Instruction Cycle
The clock input (from OSC1) is internally divided by four to generate four non-overlapping
quadrature clocks, namely Q1, Q2, Q3, and Q4. Internally, the program counter (PC) is incremented every Q1, and the instruction is fetched from the program memory and latched into the
instruction register in Q4. The instruction is decoded and executed during the following Q1
through Q4. The clocks and instruction execution flow are illustrated in Figure 4-3, and
Example 4-1.
Figure 4-3: Clock/Instruction Cycle
TCY1
Q1
Q2
Q3
TCY2
Q4
Q1
Q2
Q3
TCY3
Q4
Q1
Q2
Q3
Q4
OSC1
Q1
Q2
Internal
phase
clock
Q3
Q4
PC
PC
PC+1
PC+2
OSC2/CLKOUT
(RC mode)
Fetch INST (PC)
Execute INST (PC-1)
Fetch INST (PC+1)
Execute INST (PC)
Fetch INST (PC+2)
Execute INST (PC+1)
4
Architecture
 1997 Microchip Technology Inc.
DS31004A-page 4-5
PICmicro MID-RANGE MCU FAMILY
4.3
Instruction Flow/Pipelining
An “Instruction Cycle” consists of four Q cycles (Q1, Q2, Q3, and Q4). Fetch takes one instruction
cycle while decode and execute takes another instruction cycle. However, due to Pipelining, each
instruction effectively executes in one cycle. If an instruction causes the program counter to
change (e.g. GOTO) then an extra cycle is required to complete the instruction (Example 4-1).
The instruction fetch begins with the program counter incrementing in Q1.
In the execution cycle, the fetched instruction is latched into the “Instruction Register (IR)” in
cycle Q1. This instruction is then decoded and executed during the Q2, Q3, and Q4 cycles. Data
memory is read during Q2 (operand read) and written during Q4 (destination write).
Example 4-1 shows the operation of the two stage pipeline for the instruction sequence shown.
At time TCY0, the first instruction is fetched from program memory. During TCY1, the first instruction executes while the second instruction is fetched. During TCY2, the second instruction executes while the third instruction is fetched. During TCY3, the fourth instruction is fetched while the
third instruction (CALL SUB_1) is executed. When the third instruction completes execution, the
CPU forces the address of instruction four onto the Stack and then changes the Program Counter
(PC) to the address of SUB_1. This means that the instruction that was fetched during TCY3 needs
to be “flushed” from the pipeline. During TCY4, instruction four is flushed (executed as a NOP) and
the instruction at address SUB_1 is fetched. Finally during TCY5, instruction five is executed and
the instruction at address SUB_1 + 1 is fetched.
Example 4-1: Instruction Pipeline Flow
1. MOVLW 55h
TCY0
TCY1
Fetch 1
Execute 1
2. MOVWF PORTB
3. CALL SUB_1
4. BSF
PORTA, BIT3 (Forced NOP)
5. Instruction @ address SUB_1
Fetch 2
TCY2
TCY3
TCY4
TCY5
Execute 2
Fetch 3
Execute 3
Fetch 4
Flush
Fetch SUB_1 Execute SUB_1
Fetch SUB_1 + 1
All instructions are single cycle, except for any program branches. These take two cycles since the fetch
instruction is “flushed” from the pipeline while the new instruction is being fetched and then executed.
DS31004A-page 4-6
 1997 Microchip Technology Inc.
Section 4. Architecture
4.4
I/O Descriptions
Table 4-1 gives a brief description of the functions that may be multiplexed to a port pin. Multiple
functions may exist on one port pin. When multiplexing occurs, the peripheral module’s functional
requirements may force an override of the data direction (TRIS bit) of the port pin (such as in the
A/D and LCD modules).
Table 4-1:
Pin Name
I/O Descriptions
Pin
Type
Buffer
Type
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
P
P
I
I
I/O
I/O
O
Analog
Analog
Analog
Analog
Analog
Analog
Analog
Analog
Analog
Analog
Analog
Analog
Analog
Analog
Analog
Analog
P
P
Analog
Analog
ST
ST
Analog
Description
Analog Input Channels
AN0
AN1
AN2
AN3
AN4
AN5
AN6
AN7
AN8
AN9
AN10
AN11
AN12
AN13
AN14
AN15
AVDD
AVSS
C1
C2
CCP1
CCP2
CDAC
 1997 Microchip Technology Inc.
DS31004A-page 4-7
4
Architecture
Analog Power
Analog Ground
LCD Voltage Generation
LCD Voltage Generation
Capture1 input/Compare1 output/PWM1 output
Capture2 input/Compare2 output/PWM2 output.
A/D ramp current source output. Normally connected to external
capacitor to generate a linear voltage ramp.
CK
I/O
ST
USART Synchronous Clock, always associated with TX pin function
(See related TX, RX, DT)
CLKIN
I
ST/CMOS
External clock source input. Always associated with pin function
OSC1. (See related OSC1/CLKIN, OSC2/CLKOUT pins)
CLKOUT
O
—
Oscillator crystal output. Connects to crystal or resonator in crystal
oscillator mode. In RC mode, OSC2 pin outputs CLKOUT which has
1/4 the frequency of OSC1, and denotes the instruction cycle rate.
Always associated with OSC2 pin function. (See related OSC2,
OSC1)
CMPA
O
—
Comparator A output
CMPB
O
—
Comparator B output
Legend: TTL = TTL-compatible input
CMOS = CMOS compatible input or output
ST = Schmitt Trigger input with CMOS levels
SM = SMBus compatible input. An external resistor is required if this pin is used as an output
NPU = N-channel pull-up
PU = Weak internal pull-up
No-P diode = No P-diode to VDD
AN = Analog input or output
I = input
O = output
P = Power
L = LCD Driver
PICmicro MID-RANGE MCU FAMILY
Table 4-1:
I/O Descriptions (Cont.’d)
Pin
Type
Buffer
Type
L
L
L
L
—
—
—
—
CS
DT
I
I/O
TTL
ST
GP0
I/O
TTL/ST
GP1
I/O
TTL/ST
GP2
GP3
GP4
GP5
INT
MCLR/VPP
I/O
I
I/O
I/O
I
I/P
ST
TTL
TTL
TTL
ST
ST
NC
OSC1
—
I
—
ST/CMOS
OSC2
O
—
PBTN
PSP0
PSP1
PSP2
PSP3
PSP4
PSP5
PSP6
PSP7
I
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
ST
TTL
TTL
TTL
TTL
TTL
TTL
TTL
TTL
Pin Name
COM0
COM1
COM2
COM3
Description
LCD Common Driver0
LCD Common Driver1
LCD Common Driver2
LCD Common Driver3
chip select control for parallel slave port (See related RD and WR)
USART Synchronous Data. Always associated RX pin function. (See
related RX, TX, CK)
GP is a bi-directional I/O port. Some pins of port GP can be software
programmed for internal weak pull-ups on the inputs.
TTL input buffer as general purpose I/O, Schmitt Trigger input buffer
when used as the serial programming mode.
TTL input buffer as general purpose I/O, Schmitt Trigger input buffer
when used as the serial programming mode.
External Interrupt
Master clear (reset) input or programming voltage input. This pin is
an active low reset to the device.
These pins should be left unconnected.
Oscillator crystal input or external clock source input. ST buffer when
configured in RC mode. CMOS otherwise.
Oscillator crystal output. Connects to crystal or resonator in crystal
oscillator mode. In RC mode, OSC2 pin outputs CLKOUT which has
1/4 the frequency of OSC1, and denotes the instruction cycle rate.
Input with weak pull-up resistor, can be used to generate an interrupt.
Parallel Slave Port for interfacing to a microprocessor port. These
pins have TTL input buffers when PSP module is enabled.
PORTA is a bi-directional I/O port.
RA0
I/O
TTL
RA1
I/O
TTL
RA2
I/O
TTL
RA3
I/O
TTL
RA4
I/O
ST
RA4 is an open drain when configured as output.
RA5
I/O
TTL
Legend: TTL = TTL-compatible input
CMOS = CMOS compatible input or output
ST = Schmitt Trigger input with CMOS levels
SM = SMBus compatible input. An external resistor is required if this pin is used as an output
NPU = N-channel pull-up
PU = Weak internal pull-up
No-P diode = No P-diode to VDD
AN = Analog input or output
I = input
O = output
P = Power
L = LCD Driver
DS31004A-page 4-8
 1997 Microchip Technology Inc.
Section 4. Architecture
Table 4-1:
Pin Name
I/O Descriptions (Cont.’d)
Pin
Type
Buffer
Type
Description
PORTB is a bi-directional I/O port. PORTB can be software programmed for internal weak pull-ups on all inputs.
I/O
I/O
I/O
I/O
I/O
I/O
I/O
TTL
TTL
TTL
TTL
TTL
TTL
TTL/ST
RB7
I/O
TTL/ST
RC0
RC1
RC2
RC3
RC4
RC5
RC6
RC7
RD
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I
ST
ST
ST
ST
ST
ST
ST
ST
TTL
RD0
RD1
RD2
RD3
RD4
RD5
RD6
RD7
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
ST
ST
ST
ST
ST
ST
ST
ST
Interrupt on change pin.
Interrupt on change pin.
Interrupt on change pin. Serial programming clock. TTL input
buffer as general purpose I/O, Schmitt Trigger input buffer when
used as the serial programming clock.
Interrupt on change pin. Serial programming data. TTL input
buffer as general purpose I/O, Schmitt Trigger input buffer when
used as the serial programming data.
PORTC is a bi-directional I/O port.
Read control for parallel slave port (See also WR and CS pins)
PORTD is a bi-directional I/O port.
4
PORTE is a bi-directional I/O port.
RE0
I/O
ST
RE1
I/O
ST
RE2
I/O
ST
RE3
I/O
ST
RE4
I/O
ST
RE5
I/O
ST
RE6
I/O
ST
RE7
I/O
ST
Legend: TTL = TTL-compatible input
CMOS = CMOS compatible input or output
ST = Schmitt Trigger input with CMOS levels
SM = SMBus compatible input. An external resistor is required if this pin is used as an output
NPU = N-channel pull-up
PU = Weak internal pull-up
No-P diode = No P-diode to VDD
AN = Analog input or output
I = input
O = output
P = Power
L = LCD Driver
 1997 Microchip Technology Inc.
DS31004A-page 4-9
Architecture
RB0
RB1
RB2
RB3
RB4
RB5
RB6
PICmicro MID-RANGE MCU FAMILY
Table 4-1:
I/O Descriptions (Cont.’d)
Pin
Type
Buffer
Type
REFA
REFB
O
O
CMOS
CMOS
RF0
RF1
RF2
RF3
RF4
RF5
RF6
RF7
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
ST
ST
ST
ST
ST
ST
ST
ST
RG0
RG1
RG2
RG3
RG4
RG5
RG6
RG7
RX
SCL
SCLA
SCLB
SDA
SDAA
SDAB
SCK
SDI
SDO
SS
SEG00 to
SEG31
SUM
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I
O
I
I/L
ST
ST
ST
ST
ST
ST
ST
ST
ST
ST
ST
ST
ST
ST
ST
ST
ST
—
ST
ST
O
AN
Pin Name
Description
Programmable reference A output.
Programmable reference B output.
PORTF is a digital input or LCD Segment Driver Port
PORTG is a digital input or LCD Segment Driver Port
USART Asynchronous Receive
Synchronous serial clock input/output for I2C mode.
Synchronous serial clock for I2C interface.
Synchronous serial clock for I2C interface.
I2C™ Data I/O
Synchronous serial data I/O for I2C interface
Synchronous serial data I/O for I2C interface
Synchronous serial clock input/output for SPI mode.
SPI Data In
SPI Data Out (SPI mode)
SPI Slave Select input
LCD Segment Driver00 through Driver31.
AN1 summing junction output. This pin can be connected to an external capacitor for averaging small duration pulses.
T0CKI
I
ST
Timer0 external clock input
T1CKI
I
ST
Timer1 external clock input
T1OSO
O
CMOS
Timer1 oscillator output
T1OSI
I
CMOS
Timer1 oscillator input
TX
O
—
USART Asynchronous Transmit (See related RX)
Legend: TTL = TTL-compatible input
CMOS = CMOS compatible input or output
ST = Schmitt Trigger input with CMOS levels
SM = SMBus compatible input. An external resistor is required if this pin is used as an output
NPU = N-channel pull-up
PU = Weak internal pull-up
No-P diode = No P-diode to VDD
AN = Analog input or output
I = input
O = output
P = Power
L = LCD Driver
I2C is a trademark of Philips Corporation.
DS31004A-page 4-10
 1997 Microchip Technology Inc.
Section 4. Architecture
Table 4-1:
Pin Name
VLCD1
VLCD2
VLCD3
VLCDADJ
VREF
I/O Descriptions (Cont.’d)
Pin
Type
Buffer
Type
P
P
P
I
I
—
—
—
Analog
Analog
Description
LCD Voltage
LCD Voltage
LCD Voltage
LCD Voltage Generation
Analog High Voltage Reference input.
DR reference voltage output on devices with comparators.
I
Analog
Analog High Voltage Reference input.
VREF+
Usually multiplexed onto an analog pin.
VREFI
Analog
Analog Low Voltage Reference input.
Usually multiplexed onto an analog pin.
VREG
O
—
This pin is an output to control the gate of an external N-FET
for voltage regulation.
VSS
P
—
Ground reference for logic and I/O pins.
VDD
P
—
Positive supply for logic and I/O pins.
WR
I
TTL
Write control for parallel slave port (See CS and RD pins also).
Legend: TTL = TTL-compatible input
CMOS = CMOS compatible input or output
ST = Schmitt Trigger input with CMOS levels
SM = SMBus compatible input. An external resistor is required if this pin is used as an output
NPU = N-channel pull-up
PU = Weak internal pull-up
No-P diode = No P-diode to VDD
AN = Analog input or output
I = input
O = output
P = Power
L = LCD Driver
4
Architecture
 1997 Microchip Technology Inc.
DS31004A-page 4-11
PICmicro MID-RANGE MCU FAMILY
4.5
Design Tips
No related design tips at this time.
DS31004A-page 4-12
 1997 Microchip Technology Inc.
Section 4. Architecture
4.6
Related Application Notes
This section lists application notes that are related to this section of the manual. These application notes may not be written specifically for the Mid-Range MCU family (that is they may be written for the Base-Line, or High-End families), but the concepts are pertinent, and could be used
(with modification and possible limitations). The current application notes related to Architecture
are:
Title
Application Note #
No related application notes at this time.
4
Architecture
 1997 Microchip Technology Inc.
DS31004A-page 4-13
PICmicro MID-RANGE MCU FAMILY
4.7
Revision History
Revision A
This is the initial released revision of the PICmicro’s Architecture description.
DS31004A-page 4-14
 1997 Microchip Technology Inc.