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

Tutorial3

Architecture
PIC16F877A

1
SESSION'S AGENDA

 Basic architectures ???


What is Pipe lining ???
 What is an Instruction ???
 CISC Vs RISC ???
 Prerequisites to understand MCUs ???
 Basic terms used in MCUs ???
 Block diagram of PIC16F877A ???
 Some basic registers ???

2
TYPES OF ARCHITECTURES

Von Neumann Architecture


Harvard Architecture

3
VON NEUMANN

 The design has a single memory bank for storing both the
program and data.

 It has single bus which is multiplexed to be used as both


address bus and data bus

 The content of RAM can be used for both variable storage as


well as program storage.

4
VON NEUMANN ARCHITECTURE

Single bus

Princeton architecture

5
HARVARD ARCHITECTURE
 Separate memory banks for program and data storage.

 It has a RAM for data storage and separate ROM


for storing the program.

 It has two separate address buses for ;


Program memory
Data memory
….. Simultaneously access to these two buses.

6
HARVARD ARCHITECTURE
Program address bus

Data address bus

7
VON NEUMANN Vs HARVARD

Von Neumann Harvard


 Single memory for both  Separate memory for program
program and data. and data.
 Single bus used to  Separate buses available to
access both data and access program and data.
program.  Instruction parallelism can be
done.
 Instruction parallelism is
 It takes only one machine
not possible. cycle; Fetching and execution
 It takes more than one are done simultaneously.
machine cycle; Fetching
and execution are done
serially.
8
Advantages of Von Neumann architecture's
Biggest advantage is that it simplifies the microcontroller chip
design because only one memory is accessed.

For microcontrollers, its biggest asset is that the contents of


RAM can be used for both variable (data) storage, as well as
program instruction storage.

9
Advantages of Harvard architecture

The Harvard architecture tends to execute instructions in fewer

instruction cycles than the Von Neumann architecture.

This is because a much greater amount of parallelism is possible

This method of execution (parallelism) helps in easier timing of

loops and crucial code.

Best suited for processors that do not process large amount of

memory from different sources and applications have to access

this small amount of memory very quickly.

This feature is , what is used in the PIC MCUs makes it well suited

for microcontroller applications.


Instruction to be carried out is --- move Acc,Reg
Which means Transfer data from Reg to Acc
Von Neumann
Cycle 1 :
Read instruction Instruction is read in from the memory space.

Cycle 2:
- Read Data out of RAM and put into Acc..

Harvard
Cycle -1 :
- Complete Previous instruction
- Read the next instruction "move Acc,Reg" instruction
Cycle 1 :
- Execute "move Acc, Reg" instruction
- Read next instruction

11
Instruction Pipe lining
Pre-Fetched Instruction Executing Instruction

movlw 0x05 -
Instruction Cycles

Example Program T0

1 MAIN movlw 0x05 Fetch

2 movwf REG1
3 call SUB1
4 addwf REG2

51 SUB1 movf PORTB,w


52 return
53 SUB2 movf PORTC,w
54 return
Instruction Pipe lining
Pre-Fetched Instruction Executing Instruction

movwf REG1 movlw 0x05


Instruction Cycles

Example Program T0 T1

1 MAIN movlw 0x05 Fetch Execute

2 movwf REG1 Fetch

3 call SUB1
4 addwf REG2

51 SUB1 movf PORTB,w


52 return
53 SUB2 movf PORTC,w
54 return
Instruction Pipelining
Pre-Fetched Instruction Executing Instruction

call SUB1 movwf REG1


Instruction Cycles

Example Program T0 T1 T2

1 MAIN movlw 0x05 Fetch Execute Time to execute normal instruction

2 movwf REG1 Fetch Execute

3 call SUB1 Fetch

4 addwf REG2
In the third instruction cycle, the instruction fetched in
the second cycle is executed and the next instruction is
fetched.
51 SUB1 movf PORTB,w At this point, it becomes clear that because of the pipe
52 return lining, each instruction (except the first) effectively takes
only one cycle to execute because each instruction has
53 SUB2 movf PORTC,w already been fetched and is ready to execute by the time
54 return the previous instruction has finished executing.
Instruction Pipe lining
Pre-Fetched Instruction Executing Instruction

addwf REG2 call SUB1


Instruction Cycles

Example Program T0 T1 T2 T3

1 MAIN movlw 0x05 Fetch Execute

2 movwf REG1 Fetch Execute

3 call SUB1 Fetch Execute

