0% found this document useful (0 votes)
5 views

Chapter - 2

Uploaded by

toleragir482016
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Chapter - 2

Uploaded by

toleragir482016
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

Real time and Embedded System

Chapter - 2
Embedded system architecture
Hardware Architecture for Embedded systems

• An embedded system is built around a processor.

• The central processing unit does the necessary computation based on the
input it receives from various external devices.

• The functionality of the CPU in an embedded system is same as the


functionality of the CPU in a desktop, except that the CPU in an embedded
system is less powerful.

• The processor has limited internal memory and if this internal memory is
not sufficient for a given application external memory devices are used.

• The hardware also includes any components that facilitates the user-
application interaction such as display units, keypads etc.

2
Processor in ES

o The processor used in embedded systems can be of three types:


– Microcontrollers
– Microprocessors
– Digital Signal Processor
➢ Each of them is specified by clock speed (100MHz, etc.) and data word
length( 8-bit, 16-bit, 32-bit).
➢ The higher the clock speed, the faster the processor.
➢ Same way, bigger data word-length leads to higher precision.
➢ The word length also indicates the processor’s capability to address the
memory.
➢ This addressing capability is specified by the number of bits used for
addressing.
➢ For instance : an 8-bit processor can be use 8 or 16-bit for addressing.

3
Micro-controller

• A Microcontroller is a single-chip VLSI unit (also called


microcomputer) which, although having limited
computational capabilities, possesses enhanced input/output
capability and a number of on-chip functional units.
• Microcontrollers are particularly used in embedded systems
for real-time control applications with on-chip program
memory and devices.
• Micro-controllers are mainly of Intel’s 805x family,
Motorola’s 68HCxx, etc.
• A typical micro-controller contains a CPU, interrupts,
timer/counter, memory (RAM, ROM or both) and other
peripherals in same Integrated Circuit(IC).

4

• Micro-controller are often an ideal solution for control


applications because you can use them to build an embedded
system with little additional circuitry.

5
Microprocessor

▪ A microprocessor is a single VLSI chip having a CPU.


• In addition, it may also have other units such as coaches,
floating point processing arithmetic unit, and pipelining units
that help in faster processing of instructions.
• A number of 16-bit and 32-bit microprocessors are available
from ARM, Atmel, Intel, Motorola, National Semiconductors,
etc.
• In order to develop an embedded system with these processors,
you great deal of peripheral circuitry.
• However, microprocessors higher clock speeds and word-
length, so they are capable of addressing higher memory.

6

• These processors are used for high-end applications such as


handheld computers, Internet access Devices, etc.
• A microprocessor executes a collection of machine instructions
that tell the processor what to do.

7

Based on the instructions, a microprocessor does three basic


things:
• Using its ALU(Arithmetic/Logic Unit)
– a microprocessor can perform mathematical operations like
addition, subtraction, multiplication and division.
– Modern microprocessors contain complete floating-point
processors that can perform extremely sophisticated
operations on large floating-point numbers.
• A microprocessor can move data from one memory location to another.
• A microprocessor can make decisions and jump to a new set of
instructions based on those decisions.

8
Types of Microprocessors

• Two classification criteria:


– Hardware characteristics
– Application areas characteristics
Hardware characteristics
Complex Instruction Set Computer (CISC)
• It is a computer that can address a large number of instructions
Reduced Instruction Set Computer (RISC)
• fewer instructions with simple constructs so that they can be
executed much faster within the CPU without having to use
memory

9

• Difference b/n RISC and CISC

10

Characteristics of application areas


– GPP (General Purpose Processor) / MCU (Microcontroller unit)
– SPP (Special Purpose Processor)
– ASIC (Application-Specific Integrated Circuit)
– ASIP (Application-Specific Instruction-set Processor)
– GPP core(s) or ASIP core(s) on either an Application Specific
Integrated Circuit (ASIC) or a Very Large Scale Integration
(VLSI) circuit.
– DSP (Digital Signal Processor) :- is a special designed processor
to handle signals, rather than data

11
Processor Architectures

• There are two processor architectures


• Harvard architecture
• Von Neumann architecture.
• When data and code lie in different memory blocks, then the
architecture is referred as Harvard architecture.
• In case data and code lie in the same memory block, then the
architecture is referred as Von Neumann architecture.

12
Von Neumann Architecture

• The Von Neumann architecture was first proposed by a


