You are on page 1of 46

Microcontrollers and Embedded System

YMCA University of Science and Technology


Faridabad

Pradeep Kumar
Why Microcontrollers ??

Design without MCU Design with MCU


POWER
Switch
P
O
W Device M
Input Signal
E Control
R CTRL Signal
C
Temperature
U
Temperature
Sensor

Functional Requirements
Device
Device ON Temperature < 60 deg C

Device OFF Temperature > 75 deg C

3/26/2010 2
Pradeep Kumar
Why do we need to learn
Microprocessors/controllers?
• The microprocessor is the core of computer
systems.
• Nowadays many communication, digital
entertainment, portable devices, are controlled
by them.
• A designer should know what types of
components he needs, ways to reduce
production costs and product reliable.

3/26/2010 3
Pradeep Kumar
Different aspects of a microprocessor/controller

• Hardware :Interface to the real world

• Software :order how to deal with inputs

3/26/2010 4
Pradeep Kumar
The necessary tools for a
microprocessor/controller
• CPU: Central Processing Unit
• I/O: Input /Output
• Bus: Address bus & Data bus
• Memory: RAM & ROM
• Timer
• Interrupt
• Serial Port
• Parallel Port

3/26/2010 5
Pradeep Kumar
Basic Components of Digital Computer

• CPU
• Memory
• I/O
Memory
CPU
I/O

Could be a chip, a
board, or several
boards
3/26/2010 6
Pradeep Kumar
Microprocessors:

General-purpose microprocessor
• CPU for Computers
• No RAM, ROM, I/O on CPU chip itself
• Example:Intel’s x86, Motorola’s 680x0

Many chips on mother’s board


Data Bus
CPU
General-
Serial
Purpose RAM ROM I/O Timer COM
Micro- Port
Port
processor
Address Bus

General-Purpose Microprocessor System

3/26/2010 7
Pradeep Kumar
Microcontrollers

Memory
CPU
I/O

Subsystems:
Timers, Counters, Analog
A single chip Interfaces, I/O interfaces

3/26/2010 8
Pradeep Kumar

Microcontroller
A smaller computer
:
• On-chip RAM, ROM, I/O ports...
• Example:Motorola’s 6811, Intel’s 8051, Zilog’s Z8 and PIC 16X

CPU RAM ROM


A single chip
Serial
I/O Timer COM
Port
Port
Microcontroller

3/26/2010 9
Pradeep Kumar
Microcontrollers versus Microprocessors

Microcontroller differs from a microprocessor in many


ways. First and the most important is its functionality.
In order for a microprocessor to be used, other
components such as memory, or components for
receiving and sending data must be added to it. In short
that means that microprocessor is the very heart of the
computer. On the other hand, microcontroller is
designed to be all of that in one. No other external
components are needed for its application because all
necessary peripherals are already built into it. Thus, we
save the time and space needed to construct devices.

3/26/2010 10
Pradeep Kumar
Microprocessor vs. Microcontroller
Microprocessor Microcontroller
• CPU is stand-alone, RAM, • CPU, RAM, ROM, I/O and
ROM, I/O, timer are separate timer are all on a single chip
• designer can decide on the
• fix amount of on-chip ROM,
amount of ROM, RAM and I/O
ports.
RAM, I/O ports
• expansive • for applications in which cost,
• versatility
power and space are critical
• general-purpose • single-purpose

3/26/2010 11
Pradeep Kumar
Embedded System
• Embedded system means the processor is embedded into that
application.
• An embedded product uses a microprocessor or microcontroller to do
one task only.
• In an embedded system, there is only one application software that is
typically burned into ROM.
• Example:printer, keyboard, video game player

3/26/2010 12
Pradeep Kumar
CISC, RISC
• Microcontrollers with Harvard architecture are also
called "RISC microcontrollers". RISC stands for
Reduced Instruction Set Computer.

• Microcontrollers with von-Neumann's architecture


are called 'CISC microcontrollers'. Title CISC
stands for Complex Instruction Set Computer.

3/26/2010 13
Pradeep Kumar
3/26/2010 14
Pradeep Kumar
Real Time Control

Must be able to respond


predictably and in a
known amount of time

