BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) •...

89
BBM 432 EMBEDDED SYSTEMS Week-1

Transcript of BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) •...

Page 1: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

BBM 432 – EMBEDDED

SYSTEMSWeek-1

Page 2: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Welcome to Embedded Systems

• Instructor: Mehmet Koseoglu

• Email: [email protected]

• A course with practical focus.

• Accompanies the lab course BBM 434.

• Both courses should be taken together.

• Lab Sec. 1 quota is full. If you do not have a conflict, please move to Sec. 2.

• 432 quota is available.

• Register on Piazza.

Lab assistant:

• Selma Dilek

Page 3: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Textbook

• Textbook is mandatory

• A summary can be found at

http://users.ece.utexas.edu/~valvano/Volume1/E-Book/

Page 4: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Courseware

• Initially based on an EDX courses given by Prof. Valvano

University of Texas.

• Some of the course material can be found in

• https://www.edx.org/course/embedded-systems-shape-

the-world-microcontroller-inputoutput

• https://www.edx.org/course/embedded-systems-shape-

the-world-multi-threaded-interfacing

• You can watch the videos and access the course material.

Page 5: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Labs• Labs are different from last year’s course.

• Labs will be in groups of two.

• You will also submit reports for each lab.

• You will also complete a Project, write a report and attend to the project fair.

Schedule (tentative)

• Week 1:

• Week 2: Deadline for forming lab groups

• Week 3: Lab 1

• Week 4: Lab 2

• Week 5: Lab 3

• Week 6: Lab 4 - (Project proposal)

• Week 7: Lab 5

• Week 8: Lab 6

• Week 9: Lab 7

• Week 10: Lab 8

• Week 11: Project progress assesment

• Week 12: Project progress assesment

• Week 13: Project progress assesment

• Week 14: Project progress assesment

Page 6: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Lab rules

• Friday 13:00-15:00 and 15:00 – 17:00

• You need to form groups from the same lab section.

• You will submit reports before the lab.

• In the lab, you will demo your results to the TA.

• In the last weeks, your will submit your project progress

reports and make a demo of your progress.

• In the final week, you will make a demo of your project.

Page 7: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

The Launchpad – TM4C123GXL, Nokia

5110 LCD and the WiFi Adaptor

You can display data from Internet

on the LCD.

Page 8: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

The lab equipment

Each group need to buy the following (150-200 TL total, 75-

100 TL per student)

• 1) Kit for this lab course. (115 TL)

• 2) Nokia 5110 LCD Display (16 TL)

• 3) ESP8266 WiFi Module (13 TL)

• You will also buy a breadboard. (8 TL)

• You will also buy some circuit equipment. More info on

Piazza.

• You must buy for the kit the first lab (3rd week). Order as

soon as possible.

• You need to have your own laptop computer.

Page 9: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Form lab groups

• Deadline for forming lab groups is next week Friday at the

add/drop deadline.

• We will let you know how you will submit the group

information.

Page 10: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

The syllabus

• BBM 432:

• 1 midterm (%50)

• Final 50%

• Ungraded online quizzes.

• Attendance is mandatory. Online quizzes will be used for

attendance.

• BBM 434

• %60 Labs, %40 Project (Counted as the Final)

Page 11: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Based on the ARM Cortex-M4 Core

Page 12: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Purpose of the courses

BBM 432

• To teach the fundamental

concepts of embedded

system design.

BBM 434

• To apply your knowledge.

Page 13: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Topics

• Debugging and verification using a simulator and on the

real microcontroller

• How input/output using switches, LEDs, DACs, ADCs,

motors, and serial ports

• The implementation of an I/O driver, multithreaded

programming

• Analog to digital conversion (ADC), periodic sampling,

• Simple motors (e.g., open and closed-loop stepper motor

control)

• Digital to analog conversion (DAC), used to make simple

sounds

Page 14: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

What is an embedded system?

• An embedded system is a system that performs a specific

task and has a computer embedded inside.

• A system is comprised of components and interfaces

connected together for a common purpose.

• Specific topics include

• microcontrollers,

• fixed-point numbers,

• programming input/output including interrupts,

• analog to digital conversion,

