SlideShare a Scribd company logo
1 of 77
IOT Design:
An Embedded System Overview
Definitions DAY
Dr. Eng. Amr T. Abdel-Hamid
NETW 1010
Fall 2016
Dr.
Amr
Talaat
Embedded
Systems
IRing: Anti-Cheating RING
Dr.
Amr
Talaat
Embedded
Systems
IRing: Remote Control
Dr.
Amr
Talaat
Embedded
Systems
Embedded Systems
 According to forecasts, future of IT c
haracterized by terms such as
 Disappearing computer,
 Ubiquitous computing,
 Pervasive computing,
 Ambient intelligence,
 Post-PC era,
 Cyber-physical systems.
 Internet of Things
 Basic technologies:
 Embedded Systems
 Communication technologies
Dr.
Amr
Talaat
Embedded
Systems
Embedded Systems & Cyber-Physical Systems
“Dortmund“ Definition: [Peter Marwedel]
Embedded systems are information processing systems
embedded into a larger product
Berkeley: [Edward A. Lee]:
Embedded software is software integrated with physical
processes. The technical problem is managing time and
concurrency in computational systems.
 Definition: Cyber-Physical (cy-phy) Systems (CPS)
are integrations of computation with physical
processes [Edward Lee, 2006].
Dr.
Amr
Talaat
Embedded
Systems
Embedded System Hardware
 Embedded system hardware is frequently used in
a loop (“hardware in a loop“):
Dr.
Amr
Talaat
Embedded
Systems
Automotive electronics
 Multiple networks
Body, engine, telemat
ics, media, safety, ...
 Multiple networked
processors
Self DRIVING Vehicles
Functions by embedded
processing:
 ABS: Anti-lock braking
systems
 ESP: Electronic stability
control
 Airbags
 Efficient automatic
gearboxes
 Theft prevention with
smart keys
 Blind-angle alert systems
 ... etc ...
Dr.
Amr
Talaat
Embedded
Systems
Forestry Machines
 Networked computer
system
Controlling arms &
tools
Navigating the for
est
Recording the tree
s harvested
Crucial to efficient
work
 “Tough enough to be
out in the woods”
Dr.
Amr
Talaat
Embedded
Systems
Smart buildings
Examples
 Integrated cooling,
lightning, room
reservation, emergency
handling, communication
 Goal: “Zero-energy
building”
 Expected contribution to
fight against global
warming
Dr.
Amr
Talaat
Embedded
Systems
ES 2016 Grand Failure
Dr.
Amr
Talaat
Embedded
Systems
Can ES get Hacked?
Dr.
Amr
Talaat
Embedded
Systems
Embedded System Hardware
 Embedded system hardware is frequently used in
a loop (“hardware in a loop“):
Dr.
Amr
Talaat
Embedded
Systems
13
Some common characteristics of ES
 Dependability
 Single-functioned (dedicated System)
Executes a single program, repeatedly
 Tightly-constrained (Efficient)
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 with
out delay
Dr.
Amr
Talaat
Embedded
Systems
Dependability
 ES Must be dependable,
• Reliability R(t) = probability of system working
correctly provided that is was working at t=0
• Maintainability M(d) = probability of system working
correctly d time units after error occurred.
• Availability A(t): probability of system working at time t
• Safety: no harm to be caused
• Security: confidential and authentic communication
Even perfectly designed systems can fail if the assumptions about the
workload and possible errors turn out to be wrong.
Making the system dependable must not be an after-thought, it must
be considered from the very beginning
Dr.
Amr
Talaat
Embedded
Systems
Efficiency
ES must be efficient
Code-size efficient
Run-time efficient
Weight efficient
Cost efficient
Energy efficient
Dr.
Amr
Talaat
Embedded
Systems
Real-time constraints
 Many ES must meet real-time constraints
A real-time system must react to stimuli from the con
trolled object (or the operator) within the time interv
al dictated by the environment.
For real-time systems, right answers arriving too late
are wrong.
“A real-time constraint is called hard, if not me
eting that constraint could result in a catastrop
he“ [Kopetz, 1997].
All other time-constraints are called soft.
A guaranteed system response has to be explained w
ithout statistical arguments
Dr.
Amr
Talaat
Embedded
Systems
Real-Time Systems
 Embedded and Real
-Time?
Most embedded
systems are
real-time
Most real-time
systems are
embedded
embedded
real-time
embedded
real-time
© Jakob Engblom
Dr.
Amr
Talaat
Embedded
Systems
Reactive & hybrid systems
 Typically, ES are reactive systems:
“A reactive system is one which is in continual interacti
on with is environment and executes at a pace determi
ned by that environment“ [Bergé, 1995]
Behavior depends on input and current state.
 automata model appropriate,
model of computable functions inappropriate.
 Hybrid systems
(analog + digital parts).
Dr.
Amr
Talaat
Embedded
Systems
Dedicated systems
Dedicated towards a certain application
Knowledge about behavior at design time c
an be used to minimize resources and to
maximize robustness
Dedicated user interface
(no mouse, keyboard and screen)
Dr.
Amr
Talaat
Embedded
Systems
Design Challenge
 Time-to-prototype: the time needed to build a working v
ersion of the system
 Time-to-market: the time required to develop a system to
the point that it can be released and sold to customers
 NRE cost (Non-Recurring Engineering cost):
The one-time monetary cost of designing the syst
em
 Flexibility: the ability to change the functionality
of the system without incurring heavy NRE cost
Dr.
Amr
Talaat
Embedded
Systems
Design challenge – optimizing design metrics
 Obvious design goal:
Construct an implementation with desired fun
ctionality
 Key design challenge:
Simultaneously optimize numerous design me
trics
 Design metric
 A measurable feature of a system’s impleme
ntation
Optimizing design metrics is a key challenge
Dr.
Amr
Talaat
Embedded
Systems
Design metric competition -- improving one
may worsen others
 Expertise with both soft
ware and hardware is
needed to optimize
design metrics
 Not just a hardware or soft
ware expert, as is common
 A designer must be comfor
table with various technolo
gies in order to choose the
best for a given application
and constraints
Size
Performance
Power
NRE cost
Dr.
Amr
Talaat
Embedded
Systems
Hypothetical design flow
Specification
hardware
System software
Test *
Evaluation & Validation
(energy, cost,
performance, …)
Optimization
Application
mapping
Application
Knowledge
Design
repository
Generic loop: tool chains differ in the number and type of iterations
* Could be
integrated
into loop
Design
Dr.
Amr
Talaat
Embedded
Systems
Design Questions
 How much Power is needed?
 Is power an issue?
 Average Current needed?
 Max. Transient Current
 Do I need communications/Networking module?
 How far? (Distance Travelled)
 Authorized Frequencies
 Antenna Size
 Required Power
 It is 1 device or in a network?
 Do I need routing?
…………
Dr.
Amr
Talaat
Embedded
Systems
Data Rate
Dr.
Amr
Talaat
Embedded
Systems
Power Dissipation
Dr.
Amr
Talaat
Embedded
Systems
IOT EXTRA Design Challenges
 Larger Scale: Scalability, the ability of a network to support the
increase of its limiting parameters. We discuss the first four scal
ability issues here.
 Large Network Size: In the Internet of Things, we are tal
king about interaction with thousands of devices in one pl
ace.
 Massive Number of Events: A significant challenge is pos
ed by the enormous number of events generated by obje
cts.
 Mobility Rate: Higher mobility rate causes more breakag
e of links and causes more routing information becoming
out-of-date.
 Heterogeneous Devices: In the Internet of Things there i
s a wide variety of hardware and devices, in all shapes an
d sizes.
Dr.
Amr
Talaat
Embedded
Systems
IOT EXTRA Design Challenges (cont.)
 Spontaneous Interaction: Sudden interactions happen as the
objects move around and come into other objects’ wireless rang
e. This leads to the spontaneous generation of events.
 Zero Infrastructure: In the Internet of Things setting, devices