computer scientist John von Neumann.
• In this architecture, one data path or bus exists for both
instruction and data.
• As a result, the CPU does one operation at a time.
• It either fetches an instruction from memory, or performs
read/write operation on data.
• So an instruction fetch and a data operation cannot occur
simultaneously, sharing a common bus.

13
Von Neumann architecture

14
Harvard Architecture

• The Harvard architecture offers separate storage and signal


buses for instructions and data.
• This architecture has data storage entirely contained within the
CPU, and there is no access to the instruction storage as data.
• Computers have separate memory areas for program
instructions and data using internal data buses, allowing
simultaneous access to both instructions and data.
• Programs needed to be loaded by an operator, the processor
could not boot itself.
• In Harvard architecture, there is no need to make the two
memories share properties.

15
Harvard architecture

16
Difference between Von Neumann and Harvard Architecture

17
Arm Cortex-M0+ hardware overview

▪ The Arm Cortex-M0+ is the most energy efficient Arm


processor available for embedded applications with design
constraints.
• It features one of the smallest silicon footprint and minimal
code size to allow developers to achieve 32-bit performance at
16 and 8-bit price points.
• The low gate count of the processor enables deployment in
applications where simple functions are required.

18
Key advantages of Arm Cortex-M0+ MCUs

• The small footprint of the core allows it to be used as a single


core in small devices, but also as an additional embedded
companion core when specific hardware isolation or task
partitioning is required.
• The Cortex-M0+ core does not impact the trade-off to be made
among the elements of the typical MCU architecture based on
I/Os, analog and non-volatile memories.
• M0+ microcontrollers are widely used and offer high benefits
in entry-level applications.
• They meet computing performance requirements and their
basic architecture allows M0+ MCUs to reach ultra-low power
performance in applications where the number of switching
gates is minimized.
19

• The Thumb instruction set is a subset of the Cortex-M family.


• It eases the scalability of the portfolio by re-using validated
software brick for any Cortex-M products.
• The Memory Protection Unit (MPU) manages the CPU's access
to the memory and ensures a task does not accidentally corrupt
the memory or the resources used by other active tasks.
• The MPU is usually controlled by a Real-Time Operating
Systems (RTOS).
• If a program accesses a memory location that is prohibited by
the MPU, the RTOS can detect it and take action.
• The kernel can dynamically update the MPU area setting, based
on the process to be executed.
• The MPU is optional and can be bypassed.
20
A general-purpose input/output (GPIO)

• A general-purpose input/output (GPIO) is an uncommitted


digital signal pin on an integrated circuit or electronic circuit
board which may be used as an input or output, or both, and is
controllable by software.
• Device pins that are not connected to a specific peripheral
function are controlled by the GPIO registers.
• Pins may be dynamically configured as inputs or outputs.
• Multiple outputs can be set or cleared in one write operation.
• GPIO registers are on the Arm Cortex-M0+ IO bus for fastest
possible single-cycle I/O timing, allowing GPIO toggling with
rates of up to 7 MHz.
• An entire port value can be written in one instruction.

21
Analog I/O

➢ The signals from sensors that measure surrounding natural


factors such as temperature, pressure, and flow rate are often
analog signals, and most control actuators move according to
analog signals.
➢ On the other hand, only digital signals can be handled by
computers.
➢ For this reason, in order to input a signal from a sensor using a
computer, or to output a signal to an actuator, it's necessary to
have a device that can bridge the analog signal and the digital
signal handled by the computer.
➢ That bridge is called an analog I/O interface.

22

• An analog input converts a voltage level into a digital value


that can be stored and processed in a computer.
• Why would you want to measure voltages?
– There are a multitude of sensors available which convert things like
temperature, pressure, etc. into voltages.
• The voltages can then be easily measured by various kinds of
hardware, such as a LabJack U3-HV, and then read into a
computer.
• The computer can then convert the voltage value into it's
original type (temperature, pressure, etc.) and the value can
then be stored in a file, emailed to someone, or used to control
something else outside of the computer.

23
ADC/DAC

Analog I/O device classification


• Analog input device(A/D conversion)
– This device is responsible for converting analog signals
from external devices to digital signals that can be
processed by a computer.
• Analog output device(D/A conversion)
– This device converts the digital data from a computer to an
analog signal before outputting that signal to an external
device.
• Analog I/O device(A/D, D/A conversion)
– Analog I/O devices are devices with both an A/D and a
D/A conversion function.