• digital to analog conversion.

Page 15: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

A new embedded systems course

• Previous courses dominated by simple microcontrollers

like the PIC, the 9S12, and the 8051.

• The ARM platform is both low cost and high-performance

• The ARM market share is large: ARM reports that over 35

billion ARM processors have been shipped from over 950

companies. (As of July 2013)

• Students trained on the ARM will be equipped to design

systems across the complete spectrum from simple to

complex.

Page 16: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Smoke detector

• Inputs.

• chemical sensor

• button to test the battery.

• Outputs

• a LED

• the alarm.

• Low-power sleep

mode.

• Once every 30 seconds,

it wakes up If the test

Page 17: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Artificial pacemaker

• Inputs

• Sensors on the heart

• Outputs

• deliver electrical pulses

to stimulate the heart.

• Real-time systems

• delay between atrial

sensing and ventricular

triggering is critical.

Page 18: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

ABS – Anti-lock braking system

Page 19: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Examples of embedded systems

Portable devices

Page 20: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Examples of embedded systems

• Miniature wireless devices called motes.

Page 21: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Difference from general purpose

microprocessors

• Dedicated to handle a

particular task.

• Smaller

• Cheaper

• More reliability

• High performance.

Page 22: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

More examples

• Consumer/Home:

• Washing machine:

• Controls the water and spin cycles, saving water and energy

• Exercise equipment

• Measures speed, distance, calories, heart rate

• Remote controls

• Accepts key touches, sends infrared pulses,

• Clocks and watches

• Maintains the time, alarm, and display

• Games and toys

• Entertains the user, joystick input, video output

• Set-back thermostats

• Adjusts day/night thresholds saving energy

Page 23: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Next: Preliminaries

• Binary, hex conversion.

• Resistor calculations.

Page 24: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Binary Representations

0.0V

0.5V

2.8V

3.3V

0 1 0

Page 25: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Encoding Byte Values

• Byte = 8 bits

• Binary 000000002 to 111111112

• Decimal: 010 to 25510

• Hexadecimal 0016 to FF16

• Base 16 number representation

• Use characters ‘0’ to ‘9’ and ‘A’ to ‘F’

• Write FA1D37B16 in C as

• 0xFA1D37B

• 0xfa1d37b

0 0 00001 1 00012 2 00103 3 00114 4 01005 5 01016 6 01107 7 01118 8 10009 9 1001A 10 1010B 11 1011C 12 1100D 13 1101E 14 1110F 15 1111

Page 26: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Byte Ordering

• How should bytes within a multi-byte word be ordered in

memory?

• Conventions

• Big Endian: Sun, PPC Mac, Internet

• Least significant byte has highest address

• Little Endian: x86

• Least significant byte has lowest address

• The Texas Instruments TM4C microcontrollers use the

little endian format.

Page 27: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Byte Ordering Example

• Big Endian

• Least significant byte has highest address

• Little Endian

• Least significant byte has lowest address

• Example

• Variable x has 4-byte representation 0x01234567

• Address given by &x is 0x100

0x100 0x101 0x102 0x103

01 23 45 67

0x100 0x101 0x102 0x103

67 45 23 01

Big Endian

Little Endian

01 23 45 67

67 45 23 01

Page 28: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Representing Integers

Decimal: 15213

Binary: 0011 1011 0110 1101

Hex: 3 B 6 D

6D

3B

00

00

IA32, x86-64

3B

6D

00

00

Sun

int A = 15213;

93

C4

FF

FF

IA32, x86-64

C4

93

FF

FF

Sun

Two’s complement representation

(Covered later)

int B = -15213;

long int C = 15213;

00

00

00

00

6D

3B

00

00

x86-64

3B

6D

00

00

Sun

6D

3B

00

00

IA32

Page 29: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

char S[6] = "18243";Representing Strings• Strings in C

• Represented by array of characters

• Each character encoded in ASCII format

• Standard 7-bit encoding of character set

• Character “0” has code 0x30

• Digit i has code 0x30+i

• String should be null-terminated

• Final character = 0

• Compatibility

• Byte ordering not an issue

Linux/Alpha Sun

31

38

32

34

33

00

31

38

32

34