need to discover each other as well as the resources provided by
other devices in the surroundings. The challenge here is that the
re is no fixed infrastructure to manage resource publication, disc
overy and communication.
Dr.
Amr
Talaat
Embedded
Systems
IOT GENERIC Architecture
Processor
Communication Module
Power
Supply
(Battery)
Power
Manger
Processing
API
Communication
API
Database
API
Database
Sensor/
Actuator
Dr.
Amr
Talaat
Embedded
Systems
Hardware Node
Dr.
Amr
Talaat
Embedded
Systems
Controller
 Four important factors for the controller
 Number of transistors -> size, cost, power
 Number of clock cycles -> power
 Time to MARKET-> cost, acceptance
 Nonrecurring engineering cost (NRE) -> cost, a
cceptance
 Ideal: Minimize all factors at the same time!
Dr.
Amr
Talaat
Embedded
Systems
Tasks of the controller
 Running of (real time) data processing and com
munication protocols
 Perform and control the application program
 Energy management of the node
Different operation modes available (active, i
dle, listen, sleep, etc.)
Dr.
Amr
Talaat
Embedded
Systems
Embedded processors (MicroControllers )
 Programmed once by manufacturer of system
 Executes a single program (or a limited suite) wi
th few parameters
 Task-specific
can be optimized for specific application
 Interacts with environment in many ways
direct sensing and control of signal wires
communication protocols to environment and
other devices
real-time interactions and constraints
Dr.
Amr
Talaat
Embedded
Systems
Microprocessors and Microcontrollers
• A microprocessor unit (MPU) is a processor on
one silicon chip.
• Microcontrollers are used in embedded
computing.
• A Microcontroller unit (MCU) is a
microprocessor with some added circuitry on
one silicon chip.
Dr.
Amr
Talaat
Embedded
Systems
A Single Chip Microcontroller Contains
Dr.
Amr
Talaat
Embedded
Systems
C
S
E
4
7
7 CPU Memory
Display
(with
dual-port
video RAM)
Disk
I/O
(serial line,
keyboard,
mouse)
Network
Interface
standard interfaces
system bus
all the parts around the
processor are usually required
Typical general-purpose architecture
Dr.
Amr
Talaat
Embedded
Systems
Microcontroller
ROM
I/O
Interface RAM
custom
logic
standard interface
any of the parts around the
microcontroller are optional
Typical task-specific architecture
Dr.
Amr
Talaat
Embedded
Systems
Introduction to Embedded Systems & Microcontrollers
CSEN701: Embedded Systems 38
MCU Types
• MCUs can be classified according:
• MCU bits (e.g. 8-bit, 16-bit, 32-bit)
• Instruction Set Architecture (ISA)
Dr.
Amr
Talaat
Embedded
Systems
MCU Bit Definition
• The number of bits describing the data
path defines Microcontroller Bit Definition
Dr.
Amr
Talaat
Embedded
Systems
Instruction Set Architecture
• Instruction Set Architecture (ISA) is the part of the
computer architecture related to programming, including
the native data types, instructions, registers, addressing
modes, memory architecture, interrupt and exception
handling, and external I/O.
• The ISA defines:
• Operations that the processor can execute,
• The mechanism of Data Transfer and how to access data,
• Control Mechanisms (branch, jump, etc)
• “Contract” between programmer/compiler and hardware
• The main ISAs are CISC and RISC:
• CISC stands for Complex Instruction Set Computer
• RISC stands for Reduced Instruction Set Computer
Dr.
Amr
Talaat
Embedded
Systems
The CISC Approach
• Emphasis on hardware
• Includes multi-clock Instructions
• Has a large amount of different (in length) and
• complex instructions
• The philosophy behind it is that hardware is always
faster than software, therefore one should make a
powerful instruction-set,
• Memory-to-memory:
• "LOAD" and "STORE“ are incorporated in instructions
• Small code sizes (use less number of instructions),
• Requires more transistors
Dr.
Amr
Talaat
Embedded
Systems
The RISC Approach
• RISC processors only use simple instructions that can be executed
within one clock cycle.
• Because there are more lines of code, more RAM is needed to store
the assembly level instructions. The compiler must also perform
more work to convert a high-level language statement into code of
this form.
• Because each instruction requires only one clock cycle to execute,
the entire program will execute in approximately the same amount
of time as the multi-cycle "MULT" command.
• These RISC "reduced instructions" require less transistors of
hardware space than the complex instructions, leaving more room
for general purpose registers.
• Because all of the instructions execute in a uniform amount of time
• (i.e. one clock), pipelining is possible.
• It’s also called : Load-Store Architecture
Dr.
Amr
Talaat
Embedded
Systems
Microcontroller Features
 Processor speed: Fundamental measure of pro
cessing rate of device
Value of interest is in MIPS, not MHz
 Supply voltage/current: Measure of the amount
of power required to run the device
 Multiple modes (sleep, idle, etc)
Dr.
Amr
Talaat
Embedded
Systems
Common Memory Types in MCUs
• RAM
• EEPROM
• Flash Memory
Dr.
Amr
Talaat
Embedded
Systems
RAM: Random Access Memory
• Volatile or Non-Permanent Memory, i.e., data is lost after the
removal of power,
• Can be Written too Many Times,
• It is a general purpose memory which is typically used for
storing user data, temporary or Changeable Data
• Most microcontrollers have some amount of internal RAM.
Generally, 1 kbytes (“Embedded” in MCUs) is a common
amount, although some microcontrollers have more, some
less.
Dr.
Amr
Talaat
Embedded
Systems
It is electrically-erasable-and-programmable.
Internally, they are similar to EPROMs, but the erase
operation is accomplished electrically, rather than by
exposure to ultraviolet light. Any byte within an
EEPROM may be erased and rewritten.– Erased by
higher voltage.
The primary tradeoff for this improved
functionality is higher cost, though write cycles are
also significantly longer than writes to a RAM.
EEPROM are typically used to store permanent data
EEPROM: Electrically Erasable Programmable Read-Only Memory
Dr.
Amr
Talaat
Embedded
Systems
Flash Memory
• Flash memory devices are
• high density,
• low cost,
• nonvolatile,
• fast (to read, but not to write), and
• electrically reprogrammable.
• Write/Erase large blocks of bytes
• Read bytes
• EEPROM is similar to flash memory (sometimes called flash
EEPROM).
• The principal difference is that
• EEPROM requires data to be written or erased one byte at a time
whereas flash memory allows data to be written or erased in
blocks.
• Flash memory is typically used in MCUs for storing program code
Dr.
Amr
Talaat
Embedded
Systems
Popular Microcontrollers
• Intel 8051
• Microchip PIC
• Atmel AVR
• ARM
Dr.
Amr
Talaat
Embedded
Systems
49
Why study the ARM architecture
(and the Cortex-M3 in particular)?
Dr.
Amr
Talaat
Embedded
Systems
50
Lots of manufacturers ship ARM products
Dr.
Amr
Talaat
Embedded
Systems
Introduction to ARM
 Acorn Computers Ltd. (Cambridge, England) Nov.
1990
 First called Acorn RISC Machine, then Advanced R
ISC Machine
 Based on RISC architecture work done at UCal Be
rkley and Stanford
 ARM only sells licenses for its core architect
ure design
 Optimized for low power & performance
 VersatileExpress board with Cortex-A9 (ARMv7) c
ore will be “emulated” using Linaro builds.
 This also means some things may not work. You’v
e been warned.
Dr.
Amr
Talaat
Embedded
Systems
ARM architecture versions
Architecture Family
ARMv1 ARM1
ARMv2 ARM2, ARM3
ARMv3 ARM6, ARM7
ARMv4 StrongARM, ARM7TDMI, ARM9TDMI
ARMv5 ARM7EJ, ARM9E, ARM10E, Xscale
ARMv6 ARM11, ARM Cortex-M
ARMv7 ARM Cortex-A, ARM Cortex-M, ARM Cortex-R
ARMv8 Not available yet. Will support 64-bit addressing +
data
52
Dr.
Amr
Talaat
Embedded
Systems
Handling electronics - How NOT to Do It!
Improper Handling - NEVER!!!
Dr.
Amr
Talaat
Embedded
Systems
Handling electronics - The Proper Way
Proper Handling - by the edges!!!
Dr.
Amr
Talaat
Embedded
Systems
ATmega328 Microcontroller
Pin number
Pin name
Special
function
Dr.
Amr
Talaat
Embedded
Systems
Microcontroller Ports and Pins
 The communication channels