Environment cannot wait


for microcontroller to
respond.

3/26/2010 15
Pradeep Kumar
Common Microcontrollers

•Atmel •Motorola
•ARM •8-bit
•Intel •68HC05
•8-bit •68HC08
•8XC42 •68HC11
•MCS48 •16-bit
•MCS51 •68HC12
•8xC251 •68HC16
•16-bit •32-bit
•MCS96 •683xx
•MXS296 •Texas Instruments
•National Semiconductor •TMS370
•COP8 •MSP430
•Microchip •Zilog
•12-bit instruction PIC •Z8
•14-bit instruction PIC •Z86E02
•PIC16F84
•16-bit instruction PIC
•NEC

3/26/2010 16
Pradeep Kumar
Three criteria in Choosing a Microcontroller

1) meeting the computing needs of the task efficiently and cost


effectively
speed, the amount of ROM and RAM, the number of I/O
ports and timers, size, packaging, power consumption
easy to upgrade
cost per unit
2) availability of software development tools
assemblers, debuggers, C compilers, emulator, simulator,
technical support
3) wide availability and reliable sources of the microcontrollers.

3/26/2010 17
Pradeep Kumar
Embedded Systems

• Account for >99% of new


microprocessors
– Consumer electronics
– Vehicle control systems
– Medical equipment
– Sensor networks

3/26/2010 18
Pradeep Kumar
Definitions
• Embedded system – Almost any
special-purpose computer
– I.e. not a PC, workstation, or server box
• Microprocessor – regular CPU
• Microcontroller – small system on a
chip, contains extra logic to help talk to
the real world
– A/D and D/A
– PWM
– UARTs, SPI, CAN, USB, etc…

3/26/2010 19
Pradeep Kumar
Embedded Characteristics

• Close interaction with the physical world


– Often must operate in real time
• Constrained resources
– Memory
• SRAM, DRAM, flash, EEPROM, …
– Power
– CPU cycles

3/26/2010 20
Pradeep Kumar
More Characteristics

• Often there is no:


– Virtual memory
– Memory protection
– Hardware supported user-kernel boundary
– Secondary storage
• Hard to upgrade once deployed
• Cost sensitive
– Per-unit cost can dominate overall cost

3/26/2010 21
Pradeep Kumar
Important Difference
• Platform is known in advance
– This is good: App can be tailored very specifically to
platform
– This is bad: All this tailoring is hard work

3/26/2010 22
Pradeep Kumar
CPU Design Space

• Custom hardware
– May be no software at all

• 4-bit microcontroller
– Few bytes of RAM
– No OS
– Software all in assembly
– These are getting less popular

3/26/2010 23
Pradeep Kumar
CPU Design Space

• 8-bit microcontroller
– A few bytes to a few hundred KB of RAM
– At the small end software is in asm, at the high
end C, C++, Java
– Might run a home-grown OS, might run a
commercial RTOS
– Typically costs a few $$

3/26/2010 24
Pradeep Kumar
CPU Design Space

• 16- and 32-bit microcontrollers


– Few KB to many MB of RAM
– Usually runs an RTOS: vxWorks, WinCE,
QNX, ucLinux, …
– May or may not have caches
– Wide range of costs
• 32- or 64-bit microprocessor
– Basically a PC in a small package
– Runs Win XP, Linux, or whatever
– Relatively expensive

3/26/2010 25
Pradeep Kumar
Sources of Variation

• Power
1. Must run for years on a tiny battery (hearing
aid, pacemaker)
2. Unlimited power (ventilation control)
• Real-time
1. Great harm is done if deadlines are missed
(avionics)
2. Few time constraints (microwave)

3/26/2010 26
Pradeep Kumar
More Variation

• Importance
1. Device is safety critical (nuclear plant)
2. Failure is irrelevant (greeting card, electric
toothbrush)
• Upgradability
– Impossible to update (spacecraft, pacemaker)
– Easily updated (firmware in a PC network card)

3/26/2010 27
Pradeep Kumar
More Variation
• Cost sensitivity
1. A few % in extra costs will kill profitability (many
products)
2. Cost is largely irrelevant (military applications)

3/26/2010 28
Pradeep Kumar
Programming Languages