33

00

Page 30: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Today: Bits, Bytes, and Integers

• Representing information as bits

• Bit-level manipulations

• Integers

• Representation: unsigned and signed

• Conversion, casting

• Expanding, truncating

• Addition, negation, multiplication, shifting

• Summary

Page 31: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Boolean Algebra

• Developed by George Boole in 19th Century

• Algebraic representation of logic

• Encode “True” as 1 and “False” as 0And

A&B = 1 when both A=1 and B=1

Or

A|B = 1 when either A=1 or B=1

Not

~A = 1 when A=0

Exclusive-Or (Xor)

A^B = 1 when either A=1 or B=1, but not both

Page 32: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

General Boolean Algebras

• Operate on Bit Vectors

• Operations applied bitwise

• All of the Properties of Boolean Algebra Apply

01101001

& 01010101

01000001

01101001

| 01010101

1111101

01101001

^ 01010101

00111100

~ 01010101

1010101001000001 01111101 00111100 10101010

Page 33: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Representing & Manipulating Sets

• Representation• Width w bit vector represents subsets of 0, …, w–1

• aj = 1 if j ∈ A

• 01101001 0, 3, 5, 6

• 76543210

• 01010101 0, 2, 4, 6

• 76543210

• Operations• & Intersection 01000001 0, 6

• | Union 01111101 0, 2, 3, 4, 5, 6

• ^ Symmetric difference 00111100 2, 3, 4, 5

• ~ Complement 10101010 1, 3, 5, 7

Page 34: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Bit-Level Operations in C

• Operations &, |, ~, ^ Available in C• Apply to any “integral” data type

• long, int, short, char, unsigned

• View arguments as bit vectors

• Arguments applied bit-wise

• Examples (Char data type)• ~0x41 = 0xBE

• ~010000012 = 101111102

• ~0x00 = 0xFF

• ~000000002 = 111111112

• 0x69 & 0x55 = 0x41

• 011010012 & 010101012 = 010000012

• 0x69 | 0x55 = 0x7D

• 011010012 | 010101012 = 011111012

Page 35: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Contrast: Logic Operations in C

• Contrast to Logical Operators

• &&, ||, !

• View 0 as “False”

• Anything nonzero as “True”

• Always return 0 or 1

• Early termination

• Examples (char data type)• !0x41 = 0x00

• !0x00 = 0x01

• !!0x41 = 0x01

• 0x69 && 0x55 = 0x01

• 0x69 || 0x55 = 0x01

Page 36: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Shift Operations

• Left Shift: x << y

• Shift bit-vector x left y positions

• Throw away extra bits on left

• Fill with 0’s on right

• Right Shift: x >> y

• Shift bit-vector x right y positions

• Throw away extra bits on right

• Logical shift

• Fill with 0’s on left

• Arithmetic shift

• Replicate most significant bit on right

• Undefined Behavior

• Shift amount < 0 or ≥ word size

01100010Argument x

00010000<< 3

00011000Log. >> 2

00011000Arith. >> 2

10100010Argument x

00010000<< 3

00101000Log. >> 2

11101000Arith. >> 2

0001000000010000

0001100000011000

0001100000011000

00010000

00101000

11101000

00010000

00101000

11101000

Page 37: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Today: Bits, Bytes, and Integers

• Representing information as bits

• Bit-level manipulations

• Integers

• Representation: unsigned and signed

• Conversion, casting

• Expanding, truncating

• Addition, negation, multiplication, shifting

• Summary

Page 38: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Encoding Integers

short int x = 15213;

short int y = -15213;

• C short 2 bytes long

• Sign Bit

• For 2’s complement, most significant bit indicates sign

• 0 for nonnegative

• 1 for negative

B2T (X ) xw1 2w1

xi 2i

i0

w2

B2U(X ) xi 2i

i0

w1

Unsigned Two’s Complement

SignBit

Decimal Hex Binary x 15213 3B 6D 00111011 01101101

y -15213 C4 93 11000100 10010011

Page 39: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Encoding Example (Cont.)x = 15213: 00111011 01101101

y = -15213: 11000100 10010011

Weight 15213 -15213

