Microcontroller[1]
Microcontroller[1]
GENERAL PURPOSE
CRITERIA EMBEDDED SYSTEMS
COMPUTERS/PROCESSORS
What is microcontroller?
MICROCONTROLLER
MICROCONTROLLER Schematic Representation
▪ A microcontroller is a device which integrates a number of
components of a microprocessor onto a single chip.
▪ A micro-controller combines onto a same microchip:
▪ The CPU core
▪ Memory (both RAM and ROM)
▪ Some parallel digital I/O and many other peripherals
BLOCK DIAGRAM:
▪ CPU
▪ I/O ports
▪ Memory
▪ All connected via bus.
▪ All these things are integrated on the same silicon chip.
▪ There are other component of microprocessor as well.
COMPONENTS OF MICROCONTROLLER
MICROCONTROLLER COMPONENTS Schematic Representation
▪ A timer module to allow microcontroller to perform task for
certain time periods.
▪ A serial I/O port to allow data to flow between the
microcontroller and other devices such as PC or another
microcontroller.
▪ An ADC to allow the microcontroller to accept analog input
data for processing.
WHY MICROCONTROLLER?
WHY MICROCONTROLLER?
▪ Low cost and small packaging
▪ Low power consumption
▪ Programmable, reprogrammable
▪ Lots of I/O capabilities
▪ Easy integration with circuits
▪ For application in which cost, power and space are
critical
▪ Single-purpose
COMPUTER ARCHITECTURE
1. VONNEUMAN ARCHITECTURE Schematic Representation
▪ Only one bus between CPU and memory
▪ RAM and program memory share the same bus and the same
Memory, and so must have the same bit width
▪ Bottleneck, Getting instructions interfaces with accessing RAM
Program
and
▪ Address is provided from the CPU to the memory to fetch instruction Data
as well as to fetch data and we use the bus to read the data as well BUS
Memory
as write the data on to that memory.
▪ There is no difference between the data and instruction in VonNeuman
architecture.
▪ Both program and data memory is connected to the CPU by the same
address and data bus.
▪ we can get a bottleneck because getting instructions may interfere
accessing RAM for data.
▪ we have the same bus and hence the instruction and the data word is
typically of the same bit width.
COMPUTER ARCHITECTURE
2. HARVARD ARCHITECTURE Schematic Representation
▪ Uses two separate memory spaces for program
instruction and data
▪ Improved operation bandwidth
▪ Allows for different bus widths
▪ Instruction pipelining easy
Data
▪ Program memory different from that of the data Memory
memory. Program 8-Bits
▪ Two distinct buses connecting CPU to the program Memory
12/14/16-Bits
memory and data memory.
▪ Two distinct buses their bit widths can be different.
▪ Status Registers
▪ Processor Modes
History
• ARM7
• 3 pipeline stages (fetch/decode/execute)
• High code density / low power consumption
• Most widely used for low-end systems
• ARM9
• Compatible with ARM7
• 5 stages (fetch/decode/execute/memory/write)
• Separate instruction and data cache
• ARM10
• 6-stages (fetch/issue/decode/execute/memory/write)
ARM Family Comparison
Barrel shifter can shift to the right/left or rotate the date before
P
it fed to the ALU. C incr ementer
decode
A
Incremental block: Enables the decrement or increment in register L
multiply
r egister
&
U
Values independent of the ALU. A B
control
b
u b b
s u u
Instruction decode & Control: Provides the control signals. s bar rel s
shifter
operation for manipulating data and addresses and data in the D[31:0]
registers.
Basic ARM Architecture/ Data Flow Model
❖ Address Register
❑ It is used to hold the operand address for load and store
instruction
❑ It has dedicated Incrementer for accessing the data from
subsequent location
❑ Incrementer plays a very important role in Base Index
Addressing Mode {Indirect Addressing Mode}.
Registers
▪ ARM7 has total 37 registers of size 32 bits.
▪ General Purpose registers (GPR) hold either data or address
▪ In user mode (common operating mode) 16 data registers and 2 status registers are visible
▪ Data registers: r0 to r15
▪ Three registers r13, r14, r15 perform special functions
▪ r13: stack pointer (There is no stack in ARM architecture. It is used as a pointer for software
managed stack)
▪ r14: link register ( Saves a copy of PC when executing the BL instruction/(subroutine call) or
when jumping to an exception or an interrupt handler)
▪ where return address is put whenever a subroutine is called)
▪ r15: program counter (pointed to the current instruction what is being executed )
• Depending upon context, registers r13 and r14 can also be used as GPR
• Any instruction which use r0 can as well be used with any other GPR (r1-r13)
• In addition, there are two status registers: set the processor operating mode, control of
enable/disable interrupts
• CPSR: current program status register
• SPSR: saved program status register
Program Counter (Register: r15)
▪ When the processor is executing in ARM state/mode
▪ All instructions are 32 bit wide
▪ All instructions are word aligned ( that mean all instructions must start from
an address that is multiple of 4)
▪ 32 bit address in ARM refers to Byte location
▪ Each Byte is associated with a unique address
▪ Total blocks of 4 Bytes
▪ PC value is stored in bits [31:2] with bits [1:0] undefined or 00 (as multiple of
4 byte )
▪ Due to pipelining, PC points 8 bytes ahead of the current instruction or 12
byte ahead if the current instruction includes a register specific shift
▪ When the processor is executing in Thumb Mode
▪ All instructions are 16 bit wide and are half word aligned (multiple of 2)
▪ The last bit of PC is 0 (i.e. not used)
Status Registers: CPSR
CPSR:
▪ Current program status register
▪ monitors and control internal operations
N: Negative Flag
1 = result negative or less than in last Condition code flags Interrupt Disable bits.
operation N = Negative result from ALU I = 1: Disables the IRQ.
0 = result positive or greater than. Z = Zero result from ALU F = 1: Disables the FIQ.
Z: Zero flag C = ALU operation Carried out
1 = result of 0 in last operation V = ALU operation oVerflowed T Bit
0 = nonzero result. Architecture xT only
C: Carry/Borrow flag T = 0: Processor in ARM state
1 = carry or borrow in last operation T = 1: Processor in Thumb state
0 = no carry or borrow.
Sticky Overflow flag - Q flag
V: ALU operation overflowed Architecture 5TE/J only
1 = overflow in last operation Indicates if saturation has occurred M: Mode field
0 = no overflow. b10000 = User mode
b10001 = FIQ mode
b10010 = IRQ mode
Q flag: Saturation Arithmetic Flag b10011 = Supervisor mode
b10111 = Abort mode
Note: In ARM like having Architecture 5TEJ, J bit is also there b11011 = Undefined mode
J = 1: Processor in Jazelle state b11111 = System mode.
Processor Modes
▪ Processor modes determine
▪ which registers are active, and
▪ access rights to CPSR register itself
▪ Each processor mode is either
▪ Privileged:
▪ full read-write access to the CPSR
▪ Change the control bits
▪ Change the processor mode
▪ Enable disable interrupts
▪ Non-privileged:
▪ only read access to the control field of CPSR but can not be changed
▪ read-write access to the condition flags
▪ ARM has seven modes
▪ Privileged: abort, fast interrupt request, interrupt request, supervisor, system and undefined
▪ Non-privileged: user
▪ User mode is used for programs and applications
Non - Privileged Mode
User Mode :
• only non-unprivileged mode
• This is normal mode in which user programs are executed.
• It has limited access to the memory, I/O and flags
• All other modes are entered through interrupts.
Privileged Mode
• Every processor mode except user mode can change mode by writing directly to the
mode bits of the cpsr. (the processor core has to be in privileged mode) or by
hardware when the core responds to an exception or interrupt.
• A banked register maps one-to one onto a user mode register.
• If you change processor mode, a banked register from the new mode will replace an
existing register.
• For example, when the processor is in the interrupt request mode, the instructions
you execute still access registers named r13 and r14. However, these registers are
the banked registers r13_irq and r14_irq. The user mode registers r13_usr and
r14_usr are not affected by the instruction referencing these registers.
▪ To return to user mode a special return instruction is used that instructs the core to
restore the original CPSR and banked registers
Register Organization
▪ In privileged mode
processors write the
original data in the
register bank of which
the fresh copy is not
available.
▪ These register data
should be saved in
stack in order to get it
back when user process
is resumed.
▪ Software latency is
reduced for FIQ mode
because It has large
number of register
available i.e. r8-r14
ARM State Vs Thumb State
ARM State Thumb State
CPSR<T bit> T=0 T=1
Instruction Size 32 bits 16 bits
All instructions must be word aligned All instructions must be halfword aligned
Core Instructions 68 30
Conditional Execution Most Only Branch Instruction
CPSR Accessibility Full Access in System Mode No direct access
Register Usage 15 GPR + PC 8 GPR + 7 High Registers + PC
Code Density Low High
System Use Full use in ARM State Partial use of System in Thumb State
Application High Profile Applications Low Profile Applications
Memory Requirements More Memory required as size of Less Memory required as size of
instructions are 32 bit instructions are 16 bit
ARM7 Pipelining
❖ ARM10 uses 6 stage pipeline: Fetch, Issue, Decode, Execute, Memory Write & Register Write
ARM7 Exception Handling
▪ Vector table – a table of addresses that the ARM core branches, may not
have space to put in complete service routine
▪ In the table it has a branch instruction, it changes the PC
FIQ
▪ Occurs when an external peripheral generates the FIQ input signal
▪ Core disables both FIQ and IRQ interrupts
IRQ
▪ Occurs when when an external device generates the IRQ input signal
▪ IRQ handler will be entered if neither an FIQ exception or Data abort exception occurs
▪ On entry IRQ exception is disabled and should remain disabled for the handler if not enabled by the handler
Prefetch Abort
▪ Occurs when an attempt to fetch an instruction results in memory fault
▪ FIQ exception can be serviced
Undefined instruction
▪ Occurs when an instruction is not in the ARM or Thumb instruction
▪ SWI and undefined instruction have the same level of priority because they cannot occur together
Coprocessors
• Coprocessors can be attached to the ARM processor.
• A coprocessor extends the processing features of a core by extending the instruction set
or by providing configuration registers.
• More than one coprocessor can be added to the ARM core via the coprocessor interface.
• The coprocessor can be accessed through a group of dedicated ARM instructions that
provide a load-store type interface.
• The coprocessor can also extend the instruction set by providing a specialized group of
new instructions.
• These new instructions are processed in the decode stage of the ARM pipeline. If the
decode stage sees a coprocessor instruction, then it offers it to the relevant coprocessor.
But if the coprocessor is not present or doesn’t recognize the instruction, then the ARM
takes an undefined instruction exception, which allows you to emulate the behavior of
the coprocessor in software.