You are on page 1of 59

EMBEDDED

SYSTEMS

What is Embedded Systems?

Which is designed/developed to perform one or more(limited) dedicated task


An Embedded System is a microprocessor/microcontroller based system that
is embedded as a subsystem, in a larger system (which may or may not be a
computer system)

Application Oriented

Must have Microcontroller/Microprocessor

Connected Peripherals

Must have memory ( most of them )


Quiz: Name one without memory?

Real Time Constraints of System

Application areas

Automotive electronics

Aircraft electronics

Trains

Telecommunication

Application areas
Medical
Medicalsystems
systems

Military
Militaryapplications
applications

Authentication
Authentication
4

Application areas
Consumer
Consumerelectronics
electronics

Fabrication
Fabricationequipment
equipment

Smart
Smartbuildings
buildings

Difference between a Microprocessor


and Microcontroller?
Note : RAM, ROM, I/O, Timer, Serial Com port

Quiz :Examples of Both


How to decide which one to select ?
1.
2.
3.
4.
5.

Cost
Speed
Utilization
Power Utilization
Need of the system/Application

What is a Microprocessor ?

An arithmetic logic unit (ALU) for processing

Permanent memory for keeping the program (= ROM)

Volatile memory for computation (= RAM)

Rewritable permanent memory for logging, tuning, storing intermediate


data (= EEPROM)

Connectivity to peripherals

Binary outputs via single chip pins

Integrated asynchronous and synchronous serial interfaces such as


UART, I2C, RS232, CAN,SPI

Embedded System Structure


(Generic)

Sensor

AD

Processor &
ASICs

Memory

DA

Actuator

General Characteristics of
Embedded Systems

Perform a single task


Usually not general purpose

Increasingly high performance and real time constrained

Power, cost and reliability are important considerations