24
Communication :
Parallel, USB/Serial, UART, SPI, TWI, Ethernet, Wireless
• Communication between electronic devices is like communication
between humans.
• Both sides need to speak the same language.
• In electronics, these languages are called communication protocols.
• Luckily for us, there are only a few communication protocols
(SPI,I2C,UART,USB) we need to know when building most
electronics projects.
• SPI, I2C, and UART are quite a bit slower than protocols like USB,
Ethernet, Bluetooth, and Wi-Fi, but they’re a lot simpler and use less
hardware and system resources.
• SPI, I2C, and UART are ideal for communication between
microcontrollers and between microcontrollers and sensors where
large amounts of high speed data don’t need to be transferred.

25
Data Communication Types

– Parallel
– Serial
Parallel Communication:
• In parallel communication, all the bits of data are transmitted
simultaneously on separate communication lines.
– Used for shorter distance.
– In order to transmit n bit, n wires or lines are used.
– More costly.
– Faster than serial transmission.
– Data can be transmitted in less time

26

Serial Communication
• In serial communication the data bits are transmitted serially
one by one i.e. bit by bit on single communication line
• It requires only one communication line rather than n lines to
transmit data from sender to receiver.
• Thus all the bits of data are transmitted on single lines in serial
fashion.
• Less costly.
• Long distance transmission.

27
Serial communication uses two methods

– Asynchronous.
– Synchronous.
Asynchronous
• transfers single byte at a time
• No need of clock signal
Example: UART (universal asynchronous receiver transmitter)
Synchronous
• Transfers a block of data (characters) at a time.
• Requires clock signal
Example: SPI (serial peripheral interface)
I2C (inter integrated circuit).

28

▪ Synchronous and asynchronous communication protocols are


well-defined standards and can be implemented in either hardware
or software.
▪ In the early days of embedded systems, Software implementation of
I2C and SPI was common as well as a tedious work and used to take
long programs.
▪ Gradually, most the microcontrollers started incorporating the
standard communication protocols as hardware cores.
▪ This development in early 90’s made job of the embedded software
development easy for communication protocols.
• Microcontroller supports UART, CAN, SPI, I2C and USB protocols.
• Those mentioned communication protocols are available in most of
the modern day microcontrollers.

29

• UART(Universal Asynchronous Receiver Transmitter) is a


dedicated hardware associated with serial communication.
• The hardware for UART can be a circuit integrated on the
microcontroller or a dedicated IC.
• UART is one of the most simple and most commonly used
Serial Communication techniques.
• Today UART is being used in many applications like -
– GPS Receivers
– Bluetooth Modules
– GSM and GPRS Modems
– Wireless Communication Systems
– RFID based applications etc.
30

• In UART communication, two UARTs communicate directly


with each other.
• The transmitting UART converts parallel data from a controlling
device like a CPU into serial form, transmits it in serial to the
receiving UART, which then converts the serial data back into
parallel data for the receiving device.
• Only two wires are needed to transmit data between two UARTs.
• Data flows from the Tx pin of the transmitting UART to the Rx
pin of the receiving UART:
• UARTs transmit data asynchronously, which means there is no
clock signal to synchronize the output of bits from the
transmitting UART to the sampling of bits by the receiving
UART.

31

• Instead of a clock signal, the transmitting UART adds start


and stop bits to the data packet being transferred.
• These bits define the beginning and end of the data packet so
the receiving UART knows when to start reading the bits

32
SPI Communication Protocol

• SPI is a common communication protocol used by many different


devices.
• For example: Secure Digital card (SD card) modules, RFID
card reader modules, and 2.4 GHz wireless transmitter/receivers
all use SPI to communicate with microcontrollers.
• One unique benefit of SPI is the fact that data can be transferred
without interruption.
• Any number of bits can be sent or received in a continuous
stream.
• With I2C and UART, data is sent in packets, limited to a specific
number of bits.
• Start and stop conditions define the beginning and end of each
packet, so the data is interrupted during transmission.
33

• Devices communicating via SPI are in a master-slave


relationship.
• The master is the controlling device (usually a
microcontroller), while the slave (usually a sensor, display, or
memory chip) takes instruction from the master.
• The simplest configuration of SPI is a single master, single
slave system, but one master can control more than one slave
(more on this below)

34

• MOSI (Master Output/Slave Input)


– Line for the master to send data to the slave.
• MISO (Master Input/Slave Output)
– Line for the slave to send data to the master SCLK (Clock) - Line
for the clock signal.
• SS/CS (Slave Select/Chip Select)
– Line for the master to select which slave to send data to