through which information
flows into or out of the
microcontroller
 Ex. PORTB
 Pins PB0 – PB7
 May not be contiguous
 Often bi-directional
C
Dr.
Amr
Talaat
Embedded
Systems
Port Pin Data Directionality
 Input
When you want to take information from the e
xternal world (sensors) into the MCU
 Output
When you want to change the state of somethi
ng outside the MCU (turn a motor on or off, e
tc.)
 Pins default to input direction on power-up
or reset
 Your program can set or change the direct
ionality of a pin at any time
Dr.
Amr
Talaat
Embedded
Systems
ATmega328
Block Diagram
Input
Output
Dr.
Amr
Talaat
Embedded
Systems
Setting the Pin Data Direction
 Arduino
pinMode(pin_no., dir)
Ex. Make Arduino pin 3 (PD3) an output
pinMode(3, OUTPUT);
pinMode(PIN_D3, OUTPUT); // with me
106.h
Note: one pin at a time
Suppose you wanted Arduino pins 3, 5, and
7 (PD3, PD5, and PD7) to be outputs?
Is there a way to make them all outputs at t
he same time?
Yes! Answer coming later…
Dr.
Amr
Talaat
Embedded
Systems
Pin Voltages
 Microcontrollers are fundamentally digital device
s. For digital IO pins:
Information is ‘coded’ in two discrete states:
HIGH or LOW (logic: 1 or 0)
Voltages
TTL
5 V (for HIGH)
0 V (for LOW)
3.3 V CMOS
3.3 V (for HIGH)
0 V (for LOW)
Dr.
Amr
Talaat
Embedded
Systems
Pin Used as an Output
 Turn on an LED, which is co
nnected to pin Arduino pin 0
(PD0) (note the resistor!)
What should the data directio
n be for pin 0 (PD0)?
pinMode(____, ____);
Turn on the LED
digitalWrite(PIN_LED,HIGH);
Turn off the LED
digitalWrite(PIN_LED,LOW);
ATmega328
Arduino
pin 0
(PD0)
Dr.
Amr
Talaat
Embedded
Systems
Pins as Inputs and Pull-up Resistors - 1
 Using a switch as a sensor
 Ex. Seat belt sensor
 Detect the switch state
What should the data directio
n be for Arduino pin 3 (PD3)?
pinMode(____, ____);
What will the voltage be on P
D3 when the switch is closed?
What will the voltage be on P
D3 when the switch is open?
Indeterminate!
ATmega328
Arduino
pin 3
(PD3)
SPST
momentary
Dr.
Amr
Talaat
Embedded
Systems
Pins as Inputs and Pull-up Resistors - 2
 Switch as a sensor, cont.
Make the voltage on the pin d
eterminate by turning on the
pull-up resistor for PD3
Assuming PD3 is an input:
 digitalWrite(PIN_SWITCH,HIGH); tur
ns on the “pull-up” resistor
 pinMode(PIN_SWITCH,INPUT_PULLUP);
What will the voltage on PD3 be
when the switch is open?
VTG
What will the voltage on PD3 be
when the switch is closed?
ATmega328
PD3
1
VTG= +5V
0
Dr.
Amr
Talaat
Embedded
Systems
Pins as Inputs and Pull-up Resistors - 3
 Switch as a sensor, cont.
To turn off the pull-up resist
or
Assuming PD3 is an input
:
digitalWrite(PIN_SWITCH,LOW); tur
ns the “pull-up” resistor off
ATmega328
PD3
VTG= +5V
0
1
Dr.
Amr
Talaat
Embedded
Systems
Pins as Inputs and Pull-up Resistors - 4
 Possibility of ‘weak drive’ when
pull-up resistor is turned on
Pin set as an input with a pul
l-up resistor turned on can s
ource a small current
Remember this!
ATmega328
PD3
VTG= +5V
0
1
iweak
Dr.
Amr
Talaat
Embedded
Systems
Example 1
 Arduino approach  Alternate approach
 Make Arduino pins 3, 5, and 7 (PD3, PD5, and
PD7) to be outputs
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(7, OUTPUT);
DDRD = 0b10101000;
or
DDRD = 0xA8;
or
DDRD | = 1<<PD7 | 1<<PD5 | 1<<PD3;
More on this coming soon!
Or if me106.h is used:
pinMode(PIN_D3, OUTPUT);
pinMode(PIN_D5, OUTPUT);
pinMode(PIN_D7, OUTPUT);
Dr.
Amr
Talaat
Embedded
Systems
Example 2
 Arduino approach  Alternate approach
 Make pins Arduino pins 0 and 1 (PD0 and PD1)
inputs, and turn on pull-up resistors
pinMode(0, INPUT);
pinMode(1, INPUT);
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
DDRD = 0; // all PORTD pins inputs
PORTD = 0b00000011;
or
PORTD = 0x03;
or better yet:
DDRD & = ~(1<<PD1 | 1<<PD0);
PORTD | = (1<<PD1 | 1<<PD0);
More on this coming soon!
Or if me106.h is used:
pinMode(PIN_D0, INPUT);
pinMode(PIN_D1, INPUT);
digitalWrite(PIN_D0, HIGH);
digitalWrite(PIN_D1, HIGH);
Dr.
Amr
Talaat
Embedded
Systems
Structure of an Arduino Program
 An arduino program == ‘ske
tch’
 Must have:
 setup()
 loop()
 setup()
 configures pin modes an
d registers
 loop()
 runs the main body of th
e program forever
 like while(1) {…}
 Where is main() ?
 Arduino simplifies things
 Does things for you
/* Blink - turns on an LED for DELAY_ON msec,
then off for DELAY_OFF msec, and repeats
BJ Furman rev. 1.1 Last rev: 22JAN2011
*/
#define LED_PIN 13 // LED on digital pin 13
#define DELAY_ON 1000
#define DELAY_OFF 1000
void setup()
{
// initialize the digital pin as an output:
pinMode(LED_PIN, OUTPUT);
}
// loop() method runs forever,
// as long as the Arduino has power
void loop()
{
digitalWrite(LED_PIN, HIGH); // set the LED on
delay(DELAY_ON); // wait for DELAY_ON msec
digitalWrite(LED_PIN, LOW); // set the LED off
delay(DELAY_OFF); // wait for DELAY_OFF msec
}
Dr.
Amr
Talaat
Embedded
Systems
Digital IO – Practice 1
 ‘Reading a pin’
Write some lines of C code for t
he Arduino to determine a cour
se of action if the seat belt has
been latched (switch closed).
If latched, the ignition should be e
nabled through a call to a function
ig_enable().
If not latched, the ignition should b
e disabled through a call to a functi
on ig_disable()
Write pseudocode first
ATmega328
PD3
Dr.
Amr
Talaat
Embedded
Systems
Digital IO – Practice 1 Pseudocode
 ‘Reading a pin’
Pseudocode:
Set up PD3 as an input
Turn on PD3 pull-up resistor
Read voltage on Arduino pin 3 (PIN_D3)
IF PIN_D3 voltage is LOW (latched), THE
N
call function ig_enable()
ELSE
call function ig_disable()
ATmega328
PD3
VTG= +5V
0
1
Dr.
Amr
Talaat
Embedded
Systems
Digital IO – Practice 1 Code
 ‘Reading a pin’
 Pseudocode:
Set up PD3 as an input
Turn on PD3 pull-up resistor
Read voltage on Arduino pin 3 (PIN_D3)
IF PIN_D3 voltage is LOW (latched), THEN
call function ig_enable()
ELSE
call function ig_disable()
ATmega328
PD3
VTG= +5V
0
1
#define PIN_SWITCH 3
#define LATCHED LOW
pinMode(PIN_SWITCH,INPUT_PULLUP);
belt_state = digitalRead(PIN_SWITCH);
if (belt_state == LATCHED)
{ ig_enable(); }
else
{ ig_disabled(); }
One way 
(snippet, not full program)
Dr.
Amr
Talaat
Embedded
Systems
Digital IO – Practice 2
 ‘Reading from and writing t
o a pin’
Write some lines of C code fo
r the Arduino to turn on a la
mp (PD2) and buzzer (PD3) i
f the key is in the ignition (P
D0 closed), but seat belt is n
ot latched (PD1 open)
(diagram shows only one of the
two switches, but both are simil
ar)
Pseudocode first
ATmega328
PD0, PD1
PD2
PD3
Dr.
Amr
Talaat
Embedded
Systems
Digital IO – Practice 2 Pseudocode
 Pseudocode:
Set up data direction of pins
Make PD0 and PD1 inputs
Turn on pull up resistors for PD0 and PD1
Make PD2 and PD3 outputs
Loop forever
IF key is in ignition THEN
IF belt is latched, THEN
Turn off buzzer
Turn off lamp
ELSE
Turn on lamp
Turn on buzzer
ELSE
Turn off buzzer
Turn off lamp
ATmega328
PD0, PD1
VTG= +5V
0
1
PD2
PD3
Dr.
Amr
Talaat
Embedded
Systems
Digital IO – Practice 2 (Arduino style code)
#define PIN_IGNITION 0
#define PIN_SEATBELT 1
#define PIN_LED 2
#define PIN_BUZZER 3
#define SEATBELT_LATCHED LOW
#define KEY_IN_IGNITION LOW
#define LED_ON HIGH
#define LED_OFF LOW
#define BUZZER_ON HIGH
#define BUZZER_OFF LOW
void setup()
{
pinMode(PIN_IGNITION, INPUT_PULLUP); // key switch
pinMode(PIN_SEATBELT, INPUT_PULLUP); // belt latch
switch
pinMode(PIN_LED, OUTPUT); // lamp
pinMode(PIN_BUZZER, OUTPUT); // buzzer
}
void loop()
{ /* see next page for code */}
ATmega328
PD0, PD1
VTG= +5V
0
1
PD2
PD3
Dr.
Amr
Talaat
Embedded
Systems
Digital IO – Practice 2 (Arduino style code)
/* see previous page for code before loop() */
void loop()
{
int key_state = digitalRead(PIN_IGNITION);
int belt_state = digitalRead(PIN_SEATBELT);
if (key_state == KEY_IN_IGNITION)
{
if (belt_state == SEATBELT_LATCHED)
{
digitalWrite(PIN_BUZZER, BUZZER_OFF);
digitalWrite(PIN_LED, LED_OFF);
}
else // key is in ignition, but seatbelt NOT
latched
{
digitalWrite(PIN_BUZZER, BUZZER_ON);
digitalWrite(PIN_LED, LED_ON);
}
else // key is NOT in ignition
{
digitalWrite(PIN_BUZZER, BUZZER_OFF);
digitalWrite(PIN_LED, LED_OFF);
}
}
}
ATmega328
PD0, PD1
VTG= +5V
0
1
PD2
PD3
Dr.
Amr
Talaat
Embedded
Systems
Digital IO – Practice 3 (Register style code)
/* NOTE: #defines use predefined PORT pin numbers for ATmega328 */
#define PIN_IGNITION PD0
#define PIN_SEATBELT PD1
#define PIN_LED PD2
#define PIN_BUZZER PD3
#define SEATBELT_LATCHED LOW
#define KEY_IN_IGNITION LOW
#define LED_ON HIGH
#define LED_OFF LOW
#define BUZZER_ON HIGH
#define BUZZER_OFF LOW
#define _BIT_MASK( bit ) ( 1 << (bit) ) // same as _BV( bit)
void setup()
{
PORTD = 0; // all PORTD pullups off
DDRD = _BIT_MASK(PIN_LED) | _BIT_MASK(PIN_BUZZER); // LED and buzzer
PORTD | = _BV(PIN_IGNITION) | _BV(PIN_SEATBELT); // pullups for switches
}
/* See next page for loop() code */
ATmega328
PD0, PD1
VTG= +5V
0
1
PD2
PD3
Dr.
Amr
Talaat
Embedded
Systems
Digital IO – Practice 3 (Register style code)
/* see previous page for setup() code */
void loop()
{
uint8_t current_PORTD_state, key_state, belt_state;
current_PORTD_state = PIND; // snapshot of PORTD pins
key_state = current_PORTD_state & _BV(PIN_IGNITION);
belt_state = current_PORTD_state & _BV(PIN_SEATBELT);
if (key_state == KEY_IN_IGNITION)
{
if (belt_state == SEATBELT_LATCHED)
{
PORTD & = ~( _BV(PIN_LED) | _BV(PIN_BUZZER) );
}
else
{
PORTD | = ( _BV(PIN_LED) | _BV(PIN_BUZZER) );
}
}
else
{
PORTD & = ~( _BV(PIN_LED) | _BV(PIN_BUZZER) );
}
}
ATmega328
PD0, PD1
VTG= +5V
0
1
PD2
PD3

More Related Content

Similar to IOT based embedded systems using arduino

Similar to IOT based embedded systems using arduino (20)

Embeddedsystems 091130091010-phpapp02
Embeddedsystems 091130091010-phpapp02Embeddedsystems 091130091010-phpapp02
Embeddedsystems 091130091010-phpapp02
 
Embeddedsystem 110412132957-phpapp02
Embeddedsystem 110412132957-phpapp02Embeddedsystem 110412132957-phpapp02
Embeddedsystem 110412132957-phpapp02
 
UNIT I_Introduction.pptx
UNIT I_Introduction.pptxUNIT I_Introduction.pptx
UNIT I_Introduction.pptx
 
EMBEDDED SYSTEMS INTRODUCTION.pptx
EMBEDDED SYSTEMS INTRODUCTION.pptxEMBEDDED SYSTEMS INTRODUCTION.pptx
EMBEDDED SYSTEMS INTRODUCTION.pptx
 
UNIT I.pptx
UNIT I.pptxUNIT I.pptx
UNIT I.pptx
 
It 443 lecture 1
It 443 lecture 1It 443 lecture 1
It 443 lecture 1
 
Introduction To Embedded Systems
Introduction To Embedded SystemsIntroduction To Embedded Systems
Introduction To Embedded Systems
 
Embedded Systems Programming
Embedded Systems ProgrammingEmbedded Systems Programming
Embedded Systems Programming
 
Unit-I Basic Embedded System Notes
Unit-I Basic Embedded System NotesUnit-I Basic Embedded System Notes
Unit-I Basic Embedded System Notes
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded Systems
 
es1-150721100817-lva1-app6891.pdf
es1-150721100817-lva1-app6891.pdfes1-150721100817-lva1-app6891.pdf
es1-150721100817-lva1-app6891.pdf
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systems
 
ERTS_Unit 1_PPT.pdf
ERTS_Unit 1_PPT.pdfERTS_Unit 1_PPT.pdf
ERTS_Unit 1_PPT.pdf
 
Embedded system
Embedded systemEmbedded system
Embedded system
 
Architecture design of a virtual embedded system report
Architecture design of a virtual embedded system reportArchitecture design of a virtual embedded system report
Architecture design of a virtual embedded system report
 
Real timedata
Real timedataReal timedata
Real timedata
 
Embeddedsystems
EmbeddedsystemsEmbeddedsystems
Embeddedsystems
 
Embedded system
Embedded systemEmbedded system
Embedded system
 
Embedded Intro India05
Embedded Intro India05Embedded Intro India05
Embedded Intro India05
 
Embedded System Presentation
Embedded System PresentationEmbedded System Presentation
Embedded System Presentation
 