4 addwf REG2 Fetch

Exception to the rule of single cycle execution,


That occurs whenever the program counter is modified
51 SUB1 movf PORTB,w When a call or goto instruction is executed.
52 return In this case, a call instruction is executing
53 SUB2 movf PORTC,w which will cause the program to jump to a location
elsewhere in memory.
54 return
However, while the call instruction is executing,
the next sequential instruction is being fetched even
though this is not the instruction we want to execute nex
SOME BASIC TERMS USED
Arithmetic Logic Unit (ALU):
In-charge of all mathematical and logical operations
over data.
Accumulator:
A special register interconnected with ALU. It can
be described as a working desk for any operation
performed on data (adding, shifting, etc).

Instruction Decoder:
Part of the electronics which "recognizes" different
program instructions and directs the other circuits
accordingly.
16
SOME BASIC TERMS USED!!!
Read Only Memory (ROM):
ROM is the memory which stores the program to be
executed. It can be either internal (on-chip) or external
(interfaced) with respect to the Micro controller and the
data stored cannot be changed during runtime.

Random Access Memory:


RAM is used for temporary storage of data during runtime
and hence it does not retain the stored information when
the power is interrupted.

EEPROM Memory:
EEPROM is a special kind of memory that can be changed
during runtime and also the data is retained after power is
17
off and it is not available with all MCUs.
SOME BASIC TERMS USED!!!

SFR Registers:
 Special Function Registers are special elements of RAM with
their purpose predefined and also named by the
manufacturer. Each and every SFR controls a certain
subsystem of MCU.

Program Counter:
 This is the "engine" which starts the program and points to the
memory address of the instruction to be executed.
Immediately upon execution, value of PC increments by 1.

I/O Ports:

To be of any practical use, Micro Controller needs to be
connected to other electronics and to the environment. For
this purpose, pins are provided on input/output -- I/O ports 18
SOME BASIC TERMS USED!!!
Oscillator:
Stable waveform provided by oscillator allows
synchronous functioning of all parts of MCU. The
oscillator frequency is mostly stabilized using a quartz-
crystal or a ceramic resonator though it can also work
without an element for stabilizing frequency (as RC
oscillator).
Bit:
A data which can be of either zero or one (binary digit).
Byte:
Collection of 8 bits add-up to form a byte of data.
Word in our case is 14bit wide 19
SOME BASIC TERMS USED!!!
Set To force a bit/register to a value of logic ‘1’.
Clear To force a bit/register to a value of logic ‘0’
Reset 1) To force a register/bit to its default state.
2) A condition in which the device places itself
after a device reset occurs.
Instruction cycle
The events for an instruction to execute. There are
four events which can generally be described as:
Decode, Read, Execute, and Write.
Four external clocks (Tosc) make one instruction
cycle (TCY).

20
BLOCK DIAGRAM
OF
PIC16F877A

21
22
PORTS A…E

SUPPORTING
FUNCTIONS CPU
BASIC FUNCTIONAL BLOCK

24
About the Architecture

The Modules Present in the CPU are:-


ALU
Memory
Ports
Program Counter
Stack Pointer
Instruction register
Instruction decoder
W REGISTER
25
PIC16F877A
Peripheral Modules:
The modules present in PIC16F877A are:
Timers, MSSP, USART, A to D converter, Comparator,
PSP, EEPROM, CCP. SSP

Each module will be discussed in their tutorials.

Stack Pointer
The stack pointer is present in memory organization, it is used to store
the address of the program in LIFO method, the detail description
about the SP(Stack Pointer) will come in memory Organization.

26
TIMER 0
The Timer0 module has the following features:
• 8-bit timer/counter
• Readable and writeable
TIMER 1
The Timer1 module is a 16-bit timer/counter .
The TMR1 Register pair (TMR1H:TMR1L) increments from
0000h to FFFFh and rolls over to 0000h.
Timer1 can operate in one of three modes:
• As a synchronous timer
• As a synchronous counter
• As an asynchronous counter
Timer2
Timer 2 is an 8-bit timer for pulse width modulation mode of
operation
Synchronous Serial Port (SSP) module

It is a serial interface useful for communicating with other


peripherals devices.
These peripheral devices may be serial EEPROMs shift
registers, display drivers, A/D converters, etc.

The SSP module can operate in one of two modes:


• Serial Peripheral Interface SPI
• Inter-Integrated Circuit I2C
I2C bus - Inter-Integrated Circuit bus (Philips)

