Embedded System Chapter-2
Embedded System Chapter-2
AMSALU FENTIE
amsalufen3385@gmail.com
Chapter 2
Embedded Microcontrollers
SESSION OBJECTIVES:
The objective of this session is to impart students
for a solid understanding of
‣ Structure of a basic computer system
‣ The Core of the Embedded Systems
‣ Basic I/O devices and technologies
‣ Interrupts and Memories
Structure of a basic computer system
‣ A computer is one that can computes; specifically : programmable electronic device that can store,
retrieve, and process data [Merriam-Webster Dictionary].
‣ A computer is a machine that manipulates data according to a list of instructions [Wikipedia] .
Basic Components of Digital Computer
I/O CPU
Memory
Structure of a basic computer system
General-purpose microprocessor
• CPU for Computers
• No RAM, ROM, I/O on CPU chip itself
• Example:Intel’s x86, Motorola’s 680x0
HARDWARE
‣ It has Hardware: Processor, Timers, Interrupt controller, I/O Devices, Memories, Ports, etc.
‣ It has main Application Software: Which may perform concurrently the series of tasks or multiple
tasks.
‣ It has Real Time Operating System (RTOS): defines the way the system work. Which supervise the
application software. It sets the rules during the execution of the application program. A small scale
embedded system may not need an RTOS.
Embedded System General Block Diagram
COMPONENTS OF EMBEDDED SYSTEM
The core of the embedded system falls into any one of the following categories.
1. General Purpose and Domain Specific Processors
‣ Microprocessors
‣ Microcontrollers
‣ Digital Signal Processors
2. Programmable Logic Devices (PLDs)
3. Application Specific Integrated Circuits (ASICs)
4. Commercial off the shelf Components (COTS)
The Core of the Embedded Systems
1. GENERAL PURPOSE AND DOMAIN SPECIFIC PROCESSOR
‣ The processor may be microprocessor or a microcontroller or digital signal processor, depending on the domain and
application.
A. Microprocessor:
‣ A silicon chip representing a Central Processing Unit (CPU), which is capable of performing arithmetic as well as logical
operations according to a pre-defined set of Instructions, which is specific to the manufacturer
‣ In general the CPU contains the Arithmetic and Logic Unit (ALU), Control Unit and Working registers
‣ Microprocessor is a dependent unit and it requires the combination of other hardware like Memory, Timer Unit, and Interrupt
Controller etc. for proper functioning.
‣ Intel claims the credit for developing the first Microprocessor unit Intel 4004, a 4 bit processor which was released in Nov 1971
The Core of the Embedded Systems
1. GENERAL PURPOSE AND DOMAIN SPECIFIC PROCESSOR
B. Microcontroller:
‣ A highly integrated silicon chip containing a CPU, scratch pad RAM, Special and General purpose Register Arrays, On Chip
ROM/FLASH memory for program storage, Timer and Interrupt control units and dedicated I/O ports
‣ Microcontroller can be general purpose (like Intel 8051, designed for generic applications and domains) or application specific
(Like Automotive AVR from Atmel Corporation, designed specifically for automotive applications)
‣ Since a microcontroller contains all the necessary functional blocks for independent working, they found greater place in the
embedded domain in place of microprocessors.
‣ Microcontrollers are cheap, cost effective and are readily available in the market
‣ Powerful special purpose 8/16/32 bit microprocessors designed specifically to meet the computational demands and power constraints of
today's embedded audio, video, and communications applications
‣ Digital Signal Processors are 2 to 3 times faster than the general purpose microprocessors in signal processing applications
‣ DSPs implement algorithms in hardware which speeds up the execution whereas general purpose processors implement the algorithm in
firmware and the speed of execution depends primarily on the clock for the processors
‣ DSP can be viewed as a microchip designed for performing high speed computational operations for „addition‟, „subtraction‟,
„multiplication‟ and „division‟
‣ A typical Digital Signal Processor incorporates Program Memory, Data Memory, Computational Engine, and I/O key units
‣ Audio video signal processing, telecommunication and multimedia applications are typical examples where DSP is employed.
The Core of the Embedded Systems
1. GENERAL PURPOSE AND DOMAIN SPECIFIC PROCESSOR (Microprocessors, Microcontrollers, Digital Signal Processors)
RISC V/s CISC Processors/Controllers:
The Core of the Embedded Systems
1. GENERAL PURPOSE AND DOMAIN SPECIFIC PROCESSOR
Harvard V/s Von-Neumann Processor/Controller Architecture:
The Core of the Embedded Systems
2. Programmable Logic Devices (PLDs)
‣ Logic devices provide specific functions, including device-to-device interfacing, data communication, signal processing, data display, timing and
control operations, and almost every other function a system must perform.
‣ Logic devices can be classified into two broad categories - Fixed and Programmable. The circuits in a fixed logic device are permanent, they
perform one function or set of functions - once manufactured, they cannot be changed.
‣ Unlike digital logic constructed using discrete logic gates with fixed functions, a PLD has an undefined function at the time of manufacture.
‣ Designers can use inexpensive software tools to quickly develop, simulate, and test their logic designs in PLD based design. The design can be
quickly programmed into a device, and immediately tested in a live circuit.
‣ PLDs are based on re-writable memory technology and the device is reprogrammed to change the design.
The Core of the Embedded Systems
2. Programmable Logic Devices (PLDs)
‣ Field Programmable Gate Arrays (FPGAs) and Complex Programmable Logic Devices (CPLDs) are the two major types
of programmable logic devices.
FPGA:
‣ FPGA is an IC designed to be configured by a designer after manufacturing.
‣ The FPGA configuration is generally specified using a hardware description language (HDL)
‣ FPGAs offer the highest amount of logic density, the most features, and the highest performance.
‣ Logic gate is Medium to high density ranging from 1K to 500K system gates
‣ These advanced FPGA devices also offer features such as built-in hardwired processors, substantial amounts of
memory, clock management systems, and support for many of the latest, very fast device-to-device signaling
technologies.
‣ FPGAs are used in a wide variety of applications ranging from data processing and storage, to instrumentation,
telecommunications, and digital signal processing
The Core of the Embedded Systems
2. Programmable Logic Devices (PLDs)
‣ Field Programmable Gate Arrays (FPGAs) and Complex Programmable Logic Devices (CPLDs) are the two major types of
programmable logic devices.
CPLD:
‣ A complex programmable logic device (CPLD) is a logic device with completely
programmable AND/OR arrays.
‣ CPLDs, by contrast, offer much smaller amounts of logic - up to about 10,000 gates.
‣ CPLDs offer very predictable timing characteristics and are therefore ideal for critical control applications.
‣ The difference between FPGA and CPLD is that FPGA has a complex architecture, which is considered fine-grain,
whereas CPLD has a simpler architecture, which is considered a coarse grain.
‣ FPGA is based on RAM, it is volatile, suitable for complex applications, consumes more power
in comparison and more expensive.
‣ On the other hand, CPLD is designed with the help of EEPROM, and it has a simple architecture, suitable for simpler
applications, it is non-volatile, it tends to consume less power when compared to FPGA.
The Core of the Embedded Systems
2. Programmable Logic Devices (PLDs)
ADVANTAGES OF PLDs:
‣ PLDs offer customer much more flexibility during design cycle
‣ PLDSs do not require long lead times for prototype or production-the PLDs are already on a distributor‟s self and ready
for shipment
‣ PLDs allow customers to order just the number of parts required when they need them. allowing them to control
inventory.
‣ PLDs are reprogrammable even after a piece of equipment is shipped to a customer.
‣ The manufacturers able to add new features or upgrade the PLD based products that are in the field by uploading new
programming file.
The Core of the Embedded Systems
3. Application Specific Integrated Circuits (ASICs)
‣ A microchip designed to perform a specific or unique application. It is used as replacement to conventional general
purpose logic chips.
‣ ASIC integrates several functions into a single chip and thereby reduces the system development cost
‣ Most of the ASICs are proprietary products. As a single chip, ASIC consumes very small area in the total system and
thereby helps in the design of smaller systems with high capabilities/functionalities.
‣ ASICs can be pre-fabricated for a special application or it can be custom fabricated by using the components from a
re-usable „building block‟ library of components for a particular customer application
The Core of the Embedded Systems
3. Application Specific Integrated Circuits (ASICs)
‣ Fabrication of ASICs requires a non-refundable initial investment (Non Recurring Engineering (NRE) charges) for the
process technology and configuration expenses
‣ If the Non-Recurring Engineering Charges (NRE) is born by a third party and the Application Specific Integrated Circuit
(ASIC) is made openly available in the market, the ASIC is referred as Application Specific Standard Product (ASSP)
‣ The ASSP is marketed to multiple customers just as a general-purpose product , but to a smaller number of
customers since it is for a specific application.
‣ Some ASICs are proprietary products , the developers are not interested in revealing the internal details.
The Core of the Embedded Systems
4. Commercial off the shelf Components (COTS)
‣ A Commercial off-the-shelf (COTS) product is one which is used „as-is‟
‣ Describes goods that are used as-is.
‣ COTS products are designed in such a way to provide easy integration and interoperability with existing system
components
‣ Typical examples for the COTS hardware unit are Remote Controlled Toy Car control unit including the RF Circuitry
part, High performance, high frequency microwave electronics (2 to 200 GHz), High bandwidth analog-to-digital
converters, Devices and components for operation at very high temperatures, Electro-optic IR imaging arrays, UV/IR
Detectors etc
The Core of the Embedded Systems
4. Commercial off the shelf Components (COTS)
‣ A COTS component in turn contains a General Purpose Processor (GPP) or Application Specific Instruction Set
Processor (ASIP) or Application Specific Integrated Chip (ASIC)/Application Specific Standard Product (ASSP) or
Programmable Logic Device (PLD)
‣ The major advantage of using COTS is that they are readily available in the market, cheap and a developer can cut
down his/her development time to a great extend.
‣ There is no need to design the module yourself and write the firmware .
‣ The major drawback of using COTs component in embedded design is that the manufacturer may withdraw the
product or discontinue the production of the COTs at any time if rapid change in technology
‣ This problem adversely affect a commercial manufacturer of the embedded system which makes use of the specific
COTs
Basic I/O devices and technologies
The I/O Subsystem:
‣ The I/O subsystem of the embedded system facilitates the interaction of
the embedded system with external world.
‣ The sensors may not be directly interfaced to the Input ports, instead
they may be interfaced through signal conditioning and translating
systems like ADC.
Basic I/O devices and technologies
Sensors & Actuators:
‣ Embedded system is in constant interaction with the real world.
‣ LED can be used as an indicator for the status of various signals or situations.
GND
‣ Typical examples are indicating the presence of power conditions like „Device ON‟, „Battery low‟ or „Charging of battery‟
for a battery operated handheld embedded devices
‣ For proper functioning of the LED, the anode of it should be connected to +ve terminal of the supply voltage and cathode to
the –ve terminal of supply voltage
‣ The current flowing through the LED must limited to a value below the maximum current that it can conduct.
‣ A resister is used in series between the power supply and the resistor to limit the current through the LED
Basic I/O devices and technologies
2. I/O Devices – 7-Segment LED Display:
‣ The 7 – segment LED display is an output device for displaying alpha numeric characters
‣ It contains 8 light-emitting diode (LED) segments arranged in a special form. Out of the 8 LED segments, 7 are used for displaying alpha numeric
characters
‣ The LED segments are named A to G and the decimal point LED segment is named as DP
‣ The LED Segments A to G and DP should be lit accordingly to display numbers and characters
Basic I/O devices and technologies
3. I/O Devices – Stepper Motor:
‣ Stepper motor is an electro mechanical device which generates discrete displacement (motion) in response to dc electrical signals
‣ It differs from the normal dc motor in its operation. The dc motor produces continuous rotation on applying dc voltage whereas a stepper motor
produces discrete rotation in response to the dc voltage applied to it
‣ Stepper motors are widely used in industrial embedded applications, consumer electronic products and robotics control systems
‣ The paper feed mechanism of a printer/fax makes use of stepper motors for its functioning.
Basic I/O devices and technologies
4. The I/O Subsystem – I/O Devices -Piezo Buzzer:
‣ It is a piezoelectric device for generating audio indications in embedded applications.
‣ A Piezo buzzer contains a piezoelectric diaphragm which produces audible sound in response to the voltage applied to it.
‣ Piezoelectric buzzers are available in two types
‣ 1. Self-driving 2. External driving
‣ Self-driving contains are the necessary components to generate sound at a predefined tone.
‣ External driving piezo Buzzers supports the generation of different tones.
‣ The tone can be varied by applying a variable pulse train to the piezoelectric buzzer.
‣ A Piezo Buzzer can be directly interfaced to the port pin of the processor/Controller.
Basic I/O devices and technologies
7. The I/O Subsystem – I/O Devices – Push button switch:
‣ Push Button switch is an input device.
‣ Push button switch comes in two configurations, namely „Push to Make‟ and „Push to Break‟
‣ The switch is normally in the open state and it makes a circuit contact when it is pushed or pressed in the „Push to Make‟
configuration.
‣ In the „Push to Break‟ configuration, the switch is normally in the closed
state and it breaks the circuit contact when it is pushed or pressed
‣ The push button stays in the „closed‟ (For Push to Make type) or „open‟ (For Push
to Break type) state as long as it is kept in the pushed state and it breaks/makes the
circuit connection when it is released.
Interrupts
‣ Fundamental concept in computation
‣ Interrupt execution of a program to “handle” an event
‣ Don’t have to rely on program relinquishing control
‣ Can code program without worrying about others
‣ Issues
‣ What can interrupt and when?
‣ Where is the code that knows what to do?
‣ How long does it take to handle interruption?
‣ Can an interruption be, in turn, interrupted?
‣ How does the interrupt handling code communicate its results?
‣ How is data shared between interrupt handlers and programs?
Interrupts
‣ Reaction to something in I/O (human, comm link)
‣ Usually asynchronous to processor activities
‣ “interrupt handler” or “interrupt service routine” (ISR) invoked to take care of condition
causing interrupt
‣ Change value of internal variable (count)
‣ Read a data value (sensor, receive)
‣ Write a data value (actuator, send)
‣ Discussion questions:
‣ Assume critical functionality is provided by software
‣ What are the worst potential hazards?
‣ What is a likely acceptable failure rate?
‣ Who is responsible for ensuring safe operation within design flow?
Interrupts
Saving and Restoring Context
‣ Where to find ISR code?
‣ Different interrupts have separate ISRs
‣ Who does dispatching?
‣ Direct
‣ Different address for each interrupt type
‣ Supported directly by processor architecture
‣ Indirect
‣ One top-level ISR
‣ Switch statement on interrupt type
‣ A mix of these two extremes?
‣ How much context to save?
‣ Registers, flags, program counter, etc.
‣ Save all or part?
‣ Agreement needed between ISR and program
‣ Where should it be saved?
‣ Stack, special memory locations, shadow registers, etc.
‣ How much room will be needed on the stack?
‣ Nested interrupts may make stack reach its limit – what then?
‣ Restore context when ISR completes
Interrupts
Ignoring Interrupts
‣ Can interrupts be ignored?
‣ It depends on the cause of the interrupt
‣ No, for nuclear power plant temperature warning
‣ Yes, for keypad on cell phone (human timescale is long)
‣ When servicing another interrupt
‣ Ignore others until done
‣ Can’t take too long – keep ISRs as short as possible
‣ Just do a quick count, or read, or write – not a long computation
‣ Interrupt disabling
‣ Will ignored interrupt “stick”?
‣ Rising edge sets a flip-flop
‣ Or will it be gone when you get to it?
‣ Level changes again and its as if it never happened
‣ Don’t forget to re-enable
Interrupts
Prioritizing Interrupts
‣ When multiple interrupts happen simultaneously
‣ Which is serviced first?
‣ Fixed or flexible priority?
‣ Priority interrupts
‣ Higher priority can interrupt
‣ Lower priority can’t
‣ Maskable interrupts
‣ “don’t bother me with that right now”
‣ Not all interrupts are maskable, some are non-maskable
Memory
‣ Memory is an important part of an embedded system. The memory used
in embedded system can be either Program Storage Memory (ROM) or
Data memory (RAM)
‣ Certain Embedded processors/controllers contain built in program
memory and data memory and this memory is known as on-chip
memory
‣ Certain Embedded processors/controllers do not contain sufficient
memory inside the chip and requires external memory called off-chip
memory or external memory.
Memory
Memory – Program Storage Memory:
‣ Stores the program instructions
‣ Retains its contents even after the power to it is turned off. It is generally known as Non volatile
storage memory
‣ Depending on the fabrication, erasing and programming techniques they are classified into
Memory
1. Masked ROM (MROM):
‣ One-time programmable memory.
‣ Uses hardwired technology for storing data.
‣ The device is factory programmed by masking and metallization process according to the data
provided by the end user.
‣ The primary advantage of MROM is low cost for high volume production.
‣ MROM is the least expensive type of solid state memory.
‣ The limitation with MROM based firmware storage is the inability to modify the device firmware against
firmware upgrades.
‣ The MROM is permanent in bit storage, it is not possible to alter the bit information.
Memory
2. Programmable Read Only Memory (PROM) / (OTP) :
‣ It is not pre-programmed by the manufacturer
‣ The end user is responsible for Programming these devices.
‣ PROM/OTP has nichrome or polysilicon wires arranged in a matrix, these wires can be functionally
viewed as fuses.
‣ It is programmed by a PROM programmer which selectively burns the fuses according to the bit
pattern to be stored.
‣ OTP is widely used for commercial production of embedded systems whose proto-typed versions are
proven and the code is finalized.
‣ It is a low cost solution for commercial production.
‣ OTPs cannot be reprogrammed.
Memory
3. Erasable Programmable Read Only Memory (EPROM):
‣ Erasable Programmable Read Only (EPROM) memory gives the flexibility to re-program the same
chip.
‣ EPROM stores the bit information by charging the floating gate of an FET
‣ Bit information is stored by using an EPROM Programmer, which applies high voltage to charge the
floating gate
‣ EPROM contains a quartz crystal window for erasing the stored information. If the window is exposed
to Ultra violet rays for a fixed duration, the entire memory will be erased
‣ Even though the EPROM chip is flexible in terms of re-programmability, it needs to be taken out of the
circuit board and needs to be put in a UV eraser device for 20 to 30 minutes
Memory
4. Electrically Erasable Programmable Read Only Memory (EEPROM):
‣ Erasable Programmable Read Only (EPROM) memory gives the flexibility to re-program the same chip
using electrical signals
‣ The information contained in the EEPROM memory can be altered by using electrical signals at the
register/Byte level
‣ They can be erased and reprogrammed within the circuit
‣ These chips include a chip erase mode and in this mode they can be erased in a few milliseconds
‣ It provides greater flexibility for system design
‣ The only limitation is their capacity is limited when compared with the standard ROM (A few kilobytes).
Memory
5. Program Storage Memory – FLASH
‣ FLASH memory is a variation of EEPROM technology.
‣ FALSH is the latest ROM technology and is the most popular ROM technology used in today‟s embedded
designs
‣ It combines the re-programmability of EEPROM and the high capacity of standard ROMs
‣ FLASH memory is organized as sectors (blocks) or pages
‣ FLASH memory stores information in an array of floating gate MOSFET transistors
‣ The erasing of memory can be done at sector level or page level without affecting the other sectors
or pages
‣ Each sector/page should be erased before re-programming
Memory
Read-Write Memory/Random Access Memory (RAM)
‣ RAM is the data memory or working memory of the controller/processor
‣ RAM is volatile, meaning when the power is turned off, all the contents are destroyed
‣ RAM is a direct access memory, meaning we can access the desired memory location directly without
the need for traversing through the entire memory locations to reach the desired memory position
(i.e. Random Access of memory location)
Memory
Read-Write Memory/Random Access Memory (RAM)
‣ 1. Static RAM (SRAM):
‣ Static RAM stores data in the form of Voltage.
‣ They are made up of flip-flops
‣ In typical implementation, an SRAM cell (bit) is realized using 6 transistors (or 6 MOSFETs).
‣ Four of the transistors are used for building the latch (flip-flop) part of the memory cell and 2 for controlling the access.
‣ Static RAM is the fastest form of RAM available.
‣ SRAM is fast in operation due to its resistive networking and switching capabilities
‣ 2. Dynamic RAM (DRAM)
‣ Dynamic RAM stores data in the form of charge. They are made up of MOS transistor gates.
‣ The advantages of DRAM are its high density and low cost compared to SRAM.
‣ The disadvantage is that since the information is stored as charge it gets leaked off with time and to prevent this they need to be
refreshed periodically.
‣ Special circuits called DRAM controllers are used for the refreshing operation. The refresh operation is done periodically in
milliseconds interval.
Memory
Read-Write Memory/Random Access Memory (RAM)