1 1 1 1 1 2 0 0 1 2 4 1 4 0 0 8 1 8 0 0

16 0 0 1 16 32 1 32 0 0 64 1 64 0 0

128 0 0 1 128 256 1 256 0 0 512 1 512 0 0

1024 0 0 1 1024 2048 1 2048 0 0 4096 1 4096 0 0 8192 1 8192 0 0

16384 0 0 1 16384 -32768 0 0 1 -32768

Sum 15213 -15213

Page 40: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Precision and alternatives

• Precision is the number of distinct or different values. We

express precision in alternatives, decimal digits, bytes, or

binary bits.

• Alternatives are defined as the total number of

possibilities. For example, an 8-bit number format can

represent 256 different numbers.

• An 8-bit digital to analog converter (DAC) can generate

256 different analog outputs. An 8-bit analog to digital

converter (ADC) can measure 256 different analog

inputs.

Page 41: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Specifying precision

• When programming in C, we will use data types char

short and long when we wish to explicitly specify the

precision as 8-bit, 16-bit or 32-bit.

• Whereas, we will use the int data type only when we don’t

care about precision, and we wish the compiler to choose

the most efficient way to perform the operation.

• For most compilers for the ARM processor, int will be 32

bits.

Page 42: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Today

• Course Information

• Review of binary representation of numbers

• Review of basic electronics

• Introduction to embedded systems

Page 43: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Introduction to Electronics

• Current, I, is defined as the movement of electrons. In

particular, 1 ampere (A) of current is 6.241×1018 electrons

per second, or one coulomb per second.

• Current is measured at one point as the number of

electrons travelling per second.

• Current has an amplitude and a direction.

• Because electrons are negatively charged, if the electrons

are moving to the left, we define current as flowing to the

right.

Page 44: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Voltage

• Voltage, V, is an electrical term representing the potential

difference between two points.

• The units of voltage are volts (V), and it is always

measured as a difference.

• Voltage is the electromotive force or potential to produce

current.

Page 45: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Resistor

• We will see two types of conducting media: a wire and a

resistor.

• Wires, made from copper, will allow current to freely flow,

but forcing current to flow through a resistor will require

energy.

• The electrical property of a resistor is resistance in ohms

(Ω).

• Ideally, a wire is simply a resistor with a resistance of 0 Ω.

Page 46: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Ohm’s Law

• The basic relation between voltage, current, and

resistance for a resistor is known as Ohm’s Law, which

can be written three ways:

• V = I * R Voltage = Current * Resistance

• I = V / R Current = Voltage / Resistance

• R = V / I Resistance = Voltage / Current

Page 47: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Ohm’s Law

Page 48: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Analogous systems

Page 49: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Power

• The power (P in watts) dissipated in a resistor can be

calculated from voltage (V in volts), current (I in amps),

and resistance (R in ohms).

• Power has neither a polarity nor a direction.

P = V * I Power = Voltage * Current

P = V2 / R Power = Voltage2 / Resistance

P = I2 * R Power = Current2 * Resistance

Page 50: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Electric circuits

• A switch is an element used to modify the behavior of the

circuit.

• If the switch is pressed, its resistance is 0, and current

can flow across the switch.

• If the switch is not pressed, its resistance is infinite, and

no current will flow.

• The classic electrical circuit involves a battery, a light bulb

(modeled in this circuit as a 100Ω resistor), and a switch.

Page 51: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Kirchhoff's Current Law (KCL)

• The sum of the currents into a node equal the sum of the

currents leaving a node as shown in the figure.

Page 52: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Series resistance

• If resistor R1 is in series with resistor R2, this combination

behaves like one resistor with a value equal to R1+R2.

• By KCL, the currents through the two resistors are the

same. These two facts can be used to derive the voltage

divider rule

• V2 = I*R2 = (V/R)*R2 = V*R2/(R1+R2)

Page 53: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Parallel resistance

• Parallel resistance. If resistor R1 is in parallel with resistor

R2, this combination behaves like one resistor with a

value equal to

Page 54: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Introduction to Digital Logic

• A binary bit can exist in one of two possible states.

• In positive logic, the presence of a voltage is called the

‘1’, true, asserted, or high state.