The I2C bus is a simple 2 wire serial interface developed by Philips.

It was developed for 8 bit applications and is widely used in consumer


electronics, automotive and industrial applications.

The I2C bus is a two line, multi-master, multi-slave network interface with
collision detection. Up to 128 devices can exist on the network and they
can be spread out over 10 meters.

Each node (microcontroller or peripheral) may initiate a message, and


then transmit or receive data. The two lines of the network consist of the
serial data line and the serial clock line.

Each node has a unique address which accompanies any message


passed between nodes. Since only 2 wires are needed, it is easy to
interconnect a number of devices.
SPI
SPI (3+n)-wire serial busses. (n= # of slaves). In single master, multiple
slave configurations, as shown each slave device requires a dedicated
Slave Select (SS) signal,which is created by the master using standard I/O pins.
USART
Universal Synchronous Asynchronous Receiver Transmitter (USART)
It is one of the two serial I/O modules (other is the SSP module)
The USART is also known as a Serial Communications Interface
or SCI.

The USART can be configured in the following modes:


• Asynchronous (full duplex)
• Synchronous - Master (half duplex)
• Synchronous - Slave (half duplex)
The USART can communicate with peripheral devices such as
personal computers Asynchronous (full duplex)
The Analog-to-Digital (A/D) Converter module
It has eight inputs 5 on Port A and 3 on Port E
.
The conversion of an analog input signal results in a corresponding
10-bit digital number.

The A/D converter has a unique feature of being able to operate while
the device is in Sleep mode.
COMPARATOR MODULE
The comparator module contains two analog comparators.

When the analog input at VIN+ is less than the analog input

VIN-, the output of the comparator is a digital low level.


When the analog input at VIN+ is greater than the analog input VIN-, the
output of the comparator is a digital high level.
Parallel Slave Port (PSP)
It is a 8-bit wide Parallel Slave Port (PSP)
The PORT operates as an 8-bit wide Parallel Slave
Port, or a microprocessor port
In slave mode the module is asynchronously readable
and writeable by the external world control input pin.
It can directly interface to an 8-bit microprocessor
data bus.
The external microprocessor can read or write the PORT.
EEPROM
The EEPROM data memory is readable and writeable
This memory is not directly mapped in the register file space.
Instead it is indirectly addressed through the Special Function
Registers.
256 Bytes are available to us for storing of data
CAPTURE/COMPARE/PWM MODULES
Each Capture/Compare/PWM (CCP) module contains
a 16-bit register which can operate as a:
• 16-bit Capture register
• 16-bit Compare register
• PWM Master/Slave Duty Cycle register
Capture

Captures the time when an event occurs.

When an external event occurs e.g. a signal transition from low to high ,the value
of both Timer1 registers is stored in the CCP registers.

Stored values determine the time t when the event has occurred

Compare

Compares the Timer1 value to the CCP value and generates an output signal when
a match occurs which helps in generating an output at a specific time.

One internal use of this mode is to send a 'special event trigger signal' to start an
ADC conversion - this would be useful in a data logger.

PWM (The most useful out of the three ) .

PWM has many uses from controlling the speed of a DC motor , generating an
analogue signal or controlling the brightness of a bulb.

The basic principle is that the output is fully on or off but by varying the
percentage of time that the output is on then the average current delivered to the
load can be controlled.
.
SUPPORING FUNCTIONAL BLOCKS
WATCH DOG TIMER (WDT)

It is an internal and independent Timer for providing Reset function for


the following contingencies of HANG state

The program gets stuck


The PIC gets caught in an endless loop

The WDT is running independently , it is being incremented by 1 and will


complete its count irrespective of the fact that the program is not
advancing On completion of its count it will generate the Reset pulse .

To avoid unwanted Resetting under normal condition, the CLRWDT


command is written the code which clear the WDT before it resets the
MCU
39
Reset Functions
.
Power On Reset:-

A Power-on Reset pulse is generated on-chip when


VDD rise is detected (in the range of 1.2V - 1.7V).

A maximum rise time for VDD is specified. When the


device starts normal operation
(exits the RESET condition),

Device operating parameters (voltage, frequency,


temperature, etc.) must be met to ensure operation.

If these conditions are not met, the device must be held


in RESET until the operating conditions are met.

40
Power-up Timer (PWRT)

The Power-up Timer provides a fixed 72 ms nominal


time-out on power-up only from the POR.

The Powerup Timer operates on an internal RC oscillator.

The chip is kept in RESET as long as the PWRT is active.

The PWRT’s time delay allows VDD to rise to an acceptable


level.

A configuration bit is provided to enable or disable the PWRT.

Recommended the power-up timer be enabled as a


matter of routine.
Oscillator Start up Timer

When the supply power is applied to the programmed MCU,


the start of program execution is delayed until the power
supply and clock are stable, otherwise the program may not
run correctly.

Power- up Timer provides a delay between the power


coming on and an internal MCU reset of about 72 ms.

This is followed by an oscillator start up delay of 1024 cycles


of the clock before program execution starts.

At a clock frequency of 4 MHz, this works out to 256 μs.


Reset Functions

Brown Out Reset:-


Brown out refers to a short dip in the power- supply voltage, caused by
mains supply fluctuation, or some other supply fault, which might disrupt the
program execution.
When voltage drops below a particular threshold, the device is held in reset
Reset generated by BOR protects a microcontroller against undetermined
erratic behaviour

If the Brown-Out Detect Enable bit (BODEN) is set, a PSU glitch of longer than
about 100 μs will cause the device to be held in reset until the supply recovers,
and then wait for the power-up timer to time out, before restarting.

43
(P)BOR – Brown Out Reset
 Holds PIC® MCU in reset until ~72ms after VDD rises back above threshold

VDD
BVDD

72ms
Internal
Reset

VDD
BVDD

72ms
Internal
Reset <72ms

VDD
BVDD

72ms
Internal
Reset
WDT
WORKING OF A MICROCONTROLLER
OSC
ROM PC
TIMERS Inst decoder
RAM CPU
R
SF CONTROL

R Op code Op code Address


GP

Data
W REG

A/D

I/O PORT
1 0 EEPROM
EEPROM
PIN 7 PIN 3
TYPICAL INTERFACING OF PERIPHIRALS
LOW VOLTAGE PROGRAMMING

Under normal conditions a high voltage (12–14 V) is


applied to the PGM pin (RB3) for programming the chip.

To avoid the need to supply this voltage during in-circuit programming


, a low-voltage programming mode is available

Use of this mode has the disadvantage that RB3 is not then available
for general I/O functions during normal operation.
IN-CIRCUIT DEBUGGING

In-circuit debugging (ICD) allows the program to be


downloaded after the chip has been fitted in the application circuit,
and allows it to be tested with the real hardware.

This is more useful than the previous method, which requires


the chip to be programmed in a separate programmer unit
before insertion in its socket on the board.

With ICD, the chip can be programmed, and reprogrammed


during debugging, while avoiding possible electrical and
mechanical damage caused by removal from the circuit.

The normal debugging techniques of single stepping,


breakpoints and tracing can be applied in ICD mode. This allows a
final stage of debugging in the prototype hardware, where
problems with the interaction of the MCU with the real hardware
can be resolved.
SOME BASIC REGISTERS
W Register (WREG):
Accumulator is termed as WREG.
File Register (f):
Registers that are declared in the runtime that acts as variables.
Status Register:
Gives the changes effected by previous instruction (carry, zero, etc)
Port Registers:
Certain pins of micro controllers are termed as port(I/O) pins that are
directly associated with 8 bits of port registers. Eg. PortA register
controls the status of PortA. In our case 33 pins are there in 5 ports
49
Integrated Development Environments (IDEs)

They are powerful PC-based programs which include:

Edit - Assemble, Compile, Link, Simulate,


Debugging of the program

Downloading of the generated executable code to the


physical microcontroller chip using a programmer
device.

These programs are in graphical user interface (GUI), where the


user can select various options from the program without having to exit
it.

IDEs are extremely useful when developing microcontroller- based


systems.
NOW WE KNOW !!!

 Basic architectures ???


 What is Pipe lining ???
 What is an Instruction ???
 CISC Vs RISC ???
 Prerequisites to understand MCUs ???
 Basic terms used in MCUs ???
 Block diagram of PIC16F877A ???
 Some basic registers ???

51
END OF TUTORIAL 3

52
CISC
 CISC stands for "Complex Instruction Set Computer"

A microprocessor that understands a large number of


(complex) instructions, but it processes them relatively
slowly.

Internal(micro) instructions involve many individual


execution steps and thus many clock cycles.

The designing is complex, costly and also the instruction


set consists of more than 100 instructions. G. 8051 family
53
RISC

 RISC stands for "Reduced Instruction Set Computer"

 Micro controller design that uses a relatively simple


architecture, with fewer built-in commands.

 The benefit is a significant increase in speed, enough to


make up for not having as many instructions.

 Designing is relatively simpler, economical and usually has


less than 100 instructions. Eg. PIC family

54
RISC Vs CISC

RISC CISC

 Less number of instructions,  More number of instructions,


usually less than 100. usually more than 100.
 All are single cycle instructions  Each instructions take at least 2 or 3
machine cycles.
other than some exceptional.
 Designing the architecture is
 Designing the architecture is
complex and costly.
easier and cheap.
 Program length is less; variety of
 Program length get increased instructions available.
due to shortage of instructions  Execution speed is low since the
 Execution speed is faster since instructions takes many machine
most instructions are single- cycles.
cycled.  Eg. 8051 family, Pentium

 Eg. PIC series, ARM processor


55
EPROM
EPROM, erasable programmable read only memory, is similar to ROM,
but EPROM can be programmed using a suitable programming device.
An EPROM memory has a small clear-glass window on top of the chip
where the data can be erased under strong ultraviolet light.
Once the memory is programmed, the window can be covered with
dark tape to prevent accidental erasure of the data.
An EPROM memory must be erased before it can be reprogrammed.
Many developmental versions of microcontrollers are manufactured with
EPROM memories where the user program can be stored.
These memories are erased and reprogrammed until the user is
satisfied with the program.

Some versions of EPROMs, known as OTP (one time programmable),


can be programmed using a suitable programmer device but cannot be
erased. OTP memories cost much less than EPROMs. OTP is useful
after a project has been developed completely and many copies of the
program memory must be made.
EEPROM
EEPROM, electrically erasable programmable read only memory, is a nonvolatile
memory that can be erased and reprogrammed using a suitable programming
device.
EEPROMs are used to save configuration information, maximum and minimum
values, identification data, etc. Some microcontrollers have built-in EEPROM
memories. For instance, the PIC16F877 A contains a 256-byte EEPROM memory
where each byte can be programmed and erased directly by applications
software.

EEPROM memories are usually very slow. An EEPROM chip is much costlier than
an EPROM chip.

Flash EEPROM
Flash EEPROM, a version of EEPROM memory, has become popular in
microcontroller applications and is used to store the user program. Flash
EEPROM is nonvolatile and usually very fast. The data can be erased and then
reprogrammed using a suitable programming device. Some microcontrollers have
only 1K flash EEPROM while others
have 32K or more.
MCU normally operate at 0 to 5V voltage levels, the RS232 signals must be
converted to 0 to 5V when input to a microcontroller. Similarly, the output of
the microcontroller must be converted to 12V before sending to the receiving
RS232 device. The voltage conversion is usually carried out with RS232
converter chips, such as the MAX232, manufactured by Maxim Inc.

Serial communication may be implemented in hardware using a specific pin


of a microcontroller, or the required signals can be generated in software
from any required pin of a microcontroller.

Hardware implementation requires either an on-chip UART (or USART)


circuit or an external UART chip that is connected to the microcontroller.
Software-based UART is more commonly used and does not require any
special circuits.

Serial data is generated by delay loops in software based UART


applications.
Linker
 The linker performs the following
o It combines object files by merging object file sections.
 .text section for code
 .data section for initialized global variables
 .bss section for uninitialized global variables
o It resolves all unresolved symbols.
 External variables
 Function calls
o Reports errors about unresolved symbols.
o Appends the start-up code (see next slide)
o Provide symbolic debug information
 The linker produces a relocatable file. For standard
operating systems with a dynamic loader, the processes
is now finished – not so for embedded systems which
need absolutely located binaries.
Data Bus
• The Data Bus carries the data which is transferred
throughout the system. ( bi-directional)

• Examples of data transfers


– Program instructions being read from memory into MPU.
– Data being sent from MPU to I/O port
– Data being read from I/O port going to MPU
– Results from MPU sent to Memory

• These are called read and write operations


Control Bus
• The Control Bus: is another group of signals whose
functions are to provide synchronization ( timing
control ) between the MPU and the other system
components.

• Control signals are unidirectional, and are mainly


outputs from the MPU.

• Example Control signals


– RD: read signal asserted to read data into MPU
– WR: write signal asserted to write data from MPU
Address Bus
• An address is a binary number that identifies a
specific memory storage location or I/O port
involved in a data transfer

• The Address Bus is used to transmit the address


of the location to the memory or the I/O port.

• The Address Bus is unidirectional ( one way ):


addresses are always issued by the MPU.

You might also like