Sei sulla pagina 1di 21

EE192C - Lecture 1

EE192C: Embedded Systems Engineering!


Course Overview & Basics Review! April 1, 2008!

Max Klein ! STARLab - VLF Group ! Ofce: Packard 351, x33789 ! Lab: Packard 075, x60333 ! maxklein@stanford.edu !
EE192C - Klein! 1 !

What is an Embedded System?


!" No standard (e.g. IEEE, etc) denition! !" A system in which a processor/microcontroller/computer is embedded to perform a specic task or tasks!
!" Often have sensing, processing, storage, and communication!

!" Although task-specic, general purpose processor are often used!


!" ASICs enhance performance, but cost time and money to develop!

!" Blurry, moving line between ES and PCs!

EE192C - Klein!

2 !

Motivation
!" Embedded Systems are extremely common in everyday life!
!" Cell phones, MP3 Players, home appliances, vehicle navigation, collision detection, etc!

!" Real Time ES support critical applications, with huge stakes!


!" Aircraft control, nuclear power plant management, targeting and re control systems, medical applications!

!" Building these systems is very rewarding, and is a truly interdisciplinary activity!
!" Requires both hardware and software! !" Hardware interfaces to the real world!
!" Sensors and actuators!

!" Software controls this real-world interaction! !" End product is a tangible item that does something for you!

!" The ES industry is huge, and growing each year!


!" About 98% of processors shipped are used in embedded systems (embedded.com)!
EE192C - Klein! 3 !

EE192C: What is it?


!" Hands on!
!" You will start by programming an existing hardware development kit! !" During the second half of the course, you will design the hardware itself!

!" Generalized !
!" Some assignments will be done the hard way!
!" The knowledge you will gain will apply to implementing subsystems of future protocols, even when not directly supported in hardware!

!" We must have a platform to learn on, however the principals are generic!
!" We"ll use an inexpensive, relatively simple 8-bit RISC microcontroller! !" Future work with ARM, XSCALE, etc is just an increased set of registers and peripherals!

!" Gadget Class!


!" We"re not going to be using gadgets, but rather designing them!!
!" Goal is to create systems to ll a gap in what"s available COTS! !" They won"t be pretty to start with, so make friends in Product Design!

EE192C - Klein!

4 !

Course Flow
!" We"ll start by programming known-good hardware!
!" This programming requires an understanding of the underlying hardware! !" It"s much easier to debug a system when you already know that either the software OR hardware is functional! !" Along the way, we"ll cover the actual hardware and electronics of the peripherals you are utilizing in software! !" The midterm project will be software-only, developing an integrated systems utilizing most of the available peripherals in the development kit!

!" In the second half of the class, you will design hardware!
!" At this point, you will understand the software implication of how you implement your hardware! !" We will design hardware beginning with a functionality description, all the way through an actual PCB layout !
!" You are welcome to fabricate the hardware outside of class!

EE192C - Klein!

5 !

Course Outline
!" Basics Review!
!" Number Systems, binary and hexadecimal math!

!" Microcontroller Overview!


!" System Blocks! !" Registers, memory, and address space! !" How a processor can interact with external devices!

!" General Purpose I/O!


!" Outputs (LEDs)! !" Inputs (Buttons, Keypad)!

!" Communication Methods!


!" !" !" !" RS-232! Character LCDs! I2C / TWI! SPI!

!" Solid State Storage!


!" Compact Flash / IDE! !" Secure Digital / MMC!
EE192C - Klein! 6 !

Course Outline (cont.)


!" Timers, Interrupts, and Real Time Systems!
!" Denition of hard vs soft real time! !" IRQs and ISRs! !" Preemption!

!" Mid-term Project: Software Design! !" System Design!


!" Requirements specication! !" Hardware selection!
!" ASICs! !" Power Budgets, Batteries, chargers!

!" Software implications of hardware choices! !" OrCAD PCB Design Suite!
!" Capture CIS for schematics! !" Layout Plus for PCB routing! !" Lots of practical information and hints for PCB layout!
!" Avoiding noise, power planes, analog and digital separation!

