ES Lecture Till 16 Feb
ES Lecture Till 16 Feb
1
Today
Course outline
CLOs & PLOs Mapping
Introduction to Real-Time Operating Systems & Embedded
Systems
2
Organization & Evaluation
Lect.: Mon: 08:00am – 09:00am
Thu: 08:00am – 09:00am
Evaluation: Written
Quiz-I
Assignment-I
Mid Term
Quiz-II
Assignment-II
Final Term (20% Mid Term Course)
3
Lab Organization & Evaluation
Lab:
Thu: 09:00am – 12:00pm (ECD Lab)
Evaluation:
Sessional (Lab Performance, Tasks)
Lab Report / Viva (Understanding, Communication)
Home Tasks/Assignments (Performance)
Project (Performance, Societal, Resource management &
Handling, Communication)
4
CLOs and PLOs
MCT- 238 & Embedded CLOs Level PLOs Level
MCT-238L Systems-II
MCT-238:
1. Elaborate on ARM Cortex-M Architecture, I/Os, communication C2 PLO1 High
interfaces and protocols including data acquisition techniques.
2. Implementing the timers, interrupts, communication, data
acquisition techniques, CCP and Motor control systems for C3 PLO1 High
embedded applications
3. Case-studies detailing complete embedded systems design cycle,
implementation, integration and deployment C4 PLO2 High
MCT-238L
1. Design embedded systems for diverse range of applications based on I/O P2 PLO5 Medium
ports programming, Interrupts, Serial communication, data acquisition
techniques and Motor control.
2. Skillfully demonstrate a solution as individual/group in Lab sessions/Term
Project. P4 PLO6 Medium
3. To demonstrate the project handling including use of time, resources, and
skills during its execution thus exhibiting it. A4 PLO11 Medium
4. To effectively present and communicate diverse concepts and designs for
experiments and projects utilizing embedded systems. A3 PLO10 Medium
5
Cognitive
6
Psychomotor
7
8
Course Description
This course covers the microprocessors and microcontrollers, the
core of a digital system. The architecture, assembly/C language,
system development/simulation tools for a modern (RISC/CISC)
microcontroller are introduced.
Complete digital systems with different peripherals and data
communication are designed, simulated and implemented.
This is a hands-on, learn-by-doing course that shows you how to
build solutions to real-world problems using embedded systems.
9
The course uses a bottom-up approach to problem solving,
building gradually from simple interfacing of switches and
LEDs to complex concepts like display drivers, digital to
analog conversion, generation of sound, analog to digital
conversion, graphics and interrupts.
10
Details
Introduction: Introduction to microcontrollers and embedded
processors, microcontroller’s survey-four bit, eight bit, sixteen bit, thirty
two bit microcontrollers, comparing microprocessors and microcontrollers
Architecture: Overview of the hardware architecture, special function
registers, program counter, introduction to pic assembly programming,
delay generation and instruction pipelining and I/O port programs.
arithmetic, logic instructions and programs, bank switching, hardware
connections. FPGA boards.
Programming: Writing firmware in assembly language, baseline
programming in C language, timer programming in assembly and C, serial
communication, line drivers, USART programming, interrupt
programming, FPGA board programming.
11
Interfacing and ADC: LCD and keyboard interfacing, Analog-
to-Digital converters, ADC Programming and sensor interfacing,
Introduction to data acquisition systems, I2C communication
Motor Control: Introduction to pulse width modulation, CCP
programming, H-bridge and DC motor control, servo motor and
stepper motor control
12
Suitable Microcontroller Options:
Arduino UNO: Suitable for beginners, provides a solid platform for learning
serial communication, basic control, and interfacing.
The TM4C or MSP432 microcontroller: developed by Texas Instruments (TI),
suitable for IoT Devices, These controllers are commonly used in Internet of
Things (IoT) applications due to integrated features like UART, SPI, and I2C,
which are essential for wireless communication.
STM32 Nucleo: Offers more advanced features, suitable for implementing real-
time tasks and complex control systems.
ESP32: Ideal for wireless communication experiments (Bluetooth and Wi-Fi) due
to its built-in capabilities.
13
Raspberry Pi Pico: Good for experimenting with microPython and GPIO
control, although it's not a full-fledged microcontroller like others on the list.
PIC Microcontrollers: Suitable for in-depth exploration of PIC microcontroller
architecture and features.
ARM Cortex-M based microcontrollers: These are versatile and widely used
in industrial applications, offering a range of options for different levels of
complexity.
14
Opportunities
Projects
Practical
Thesis
15
Books
Textbook:
16
Grading Policy
Sessional 20+10 Marks
Mid Term 30 Marks
End Term 40 Marks
Includes 20% of Mid-term course
Prerequisites:
Computer Programming-I
17
Introduction
18
Embedded Systems
smart device with a processor that has a special and dedicated
purpose.
user usually does not or cannot upgrade the hardware/software or
change what the system does.
Real time system must respond to critical events within a strictly
defined time, called the deadline.
Timing must be deterministic guarantee to meet all deadlines if
the behavior of the operating system can be predicted.
19
Software functions
Functions the processor can perform in an embedded system.
Similar to a general-purpose computer, it can perform mathematical and/or
data processing operations. Can analyze data and make decisions based on the
data.
A second type handling and managing time: as
an input (e.g., measure period), an output (e.g., output waveforms), and a
means to synchronize tasks (e.g., run 1000 times a second).
A third type real-time input/output for the purpose of measurement or
control.
The fourth type digital signal processing (DSP), which are mathematical
calculations on data streams. Examples include audio, video, radar, and sonar.
20
The last type is communication and networking. As embedded systems become
more complex, how the components are linked together will become increasingly
important.
21
Embedded Systems Classifications
A transformative system collects data from inputs, makes decisions, and affects its
environment by driving actuators. The robot systems are examples of
transformative systems.
A reactive system collects data in a continuous fashion and produce outputs also in
a continuous fashion. Digital signal processing algorithms are examples of reactive
systems.
22
Embedded Systems Constraints
First, they are small size. For example, many systems must be handheld.
Second, they must have low weight. If the device is deployed in a system
that moves, e.g., attached to a human, aircraft or vehicle, then weight incurs
an energy cost.
Third, they often must be low power. For example, they might need to
operate for a long time on battery power. Low power also impacts the amount
of heat they are allowed to generate.
Fourth, embedded systems often must operate in harsh environments,
such as heat, pressure, vibrations, and shock. They may be subject to noisy
power, RF interference, water, and chemicals..
23
Fifth, embedded systems are often used in safety critical systems. Real-time
behavior is essential. For these systems they must function properly at extremely
high levels of reliability.
Lastly, embedded systems are extremely sensitive to cost. Most applications are
profit-driven. For high-volume systems a difference in pennies can significantly
affect profit
24
Binary Information Implemented with MOS transistors
Binary Representation:
Information on a computer is stored in binary form.
Binary bits can exist in one of two possible states: 1 or 0.
Positive Logic:
Presence of voltage is associated with '1', true, asserted, or high state.
Absence of voltage is associated with '0', false, not asserted, or low state.
CMOS Circuit Output:
Complementary Metal Oxide Semiconductor (CMOS) circuits are commonly used.
Figure 1.8 depicts the output of a typical CMOS circuit.
Left side represents the true bit output, and the right side represents the false bit output.
Digital Circuit Output:
Output of digital circuits consists of a p-type transistor on top of an n-type transistor.
Each transistor in digital circuits is either on or off.
When on, a transistor is equivalent to a short circuit between its output pins.
When off, a transistor is equivalent to an open circuit between its output pins.
Cortex-M Microcontrollers on TI:
The Cortex-M microcontrollers from Texas Instruments (TI) operate with a 3.3 V supply.
A voltage between 2 and 5 V is considered high.
A voltage between 0 and 1.3V is considered low, as illustrated in Figure 1.9.
Voltage Thresholds:
High voltage: 2 to 5 V.
Low voltage: 0 to 1.3 V.
There is a 0.7V separation between the high and low voltage regions.
Reliable Operation at High Speeds:
The 0.7 V separation is designed to ensure reliable operation at very high speeds.
This separation helps prevent issues in digital logic functioning.
Transistor-Level Circuit Design:
The book does not delve into the design of transistor-level digital circuits.
It emphasizes that the focus is not on the intricate details of transistor-level circuit
design.
Binary Representation:
Digital data exist as binary bits.
Binary bits are encoded using high and low voltages.
Multistate Representation with Bits:
To represent information with more than two states, multiple bits are used.
A collection of 2 bits has 4 possible states (00, 01, 10, and 11).
A collection of 3 bits has 8 possible states (000, 001, ..., 111).
In general, a collection of n bits has 2^n states.
Byte Representation:
A byte consists of eight bits.
It is formed by grouping eight binary bits into one object.
Another term for a collection of eight bits is an "octet," derived from Latin and Greek,
meaning 8.
Information Forms:
Information can take various forms, including numbers, logical states, text, instructions,
sounds, or images.
The interpretation of bits depends on how the information is organized and, more importantly,
how it is used.
Example of Binary Representation:
The figure shows a byte in the state representing the binary number 01100111.
Each bit in the byte represents a binary value (0 or 1).
The output voltage of 3.3V corresponds to true or 1, while 0V corresponds to false or
0.
Digital Information stored in Memory
Memory in a Computer:
Memory consists of hardware elements in a computer for storing information.
Byte-Addressable Memory:
Each memory cell holds one byte and has a unique, sequential address.
Memory Operations:
Writing to memory involves specifying an address and 8, 16, or 32 bits of data.
During a write cycle, data flows from the processor to memory.
Port A (GPIO_PORTA_DATA_R):
Collection of pins (usually 8).
Configurable for input or output.
If Input:
Reading from GPIO_PORTA_DATA_R provides 8 bits representing digital levels (high or low).
If Output:
Writing to GPIO_PORTA_DATA_R sets the outputs on the eight pins to high (1) or low (0) based
on the written data value.
Applications Involving Embedded Systems
Embedded Computer System Definition:
A microcomputer integrated with mechanical, chemical, and electrical devices.
Programmed for a specific dedicated purpose.
Packaged as a complete system.
Application Scope:
Any electrical, mechanical, or chemical system with inputs, decisions, calculations,
analyses, and outputs is a candidate for implementation as an embedded system.
Functional Components:
Sensors:
Collect information (electrical, mechanical, chemical).
tachometer is a sensor that measures the revolutions per second of a rotating shaft.
Electronic Interfaces: (Signal Conditioning, e.g. ADC)
Convert sensor signals into a form acceptable for the microcomputer.
Microcomputer Software: (Decision Making)
Performs decisions, calculations, and analyses.
Additional Interface Electronics: (DAC)
Convert microcomputer outputs into the necessary form.
Actuators:
Create mechanical or chemical outputs.
Example: Electrical motor converts electrical power into mechanical power.
General-Purpose Computer System Characteristics:
Typically equipped with a keyboard, disk, and graphics display.
Programmable for a wide variety of purposes.
Common applications include word processing, electronic mail, business
accounting, scientific computing, and database systems.
User Access and Control:
Users have access to and control over the software that governs the system.
Users can choose the operating system and applications to run.
Removable disk or network interface facilitates easy addition of new programs.
Common Types and Cost Range:
Personal Computer (PC):
Example: Apple MacBook.
Cost: Less than $3,000.
Workstations:
Cost: Ranges from $3,000 to $50,000.
Supercomputers:
Cost: Above $50,000.
Often employ multiple processors and have extensive memory.
Usage Scenarios:
Workstations and supercomputers are employed for handling large amounts of information
(business applications) or performing extensive calculations (scientific research).
Book Focus:
The book will primarily cover embedded computers, and while the principles apply
broadly, it won't specifically address general-purpose computers.
Impact of Embedded Microcomputers in Daily Life:
Consumer Electronics:
Examples: Smartphones, TVs, Audio Systems.
Integration of microcontrollers enhances functionality and interactivity.
Home:
Automation and control systems.
Home appliances with embedded microcontrollers for improved performance.
Communications:
Cell phones and communication devices.
Networking equipment and infrastructure.
Automotive:
Modern vehicles employ numerous microcontrollers for various functions.
Engine control, safety systems, entertainment, and navigation.
Military:
Defense systems and equipment.
Embedded microcomputers play a critical role in military applications.
Industrial:
Manufacturing processes and control systems.
Industrial automation and robotics.
Business:
Embedded systems support various business operations.
Point-of-sale terminals, inventory management, and data processing.
Shipping:
Embedded systems used in logistics and tracking.
Control systems for shipping and transportation.
Medical:
Medical devices and equipment.
Patient monitoring, diagnostic tools, and treatment systems.
Computer Components:
Embedded microcontrollers in computer hardware.
Enhancing functionality and performance of computer systems.
Product Life Cycle
Analyze Phase
Specifications:
Definition: Specifications are detailed and quantifiable descriptions of how the
system should meet its requirements. They are more technical and precise.
Process: Converting general requirements into specific metrics or features.
Example: For a motor controller, specifying the exact range of operating
temperatures or the precise response time in milliseconds.
Constraints:
Definition: Constraints are the limitations or boundaries within which the system
must be developed and operated.
Types: These can include budgetary limits, safety standards, compatibility
requirements, component availability, and timeline constraints.
Example: The motor controller must be developed within a set budget, adhere to safety
standards, and be compatible with existing systems.
Measures which are often considered during the analysis phase of aproject:
High–level design phase
Modular Design: (Block Diagram)
Definition: Dividing the system into distinct modules or subcomponents, each with
a specific functionality.
Benefit: Enhances understandability, simplifies development, and aids in maintenance.
Data Flow Graphs:
Use in High-Level Design: Data flow graphs are instrumental in visualizing how
information moves through the system.
Elements: Arrows (indicating the flow of information), rectangles (representing
hardware components), and ovals (denoting software modules).
Advantage: They provide a clear, simplified view of the system’s operation without
getting bogged down in intricate details.
Engineering Design
Top-Down Hierarchical Structure:
Process: Refining and finalizing the hierarchical structure of the system.
Mock-Ups: Creating prototypes of mechanical parts (like connectors, chassis, cables) and user
software interfaces using tools like 3-D CAD systems for realistic visualization.
Detailed Hardware Design: Involves creating detailed mechanical drawings and ensuring there
are backup suppliers (second sources) for critical components.
Call Graphs:
Definition: Graphical representations showing how software and hardware modules interact.
High-Level vs. Detailed Call Graphs: High-level call graphs depict major modules, while
detailed ones include each software function and I/O port.
Example: In your position measurement system, the call graph would illustrate how the timer
hardware interacts with the ADC software and the LCD interface.
Data Structure:
Organization of information and mechanisms to access the data
Integration of I/O Ports:
Organization: Grouping and integrating I/O ports effectively within the system.
Representation in Call Graph: I/O ports are typically placed at the bottom of the
call graph for clarity.
Implementation Phase
Also called development stage because we will develop a possible solution.
Top-Down Design and Parallel Development:
Advantage: Allows for the simultaneous development of subcomponents, enhancing efficiency and
speed in the development process.
Approach: Different teams or individuals can work on various aspects of the project concurrently,
provided they follow the agreed-upon design specifications and interfaces.
Use of Simulation in Early Stages:
Benefits: Simulations offer a faster, more flexible, and often more cost-effective method for initial
implementation compared to building physical prototypes.
Rapid Prototyping: Facilitates quick iterations through the analysis-design-implementation-
testing-deployment cycle, leading to more refined and sophisticated products.
Testing
First, debug the system and validate basic functions.
Next,use careful measurements to optimize performance such as
static efficiency (memory requirements),
dynamic efficiency (execution speed),
accuracy (difference between expected truth and measured),
and stability (consistent operation.)
Maintenance
Maintenance is the process of correcting mistakes, adding new features,
optimizing for execution speed or program size, porting to new computers or
operating systems, and reconfiguring the system to solve a similar problem.
No system is static. Customers may change or add requirements or constraints.
To be profitable, we probably will wish to tailor each system to the individual
needs of each customer.
Maintenance is not really a separate phase, but rather involves additional loops
around the life cycle.
Successive Refinement
Successive refinement, stepwise refinement, and systematic decomposition are three
equivalent terms for a technique to convert a problem statement into a software algorithm.
Example 2.1. Build a digital door lock using
seven switches.
Quality Design
Quantitative criteria include dynamic efficiency (speed of execution), static
efficiency (memory requirements), and accuracy of the results.
Qualitative criteria center on ease of software maintenance.
Another qualitative way to evaluate software is ease of understanding.
If your software is easy to understand, then it will be:
Easy to debug (fix mistakes)
Easy to verify (prove correctness)
Easy to maintain (add features)
Quantitative Performance Measurements:
Dynamic efficiency is a measure of how fast the program executes. It is measured in seconds
or processor bus cycles.
Static efficiency is the number of memory bytes required. Since most embedded computer
systems have both RAM and ROM, we specify memory requirement in global variables, stack
space, fixed constants and program
Qualitative Performance Measurements:
self-documented code,
abstraction, modularity, and layered software.
These issues indeed play a profound effect on the bottom-line financial success of our projects.
Attitude
Good engineers employ well-defined design processes when developing complex systems.
When we work within a structured framework, it is easier to prove our system works
(verification) and to modify our system in the future (maintenance.)
Debugging theory
Every programmer is faced with the need to debug and verify the correctness of his
or her software.
A debugging instrument is hardware or software used for the purpose of debugging.
Hardware-level probes like the logic analyzer, oscilloscope, and Joint Test Action Group
(JTAG standardized as the IEEE 1149.1);
software-level tools like simulators, monitors, and profilers; and
manual tools like inspection and print statements
Black-box testing is simply observing the inputs and outputs without looking
inside. Black-box testing has an important place in debugging a module for its
functionality.
On the other hand, whitebox testing allows you to control and observe the internal
workings of a system. A common mistake made by new engineers is to just
perform black box testing. Effective debugging uses both. One must always start
with black-box testing by subjecting a hardware or software module to appropriate
testcases.
Once we document the failed test-cases, we can use them to aid us in effectively
performing the task of white-box testing.
2.7. Switch and LED Interfaces
Switch Interface:
Switch Types:
Single Pole Single Throw (SPST): Has two connections.
Normally Open (NO): Resistance is infinite when not pressed, and zero when pressed.
Positive Logic Interface:
Asserted State: Larger voltage when pressed (3.3V).
Connection: One side of the switch connected to +3.3V.
Pull-Down Resistor: Added to ground the signal when not pressed.
Pull-Down Resistor Value: Typically 10 kΩ.
Negative Logic Interface:
Asserted State: Smaller voltage when not pressed (3.3V).
Connection: One side of the switch connected to 0V.
Pull-Up Resistor: Added to +3.3V to achieve desired logic levels.
Pull-Up Resistor Value: Typically, 10 kΩ.
Dealing with Switch Bounce:
Issue: Mechanical switches can bounce.
Solution: Software design to wait at least 10 ms between reading switch values.
2. LED Interface:
LED Polarity:
Anode: Labeled as a or + (longer lead).
Cathode: Labeled as k or - (shorter lead).
Brightness Control:
Brightness depends on electrical power (P=IV).*
LED Voltage: Approximately constant in the active region.
Brightness Control: Achieved by setting the current.
Current Limiting Resistor:
Purpose: Limits the current through the LED.
Calculation: Use Ohm's Law (R=V/I) based on the desired current.
Typical Value: Often chosen to be around 330 Ω.
Current Limiting:
If LED current > 8 mA, direct connection may damage the microcontroller.
Use current limiting resistor to control LED current.
Interface Circuits:
Two possible circuits shown in Figure 2.9.
Circuit Operation:
Software Output High: LED ON (Italics indicate LED ON in Figure 2.9).
Software Output Low: LED OFF (Italics indicate LED OFF in Figure 2.9).
Circuit Details (Using 7405/PN2222):
Logic 1: Input to 7405/PN2222 becomes high, output becomes low, 10 mA through
LED (LED ON).
Logic 0: Input to 7405/PN2222 becomes low, output floats, no current through LED
(LED OFF).
ResistorValue:
Selected to establish proper LED current.
Active LED Voltage: ~2 V.
Power Delivered Controlled by Current.
When the LED current is less than 8 mA,
we can interface it directly to an output pin without using a driver.
The LED shown in Figure 2.10 has an operating point of 1.7 V and 1 mA.
Introduction to C
From book vol 1 page 95
Macro Definition:
Macro Creation:
Macro created using #define to define constants.
Example: #define SIZE 10
Macro Purpose:
Wherever SIZE is found as a token, it is replaced with the number 10.
Header File Inclusion:
Directive:
#include directive used for including another entire file at the specified position in the
program.
Example:
#include "tm4c123ge6pm.h"
File Content:
The included file (tm4c123ge6pm.h) defines all the I/O port names for the TM4C123
microcontroller.
Usage:
Provides access to pre-defined I/O port names and configurations for the specified
microcontroller.
Introduction to the ARM ® Cortex -M Processor
Computer Architecture
Computer:
Central processing unit (CPU), random access memory (RAM), read only memory
(ROM), and input/output (I/O) ports
Common bus in Figure 1.3 defines the von Neumann architecture.
106
Software
An ordered sequence of very specific instructions that are stored in memory (ROM),
defining exactly what and when certain tasks are to be performed
CPU/Processor:
executes the software by retrieving (from memory) and interpreting these instructions
one at a time. .
107
Introduction to the ARM ® Cortex -M
Processor
Cortex -M Architecture
An ARM Cortex-M microcontroller includes a processor, memory and input/output
via multiple buses
Instructions are fetched via the ICode bus and data are fetched via the System bus,
classified as a Harvard architecture.
Having multiple busses allows the system to do several things simultaneously.
For example, the processor could be reading an instruction from ROM using the
ICode bus and writing data to RAM using the System bus.
Figure 1.6 shows a simplified block diagram of a microcontroller based on the
ARM Cortex-M processor.
It is a Harvard architecture because it has separate data and instruction buses.
Instructions are fetched from flash ROM using the ICode bus.
Data are exchanged with memory and I/O via the system bus interface.
There are many sophisticated debugging features utilizing the DCode bus.
109
Having multiple buses means the processor can perform multiple tasks in parallel.
On the TM4C123, general purpose input/output (GPIO) ports can be accessed
using either the PPB or AHPB.
The following is some of the tasks that can occur in parallel
ICode bus Fetch opcode from ROM
DCode bus Read constant data from ROM
System bus Read/write data from RAM or I/O, fetch opcode from RAM
PPB Read/write data from internal peripherals like the NVIC
AHPB Read/write data from internal peripherals like the USB
110
Registers
Registers are high-speed storage inside the processor.
The registers are depicted in Figure 3.2.
R0 to R12 are general purpose registers and contain either data or addresses.
Register R13 (also called the stack pointer, SP) points to the top element of the stack.
Register R14 (also called the link register, LR) is used to store the return location for
functions. The LR is also used in a special way during exceptions, such as interrupts.
Interrupts are covered in Chapter 9.
Register R15 (also called the program counter, PC) points to the next instruction to be
fetched from memory.
The processor fetches an instruction using the PC and then increments the PC.
Processor Registers
ARM Architecture Procedure Call Standard
AAPCS, part of the ARM (ABI) Application Binary Interface
AAPCS Register Usage:
R0, R1, R2, R3: Used for passing input parameters to a C function.
R4–R11: Must be preserved by functions (callee-saved registers).
Return parameter: Placed in Register R0.
Stack Alignment in AAPCS:
Push and pop an even number of registers.
Maintain an 8-byte alignment on the stack.
Main Stack Pointer (MSP) is used, not the Process Stack Pointer (PSP).
Three Status Registers in ARM Architecture:
Combined as the Program Status Register (PSR).
APSR (Application Program Status Register)
IPSR (Interrupt Program Status Register)
EPSR (Execution Program Status Register)
134
Thumb State:
In Thumb state, the processor executes a more compact instruction set
called the Thumb instruction set. Thumb instructions are 16 bits long,
which makes them more memory-efficient.
Thumb state is designed for situations where memory bandwidth or
storage is constrained, making it suitable for applications with limited
resources.
Thumb instructions are generally simpler than ARM instructions.
135
ARM Cortex-M Assembly Language
Cortex-M microcontrollers executes Thumb instructions
extended with Thumb-2 technology
Syntax:
Instructions have four fields separated by spaces
Labels opcodes or ops operands Comments
Labels: The label field is optional and starts in the first column
Opcodes or pseudo-ops: The opcode field specifies which
processor command to execute.
LDR STR MOV PUSH POP B BL BXADD SUB CPSID and
CPSIE .
Opcodes that uses to control features of the assembly process
AREA EQU IMPORT EXPORT and ALIGN
Operands: specifies where to find the data to execute the
136
instruction. 0, 1, 2, 3, or more operands
Comments: optional and is ignored by the assembler, making it easier to
understand.
a semicolon must separate the operand and comment fields.
137