More from Nagen87

UNIT1 concepts of measurements and instrumen
UNIT1 concepts of measurements and instrumenUNIT1 concepts of measurements and instrumen
UNIT1 concepts of measurements and instrumenNagen87
 
ppt-of-ehv-ac-transmission-pdf.pptx
ppt-of-ehv-ac-transmission-pdf.pptxppt-of-ehv-ac-transmission-pdf.pptx
ppt-of-ehv-ac-transmission-pdf.pptxNagen87
 
theeffectofsaltfogtestoninsulator-130618054216-phpapp02.pptx
theeffectofsaltfogtestoninsulator-130618054216-phpapp02.pptxtheeffectofsaltfogtestoninsulator-130618054216-phpapp02.pptx
theeffectofsaltfogtestoninsulator-130618054216-phpapp02.pptxNagen87
 
solid layer.pptx
solid layer.pptxsolid layer.pptx
solid layer.pptxNagen87
 
J.N-FEP 05.02.22.ppt
J.N-FEP 05.02.22.pptJ.N-FEP 05.02.22.ppt
J.N-FEP 05.02.22.pptNagen87
 
Chromatography-PPT.pptx
Chromatography-PPT.pptxChromatography-PPT.pptx
Chromatography-PPT.pptxNagen87
 
Infrared-Spectroscopy-ppt.pptx
Infrared-Spectroscopy-ppt.pptxInfrared-Spectroscopy-ppt.pptx
Infrared-Spectroscopy-ppt.pptxNagen87
 
Electrophoresis.pptx
Electrophoresis.pptxElectrophoresis.pptx
Electrophoresis.pptxNagen87
 
Lipids-PPT.pptx
Lipids-PPT.pptxLipids-PPT.pptx
Lipids-PPT.pptxNagen87
 
J.N-FEP 26.02.22.ppt
J.N-FEP 26.02.22.pptJ.N-FEP 26.02.22.ppt
J.N-FEP 26.02.22.pptNagen87
 
Emerging Trends Library Science.ppt
Emerging Trends Library Science.pptEmerging Trends Library Science.ppt
Emerging Trends Library Science.pptNagen87
 
Brushless_Permanent_Magnet_and_Reluctance_Motor_Drives__Monographs_in_Electri...
Brushless_Permanent_Magnet_and_Reluctance_Motor_Drives__Monographs_in_Electri...Brushless_Permanent_Magnet_and_Reluctance_Motor_Drives__Monographs_in_Electri...
Brushless_Permanent_Magnet_and_Reluctance_Motor_Drives__Monographs_in_Electri...Nagen87
 

More from Nagen87 (14)

UNIT1 concepts of measurements and instrumen
UNIT1 concepts of measurements and instrumenUNIT1 concepts of measurements and instrumen
UNIT1 concepts of measurements and instrumen
 
ppt-of-ehv-ac-transmission-pdf.pptx
ppt-of-ehv-ac-transmission-pdf.pptxppt-of-ehv-ac-transmission-pdf.pptx
ppt-of-ehv-ac-transmission-pdf.pptx
 
theeffectofsaltfogtestoninsulator-130618054216-phpapp02.pptx
theeffectofsaltfogtestoninsulator-130618054216-phpapp02.pptxtheeffectofsaltfogtestoninsulator-130618054216-phpapp02.pptx
theeffectofsaltfogtestoninsulator-130618054216-phpapp02.pptx
 
solid layer.pptx
solid layer.pptxsolid layer.pptx
solid layer.pptx
 
J.N-FEP 05.02.22.ppt
J.N-FEP 05.02.22.pptJ.N-FEP 05.02.22.ppt
J.N-FEP 05.02.22.ppt
 
Chromatography-PPT.pptx
Chromatography-PPT.pptxChromatography-PPT.pptx
Chromatography-PPT.pptx
 
Infrared-Spectroscopy-ppt.pptx
Infrared-Spectroscopy-ppt.pptxInfrared-Spectroscopy-ppt.pptx
Infrared-Spectroscopy-ppt.pptx
 
Electrophoresis.pptx
Electrophoresis.pptxElectrophoresis.pptx
Electrophoresis.pptx
 
Lipids-PPT.pptx
Lipids-PPT.pptxLipids-PPT.pptx
Lipids-PPT.pptx
 
J.N-FEP 26.02.22.ppt
J.N-FEP 26.02.22.pptJ.N-FEP 26.02.22.ppt
J.N-FEP 26.02.22.ppt
 
Emerging Trends Library Science.ppt
Emerging Trends Library Science.pptEmerging Trends Library Science.ppt
Emerging Trends Library Science.ppt
 
ev.ppt
ev.pptev.ppt
ev.ppt
 
HVE.ppt
HVE.pptHVE.ppt
HVE.ppt
 
Brushless_Permanent_Magnet_and_Reluctance_Motor_Drives__Monographs_in_Electri...
Brushless_Permanent_Magnet_and_Reluctance_Motor_Drives__Monographs_in_Electri...Brushless_Permanent_Magnet_and_Reluctance_Motor_Drives__Monographs_in_Electri...
Brushless_Permanent_Magnet_and_Reluctance_Motor_Drives__Monographs_in_Electri...
 

Recently uploaded

Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf203318pmpc
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 

Recently uploaded (20)

Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 