• The absence of a voltage is called the ‘0’, false, not

asserted, or low state.

Page 55: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

High and low voltages

• Stellaris® microcontroller powered with 3.3 V supply, a

voltage between 2 and 5 V is considered high, and a

voltage between 0 and 1.3 V is considered low,

• Separating the two regions by 0.7 V allows digital

logic to operate reliably at very high speeds.

• Digital data exist as binary bits and encoded as

high and low voltages.

Page 56: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Logical AND on numbers

• When writing software we will have two kinds of logic

operations. When operating on numbers (collection of

bits) we will perform logic operations bit by bit. In other

words, the operation is applied independently on each bit.

In C, the logic operator for AND is &. For example, if

number A is 01100111 and number B is 11110000 then

• A = 01100111

• B = 11110000

• A&B 01100000

Page 57: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Logical AND on Boolean

• The other type of logic operation occurs when operating

on Boolean values. In C, the condition false is

represented by the value 0, and true is any nonzero

value. In this case, if the Boolean A is 01100111 and B is

11110000 then both A and B are true. The standard value

for true is the value 1. In C, the Boolean operator for AND

is &&. Performing Boolean operation yields

• A = 01100111

• B = 11110000

• A&&B 1

Page 58: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Logical OR on numbers

• In C, the logic operator for OR is |. The logic operation is

applied independently on each bit. E.g.,

• A = 01100111

• B = 11110000

• A|B 11110111

Page 59: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Logical OR on boolean

• In C, the Boolean operator for OR is ||. Performing

Boolean operation of true OR true yields true. Although 1

is the standard value for a true, any nonzero value is

considered as true.

• A = 01100111

• B = 11110000

• A||B 1

Page 60: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

A question

• Let A bit an 8-bit number, and consider the operation

B=A&0x20, where A&0x20 is performed bit by bit. Now, if

we consider B as a Boolean value, what is the

relationship between A and B?

• B will be 0x20 if bit 5 of A is 1, and will be 0x00 if bit 5 of A

is 0. Since B is Boolean, B will be true if and only of bit 5

of A is 1.

Page 61: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Another question

• Let C be an 8-bit number and consider the operation

C=C&0xDF. How does this operation affect C?

• Checkpoint 4.6: The value 0xDF has bit 5 low, and other

bits high. The AND with 0x20 will clear bit 5 of C.

Page 62: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Another question

• Let D bit an 8-bit number, and consider the operation

D=D|0x20. How does this operation affect D?

• The OR with 0x20 will set bit 5 of D.

Page 63: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Another question• Let C bit an 8-bit number. Are these two operations the

same or different? C=C&0xDF C=C&(~0x20)

Since ~0x20 is equal to 0xDF, they are the same. The

second is a clearer way to signify clear bit 5.

Page 64: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Today

• Course Information

• Review of binary representation of numbers

• Review of basic electronics

• Introduction to embedded systems

Page 65: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Embedded systems

• Processor, RAM, ROM and I/O ports in a single package

• Low cost, small size, and low power requirements.

• TM4C has a wide variety of I/O devices, • parallel ports,

• serial ports,

• timers,

• digital to analog converters (DAC),

• analog to digital converters (ADC).

Page 66: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Embedded systems

• ROM - stores the software and fixed constant data

• RAM - stores temporary information.

• Most use Flash EEPROM, which is an electrically-

erasable programmable ROM, because the information

can easily be erased and reprogrammed.

• The functionality of a digital watch is defined by the

software programmed into its ROM.

• When you remove the batteries from a watch and insert

new batteries, it still behaves like a watch because the

ROM is nonvolatile storage.

Page 67: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

A simple embedded system

• Two inputs: the mode selection dial on the front and the red/black test probes.

• The output is a liquid crystal display (LCD) showing the measured parameter.

• The large black chip inside the box is a microcontroller.

• The software that defines its very specific purpose is programmed into the ROM of the microcontrollers.

Page 68: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Difference from a computer

• Most embedded systems do not have a keyboard, a

graphics display, or secondary storage (disk).

• First method: No operating system, so the entire

software system is developed.

• Suitable for low-cost, low-performance systems.

• Second method: Code runs over an operating system.

