Reconfigurable computing
Small Embedded Systems
Unit 1.6
Microcontroller architecture
Introduction
Overview of typical microcontroller architecture
Memory
Types of memory
Memory map
Input/Output
Interrupts
Block Diagram of a Computer
Any computer can be logically divided into three parts:
Central processing unit (CPU)
Memory
Input/Output devices
All instructions are encoded as binary words in memory
All data items are encoded as binary words in memory
Input/Output Devices
Memory
CPU
Communication highways
Block Diagram of a Computer
Computation progresses by repeated Fetch-Execute cycles:
An instruction is shifted from memory into CPU
The required data is shifted from memory into CPU
The CPU computes the required result
The result is written back from CPU to memory
Input/Output Devices
Memory
CPU
Communication highways
Types of Memory
ROM (Read Only Memory)
We can read values from memory, but cannot store new values into memory
RAM (Random Access Memory)
We can read values from the memory
We can store new values into the memory
Memories
Memory is a device that stores and retrieves a data word from one of a set of locations:
Address picks out which item we want to access
Read/Write determines what we do to that item
Data
Address
Read/Write
Enable
n
m
Word 0
Word 1
Word 2
Word 3
Word 2n-1
Word 4
Word 2n-2
Memories
Memory is a device that stores and retrieves a data word from one of a set of locations:
n is number of bits in an address
m is number of bits in a data word
Data
Address
Read/Write
Enable
Word 0
Word 1
Word 2
Word 3
n
m
Word 2n-1
Word 4
Word 2n-2
An example
Say n=10. There are 210 = 1024 possible addresses.
In this example, m=8. Each word is 8-bits long
Data
Address
Read/Write
Enable
Word 0
Word 1
Word 2
Word 3
10
8
Word 1023
Word 4
Word 1022
Writing a Data Word to Memory
Let’s write an example data value of 6 into location 2
Data
Address
Read/Write
Enable
Word 0
Word 1
Word 2
Word 3
10
8
Word 1023
Word 4
Word 1022
0000000010
0
1
00000110
Apply address
Data is written to that location
Set enable=1 so memory responds to inputs
Set Read/Write to 0 to show this is a write
Writing a Data Word to Memory
Let’s write an example data value of 6 into location 2
Data
Address
Read/Write
Enable
Word 0
Word 1
Word 2
Word 3
10
8
Word 1023
Word 4
Word 1022
0
1
Set enable=1 so memory responds to inputs
Set Read/Write to 0 to show this is a write
Apply address
Data is written to that location
00000110
00000110
0000000010
Reading a Data Word from Memory
Let’s read the data value stored at location 3
Data
Address
Read/Write
Enable
Word 0
Word 1
Word 2
Word 3
10
8
Word 1023
Word 4
Word 1022
1
1
Set enable=1 so memory responds to inputs
Set Read/Write to 1 to show this is a read
Apply address
Data at location 3 is read
Output data value
0000000011
Types of Memory
Volatile memory
Memory that requires power to maintain stored information
Memory contents are lost when device is switched off
At switch-on memory contains no useful data
Non-volatile memory
Memory that retains stored information even when not powered
Memory contents are preserved when device is switched off
At switch on, memory contains same data as it had at switch-off
Non-Volatile Memory
Microcontrollers contain non-volatile memory on chip to hold the program or constant data
C examples of code stored on non-volatile memory:
const int LED_PIN=13; // Variables declared as constant
”Hello World”; // Literals
while(1) continue; // program code
Non-Volatile Memory
EEPROM:
Field programmable
Can be re-programmed
Individual bytes/words can be erased
Flash:
Similar to EEPROM
Erased in units of blocks (which are large)
Cheaper than EEPROM and faster to program large amounts
Volatile Memory
Volatile memory is used for temporary storage of data during program execution
A C example of code stored in volatile memory:
int i=1; // Non-Constant data items:
int j; // New values can be written to
char c; // them during program execution
Volatile Memory
SRAM – Static Random Access Memory
Normal place to store data that is non-constant
Volatile memory (data is lost with power loss)
Used as temporary storage on chip
Fast reads and writes
Many microcontrollers also have small amount of additional EEPROM for non-volatile data storage on chip:
Writes to these memories are slow.
Reads and writes require special instructions and programming procedures
Von-Neumann Architecture
There is one memory for program and one address bus between processor and memory
Instructions and data have to be fetched sequentially (known as the von Neumann Bottleneck) limiting the operation bandwidth
Central Processing Unit
Program and Data Memory
Data
Address
Harvard Architecture
Harvard architecture uses separate memories for instructions and data with different buses
Instructions and operands are fetched in parallel
Different program and data bus widths are possible, allowing program and data memory to optimized to the architectural requirements
Central Processing Unit
Data Memory
Data
Address
Program memory
Data
Address
Registers
A register is a volatile memory location that stores a single word
Two main types:
General purpose register
Used by the CPU to store data items that are currently being worked on
Special function register
Used to provide interface to the hardware devices on the microcontroller
Input/Output Devices
To achieve anything useful, the CPU must communicate with I/O devices, e.g.
I/O pins on the chip
Analogue-to-digital converter
Communication controllers
To achieve communication requires a memory location that both CPU and I/O device can read and write
I/O Device
CPU
Input/Output Devices
Communication is through registers in I/O device
CPU can read or write I/O device’s registers
I/O device can read and write its own registers
Some registers may be for control
e.g. instruction to ADC to read analogue data
Some are may be for data
e.g. size of voltage read by ADC
I/O Device
CPU
Register
Memory Mapped I/O
Common way to handle I/O devices:
Allocate some memory addresses to the control and data registers of I/O devices
0x0000
Available data
memory addresses
Input-output devices
0x0100
0x0900
0xFFFF
RAM
No device at these addresses
Polling of I/O Devices
The I/O device can write to its own registers, but can’t write to CPU’s registers
So CPU must periodically read the I/O device register to see if anything new is there
This is called polling. It has several drawbacks:
Wastes CPU time checking when there is no new data
When there is new data, CPU won’t know immediately
I/O Device
CPU
Register
Interrupts
Interrupt is additional line enables I/O device to signal that it needs attention
Interrupt normally provides some additional information (interrupt number) so that CPU can decide what needs to happen next
I/O Device
CPU
Register
Interrupt line
Interrupts
When interrupt signal is received:
CPU saves information needed to resume current task later
Stops current task, and jumps to handler code for that interrupt number
In this example, interrupt handler will cause CPU to read data from I/O device
Completes interrupt handler code and restores saved information about task it was previously doing
Resumes previous task
I/O Device
CPU
Register
Interrupt line
Summary
Memory
Flash used for program and constant data
SRAM used for data that changes during execution
Memory map
Registers used by CPU
RAM used by CPU
Special function registers to control peripherals
/docProps/thumbnail.jpeg