• Assembler
– No space overhead
– Good programmers write fast code
– Non-portable
– Hard to debug
• C
– Little space and time overhead
– Somewhat portable
– Good compilers exist

3/26/2010 29
Pradeep Kumar
More Languages

• C++
– Often used as a “better C”
– Low space and time overhead if used
carefully
• Java
– More portable
– Full Java requires lots of RAM
– J2ME popular on cell-phone types of
devices
– Bad for real-time!

3/26/2010 30
Pradeep Kumar
RTOS

• Low end: Not much more than a threads


library
• High end: Not much smaller than Linux
or WinXP
• Important:
– Predictability
– Reliability
– Efficiency

3/26/2010 31
Pradeep Kumar
What’s Hard?

• Concurrency is always hard


• Figuring out what’s going on
– No printf
– Debugging in Morse code no fun
– Better tools exist…
• Creating something that will work
forever
• Creating something very rapidly
• Fitting code into available RAM and
ROM

3/26/2010 32
Pradeep Kumar
Some Tradeoffs

• Advanced tools are expensive ($10,000+ per


developer) but can help a lot
• Buying an OS helps but usually results in less
efficient systems
• Complex software architecture provides rich
functionality but may be slow and hard to
debug

3/26/2010 33
Pradeep Kumar
Creating Embedded SW

1. Pick:
 Cheapest CPU that seems like it’ll work
 Appropriate language
 Appropriate OS
 Appropriate software architecture
2. Code… test… repeat

3/26/2010 34
Pradeep Kumar
Common features of Embedded Systems
•Is a microprocessor based system.
•Built into a device to control a function or a range of functions.
•Not designed to be programmed by the end-user (i.e. like a PC).
•Executes an in-built single program repeatedly
•Tight coupling between hardware and software.
•Designed to work in highly constrained environments.
•Low cost, low power, small, fast, etc.
•Reactive and real-time
•Continually reacts to changes in the system’s environment
•Must compute certain results in real-time without delay

3/26/2010 35
Pradeep Kumar
Why use Embedded Systems
•Replacements for discrete-logic based systems.
•To provide functional upgrades.
•To provide easy maintenance upgrades.
•Improve mechanical performance.
•Protection of intellectual property.
•Flexibility in design.
•Re-usable hardware designs / circuits.
•Replacements for analog circuits.

3/26/2010 36
Pradeep Kumar
An Embedded System Example

3/26/2010 37
Pradeep Kumar
Processor technology

3/26/2010 38
Pradeep Kumar
Processor technology

3/26/2010 39
Pradeep Kumar
General-purpose processors

3/26/2010 40
Pradeep Kumar
Single-purpose processors

3/26/2010 41
Pradeep Kumar
Application-specific processors

3/26/2010 42
Pradeep Kumar
IC technology
Three types of IC technologies

• Full-custom/VLSI
• Semi-custom ASIC (gate array and standard
cell)
• PLD (Programmable Logic Device)

3/26/2010 43
Pradeep Kumar
Full-custom/VLSI
• All layers are optimized for an embedded system’s
particular digital implementation
• Placing transistors
• Sizing transistors
• Routing wires
• Benefits
• Excellent performance, small size, low power
• Drawbacks
• High NRE cost (e.g., $300k), long time-to-market
• Effective only with large quantities
3/26/2010 44
Pradeep Kumar
Semi-custom
• Lower layers are fully or partially built
• Designers are left with routing of wires and maybe
placing some blocks
• Benefits
• Good performance, good size, less NRE cost than
a full-custom
• implementation (perhaps $10k to $100k)
• Drawbacks
• Still require weeks to months to develop – but
faster tools are emerging
• Examples
• CPLDs

3/26/2010 45
Pradeep Kumar
PLD (Programmable Logic Device)
• All layers already exist
• Designers can purchase an IC
• Connections on the IC are either created or destroyed
• to implement desired functionality
• Field-Programmable Gate Array (FPGA) very popular
• Benefits
• Low NRE costs, almost instant IC availability
• Drawbacks
• Bigger, expensive (perhaps $30 per unit), power
hungry, slower

3/26/2010 46
Pradeep Kumar

You might also like