HW-SW systems
Software is used for more features and flexibility
Hardware (processors, ASICs, memory etc. are used for
performance and security

General Characteristics of
Embedded Systems (contd.)
Analog IO

ASIC s
Mem
Processor
Cores

Digital

ASIPs and ASICs form a significant component


Adv: customization lower power, cost and enhanced performance
Disadv: higher development effort (debuggers, compilers etc.) and
larger time to market
10

HARVARD ARCHITECTURE
Harvard Architecture refers to a
memory structure
where the processor is connected to
two different
memory banks via two sets of buses
This is to provide the processor with
two distinct data paths, one for
instruction and one for data
Through this scheme, the CPU can read
both an
instruction and data from the
respective memory
banks at the same time
This inherent independence increases

VON-NEUMANN ARCHITECTURE
A Von-Neumann Machine, in contrast to the
Harvard
Architecture provides one data path (bus) for
both
instruction and data
As a result, the CPU can either be fetching an
instruction from memory, or read/writing data
to it
Other than less complexity of hardware, it
allows for
using a single, sequential memory.
Todays processing speeds vastly outpace
memory
access times, and we employ a very fast but
small
amount of memory (cache) local to the

Little v/s BIG ENDIAN


Although numbers are always displayed in the same
way, they are not stored in the same way in memory
Big-Endian machines store the most significant byte of
data in the lowest memory address
Little-Endian machines on the other hand, store the
least significant byte of data in the lowest memory
address
A Little-Endian machine stores 0x12345678 as:
ADD+0: 0x78
ADD+1: 0x56
ADD+2: 0x34
ADD+3: 0x12
A Big-Endian machine stores 0x12345678 as:
ADD+0: 0x12
ADD+1: 0x34
ADD+2: 0x56
ADD+3: 0x78

8051 Flavors ( AT89c51)


4 Kbytes of Flash,
128 bytes of RAM,
32 I/O lines,
two 16-bit timer/counters,
6 Interrupts
5V Vcc
40 pin Packaging

Pin Description of the 8051


P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
RST
(RXD)P3.0
(TXD)P3.1
(INT0)P3.2
(INT1)P3.3
(T0)P3.4
(T1)P3.5
(WR)P3.6
(RD)P3.7
XTAL2
XTAL1
GND

1
2
3
4
5
6
7
8
9
1
1
0
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
2
9
0

8051
(8031
)

4
3
0
3
9
3
8
3
7
3
6
3
5
3
4
3
31
2
3
2
0
2
9
2
8
2
7
2
6
2
5
2
4
2
3
2
1

Vcc
P0.0(AD
P0.1(AD1)
0)
P0.2(AD
P0.3(AD3
2)
)P0.4(AD4
)P0.5(AD5)
P0.6(AD6)
P0.7(AD7
)EA/VPP
ALE/PROG
PSEN
P2.7(A15)
P2.6(A1
P2.5(A1
4)
P2.4(A1
3)
P2.3(A1
2)
P2.2(A10
1)
)P2.1(A9)
P2.0(A8)

Figure (a). XTAL Connection to 8051

Using a quartz crystal oscillator


We can observe the frequency on the XTAL2 pin.
C2
XTAL2
30pF
C1
XTAL1
30pF
GND

Pins of 8051 1/4

Vcc pin 40
Vcc provides supply voltage to the chip.
The voltage source is +5V.
GND pin 20 ground
XTAL1 and XTAL2 pins 19,18

Pins of 8051 2/4


RST pin 9 reset
It is an input pin and is active high normally low .
The high pulse must be high at least 2 machine
cycles.
It is a power-on reset.
Upon applying a high pulse to RST, the
microcontroller will reset and all values in registers
will be lost.
Reset values of some 8051 registers

Pins of 8051 3/4

/EA pin 31 external access


There is no on-chip ROM in 8031 and 8032 .
The /EA pin is connected to GND to indicate the code is
stored externally.
/PSEN ALE are used for external ROM.
For 8051, /EA pin is connected to Vcc.
/ means active low.
/PSEN pin 29 program store enable
This is an output pin and is connected to the OE pin of the
ROM.

Pins of 8051 4/4

ALE pin 30 address latch enable


It is an output pin and is active high.
8051 port 0 provides both address and data.
The ALE pin is used for de-multiplexing the address
and data by connecting to the G pin of the 74LS373
latch.
I/O port pins
The four ports P0, P1, P2, and P3.
Each port uses 8 pins.
All I/O pins are bi-directional.

Pins of I/O Port

The 8051 has four I/O ports


Port 0 pins 32-39 P0 P0.0 P0.7
Port 1 pins 1-8
P1 P1.0 P1.7
Port 2 pins 21-28 P2 P2.0 P2.7
Port 3 pins 10-17 P3 P3.0 P3.7
Each port has 8 pins.
Named P0.X X=0,1,...,7 , P1.X, P2.X, P3.X
Ex P0.0 is the bit 0 LSB of P0
Ex P0.7 is the bit 7 MSB of P0
These 8 bits form a byte.
Each port can be used as input or output (bi-direction).

Other Pins
P1, P2, and P3 have internal pull-up resisters.
P1, P2, and P3 are not open drain.
P0 has no internal pull-up resistors and does not
connects to Vcc inside the 8051.
P0 is open drain.
Compare the figures of P1.X and P0.X.
However, for a programmer, it is the same to program
P0, P1, P2 and P3.
All the ports upon RESET are configured as output.

Port 0 with Pull-Up Resistors


Vcc

Port 0

P0.0
DS5000 P0.1
P0.2
8751
P0.3
P0.4
8951
P0.5
P0.6
P0.7

10 K

Port 3 Alternate Functions


P3 Bit

Function

Pin

P3.0
P3.1
P3.2
P3.3
P3.4
P3.5
P3.6
P3.7

RxD
TxD
INT0
INT1
T0
T1
WR
RD

10
11
12
13
14
15
16
17

Register
s
SP
A
B
R0

DPTR

DPH

DPL

R1
R2

PC

PC

R3
R4
R5
R6
R7
Some 8-bitt Registers of
the 8051

Some 8051 16-bit Register

Memory mapping in 8051


ROM memory map in 8051 family
4k
0000H

8k
0000H

0FFFH

8751
AT89C51

1FFFH
8752
AT89C52

RAM memory space allocation in the 8051


7FH
Scratch pad RAM

30H
2FH
Bit-Addressable RAM
20H
1FH
18H
17H
10H
0FH
08H
07H
00H

Register Bank 3
Register Bank 2
Register Bank 1( Stack)
Register Bank 0

Stack in the 8051


The register used to access
the stack is called SP
(stack pointer) register.

7FH
Scratch pad RAM
30H
2FH

The stack pointer in the


8051 is only 8 bits wide,
which means that it can
take value 00 to FFH.
When 8051 powered up,
the SP register contains
value 07.

Bit-Addressable RAM
20H
1FH
18H
17H
10H
0FH
08H
07H
00H

Register Bank 3
Register Bank 2
Register Bank 1) Stack(
Register Bank 0

Program Counter
The Program Counter is a 16 or 32 bit
register which contains the address of
the next instruction to be executed
The PC automatically increments to the
next sequential memory location every
time an instruction is fetched
Branch, jump, and interrupt operations
load the Program Counter with an
address other than the next sequential
location
During reset, the PC is loaded from a
pre-defined memory location to signify
the starting address of the code

RestVector
The significance of the reset vector is that it
points the processor to the memory address
which contains the firmwares first instruction
Without the Reset Vector, the processor would
not know where to begin execution
Upon reset, the processor loads the Program
Counter (PC) with the reset vector value from a
pre-defined memory location
On CPU08 architecture, this is at location
$FFFE:$FFFF
A common mistake which occurs during the
debug phase when reset vector is not
necessary the developer takes it for granted
and doesnt program into the final image. As a
result, the processor doesnt start up on the
final product.

Stack Pointer
The Stack Pointer (SP), much like the reset
vector, is required at boot time for many
processors
Some processors, in particular the 8-bit
microcontrollers automatically provide the
stack pointer by resetting it to a predefined
value
On a higher end processor, the stack pointer is
usually read from a non-volatile memory
location, much like the reset vector
For example on a ColdFire microprocessor, the
first sixteen bytes of memory location must be
programmed as follows:
0x00000000: Reset Vector
0x00000008: Stack Pointer

Infinite Loop
Embedded Systems, unlike a PC, never exit
an application
They idle through an Infinite Loop waiting for
an event to happen in the form of an
interrupt, or a pre-scheduled task
In order to save power, some processors
enter special sleep or wait modes instead of
idling through an Infinite Loop, but they will
come out of this mode upon either a timer or
an External Interrupt

Interrupts
Interrupts are mostly hardware mechanisms
which tell the program an event has occurred
They happen at any time, and are therefore
asynchronous to program flow
They require special handling by the
processor, and are ultimately handled by a
corresponding Interrupt Service Routine (ISR)
Need to be handled quickly. Take too much
time servicing an interrupt, and you may miss
another interrupt.

Compilation of C file
Preprocessed
Source

Source

Compiler

Preprocessor

In Memory

Assembler

.s

O
B

Executable
Program

ASM

Executable
Loader

J
Linker

a.out

.o

E
C
T

Breaking Down CC
Preprocessed
Source

source

Compiler

Preprocessor

ASM

Assembler

.s
O
B

Executable
Program
In Memory

Executable
Loader

J
Linker

a.out

.o

E
C
T

C Preprocessor (.cpp)

Pass over source


Insert included files
Perform macro substitutions

Define macros
#define NUM 100
#define xx(v,name,op,metrics) \
>metrics)

