Embedded_Class-Jan-2024_ver1
Embedded_Class-Jan-2024_ver1
CO4: Use and design real time operating system for various
applications
Tentative Course Outline
■ Introduction to Embedded systems, Sensors and Actuators, Embedded
Processors (8 hours)
■ Introduction to 8-bit and 16-bit microcontroller: 8051 family of microcontroller,
architecture, memory organization, special function registers, timer counter,
serial interface, interrupt organization, instruction sets and programming,
instruction timing and interfacing, practical applications, introduction to 16-bit
microcontrollers. (12 hours)
■ Embedded Memory, Devices and Buses for device networks, I2C Bus, SPI Bus,
PCI bus, (8 hours)
■ Device drivers and Interrupt servicing mechanism, Programming concepts and
Embedded programming in C and C++, Program modeling concepts in single and
multiprocessor- development Process, Real time operating system. (8 hours)
Reference Textbooks:
■ M.A. Mazdi & J.G. Mazdi, The 8051 Microcontroller and Embedded System, Pearson
Education India , 2013
■ S.Heath, Embedded Systems Design, Elsevier , 2009
■ Frank Vahid and Tony Givargis, Embedded System Design: A Unified
Hardware/Software Approach, Wiley
7
GENERAL-PURPOSE COMPUTERS
• Resources can be
implemented on a single
IC.
• Include a variety of
peripherals (timers,
analog-to-digital
converters, digital-to-
analog converters, serial
interfaces).
■ What is the motivation for building an embedded system? Macroscopic view on a device level
– Better performance
– More functions and features
– Lower cost e.g. through automation Embedded
Input from Computer
Software Output to
– More dependable Environment Environment
Hardware
– Lower power
Register banks
ALU
Microprocessor
From a Processor to an Embedded System
• Microcontroller (microcontroller unit, MCU)
– Typically has a single processor core
– Has memory blocks, digital IOs, analog IOs, and other basic peripherals
– Typically used for basic control purpose, such as embedded applications
System Bus
Microcontroller
From a Processor to an Embedded System
• Embedded system
– Typically implemented using MCUs
– Often integrated into a larger mechanical or electrical system
– May have real-time constraints
Embedded
System
Attributes of Embedded Systems
• Interfacing with larger systems and environments
– Analog signals for reading sensors
• Typically use a voltage to represent a physical value
– Power electronics for driving motors, solenoids
– Digital interfaces for communicating with other digital devices
• Simple – switches
• Complex – displays
• Diagnostics
– Help service personnel determine problems quickly
Field Applications of Embedded Systems
• Closed-loop control system
– Monitor and (pre)process a system state, adjust an output to maintain a desired set point (temperature, speed,
direction, etc.)
– Remove noise, select desired signal features
• Sequencing
– Step through different stages based on environment and system
Input:
Inputs: Wheel rotation
Functions:
- Wheel rotation indicator Mode key
- Speed measurement
- Mode key
- Distance measurement
Output:
Constraints: - Liquid crystal display
- Size
- Cost Use low-performance
- Power and energy microcontroller: Output:
- 9-bit, 10 MIPS Display speed and
- Weight distance
Example: Gasoline Automobile Engine Control Unit
Functions:
- Fuel injection Many inputs and outputs:
- Air intake setting - Discrete sensors and
- Spark timing actuators
- Exhaust gas circulation - Network interface to
- Electronic throttle control rest of car
- Knock control
Constraints:
Use high-performance
- Reliability in harsh microcontroller:
environment
- E.g. 32-bit, 3 MB flash
- Cost memory, 50-300 MHz
- Size
Introduction to the Internet of Things (IoT)
• IoT generally refers to a world in which a large range of objects are
addressable via a network
Price
• Embedded chips are becoming:
– Cheaper
– Smaller
– Lower power
• Energy harvesting
• Programming language
– Programmed in the C language rather than Java (resulting in smaller and faster code – less expensive
MCU)
– Some performance-critical code may be in assembly language
• Operating system
– Typically no OS, but instead a simple scheduler
– If OS is used, it is likely to be a lean RTOS
EMBEDDED COMPUTERS
Summary: Building Embedded Systems using MCUs
• In most embedded systems, MCUs are the best solution as they offer:
– Low development and manufacturing cost
– Easy porting and updating
– Light footprint
– Relatively low power consumption
– Satisfactory performance for low-end products
In the upcoming labs, we will learn some fundamentals of developing for embedded
systems. This will be achieved using an easy-to-start MCU design suite – the Mbed
platform.
SOME BASICS OF COMPUTERS
• Multipurpose programmable machine that reads binary
instructions from its memory, accepts binary data as input,
processes data according to those instructions and provides
result as output
• It is a programmable device, made up of hardware and
software.
• The various components of the computer are called hardware
• A set of instructions written for the computer to solve a
specific task is called a program and a collection of
programs is called software.
THE COMPUTER HARDWARE
• Central Processing Unit (CPU), which
acts as the computer’s brain.
• Input unit, through which program
and data can be entered into the
computer.
• Output unit, from which the results
of computation can be displayed or
viewed
• Memory, in which the programs and
data are stored. Figure shows a
simple block diagram of a computer
The processor communicates with the memory and input/output devices using three sets of
lines called buses—address bus, data bus, and control bus. The bus is a communication path
between the processor and the peripherals.
CENTRAL PROCESSING UNIT
The Central Processing Unit (CPU), which is also called the processor, can be further divided
into three major parts:
– Register File:consists of one or more registers. A register is a storage location in the CPU.
• It is used to hold data and/or a memory address during execution of an instruction.
– Arithmetic Logic Unit: is the computer’s numerical calculator and logical operation evaluator.
• Under command from the control unit, it receives information from the memory.
• It analyses and rearranges the data and carries out the sequence of arithmetic and logical
operations to accomplish the desired job.
– Control Unit: It controls and coordinates all the activities in the computer.
• It decodes the instructions and generates the necessary control signals for the execution of
instructions.
• The system clock synchronizes the activities of the control unit.
All CPU activities are measured by clock cycles. The control unit also contains a register called the
Program Counter (PC), which contains the memory address of the next instruction to be executed.
MEMORY
• The memory is a place where programs
and data are stored.
• It is a storage device that stores
instructions, data and intermediate
results and provides that information to
the other units of the computer.
• A computer contains Semiconductor,
Magnetic or Optical memory.
• The classification of semiconductor
memory into two major types— Random
Access Memory (RAM) and Read Only
Memory (ROM)
RANDOM ACCESS MEMORY (RAM)
• RAM, popularly known as user memory, is used to store user program and
data.
• It is also known as read/write (R/W) memory because it is equivalent to a
group of addressable registers—you can either read the stored contents of
memory location or write new contents into the memory location.
• The R/W memory is volatile, which means that when the power is turned off,
the contents are lost.
• To communicate with the memory, the CPU should be able to
Select the memory chip
Select the register in the memory chip
Read from or write into the register
MODEL OF A TYPICAL READ/WRITE MEMORY
• Chip select as CS, write signal as WR and read signal as
RD — these are active low signals indicated by the bar.
• They help to select RAM and perform write and read
operations.
• A flip-flop that can store one binary bit is called a
memory cell.
• If more than one flip flop are grouped together, it is
called a register
• In Fig. (b), the random access memory contains eight
registers; each register contains eight memory cells and
are arranged in a sequence
• Here, the size of the memory is 8 x 8 bits or 8 bytes
• To write into or read from any one of the registers, a
specific register has to be selected.
• This is achieved by using a 3 to 8 decoder. Three address
lines A2, A1 and A0 are required for the decoder
• These input lines can have eight different bits
combination (000, 001, 010, 011, 100, 101, 110, 111),
and each combination can select one of the registers.
RAM TYPES
• Dynamic memory uses one MOS transistor and one capacitor to
store one bit of information in the form of electrical charge.
• Static memories are designed to store binary information
without needing periodic refreshes and require one flip-flop to
store one bit of information (four to six transistors are needed to
store one bit of information).
• Hence, it requires the use of more complicated circuitry for each
bit.
• The advantage of dynamic memory is that a large number of
transistor gates can be placed on the memory chip; thus it has
high density and is faster than static memory.
• The disadvantage is that the charge (bit information) leaks and
hence, it requires periodic refreshing, i.e. information needs to
be read and written again after every few milliseconds.
RAM TYPES
• NVRAM: Non-volatile RAM is a random access memory with battery backup. It contains static RAM based
memory and a minute battery for providing supply to the memory in the absence of external power supply.
• The memory and battery are packed together in a single package.
• NVRAM is used for the nonvolatile storage of results of operations or for setting up of flags, etc. The life span
of NVRAM is expected to be around 10 years. DS1744 from Maxim/Dallas is an example for 32KB NVRAM
Read Only Memory(ROM)
• The read only memory is the simplest kind of memory.
• It is equivalent to a group of registers and each store a word
permanently.
• It is a nonvolatile memory which means that it retains the
stored information even if the power is turned off.
• By applying control signal, we can read the contents of any
memory location and if the processor attempts to write data to
a ROM location, ROM will not accept the data.
THE MODEL OF A TYPICAL READ ONLY MEMORY
• Programmed Read Only Memory (PROM) PROM is a type of read only memory that
can be programmed in the field using a device called PROM programmer and here
the programming is permanent. In other words, the stored contents cannot be
erased.
• Erasable memory includes three types of memory—EPROM, EEPROM, and Flash
memory.
PROM
• Erasable Programmable Read Only Memory (EPROM) The information stored in this
memory is semi-permanent.
• Data is stored with PROM programmer. Subsequently, all the information can be
erased by exposing the memory to ultraviolet light through a quartz window
installed on top of the EPROM chip. It can then be reprogrammed.
• Electrically Erasable Programmable Read Only Memory (EEPROM) EEPROM is a
type of nonvolatile memory that can be erased by electrical signals and
reprogrammed.
• EEPROM allows the user to selectively erase a single location, a row, or the whole
chip. This feature requires a complicated programming circuitry. Because of this,
EEPROM cannot achieve the density of EPROM technology.
• Flash Memory Flash memory was invented to incorporate the advantages and avoid
the drawback of EPROM and EEPROM technologies. It achieves the density of
EPROM, and can be programmed and erased electrically like EEPROM.
• However, it does not allow individual location to be erased, but the user can erase
the whole chip
Input Devices & Output Devices
• Input Devices
– The input device transfers data and instructions in binary form, from the
outside world to the CPU.
– The input device, also known as a peripheral is the means through which the
user communicates data to the computer.
– The user can enter instructions and data through an input device like a
keyboard.
– Analog to digital converters, and switches can also be used as input devices.
• Output Devices
– It receives the stored result from the memory or from the CPU, converts it into
a form that the user can understand and transfers this data to the outside
world.
– Monitor, Liquid Crystal Display (LCD), seven segment display, printer, etc. are
used as output devices.
WHAT IS A MICROPROCESSOR?
• In the late 1960s, the CPU was designed with discrete logic gates.
• As semiconductor technology advanced, it was possible to fabricate more than thousand gates on a
single silicon chip—this came to be known as Large-scale integration.
• As technology moved from Small-scale Integration to Large-scale Integration, it became possible to
build a whole CPU with its related timing functions on a single chip. This came to be known as
Microprocessor.
• A computer that is designed using a microprocessor as its CPU, is known as a Microcomputer.
• Intel Corporation announced the first 4 bit microprocessor 4004 in 1971.
• The number of bits refer to the number of binary digits that the microprocessor can manipulate in one
operation.
• Intel developed an 8 bit microprocessor 8080 in 1974. The 8085 microprocessor that followed 8080,
had few more additional features compared to 8080 architecture.
• The instruction sets of 8080 and 8085 are practically the same. The 8085 microprocessor has an 8 bit
data bus, so it can read data from or write data to memory or I/O ports only 8 bit at a time.
• It has a 16 bit address bus, so it can address any one of 2^16 or 65,536 memory locations. It operates
with 3MHz clock signal
MICROPROCESSOR
• The limitations of 8085 microprocessor are
– It operates with low speed
– Less powerful addressing mode and instruction set
– Limited number of 8 bit general purpose registers
– Low memory (64 Kbytes) addressing capability
• Because of these limitations, Intel Corporation announced the first 16 bit
microprocessor 8086 in 1978.
• The 8086 microprocessor has 16 bit data bus and 20 bit address bus. It can read or
write data to memory or I/O ports either 16 bit or 8 bit at a time and it can address
any one of 1,048,576 (2^20) memory locations.
• Subsequently, Intel developed 16 bit processors such as 8088, 80186, 80188 and
80286
• 80186 and 80188 are an improved version of 8086 and 8088 respectively.
MICROPROCESSORS
• Both the processors have a few additional instruction sets compared to 8086 instruction set.
• 80286 is an improved version of 80186. It is designed to be used as CPU in multitasking computers.
• It operates in real and virtual addressing mode.
• Later, in 1985, Intel developed 32 bit microprocessor 80386.
• The 80386 can address directly up to 4 gigabytes of memory. Intel’s second generation of 32 bit
microprocessor 80486 was available in the year 1989.
• Intel introduced a third generation 80586 (Pentium processor) in 1998. Motorola, Zilog, etc. also
developed 8 bit, 16 bit and 32 bit Microprocessors. Microprocessors have been widely used after their
invention.
• Intel, AMD, Freescale, GLOBALFOUNDRIES, TI, Cyrix, NVIDIA, Qualcomm, MediaTek, etc. are the key
players in the processor market.
– However, the following limitations of the microprocessor led to the invention of the microcontroller.
• A microprocessor requires external memory to execute a program.
• A microprocessor cannot be directly interfaced with I/O devices.
• Peripheral chips are needed to interface I/O devices
Intel® Atom™ Processor
Intel® Core™2 Processor || Intel® Core™ Processor
Intel® Pentium® D Processor || Intel® Pentium® M
Processor
Intel® Itanium® Processor Family || Intel® Xeon™
Processor
Intel ® Pentium® 4 Processor || Intel® Pentium® III
Processor
Intel® Celeron® Processor || Intel® Pentium® III Xeon™
Processor
Intel® Pentium® II Xeon™ Processor || Intel®
Pentium® II Processor
Intel® Pentium® Pro Processor || Intel® Pentium
Processor
Intel486™ Processors and Earlier
WHAT IS A MICROCONTROLLER?
• As technology moved from LSI to VLSI, it became possible to build the
microprocessor, memory and I/O devices on a single chip. This came to be
known as the ‘Microcontroller.’
• A microcontroller contains a microprocessor and also one or more of the
following components.
– Memory
– Analog to Digital (A/D) converter
– Digital to Analog (D/A) converter
– Parallel I/O interface
– Serial I/O interface
– Timers and Counters
Microcontroller vs. General-purpose Microprocessor
Microcontroller vs. General-Purpose Microprocessor
Microcontrollers for Embedded Systems
HISTORICAL NOTE
• Texas Instrument’s TMS 1000 is considered as the world’s first microcontroller.
• We cannot say it as a fully functional microcontroller when we compare it with modern
microcontrollers.
• TI followed Intel’s 4004/4040, 4 bit processor design and added some amount of RAM, program
storage memory (ROM) and I/O support on a single chip, there by eliminated the requirement of
multiple hardware chips for self-functioning.
• Provision to add custom instructions to the CPU was another innovative feature of TMS 1000. TMS
1000 was released in 1974.
• In 1977 Intel entered the microcontroller market with a family of controllers coming under one
umbrella named MCS- 48 family.
• The processors came under this family were 8038HL, 8039HL, 8040AHL, 8048H, 8049H, and 8050AH.
Intel 8048 is recognized as Intel’s first microcontroller and it was the most prominent member in the
MCS- 48 family.
• It was used in the original IBM PC keyboard.
• The inspiration behind 8048 was Fairchild’s F8 microprocessor and Intel’s goal of developing a low
cost and small size processor.
• The design of 8048 adopted a true Harvard architecture where program and data memory shared the
same address bus and is differentiated by the related control signals
HISTORICAL NOTE
• Intel came out with its most fruitful design in the 8bit microcontroller
domain–the 8051 family and its derivatives.
• It is the most popular and powerful 8bit microcontroller ever built.
• It was developed in the 1980s and was put under the family MCS-51.
Almost 75% of the microcontrollers used in the embedded domain were
8051 family based controllers during the 1980–90s.
• 8051 processor cores are used in more than 100 devices by more than 20
independent manufacturers like Maxim, NXP, Atmel, etc. under the license
from Intel.
• Due to the low cost, wide availability, memory efficient instruction set,
mature development tools and Boolean processing (bit manipulation
operation) capability, 8051 family derivative microcontrollers are much
used in high-volume consumer electronic devices, entertainment industry
and other gadgets where cost-cutting is essential.
Historical Note
• Another important family of microcontrollers used in industrial control and
embedded applications is the PIC family micro controllers from Microchip
Technologies.
• It is a high performance RISC microcontroller complementing the CISC (Complex
Instruction Set Computing) features of 8051.
• Some embedded system applications require only 8bit controllers whereas some
embedded applications requiring superior performance and computational needs
demand 16/32bit microcontrollers.
• Infineon, Freescale, Philips, Atmel, Maxim, Microchip etc. are the key suppliers of
16bit microcontrollers.
• Philips tried to extend the 8051 family microcontrollers to use for 16bit applications
by developing the Philips XA (eXtended Architecture) microcontroller series
Historical Note
• 8bit microcontrollers are commonly used in embedded systems where the processing
power is not a big constraint.
• As mentioned earlier, more than 20 companies are producing different flavors of the 8051
family microcontroller.
• They try to add more and more functionalities like built in SPI, I2C serial buses, USB
controller, ADC, Networking capability, etc.
• So the competitive market is driving towards a one-stop solution chip in microcontroller
domain.
• High processing speed microcontroller families like ARM Cortex M Series are also available
in the market, which provides solution to applications requiring hardware acceleration and
high processing capability.
• Currently the ARM is the most widely used microcontroller in the world and is targeted for
the high end of the embedded market as well as the PC and tablet market.
Key Players in The Microcontroller Market
• Freescale, Renesas, Zilog, Cypress (Spansion), Infi neon, ST Micro Electronics,
EPSON, Texas Instruments, Toshiba, NXP, Microchip, Analog Devices, Daewoo, Intel,
Maxim, Sharp, Silicon Laboratories, HOLTEK, LAPIS, CYROD, Atmel, etc.
• Atmel has got special significance. They are the manufacturers of a variety of Flash
memory based microcontrollers.
• They also provide In-System Programmability for the controller. The Flash memory
technique helps in fast reprogramming of the chip and there by reduces the product
development time.
• Atmel also provides another special family of microcontroller called AVR, an 8bit RISC
Flash microcontroller, fast enough to execute powerful instructions in a single clock
cycle and provide the latitude you need to optimize power consumption
VON NEUMANN (PRINCETON) AND HARVARD ARCHITECTURE
• Microprocessors/controllers based on the Von-Neumann architecture
shares a single common bus for fetching both instructions and data.
• Program instructions and data are stored in a common main memory.
• Von-Neumann architecture based processors/controllers first fetch an
instruction and then fetch the data to support the instruction from code
memory.
• The two separate fetches slows down the controller’s operation.
• The Von Neumann Architecture is named after the mathematician and
computer scientist John Von Neumann.
• Von-Neumann architecture is also referred as Princeton architecture,
since it was developed by the Princeton University.
• The advantage of Von Neumann architecture is simple design of
microcontroller chip because only one memory is to be implemented
which in turn reduces required hardware.
• The disadvantage is slower execution of a program
• Example: Motorola 68HC11 microcontroller
HARVARD ARCHITECTURE
• Microprocessors/controllers based on the Harvard architecture will
have separate data bus and instruction bus.
• This allows the data transfer and program fetching to occur
simultaneously on both buses.
• With Harvard architecture, the data memory can be read and
written while the program memory is being accessed.
• These separated data memory and code memory buses allow one
instruction to execute while the next instruction is fetched
(“prefetching”).
• The advantage of a Harvard architecture microcontroller is that it is
faster for a given circuit complexity because it offers greater amount
of parallelism.
• The disadvantage is that it requires more hardware, because two
sets of buses and memory blocks are required.
• MCS 51 (8051 family) and PIC microcontrollers are based on
Harvard architecture
RISC AND CISC MACHINES
• The term RISC stands for Reduced Instruction Set Computing. As the name implies, all
RISC processors/controllers possess lesser number of instructions, typically in the range
of 30 to 40.
• CISC stands for Complex Instruction Set Computing-the instruction set is complex and
instructions are high in number
• From a programmers point of view RISC processors are comfortable since s/he needs to
learn only a few instructions,
• whereas for a CISC processor s/he needs to learn more number of instructions and
should understand the context of usage of each instruction (This scenario is explained
on the basis of a programmer following Assembly Language coding)
• For a programmer following C coding it doesn’t matter since the cross-compiler is
responsible for the conversion of the high level language instructions to machine
dependent code).
• Microchip PIC16F87X , Atmel AVR microcontroller are
• an example for a RISC processor and its instruction set contains only 32 instructions.
• The original version of 8051 microcontroller (e.g. AT89C51) is a CISC controller and its
instruction set contains 255 instructions
RISC AND CISC MACHINES
Word Length: 4, 8, 16, 32, 64-bit Microcontrollers
• The number of bits in a binary pattern that a microcontroller
understands and processes at a time is called word length, i.e.
number of bits on which ALU can perform operations at a time
• Microcontrollers are classified according to their word length, it
ranges from 4 or 8 bits for small systems, 16 bits for medium
systems and 32 or 64 bits for high-speed large systems.
• Bus width, internal bus width, register width and bits are the
different terms used interchangeably for the term word length
Currently Available Microcontrollers
• 32-bit
ARM, AVR32 (Atmel), ColdFire (Freescale), MIPS32,
PIC32 (Microchip), PowerPC, TriCore (Infineon), SuperH
• 16-bit
MSP430 (TI), HCS12 (Freescale), PIC24 (Microchip), dsPIC
(Microchip)
• 8-bit
8051, AVR (Atmel), HCS08 (Freescale), PIC16, PIC18
Microprocessor vs Microcontroller
Microprocessor Microcontroller
A silicon chip representing a central processing unit (CPU), A microcontroller is a highly integrated chip that
which is capable of performing arithmetic as well as logical contains a CPU, scratchpad RAM, special and
operations according to a predefined set of instructions general purpose register arrays, on chip
ROM/FLASH memory for program storage, timer
and interrupt control units and dedicated I/O ports
It is a dependent unit. It requires the combination of other It is a self-contained unit and it doesn’t require
chips like timers, program and data memory chips, interrupt external interrupt controller, timer, UART, etc. for its
controllers, etc. for functioning functioning
Most of the time general purpose in design and operation Mostly application-oriented or domain-specific
Doesn’t contain a built in I/O port. The I/O port functionality Most of the processors contain multiple built-in I/O
needs to be implemented with the help of external ports which can be operated as a single 8 or 16 or
programmable peripheral interface chips like 8255 32 bit port or as individual port pins
Targeted for high end market where performance is Targeted for embedded market where performance
important is not so critical (At present this demarcation is
invalid)
Limited power saving options compared to microcontrollers Includes lot of power saving features
Criteria for Choosing a Microcontroller
• Meeting the computing needs of the task at hand efficiently and cost
effectively
– Speed, What is the highest speed that the microcontroller
supports?
– Packaging , 40-pin DIP (dual inline package) or a QFP (quad flat
package) or other
– Power consumption - critical for battery-powered products.
ASIC high ($500K/ very low hard tiny – 1 die very low low extremely fast
mask set)
Programmable logic – low to mid mid easy small low medium to high very fast
FPGA, PLD
Microprocessor + memory low to mid mid easy small to medium low to moderate medium moderate
Software Running on
+ peripherals
Generic Hardware
Microcontroller (int. low mid to low easy small low medium slow to moderate
memory & peripherals)
Embedded PC low high easy medium moderate to high medium to high fast