EE192C - Klein!

!" Final Project: Hardware Design!

7 !

EE192C Overview
!" This course is designed to provide you with the theoretical and hands-on skills necessary to design real embedded systems. By the end of this course, you will have developed your own embedded system from scratch, both hardware and software.! !" Notes, calculators, and other aides that you would normally have in the lab are encouraged (except for the quizzes!). Don"t let a simple math mistake doom your system.! !" Documentation of what you do is required. This includes commenting your source code and schematics, as well as making notes of what you"ve tried on a project that didn"t work. Expect that someone else will improve upon your work in the future, so please try not to leave them in the dark. One day, it will be you continuing someone else"s project.! !" Ask questions! Don"t wait until the end of the lecture, interrupt anytime if something is not clear.!

EE192C - Klein!

8 !

EE192C Format
!" There is no textbook. The lecture slides will be available from http://eeclass.stanford.edu/ee192c/ . Manufacturer Data Sheets will supplement this material, a select few of which will be on the course site (most every manufacturer will provide you with one for free from their web site).! !" There will be no mid-term or nal exam! !" There will be two projects: one software and one hardware.! !" There will be weekly homework/programming assignments that will directly help you on the projects. Keep your code modular and commented.! !" There will be regular 5-10min quizzes in class over any material taught in the class to date. These are designed to ensure that you understand the material that you will need to apply on the projects and in future systems development. The quizzes should be easy if you learn the material as you go. ! !" Discussions as a class are encouraged. Don"t be shy!!
EE192C - Klein! 9 !

EE192C Grading
!" 20%: In-class quizzes!
!" Equally weighted, lowest score dropped. No credit if late.!

!" 20%: Weekly Homework / Programming Assignments!


!" Assigned in class on Thursdays! !" Due at 12:50 on Thursdays (start of class)! !" 15% per day late penalty!

!" 30%: Software Project (mid-term)!


!" 20% per day late penalty!

!" 30%: Hardware Project (nal)!


!" 20% per day late penalty!

EE192C - Klein!

10 !

Helpful Background
!" Computer architecture!
!" CPU Registers! !" Memory Addressing! !" Data Paths!

!" Basics!
!" Number Systems!
!" Decimal! !" Hex! !" Binary!

!" Electronics!
!" Ohm"s Law! !" Basic functionality and use of resistors, capacitors, transistors, and diodes!

!" Bitwise Operations!

!" C / C++!
!" !" !" !" Function Calls! Memory Allocation! Header Files! If/for/while/switch statements!

!" Data Structures!


!" !" !" !"
EE192C - Klein!

Linked Lists! Hash Tables! Ping Pong Buffers! Circular Buffers!


11 !

Number Systems
!" We"ll be using Decimal (Base 10), Hexadecimal (Base 16) and Binary (Base 2) very extensively, so make sure you know it!

Decimal [0,9]:

x102 x22 x162

x101 x21 x161

x100 x20 x160

. . .

x10-1 x2-1 x16-1

x10-2 x2-2 x16-2

x10-3 x2-3 x16-3

Binary [0,1]:

Hexadecimal [0,F]:

EE192C - Klein!

12 !

Logic / Boolean Algebra


!" We will only be reviewing AND, OR, and Equality operations!
!" Others are used, such as <, >, ==, <=, >=, <>, ~. You should already know these, as they usually function as expected! !" Most of our review will utilize C-style nomenclature (ie == is equality)!

& = bitwise AND! && = logical AND!


AND 0 0 1 0 0 1 0 1

| = bitwise OR! || = logical OR!


OR 0 0 1 0 1 1 1 1

EE192C - Klein!

13 !

Bitwise Operations
Example of bitwise AND: 0xB4 & 0x9A =! 0x90!

1 & 1 1

0 0 0

1 0 0

1 1 1

0 1 0

1 0 0

0 1 0

0 0 0

Example of bitwise OR: 0xB4 | 0x9A =! 0xBE!