v=xxinit(op,name,IR-

gcc E example.c sends preprocessor output to stdout

Breaking Down CC
Preprocessed
Source

source

Compiler

Preprocessor

In Memory

Assembler

.s

O
B

Executable
Program

ASM

Executable
Loader

J
Linker

a.out

.o

E
C
T

Compiler

gcc actually name of a script

Compiler translates one language to another (or the same???)

gcc compiler translates C to assembler

gcc S example.c saves example.s

Compiler consists of
Parser
Code generation
Mysticism

Breaking Down CC
Preprocessed
Source

Source

Compiler

Preprocessor

In Memory

Assembler

.s

O
B

Executable
Program

ASM

Executable
Loader

J
Linker

a.out

.o

E
C
T

Assembler

Another translator ??? (as example.s)

Assembler to (binary) object

Why not compile straight to binary?

gcc c example.c to save object

NM to look at object (nm example.o)

Breaking Down CC
Preprocessed
Source

Source

Compiler

Preprocessor

In Memory

Assembler

.s

O
B

Executable
Program

ASM

Executable
Loader

J
Linker

a.out

.o

E
C
T

Linker

Combine objects, both user .o files and libraries, make an


executable

gcc *.o lm yields a.out

gcc o myExec *.o lm

Use nm to look at object

Breaking Down CC
Preprocessed
Source

Source

Compiler

Preprocessor

In Memory

Assembler

.s

O
B

Executable
Program

ASM

Executable
Loader

J
Linker

a.out

.o

E
C
T

Loader

Gets an address to place program

Changes necessary addresses (if any)

Places code into memory

Project development and an


Assembler
Note: Let us assume that assembler and programmer driver is
already installed on PC.

Software tools: Editor, Assembler and EPROM driver


Hardware tools: PC and EPROM programmer

Editor

It is a software tool, used to create, edit and maintain


source file.

It creates a file in an ASCII file format.

Different types editors are in existence

They come with different features. E.g.


Refer Notepad features

Assembler
What is an assembler?
Types of assembler Single Pass & two Pass Assembler
Working on Assemblers procedure
STEP No1: Go to Command line
Open an Editor
>>edit
*/

OR

>> edit sample.asm

/* It opens a new file with name sample.asm


/* This is a source a file */

STEP No 2: Create, edit and save a source file.


STEP No 3: Assemble a source file
>> A51 sample.asm /* A51.exe is an assembler */
It creates various files, e.g. sample.hex, sample.lst etc.
STEP No 4: Open EPROM driver, download binary image to the target

board with the help of EPROM Programmer

EPROM Programmer: Model 1

EPROM Programmer: Model 2

EEPROM Programmer: Model 3

Project development and a


Compiler: (x)
Note: Assume that a compiler and programmer driver is already
installed on PC.

Software tools: Editor, Compiler and EPROM driver


Hardware tools: PC and EPROM programmer

Project development and an IDE

Integrated Development
Environment (IDE):

All software tools discussed earlier, are kept under one common
unified user interface, i.e. IDE

Becomes possible to make a code change and get the modified


code loaded with a few mouse clicks

A good IDE allows you for example to click on a syntax error


message produced by the compiler and have the source code with
the highlighted offending instruction pop up for editing in the text
editor

Some IDEs are flexible enough to allow you to incorporate different


choices of third party tools (like compilers and debuggers), others
only work with a manufacturer's own tool chain.

Debugging tools

Different types of tools differ greatly in terms of development time


spend and debugging features available e.g.
- Simulators.
- Microcontroller starter kits.
- Emulator.

Simulators

It tries to model the behavior of the complete microcontroller in


software

No matter how fast your PC, there is no simulator on the market


that can actually simulate a microcontroller's behavior in real-time

A simulator can also not talk to your target system, so functions that
rely on external components are difficult to verify

For that reason simulators are best suited to test algorithms that run
completely within the microcontroller

They are the perfect tool to complement expensive emulators for


large development teams, where buying an emulator for each
developer is financially not feasible

Microcontroller Starter Kits:

It consists of:
- Hardware board(Evaluation board).
- In system programmer.
- Some software tools like compiler,assembler, linker etc
- sometimes an IDE and code size limited evaluation version of a
compiler

A big advantage of these kits over simulators is that they work in


real-time and thus allow for easy input/output functionality
verification.

Starter kits, however, are completely sufficient and the cheapest


option to develop simple microcontroller projects

Emulators

An emulator is a piece of hardware that ideally behaves exactly like


the real microcontroller chip with all its integrated functionality

It is the most powerful debugging tool of all

Debug board modules: (DBM)

The "debug board" approach combines all of the emulator


electronics and the actual emulation chip onto a single, larger sized
PCB.

Machine Cycle VS Clock


Cycle
4Mhz to 30 Mhz , our case we will be using
11.0592 Mhz crystal.
one machine cycle lasts 12 oscillator
periods.
Period of machine cycle = 11.0592/12 =
921.6khz
machine cycle is 1/921.6khz = 1.085us.

You might also like