嵌入式系统代写代做代考 Embedded Systems Reconfigurable computing

Reconfigurable computing

Small Embedded Systems

Unit 1.7 An Example Microcontroller:
The ATmega 328P

Introduction
Overview of a typical microcontroller architecture
We’ll use ATmega 328P as a concrete example

An Example Microcontroller
We start by looking at an example microcontroller:
Atmel 328P
Data width: 8-bits
Flash: 32 kB (16k x 16 bit words)
SRAM: 2 kB
EEPROM: 1 kB

Central Processing Unit

Data memory space
Data
Address

Program memory space

Data
Address

16
15
8
12
Flash
SRAM and peripherals

The Central Processing Unit (CPU)

Program Counter holds address of next instruction
Instruction is moved into Instruction Register
Decoder sets control lines that determine what ALU should so and where its data should come from

The Central Processing Unit (CPU)

ALU performs arithmetic and logical operations
General purpose registers contain small pool of data that is currently being worked on
Data RAM contains large pool of data for program

The Data Memory Space
The data memory space contains SRAM for data memory and also special registers to control peripherals

Central Processing Unit

Data
Address

8
Gen Purpose registers
IO Ports
Timers & Counters
Analog to Digital Converter
Serial IO

Data memory

The Data Memory Map
Memory map shows which blocks of addresses are allocated to what purpose:

0x0000-0x001F

0x0020-0x00FF
0x0100-0x08FF

General purpose registers
Input-output registers
Internal SRAM
32 8-bit registers that are used by CPU
224 8-bit registers that control IO and peripherals
2048 x 8-bit memory

The Stack
The stack is a LIFO (last in first out) memory buffer
Software temporarily stores values to the stack
When a function is called the processor saves the return address and some registers to the stack
The stack is limited in size
If a function calls a function which calls a function which calls a function… to a deep level, the stack may overflow
This would be a system failure that would require recovery (or bad things might happen)
In most microcontrollers, the stack is a block within the standard SRAM data memory; some (e.g. PIC) put the stack in a separate memory and memory space

CPU Registers
CPU Registers
CPU working registers
Status register
Stack pointer
Program counter
etc.
Compilers of high level languages take care of these registers
Programmers of high level languages (C, etc.) do not need to worry about them.

32 CPU registers
224 special function registers
control IO and peripherals
2048 x 8-bit memory

Special Function Registers
Peripherals Registers
Writing to these registers can configure or set a timer, toggle an output pin, enable a serial communication etc.
If controlled by hardware they may contain the timer value, the input potential of a pin (high or low), a received byte from a serial communication etc.

32 CPU registers
224 special function registers
control IO and peripherals
2048 x 8-bit memory

ATmega328P

Here is the overall block diagram
We’ll look at the main parts briefly now
Much more detail will come later

Memories
Here we just show the memory devices
To keep the diagram simple, address busses have not been shown
Program and constant data
Transient data and stack
Long term data

IO Ports
Three 8-bit ports
Connect to pins of chip
Control direction of pins (input or output)
Store data sent to or received from outside world
Ports have addresses that can be used to send/receive data to/from them

IO Ports
Three 8-bit ports
Connect to pins of chip
Control direction of pins (input or output)
Store data sent to or received from outside world
Ports have addresses that can be used to send/receive data to/from them

Serial Communications
Serial communications are the norm on microcontrollers
Send bits of a word in successive time periods
Main protocols used:
Serial port protocol
Asynchronous protocol (don’t need to send clock)
Uses one wire for transmit and one for receive
I2C (inter-integrated circuit)
Also called TWI (two-wire interface)
One wire for data and one wire to send clock
SPI
Serial peripheral interface
Needs clock pin, send pin and receive pin

Serial Comms
Each of the ports has controller for one serial protocol
USART is for serial port protocol
Writing/reading values in special function registers manages communication

10-bit ADC
Converts input voltage to 10-bit number
Result is placed on register connected to data bus
ADC is multiplexed between six input pins

Analog-Digital Converter

Counters
Continuously count 0,1,2,3,…
Two 8-bit counters
One 16-bit counter

Timer/Counters

Two 8-bit counters: Max count value 255
One 16-bit counter: Max count value 16535
Count rate set by writing to a register
Sets division ratio from master clock
Master clock can be divided by 1, 8, 64, 256 or 1024
Max count value set by writing to another register
Comparator value is set in another register
Counter can be set to trigger specific event when count reaches value held in comparator register

Timer/Counters

Timers are used:
In Arduino IDE timing functions:
delay(number)
delayMicroseconds(number)
millis()
micros()
Timer/Counters

Pause for “number” milliseconds
Return number of ms since program started running
Pause for “number” microseconds
Return number of ms since program started running

Timers are used:
To generate timer interrupts
Signal to processor to
stop what it is doing now
jump to another function (interrupt service routine ISR)
when ISR is complete, resume execution resumes from where it left off
Timer/Counters

Resets the device if software appears to have crashed/hung
Uses its own free-running on-chip RC oscillator
During correct operation, WDT is periodically reset
If WDT reaches overflow, it resets the chip

Watchdog Timer

Summary
Memory map
Registers used by CPU
RAM used by CPU
Special function registers to control peripherals
Hardware resources
Useful peripheral functions: PWM, ADC, comms
Controlled by values written to special function registers

/docProps/thumbnail.jpeg