1 | 1 1

0 0 0

1 0 1

1 1 1

0 1 1

1 0 1

0 1 1

0 0 0
14 !

EE192C - Klein!

Bitwise vs. Logical Ops


& 00 01 10 11 && 00 01 10 11 00 00 00 00 00 00 0 0 0 0 01 00 01 00 01 01 0 1 1 1 10 00 00 10 10 10 0 1 1 1 11 00 01 10 11 11 0 1 1 1 | 00 01 10 11 || 00 01 10 11 00 00 01 10 11 00 0 1 1 1 01 01 01 11 11 01 1 1 1 1 10 10 11 10 11 10 1 1 1 1 11 11 11 11 11 11 1 1 1 1

Bitwise operations will usually return the same number of binary digits as used in the input, but is sometimes zeropadded on the left ! Notice that the logical operators return a single value, True or False. This makes equalities behave differently than intuition may dictate:! 001 && 110 = ! 100 && 001 = ! 001 && 001 ! (All are TRUE, and 1 = 1 = 1) !
15 !

EE192C - Klein!

Bit Masking
!" Bit masking allows you to set, clear, or read specic bit(s) within a byte without clobbering the remaining bits! !" Masking is simply a specic use of bitwise operations!
!" !" !" !" Two arguments will be the variable and the mask! & is used for read masking and CLEAR write masking! | is used for SET write masking! Since & requires BOTH bit in the column to be true for the result to be true, only column(s) with a 1 in the mask can possibly result in a 1 in the answer. This is how you can ignore all but selected columns in a bit string.! !" |, on the other hand, will always produce a 1 if there is a 1 in that position in the mask. This is used to set bits to 1.! !" Using &, one can create a mask to set selected bits to 0, while allowing other columns to retain their existing value!

!" This will be used later on in setting and reading various processor registers, and also provides a bit of insight on how to create your own ags that don"t occupy an entire byte!
EE192C - Klein! 16 !

Bit Masking, Read Ex.


Let#s say we only want to read the value in column 3 of the bitstring. If we use bitwise AND, we would want the mask to have a 1 in the 3rd column, and 0 in the remaining places!

1 & 0 0

0 0 0

1 0 0

1 0 0

0 0 0

1 1 1

0 0 0

0 0 0

Variable! Mask! Result!

Now that the result is a masked version of the variable only containing the column we want, we can use logical expressions to, for example, branch if that particular bit in the variable is set (1) or cleared (0).!
EE192C - Klein! 17 !

Bit Masking, Set Ex.


Now, let#s make the 4th column of the bitstring a 1, while preserving the remaining columns original values. This means the mask should have a 1 in column 4 and zeros elsewhere. Note that we now will be using a bitwise OR, so that the columns ORed with a 0 in the mask will keep their values.!

1 | 0 1

0 0 0

1 0 1

1 0 1

0 1 1

1 0 1

0 0 0

0 0 0

Variable! Mask! Result!

As expected, the 4th column is 1 and the remaining columns# values are unchanged.!
EE192C - Klein! 18 !

Bit Masking, Clear Ex.


Lastly, let#s now make column 6 a zero, while keeping every other value as-is. This is a bit more tricky. We will use the bitwise AND, and have the mask be 1 in every column except the 6th.!

1 & 1 1

0 1 0

1 0 0

1 1 1

0 1 0

1 1 1

0 1 0

0 1 0

Variable! Mask! Result!

The mask can also be computed by subtracting the value of the column(s) of interest from all ones. For the above example, this would be:! 0xFF - 0x20 = 0xDF !
EE192C - Klein! 19 !

Bit Masking Gotchas


!" Remember the difference between Logical and Bitwise operations!! !" When communicating with someone else, make sure you both know the index of whatever it is your are talking about (in this lecture we covered columns of a bit string)!
!" Some things are 0-indexed, ie the rst position is called 0, not 1!

EE192C - Klein!

20 !

Questions?

EE192C - Klein!

21 !

Potrebbero piacerti anche