• More powerful microcontroller. Such as ARM Cortex A.

• These systems typically employ an operating system. (VxWorks

etc.)

Page 69: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Interfaces

• The external devices attached to the microcontroller allow

the system to interact with its environment.

• An interface is defined as the hardware and software that

combine to allow the computer to communicate with the

external hardware.

• We must learn how to interface a wide range of inputs and

outputs that can exist in either digital or analog form.

• In general, we can classify I/O interfaces into parallel,

serial, analog or time.

Page 70: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

I/O port

• One of the simplest I/O ports on the Stellaris® microcontrollers is a parallel port or General Purpose Input/Output (GPIO).

• One such parallel port is Port A. The software will refer to this port using the name GPIO_PORTA_DATA_R.

• Ports are a collection of pins, usually 8, which can be used for either input or output.

• If Port A is an input port, then when the software reads from GPIO_PORTA_DATA_R, it gets eight bits (each bit is 1 or 0), representing the digital levels (high or low) that exist at the time of the read.

• If Port A is an output port, then when the software writes to GPIO_PORTA_DATA_R, it sets the outputs on the eight pins high (1) or low (0), depending on the data value the software has written.

Page 71: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Real-time

• An upper bound on the time required to perform the input-

calculation-output sequence.

• Guarantee a worst case upper bound on the response time

• Another real-time requirement that exists in many

embedded systems is the execution of periodic tasks.

• A periodic task has to be performed at equal-time intervals.

• Need a small and bounded limit on the time error between when a

task should be run and when it is actually run.

• Because of the real-time nature of these systems, microcontrollers

have a rich set of features to handle many aspects of time.

Page 72: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Software maintenance

• The microcomputer is embedded or hidden inside the

device.

• In an embedded system, the software is usually

programmed into ROM and therefore fixed.

• Software maintenance is extremely important.

• Microcomputers are employed in many safety-critical devices,

injury or death may result if there are hardware and/or software

faults.

• Do not want a bug in a pacemaker or ABS.

• Testing is very important

• Simulation is important.

Page 73: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Computer Architecture

• A computer combines a processor, random access

memory (RAM), read only memory (ROM), and

input/output (I/O) ports.

• Von-Neumann Architecture

• Processor executes the software.

Page 74: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Microprocessor

• A microprocessor is a small processor, where small

refers to size (i.e., it fits in your hand) and not

computational ability.

• For example, Intel Xeon E7, AMD Fusion, and Sun

SPARC are microprocessors.

Page 75: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Microcomputer

• A microcomputer is a small computer, where again small refers to size (i.e., you can carry it) and not computational ability.

• For example, a desktop PC is a microcomputer. Small in this context describes its size not its computing power.

• Consequently, there can be great confusion over the term microcomputer, because it can refer to a very wide range of devices from a PIC12C508, which is an 8-pin chip with 512 words of ROM and 25 bytes RAM, to the most powerful I7-based personal computer.

Page 76: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

I/O Ports

• A port is a physical connection between the computer

and its outside world.

• Ports allow information to enter and exit the system.

• A bus is a collection of wires used to pass information

between modules.

Page 77: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Microcontroller

• A very small microcomputer, called a microcontroller,

contains all the components of a computer (processor,

memory, I/O) on a single chip.

• As shown in the figure, the Atmel ATtiny, the Texas

Instruments MSP430, and the Texas Instruments

TM4C123 are examples of microcontrollers.

Page 78: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

RAM

• The computer can store information in RAM by writing to

it, or it can retrieve previously stored data by reading from

it.

• RAMs are volatile; meaning if power is interrupted and

restored the information in the RAM is lost.

Page 79: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

ROM

• Information is programmed into ROM using techniques more complicated than writing to RAM.

• From a programming viewpoint, retrieving data from a ROM is identical to retrieving data from RAM.

• ROMs are nonvolatile; meaning if power is interrupted and restored the information in the ROM is retained.

• Some ROMs are programmed at the factory and can never be changed.

• A Programmable ROM (PROM) can be erased and reprogrammed by the user, but the erase/program sequence is typically 10000 times slower than the time to write data into a RAM.