IOT based embedded systems using arduino

  • 1. IOT Design: An Embedded System Overview Definitions DAY Dr. Eng. Amr T. Abdel-Hamid NETW 1010 Fall 2016
  • 4. Dr. Amr Talaat Embedded Systems Embedded Systems  According to forecasts, future of IT c haracterized by terms such as  Disappearing computer,  Ubiquitous computing,  Pervasive computing,  Ambient intelligence,  Post-PC era,  Cyber-physical systems.  Internet of Things  Basic technologies:  Embedded Systems  Communication technologies
  • 5. Dr. Amr Talaat Embedded Systems Embedded Systems & Cyber-Physical Systems “Dortmund“ Definition: [Peter Marwedel] Embedded systems are information processing systems embedded into a larger product Berkeley: [Edward A. Lee]: Embedded software is software integrated with physical processes. The technical problem is managing time and concurrency in computational systems.  Definition: Cyber-Physical (cy-phy) Systems (CPS) are integrations of computation with physical processes [Edward Lee, 2006].
  • 6. Dr. Amr Talaat Embedded Systems Embedded System Hardware  Embedded system hardware is frequently used in a loop (“hardware in a loop“):
  • 7. Dr. Amr Talaat Embedded Systems Automotive electronics  Multiple networks Body, engine, telemat ics, media, safety, ...  Multiple networked processors Self DRIVING Vehicles Functions by embedded processing:  ABS: Anti-lock braking systems  ESP: Electronic stability control  Airbags  Efficient automatic gearboxes  Theft prevention with smart keys  Blind-angle alert systems  ... etc ...
  • 8. Dr. Amr Talaat Embedded Systems Forestry Machines  Networked computer system Controlling arms & tools Navigating the for est Recording the tree s harvested Crucial to efficient work  “Tough enough to be out in the woods”
  • 9. Dr. Amr Talaat Embedded Systems Smart buildings Examples  Integrated cooling, lightning, room reservation, emergency handling, communication  Goal: “Zero-energy building”  Expected contribution to fight against global warming
  • 12. Dr. Amr Talaat Embedded Systems Embedded System Hardware  Embedded system hardware is frequently used in a loop (“hardware in a loop“):
  • 13. Dr. Amr Talaat Embedded Systems 13 Some common characteristics of ES  Dependability  Single-functioned (dedicated System) Executes a single program, repeatedly  Tightly-constrained (Efficient) 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 with out delay
  • 14. Dr. Amr Talaat Embedded Systems Dependability  ES Must be dependable, • Reliability R(t) = probability of system working correctly provided that is was working at t=0 • Maintainability M(d) = probability of system working correctly d time units after error occurred. • Availability A(t): probability of system working at time t • Safety: no harm to be caused • Security: confidential and authentic communication Even perfectly designed systems can fail if the assumptions about the workload and possible errors turn out to be wrong. Making the system dependable must not be an after-thought, it must be considered from the very beginning
  • 15. Dr. Amr Talaat Embedded Systems Efficiency ES must be efficient Code-size efficient Run-time efficient Weight efficient Cost efficient Energy efficient
  • 16. Dr. Amr Talaat Embedded Systems Real-time constraints  Many ES must meet real-time constraints A real-time system must react to stimuli from the con trolled object (or the operator) within the time interv al dictated by the environment. For real-time systems, right answers arriving too late are wrong. “A real-time constraint is called hard, if not me eting that constraint could result in a catastrop he“ [Kopetz, 1997]. All other time-constraints are called soft. A guaranteed system response has to be explained w ithout statistical arguments
  • 17. Dr. Amr Talaat Embedded Systems Real-Time Systems  Embedded and Real -Time? Most embedded systems are real-time Most real-time systems are embedded embedded real-time embedded real-time © Jakob Engblom
  • 18. Dr. Amr Talaat Embedded Systems Reactive & hybrid systems  Typically, ES are reactive systems: “A reactive system is one which is in continual interacti on with is environment and executes at a pace determi ned by that environment“ [Bergé, 1995] Behavior depends on input and current state.  automata model appropriate, model of computable functions inappropriate.  Hybrid systems (analog + digital parts).
  • 19. Dr. Amr Talaat Embedded Systems Dedicated systems Dedicated towards a certain application Knowledge about behavior at design time c an be used to minimize resources and to maximize robustness Dedicated user interface (no mouse, keyboard and screen)
  • 20. Dr. Amr Talaat Embedded Systems Design Challenge  Time-to-prototype: the time needed to build a working v ersion of the system  Time-to-market: the time required to develop a system to the point that it can be released and sold to customers  NRE cost (Non-Recurring Engineering cost): The one-time monetary cost of designing the syst em  Flexibility: the ability to change the functionality of the system without incurring heavy NRE cost
  • 21. Dr. Amr Talaat Embedded Systems Design challenge – optimizing design metrics  Obvious design goal: Construct an implementation with desired fun ctionality  Key design challenge: Simultaneously optimize numerous design me trics  Design metric  A measurable feature of a system’s impleme ntation Optimizing design metrics is a key challenge
  • 22. Dr. Amr Talaat Embedded Systems Design metric competition -- improving one may worsen others  Expertise with both soft ware and hardware is needed to optimize design metrics  Not just a hardware or soft ware expert, as is common  A designer must be comfor table with various technolo gies in order to choose the best for a given application and constraints Size Performance Power NRE cost
  • 23. Dr. Amr Talaat Embedded Systems Hypothetical design flow Specification hardware System software Test * Evaluation & Validation (energy, cost, performance, …) Optimization Application mapping Application Knowledge Design repository Generic loop: tool chains differ in the number and type of iterations * Could be integrated into loop Design
  • 24. Dr. Amr Talaat Embedded Systems Design Questions  How much Power is needed?  Is power an issue?  Average Current needed?  Max. Transient Current  Do I need communications/Networking module?  How far? (Distance Travelled)  Authorized Frequencies  Antenna Size  Required Power  It is 1 device or in a network?  Do I need routing? …………
  • 27. Dr. Amr Talaat Embedded Systems IOT EXTRA Design Challenges  Larger Scale: Scalability, the ability of a network to support the increase of its limiting parameters. We discuss the first four scal ability issues here.  Large Network Size: In the Internet of Things, we are tal king about interaction with thousands of devices in one pl ace.  Massive Number of Events: A significant challenge is pos ed by the enormous number of events generated by obje cts.  Mobility Rate: Higher mobility rate causes more breakag e of links and causes more routing information becoming out-of-date.  Heterogeneous Devices: In the Internet of Things there i s a wide variety of hardware and devices, in all shapes an d sizes.
  • 28. Dr. Amr Talaat Embedded Systems IOT EXTRA Design Challenges (cont.)  Spontaneous Interaction: Sudden interactions happen as the objects move around and come into other objects’ wireless rang e. This leads to the spontaneous generation of events.  Zero Infrastructure: In the Internet of Things setting, devices need to discover each other as well as the resources provided by other devices in the surroundings. The challenge here is that the re is no fixed infrastructure to manage resource publication, disc overy and communication.
  • 29. Dr. Amr Talaat Embedded Systems IOT GENERIC Architecture Processor Communication Module Power Supply (Battery) Power Manger Processing API Communication API Database API Database Sensor/ Actuator
  • 31. Dr. Amr Talaat Embedded Systems Controller  Four important factors for the controller  Number of transistors -> size, cost, power  Number of clock cycles -> power  Time to MARKET-> cost, acceptance  Nonrecurring engineering cost (NRE) -> cost, a cceptance  Ideal: Minimize all factors at the same time!
  • 32. Dr. Amr Talaat Embedded Systems Tasks of the controller  Running of (real time) data processing and com munication protocols  Perform and control the application program  Energy management of the node Different operation modes available (active, i dle, listen, sleep, etc.)
  • 33. Dr. Amr Talaat Embedded Systems Embedded processors (MicroControllers )  Programmed once by manufacturer of system  Executes a single program (or a limited suite) wi th few parameters  Task-specific can be optimized for specific application  Interacts with environment in many ways direct sensing and control of signal wires communication protocols to environment and other devices real-time interactions and constraints
  • 34. Dr. Amr Talaat Embedded Systems Microprocessors and Microcontrollers • A microprocessor unit (MPU) is a processor on one silicon chip. • Microcontrollers are used in embedded computing. • A Microcontroller unit (MCU) is a microprocessor with some added circuitry on one silicon chip.
  • 36. Dr. Amr Talaat Embedded Systems C S E 4 7 7 CPU Memory Display (with dual-port video RAM) Disk I/O (serial line, keyboard, mouse) Network Interface standard interfaces system bus all the parts around the processor are usually required Typical general-purpose architecture
  • 37. Dr. Amr Talaat Embedded Systems Microcontroller ROM I/O Interface RAM custom logic standard interface any of the parts around the microcontroller are optional Typical task-specific architecture
  • 38. Dr. Amr Talaat Embedded Systems Introduction to Embedded Systems & Microcontrollers CSEN701: Embedded Systems 38 MCU Types • MCUs can be classified according: • MCU bits (e.g. 8-bit, 16-bit, 32-bit) • Instruction Set Architecture (ISA)
  • 39. Dr. Amr Talaat Embedded Systems MCU Bit Definition • The number of bits describing the data path defines Microcontroller Bit Definition
  • 40. Dr. Amr Talaat Embedded Systems Instruction Set Architecture • Instruction Set Architecture (ISA) is the part of the computer architecture related to programming, including the native data types, instructions, registers, addressing modes, memory architecture, interrupt and exception handling, and external I/O. • The ISA defines: • Operations that the processor can execute, • The mechanism of Data Transfer and how to access data, • Control Mechanisms (branch, jump, etc) • “Contract” between programmer/compiler and hardware • The main ISAs are CISC and RISC: • CISC stands for Complex Instruction Set Computer • RISC stands for Reduced Instruction Set Computer
  • 41. Dr. Amr Talaat Embedded Systems The CISC Approach • Emphasis on hardware • Includes multi-clock Instructions • Has a large amount of different (in length) and • complex instructions • The philosophy behind it is that hardware is always faster than software, therefore one should make a powerful instruction-set, • Memory-to-memory: • "LOAD" and "STORE“ are incorporated in instructions • Small code sizes (use less number of instructions), • Requires more transistors
  • 42. Dr. Amr Talaat Embedded Systems The RISC Approach • RISC processors only use simple instructions that can be executed within one clock cycle. • Because there are more lines of code, more RAM is needed to store the assembly level instructions. The compiler must also perform more work to convert a high-level language statement into code of this form. • Because each instruction requires only one clock cycle to execute, the entire program will execute in approximately the same amount of time as the multi-cycle "MULT" command. • These RISC "reduced instructions" require less transistors of hardware space than the complex instructions, leaving more room for general purpose registers. • Because all of the instructions execute in a uniform amount of time • (i.e. one clock), pipelining is possible. • It’s also called : Load-Store Architecture
  • 43. Dr. Amr Talaat Embedded Systems Microcontroller Features  Processor speed: Fundamental measure of pro cessing rate of device Value of interest is in MIPS, not MHz  Supply voltage/current: Measure of the amount of power required to run the device  Multiple modes (sleep, idle, etc)
  • 44. Dr. Amr Talaat Embedded Systems Common Memory Types in MCUs • RAM • EEPROM • Flash Memory
  • 45. Dr. Amr Talaat Embedded Systems RAM: Random Access Memory • Volatile or Non-Permanent Memory, i.e., data is lost after the removal of power, • Can be Written too Many Times, • It is a general purpose memory which is typically used for storing user data, temporary or Changeable Data • Most microcontrollers have some amount of internal RAM. Generally, 1 kbytes (“Embedded” in MCUs) is a common amount, although some microcontrollers have more, some less.
  • 46. Dr. Amr Talaat Embedded Systems It is electrically-erasable-and-programmable. Internally, they are similar to EPROMs, but the erase operation is accomplished electrically, rather than by exposure to ultraviolet light. Any byte within an EEPROM may be erased and rewritten.– Erased by higher voltage. The primary tradeoff for this improved functionality is higher cost, though write cycles are also significantly longer than writes to a RAM. EEPROM are typically used to store permanent data EEPROM: Electrically Erasable Programmable Read-Only Memory
  • 47. Dr. Amr Talaat Embedded Systems Flash Memory • Flash memory devices are • high density, • low cost, • nonvolatile, • fast (to read, but not to write), and • electrically reprogrammable. • Write/Erase large blocks of bytes • Read bytes • EEPROM is similar to flash memory (sometimes called flash EEPROM). • The principal difference is that • EEPROM requires data to be written or erased one byte at a time whereas flash memory allows data to be written or erased in blocks. • Flash memory is typically used in MCUs for storing program code
  • 48. Dr. Amr Talaat Embedded Systems Popular Microcontrollers • Intel 8051 • Microchip PIC • Atmel AVR • ARM
  • 49. Dr. Amr Talaat Embedded Systems 49 Why study the ARM architecture (and the Cortex-M3 in particular)?
  • 51. Dr. Amr Talaat Embedded Systems Introduction to ARM  Acorn Computers Ltd. (Cambridge, England) Nov. 1990  First called Acorn RISC Machine, then Advanced R ISC Machine  Based on RISC architecture work done at UCal Be rkley and Stanford  ARM only sells licenses for its core architect ure design  Optimized for low power & performance  VersatileExpress board with Cortex-A9 (ARMv7) c ore will be “emulated” using Linaro builds.  This also means some things may not work. You’v e been warned.
  • 52. Dr. Amr Talaat Embedded Systems ARM architecture versions Architecture Family ARMv1 ARM1 ARMv2 ARM2, ARM3 ARMv3 ARM6, ARM7 ARMv4 StrongARM, ARM7TDMI, ARM9TDMI ARMv5 ARM7EJ, ARM9E, ARM10E, Xscale ARMv6 ARM11, ARM Cortex-M ARMv7 ARM Cortex-A, ARM Cortex-M, ARM Cortex-R ARMv8 Not available yet. Will support 64-bit addressing + data 52
  • 53. Dr. Amr Talaat Embedded Systems Handling electronics - How NOT to Do It! Improper Handling - NEVER!!!
  • 54. Dr. Amr Talaat Embedded Systems Handling electronics - The Proper Way Proper Handling - by the edges!!!
  • 56. Dr. Amr Talaat Embedded Systems Microcontroller Ports and Pins  The communication channels through which information flows into or out of the microcontroller  Ex. PORTB  Pins PB0 – PB7  May not be contiguous  Often bi-directional C
  • 57. Dr. Amr Talaat Embedded Systems Port Pin Data Directionality  Input When you want to take information from the e xternal world (sensors) into the MCU  Output When you want to change the state of somethi ng outside the MCU (turn a motor on or off, e tc.)  Pins default to input direction on power-up or reset  Your program can set or change the direct ionality of a pin at any time
  • 59. Dr. Amr Talaat Embedded Systems Setting the Pin Data Direction  Arduino pinMode(pin_no., dir) Ex. Make Arduino pin 3 (PD3) an output pinMode(3, OUTPUT); pinMode(PIN_D3, OUTPUT); // with me 106.h Note: one pin at a time Suppose you wanted Arduino pins 3, 5, and 7 (PD3, PD5, and PD7) to be outputs? Is there a way to make them all outputs at t he same time? Yes! Answer coming later…
  • 60. Dr. Amr Talaat Embedded Systems Pin Voltages  Microcontrollers are fundamentally digital device s. For digital IO pins: Information is ‘coded’ in two discrete states: HIGH or LOW (logic: 1 or 0) Voltages TTL 5 V (for HIGH) 0 V (for LOW) 3.3 V CMOS 3.3 V (for HIGH) 0 V (for LOW)
  • 61. Dr. Amr Talaat Embedded Systems Pin Used as an Output  Turn on an LED, which is co nnected to pin Arduino pin 0 (PD0) (note the resistor!) What should the data directio n be for pin 0 (PD0)? pinMode(____, ____); Turn on the LED digitalWrite(PIN_LED,HIGH); Turn off the LED digitalWrite(PIN_LED,LOW); ATmega328 Arduino pin 0 (PD0)
  • 62. Dr. Amr Talaat Embedded Systems Pins as Inputs and Pull-up Resistors - 1  Using a switch as a sensor  Ex. Seat belt sensor  Detect the switch state What should the data directio n be for Arduino pin 3 (PD3)? pinMode(____, ____); What will the voltage be on P D3 when the switch is closed? What will the voltage be on P D3 when the switch is open? Indeterminate! ATmega328 Arduino pin 3 (PD3) SPST momentary
  • 63. Dr. Amr Talaat Embedded Systems Pins as Inputs and Pull-up Resistors - 2  Switch as a sensor, cont. Make the voltage on the pin d eterminate by turning on the pull-up resistor for PD3 Assuming PD3 is an input:  digitalWrite(PIN_SWITCH,HIGH); tur ns on the “pull-up” resistor  pinMode(PIN_SWITCH,INPUT_PULLUP); What will the voltage on PD3 be when the switch is open? VTG What will the voltage on PD3 be when the switch is closed? ATmega328 PD3 1 VTG= +5V 0
  • 64. Dr. Amr Talaat Embedded Systems Pins as Inputs and Pull-up Resistors - 3  Switch as a sensor, cont. To turn off the pull-up resist or Assuming PD3 is an input : digitalWrite(PIN_SWITCH,LOW); tur ns the “pull-up” resistor off ATmega328 PD3 VTG= +5V 0 1
  • 65. Dr. Amr Talaat Embedded Systems Pins as Inputs and Pull-up Resistors - 4  Possibility of ‘weak drive’ when pull-up resistor is turned on Pin set as an input with a pul l-up resistor turned on can s ource a small current Remember this! ATmega328 PD3 VTG= +5V 0 1 iweak
  • 66. Dr. Amr Talaat Embedded Systems Example 1  Arduino approach  Alternate approach  Make Arduino pins 3, 5, and 7 (PD3, PD5, and PD7) to be outputs pinMode(3, OUTPUT); pinMode(5, OUTPUT); pinMode(7, OUTPUT); DDRD = 0b10101000; or DDRD = 0xA8; or DDRD | = 1<<PD7 | 1<<PD5 | 1<<PD3; More on this coming soon! Or if me106.h is used: pinMode(PIN_D3, OUTPUT); pinMode(PIN_D5, OUTPUT); pinMode(PIN_D7, OUTPUT);
  • 67. Dr. Amr Talaat Embedded Systems Example 2  Arduino approach  Alternate approach  Make pins Arduino pins 0 and 1 (PD0 and PD1) inputs, and turn on pull-up resistors pinMode(0, INPUT); pinMode(1, INPUT); digitalWrite(0, HIGH); digitalWrite(1, HIGH); DDRD = 0; // all PORTD pins inputs PORTD = 0b00000011; or PORTD = 0x03; or better yet: DDRD & = ~(1<<PD1 | 1<<PD0); PORTD | = (1<<PD1 | 1<<PD0); More on this coming soon! Or if me106.h is used: pinMode(PIN_D0, INPUT); pinMode(PIN_D1, INPUT); digitalWrite(PIN_D0, HIGH); digitalWrite(PIN_D1, HIGH);
  • 68. Dr. Amr Talaat Embedded Systems Structure of an Arduino Program  An arduino program == ‘ske tch’  Must have:  setup()  loop()  setup()  configures pin modes an d registers  loop()  runs the main body of th e program forever  like while(1) {…}  Where is main() ?  Arduino simplifies things  Does things for you /* Blink - turns on an LED for DELAY_ON msec, then off for DELAY_OFF msec, and repeats BJ Furman rev. 1.1 Last rev: 22JAN2011 */ #define LED_PIN 13 // LED on digital pin 13 #define DELAY_ON 1000 #define DELAY_OFF 1000 void setup() { // initialize the digital pin as an output: pinMode(LED_PIN, OUTPUT); } // loop() method runs forever, // as long as the Arduino has power void loop() { digitalWrite(LED_PIN, HIGH); // set the LED on delay(DELAY_ON); // wait for DELAY_ON msec digitalWrite(LED_PIN, LOW); // set the LED off delay(DELAY_OFF); // wait for DELAY_OFF msec }
  • 69. Dr. Amr Talaat Embedded Systems Digital IO – Practice 1  ‘Reading a pin’ Write some lines of C code for t he Arduino to determine a cour se of action if the seat belt has been latched (switch closed). If latched, the ignition should be e nabled through a call to a function ig_enable(). If not latched, the ignition should b e disabled through a call to a functi on ig_disable() Write pseudocode first ATmega328 PD3
  • 70. Dr. Amr Talaat Embedded Systems Digital IO – Practice 1 Pseudocode  ‘Reading a pin’ Pseudocode: Set up PD3 as an input Turn on PD3 pull-up resistor Read voltage on Arduino pin 3 (PIN_D3) IF PIN_D3 voltage is LOW (latched), THE N call function ig_enable() ELSE call function ig_disable() ATmega328 PD3 VTG= +5V 0 1
  • 71. Dr. Amr Talaat Embedded Systems Digital IO – Practice 1 Code  ‘Reading a pin’  Pseudocode: Set up PD3 as an input Turn on PD3 pull-up resistor Read voltage on Arduino pin 3 (PIN_D3) IF PIN_D3 voltage is LOW (latched), THEN call function ig_enable() ELSE call function ig_disable() ATmega328 PD3 VTG= +5V 0 1 #define PIN_SWITCH 3 #define LATCHED LOW pinMode(PIN_SWITCH,INPUT_PULLUP); belt_state = digitalRead(PIN_SWITCH); if (belt_state == LATCHED) { ig_enable(); } else { ig_disabled(); } One way  (snippet, not full program)
  • 72. Dr. Amr Talaat Embedded Systems Digital IO – Practice 2  ‘Reading from and writing t o a pin’ Write some lines of C code fo r the Arduino to turn on a la mp (PD2) and buzzer (PD3) i f the key is in the ignition (P D0 closed), but seat belt is n ot latched (PD1 open) (diagram shows only one of the two switches, but both are simil ar) Pseudocode first ATmega328 PD0, PD1 PD2 PD3
  • 73. Dr. Amr Talaat Embedded Systems Digital IO – Practice 2 Pseudocode  Pseudocode: Set up data direction of pins Make PD0 and PD1 inputs Turn on pull up resistors for PD0 and PD1 Make PD2 and PD3 outputs Loop forever IF key is in ignition THEN IF belt is latched, THEN Turn off buzzer Turn off lamp ELSE Turn on lamp Turn on buzzer ELSE Turn off buzzer Turn off lamp ATmega328 PD0, PD1 VTG= +5V 0 1 PD2 PD3
  • 74. Dr. Amr Talaat Embedded Systems Digital IO – Practice 2 (Arduino style code) #define PIN_IGNITION 0 #define PIN_SEATBELT 1 #define PIN_LED 2 #define PIN_BUZZER 3 #define SEATBELT_LATCHED LOW #define KEY_IN_IGNITION LOW #define LED_ON HIGH #define LED_OFF LOW #define BUZZER_ON HIGH #define BUZZER_OFF LOW void setup() { pinMode(PIN_IGNITION, INPUT_PULLUP); // key switch pinMode(PIN_SEATBELT, INPUT_PULLUP); // belt latch switch pinMode(PIN_LED, OUTPUT); // lamp pinMode(PIN_BUZZER, OUTPUT); // buzzer } void loop() { /* see next page for code */} ATmega328 PD0, PD1 VTG= +5V 0 1 PD2 PD3
  • 75. Dr. Amr Talaat Embedded Systems Digital IO – Practice 2 (Arduino style code) /* see previous page for code before loop() */ void loop() { int key_state = digitalRead(PIN_IGNITION); int belt_state = digitalRead(PIN_SEATBELT); if (key_state == KEY_IN_IGNITION) { if (belt_state == SEATBELT_LATCHED) { digitalWrite(PIN_BUZZER, BUZZER_OFF); digitalWrite(PIN_LED, LED_OFF); } else // key is in ignition, but seatbelt NOT latched { digitalWrite(PIN_BUZZER, BUZZER_ON); digitalWrite(PIN_LED, LED_ON); } else // key is NOT in ignition { digitalWrite(PIN_BUZZER, BUZZER_OFF); digitalWrite(PIN_LED, LED_OFF); } } } ATmega328 PD0, PD1 VTG= +5V 0 1 PD2 PD3
  • 76. Dr. Amr Talaat Embedded Systems Digital IO – Practice 3 (Register style code) /* NOTE: #defines use predefined PORT pin numbers for ATmega328 */ #define PIN_IGNITION PD0 #define PIN_SEATBELT PD1 #define PIN_LED PD2 #define PIN_BUZZER PD3 #define SEATBELT_LATCHED LOW #define KEY_IN_IGNITION LOW #define LED_ON HIGH #define LED_OFF LOW #define BUZZER_ON HIGH #define BUZZER_OFF LOW #define _BIT_MASK( bit ) ( 1 << (bit) ) // same as _BV( bit) void setup() { PORTD = 0; // all PORTD pullups off DDRD = _BIT_MASK(PIN_LED) | _BIT_MASK(PIN_BUZZER); // LED and buzzer PORTD | = _BV(PIN_IGNITION) | _BV(PIN_SEATBELT); // pullups for switches } /* See next page for loop() code */ ATmega328 PD0, PD1 VTG= +5V 0 1 PD2 PD3
  • 77. Dr. Amr Talaat Embedded Systems Digital IO – Practice 3 (Register style code) /* see previous page for setup() code */ void loop() { uint8_t current_PORTD_state, key_state, belt_state; current_PORTD_state = PIND; // snapshot of PORTD pins key_state = current_PORTD_state & _BV(PIN_IGNITION); belt_state = current_PORTD_state & _BV(PIN_SEATBELT); if (key_state == KEY_IN_IGNITION) { if (belt_state == SEATBELT_LATCHED) { PORTD & = ~( _BV(PIN_LED) | _BV(PIN_BUZZER) ); } else { PORTD | = ( _BV(PIN_LED) | _BV(PIN_BUZZER) ); } } else { PORTD & = ~( _BV(PIN_LED) | _BV(PIN_BUZZER) ); } } ATmega328 PD0, PD1 VTG= +5V 0 1 PD2 PD3