35
I2C Communication Protocol

• Inter IC (i2c) (IIC) is important serial communication protocol


in modern electronic systems.
• Philips invented this protocol in 1986.
• The objective of reducing the cost of production of television
remote control motivated Philips to invent this protocol.
• IIC is a serial bus interface, can be implemented in software,
but most of the microcontrollers support IIC by incorporating
it as hard IP (Intellectual Property).
• IIC is used to interface chips on motherboard, generally
between a processor chip and any peripheral which supports
IIC.

36

• IIC is very reliable wire-line communication protocol for an on


board or short distances.
• I2C is a serial protocol for two-wire interface (TWI) to
connect low-speed devices like microcontrollers, EEPROMs,
A/D and D/A converters, I/O interfaces and other similar
peripherals in embedded systems
• I2C combines the best features of SPI and UARTs.
• With I2C, you can connect multiple slaves to a single master
(like SPI) and you can have multiple masters controlling
single, or multiple slaves.

37

• This is really useful when you want to have more than one
microcontroller logging data to a single memory card or
displaying text to a single LCD.
• IIC protocol uses two wires for data transfer between devices:
Serial Data Line (SDA) and Serial Clock Line (SCL).
• The reduction in number of pins in comparison with parallel
data transfer is evident.
• This reduces the cost of production, package size and power
consumption.
• IIC is also best suited protocol for battery operated devices.
• IIC is also referred as two wire serial interface (TWI).

38

39
Universal Serial Bus (USB)

• Universal Serial Bus (USB) is a set of interface specifications


for high speed wired communication between electronics
systems peripherals and devices with or without PC/computer.
• The USB was originally developed in 1995 by many of the
industry leading companies like
– Intel
– Compaq
– Microsoft
– Digital
– IBM and
– Northern Telecom.

40
ATmega32 microcontroller Architecture

• ATmega microcontroller is a single chip microcontroller create


by Atmel in mega AVR family .

• ATmega32 is a low power CMOS (complementary metal


oxide semiconductor) 8-bit microcontroller based on the AVR
enhanced RISC architecture

41
Atmel Atmega32 highlights

An 8-bit microcontroller featuring:


• 3 separate on-chip memories (Harvard architecture)
– 2KB SRAM (for data – volatile, data lost on power off)
– 1KB EEPROM (for persistent data storage – holds data after power off)
– 32KB Flash (organized as 16K of 16-bit words for persistent program
code)
• Native data size is 1 byte (SRAM and EEPROM)
• 16-bit data addressing
– Up to 64 KB (216 bytes) of data memory can be accessed
• 8-pin I/O ports named A, B, C, and D, program-configurable as:
– Digital input (for reading discrete external signals on each pin (0v or
5v) as data values 0 or 1)
– Digital output (for writing binary data values as discrete output signals
(0v or 5v)
– Analog input (for reading continuous external signals (0v-5v) as data
values)
– Serial/Parallel (for reading or writing streams of bytes)
– Pulse accumulator (for counting #changes of external signals)
42
Inside an IC package

43

44
Atmel Atmega32
⚫ Central Processing Unit
⚫ Arithmetic Logic Unit (ALU) performs
the actual arithmetic, logical, and bit-
functions
⚫ Memory – SRAM, EEPROM, Flash
⚫ Clock circuit – internal/external
⚫ I/O – Input/Output; video, serial, parallel,
USB, SCSI, etc.

45
3 Separate on-chip memories

Programs are stored in 32KB Program Flash


• Persistent: contents are retained when power is off
(non-volatile)
• Organized as 2-byte words; individual program
instructions generally take 2 bytes, but some take 4
bytes
• Each word has a unique 16-bit address (0-0x3FFF)
• Fast to read; slow to write
• Can only write entire “blocks” of memory at a time

2KB SRAM for temporary data storage


• Contents are lost when power is shut off (volatile)
• Fast read and write
• Native data size is 8 bits (1 byte)
• Each byte has a unique 16-bit address (0x60-0x85F)

1KB EEPROM for persistent data storage


• Contents are retained when power is off (non-volatile)
• Fast read; slow write
• Native data size is 8 bits (1 byte)
• Each byte has a unique 16-bit address

46
Flash Program Memory layout

Reset and interrupt vector section


⚫ There are 32KB of program memory
42 words (84 bytes)
$002A
(Flash memory)
⚫ Organized as 16K 2-byte words
⚫ Because program instructions are
either 2 (common) or 4 (less
Your programs go here!
common) bytes long

⚫ Each word (not byte) in Flash


memory has a unique address
⚫ Beginning address $0000
⚫ Ending address $3FFF

$3C00 ⚫ Some Flash memory is reserved or


protected
⚫ First 42 words (reserved)
Number of bytes depends on
user-definable configuration ⚫ Last NNN words (protected)

47
Most general-purpose microprocessors (like in your PC)
use a von Neumann Architecture
1. Data and instructions are both stored in the same main
memory
2. The content of any part of memory is addressable by
location without regard to what is stored in that location
program or data
3. Instructions are executed sequentially. In case of accidental
or intentional programming errors, data can be executed a
common attack used by viruses

48
Assembly language Programming with ATmega32
Instruction Set
• To code in assembler, one should have some idea about the
architecture of the target hardware.
• It is enough to assume that the AVR micro-controller appears
to the programmer as a set of General Purpose Registers
(GPRs: R1 to R31), Special Functions Registers (SFRs) that
controls the peripherals, some data memory (2kbytes of
SRAM for Atmega32).
• All of them are in the data address space.
• We also have Program memory and EEPROM in different
address spaces.
• Assembly language programming involves moving data between GPRs,
SFRs and RAM, and performing arithmetic and logical operations on
the data.
49

• An Assembler converts human-readable assembly language instructions


into machine-executable instruction that are stored in Program Flash
Memory
• Consider the assembly language instruction
add rD, rS
– add is a reserved assembly language instruction mnemonic
– rS and rD are operands that refer to source and destination general-
purpose registers
– This instruction adds the contents of register rS to register rD, storing
the sum in rD.
• Example: Substitute any actual register (R0-R31) for rS and rD :
add r20, r5
• case is not important; the instruction can also be written as
ADD R20, R5

50

• The ALU can only directly operate on data that has been
fetched into the Registers.
• It cannot directly operate on SRAM or EEPROM data.
• In the assembly language instruction add r20, r5
– We (the programmer) must first load some values into these
registers.
– One way of doing this is with the following instructions:
ldi r20, 2 ; load value 2 into r20
lds r5, 0x60 ; load value at SRAM addr 0x60 into r5
add r20, r5 ; add them, result is in r20

51
General Purpose Registers

• There are 32 8-bit GP registers R0-R31


– Used as accumulator - for most
math and logic
• X, Y, Z are 16-bit registers that overlap
R26-R31
– Used as address pointers or
– To contain larger values (>255)

52
Special-purpose Registers can also be operated upon directly by the
ALU (with certain specific instructions)

Stack pointer (SP, 16-bit)


⚫ Stores return address of
subroutine/interrupt calls
⚫ Storing temporary data
and local variables

Program counter (PC, 16-bit)


⚫ Holds address of next program
instruction to be loaded and
executed
⚫ Automatically incremented when
the ALU executes an instruction

Status Register (SREG, 8-bit)


⚫ Contains information of result of
most recent ALU operation

53
Yet another Development System: AVRStudio

• Editor (for writing programs in assembly language)


• Assembler (like a compiler, but much simpler)
• Program downloader (loads the assembled code to the
Atmega32)
• Debugger
– Monitor - (remote debugging on the actual Atmega32)
– Simulator - (local dubugging using a simulation of the
running Atmega32)

54
Programming in C to Interface peripherals, Interrupts,
ISR and Timers
• Interrupt: An interrupt is a signal sent to the CPU which
indicates that a system event has a occurred which needs
immediate attention.
• Interrupt ReQuest (IRQ) can be thought of as a special
request to the CPU to execute a function(small piece of code)
when an interrupt occurs.
• ISR : This function or small piece of code is technically called
an Interrupt Service Routine or ISR.
– So when an IRQ arrives to the CPU, it stops executing the current
code and start executing the ISR. After the ISR execution has
finished the CPU gets back to where it had stopped.

55

• What is ISR in connection with interrupts?


• An interrupt service routine (ISR) is a software routine that
hardware invokes in response to an interrupt.
• ISR examines an interrupt and determines how to handle it
executes the handling, and then returns a logical interrupt
value.
• If no further handling is required the ISR notifies the kernel
with a return value.
• Timer interrupts allow you to perform a task at very
specifically timed intervals regardless of what else is going on
in your code.

56
The End

You might also like