• For all the systems in this class, we will store instructions and constants in flash ROM and place variables and temporary data in static RAM.

Page 80: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

A microcontroller based on the ARM®

Cortex™-M processor

• Instructions are fetched from flash ROM using the ICode

bus.

• Data are exchanged with memory and I/O via the system

bus interface.

Page 81: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

I/O Ports

• The external devices attached to the microcontroller

provide functionality for the system.

• An input port is hardware on the microcontroller that

allows information about the external world to be entered

into the computer.

• The microcontroller also has hardware called an output

port to send information out to the external world.

Page 82: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Ports on the TM4C123

Page 83: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Interface

• An interface is defined as the collection of the I/O port,

external electronics, physical devices, and the software,

which combine to allow the computer to communicate

with the external world.

• An example of an input interface is a switch, where the

operator toggles the switch, and the software can

recognize the switch position.

• An example of an output interface is a light-emitting diode

(LED), where the software can turn the light on and off,

and the operator can see whether or not the light is

shining.

Page 84: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

I/O Interface categories

• There is a wide range of possible inputs and outputs,

which can exist in either digital or analog form. In general,

we can classify I/O interfaces into four categories

• Parallel - binary data are available simultaneously on a

group of lines

• Serial - binary data are available one bit at a time on a

single line

• Analog - data are encoded as an electrical voltage,

current, or power

• Time - data are encoded as a period, frequency, pulse

width, or phase shift

Page 85: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

CPU Registers• Registers are high-speed storage inside the processor.

• 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.

• 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.

Page 86: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Part number RAM Flash I/O I/O modules

LM3S811 8 64 32 PWM

LM3S1968 64 256 52 PWM

LM3S2965 64 256 56 PWM, CAN

LM3S3748 64 128 61 PWM, DMA, USB

LM3S6965 64 256 42 PWM, Ethernet

LM3S8962 64 256 42 PWM, CAN, Ethernet, IEEE1588

LM4F110B2QR 12 32 43 floating point, CAN, DMA

LM4F120H5QR 32 256 43 floating point, CAN, DMA, USB

TM4C123GH6P

M

32 256 43 floating point, CAN, DMA, USB, PWM

KiB KiB pins

Microcontrollers within the same family differ by the amount of memory and by the

types of I/O modules.

All LM3S and TM4C microcontrollers have a Cortex-M processor.

There are hundreds of members in this family; some of them are listed in Table

2.11.

Page 87: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Software Development

Page 88: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Software Development

• To develop software, we first use an editor to create our source code. Source code

contains specific set of sequential commands in human-readable-form.

• Next, we use an assembler or compiler to translate our source code into object code.

On ARM Keil™ uVision® we compile/assemble by executing the command Project-

>Build Target (short cut F7).

• Object code or machine instructions contains these same commands in machine-

readable-form.

• Most assembly source code is one-to-one with the object code that is executed by the

computer.

• For example, when programming in a high level language like C or Java, one line of a

program can translate into several machine instructions.

• In contrast, one line of assembly code usually translates to exactly one machine

instruction.

• The target specifies the platform on which we will be running the object code. When

testing software with the simulator, we choose the Simulator as the target.

• When simulating, there is no need to download, we simply launch the simulator by

executing the Debug->Start Debug Session command. The simulator is an easy and

inexpensive way to get started on a project. However, its usefulness will diminish as the

I/O becomes more complex.

Page 89: BBM 432 EMBEDDED SYSTEMS - Hacettepe …bbm432/files/week1.pdf•BBM 432: • 1 midterm (%50) • Final 50% • Ungraded online quizzes. •Attendance is mandatory. Online quizzes

Debugging

• In a real system, we choose the real microcontroller via its

JTAG debugger as the target.

• In this way the object code is downloaded into the EEPROM of

the microcontroller.

• Most microcontrollers contain built-in features that assist in

programming their EEPROM.

• In particular, we will use the JTAG debugger connected via a

USB cable to download and debug programs.

• The JTAG is both a loader and a debugger. We program the

EEPROM by executing the Flash->Download command. After

downloading we can start the system by hitting the reset button

on the board or we can debug it by executing Debug->Start

Debug Session command in the uVision® IDE.