You are on page 1of 40

Digital Design

Chapter 1: Introduction
Slides to accompany the textbook Digital Design, with RTL Design, VHDL, and
Verilog, 2nd Edition,
by Frank Vahid, John Wiley and Sons Publishers, 2010.
http://www.ddvahid.com

Copyright 2010 Frank Vahid


Instructors of courses requiring Vahid's Digital Design textbook (published by John Wiley and Sons) have permission to modify and use these slides for customary course-related activities,
subject to keeping this copyright notice in place and unmodified. These slides may be posted as unanimated pdf versions on publicly-accessible course websites.. PowerPoint source (or pdf
Digital
2e
with animations)
may Design
not be posted
to publicly-accessible websites, but may be posted for students on internal protected sites or distributed directly to students by other electronic means.
Copyright

2010
1
Instructors may make printouts of the slides available to students for a reasonable photocopying charge, without incurring royalties. Any other use requires explicit permission. Instructors
Frank Vahid
may obtain PowerPoint
source or obtain special use permissions from Wiley see http://www.ddvahid.com for information.

Some Useful Information


Where can I get help

www.cse.nd.edu/courses/cse20221/www/
TAs during lab time: M,T,W,T,F 3:00 5:20
email yoders1@nd.edu
325 D Cushing Hall
108 Stinson-Remick on Tues. & Thurs. during lab

What will make the lab easier

If there is a video for the lab, view it before you come to lab
Download the Xilinx software for lab on your personal computer
Review the lab assignment before you come to lab
Complete the design work before you come to lab

Questions?

Is there lab this week? No


Are there copies of the lecture? Yes, on course web site.
When are the lectures updated? 30 minutes before class.
Do I have to come to my assigned lab time? Yes
Can I demo my lab work at another lab time? Yes
Can I get late homework or lab work graded? No
Is digital logic design really all that important? Only if you
want things like an iPhone, iPod, computer, CDs or CD
players
Is this course difficult. No
Is this course fun? Absolutely!
3

1.1

Why Study Digital Design?


Look under the hood of computers
Solid understanding --> confidence, insight,
even better programmer when aware of
hardware resource issues

Electronic devices becoming digital


Enabled by shrinking and more capable chips
Enables:
Better devices: Sound recorders, cameras,
cars, cell phones, medical devices,...
New devices: Video games, PDAs, ...

Known as embedded systems


Thousands of new devices every year
Designers needed: Potential career direction
Satellites
Portable
music players
Digital Design 2e
Copyright 2010
Frank Vahid

1995

DVD
players

Cell phones

1997

1999

Video
recorders
Cameras

2001

2003

Musical
instruments
TVs

2005

2007

Years shown above indicate when digital version began to dominate

(Not the first year that a digital version appeared)

???

1.2

What Does Digital Mean?


Analog signal

Digital signal

Infinite possible values


Ex: voltage on a wire
created by microphone

Finite possible values


Ex: button pressed on a
keypad

Sound waves
move the
membrane,

which moves
the magnet,
microphone

digital
signal

analog
signal
Possible values:
1.00, 1.01, 2.0000009,
... infinite possibilities
a

time
Digital Design 2e
Copyright 2010
Frank Vahid

value

value

which creates
current in the nearby wire

4
3
2
1
0

Possible values:
0, 1, 2, 3, or 4.
Thats it.

time
5

Digital Signals with Only Two Values: Binary

Typically represented as 0 and 1


One binary digit is a bit
Well only consider binary digital signals
Binary is popular because

value

Binary digital signal -- only two


possible values

1
0

time

Transistors, the basic digital electric


component, operate using two voltages
(more in Chpt. 2)
Storing/transmitting one of two values is
easier than three or more (e.g., loud beep
or quiet beep, reflection or no reflection)

Digital Design 2e
Copyright 2010
Frank Vahid

Sample voltage at
particular rate, save
sample using bit encoding
Voltage levels still not kept
perfectly
But we can distinguish 0s
from 1s

lengthy transmission
(e.g, cell phone)

time

received signal

1
0

time
How fix -- higher, lower, ?

01 10 11 10 11

a2d
1

digitized signal

0
time

1
0
time
Can fixdistinguish 0s/1s, restore

Not a perfect re-creation


due to a2d and d2a
01 10 11 10 11

Let bit encoding be:


1 V: 01
2 V: 10
3 V: 11
Digital Design 2e
Copyright 2010
Frank Vahid

Higher sampling
rate and more bits per
encoding improves re-creation

Volts

Digitized version enables


near-perfect save/cpy/tran.

original signal

lengthy transmission
(e.g, cell phone)

2
1
0

Analog signal (e.g., audio,


video) may lose quality
Voltage levels not
saved/copied/transmitted
perfectly

Volts

Volts

Example of Digitization
Benefit

d2a
3
2
1
0

Digitization Benefit: Can Store on Digital Media


analog signal
on wire

Volts

3
1

samples

wire
microphone

00 01 10 10 11 11 11 01 10 10 00 time

analog-todigital
converter

digitized signal
0001101011111101101000

(a)

0001101011111101101000 read from tape, CD, etc.

wire

Volts

digital-toanalog
converter

Store on CD, USB drive,


etc. No deterioration.

analog signal
reproduced from
digitized signal

2
1
0
00 01 10 10 11 11 11 01 10 10 00 time

(b)
speaker
Digital Design 2e
Copyright 2010
Frank Vahid

Digitized Audio: Compression Benefit


Digitized audio can be
compressed
e.g., MP3s
A CD can hold about 20
songs uncompressed,
but about 200
compressed

Example compression scheme:


00 means 0000000000
01 means 1111111111
1X means X
0000000000 0000000000 0000001111 1111111111
a

00 00 10000001111 01

Compression also done


on digitized pictures
(jpeg), movies (mpeg),
and more
Digitization has many
other benefits too
Digital Design 2e
Copyright 2010
Frank Vahid

How Do We Encode Data as Binary for Our Digital


System?
analog
phenomena
sensors and
other inputs
electric
digital
signal
data
A2D
digital
data
Digital System
digital
data

digital
data

D2A
electric
signal
actuators and
other outputs

Digital Design 2e
Copyright 2010
Frank Vahid

button

Some inputs inherently


binary
Button: not pressed (0),
pressed (1)

Some inputs inherently


digital
Just need encoding in
binary
e.g., multi-button input:
encode red=001, blue=010,
...

Some inputs analog


Need analog-to-digital
conversion
As done in earlier slide -sample and encode with
bits

red

blue

green

black

0 0 0
red

blue

green

black

0 0 1
red

blue

green

black

0 1 0

air

33
degrees

temperature
sensor

0 0 1 0 0 0 0 1

10

How to Encode Text: ASCII, Unicode


ASCII: 7- (or 8-)
bit encoding of
each letter,
number, or
symbol
Unicode:
Increasingly
popular 16-bit
encoding
Encodes
characters from
various world
languages
Digital Design 2e
Copyright 2010
Frank Vahid

Encoding Symbol

Sample ASCII encodings

010 0000 <space>


Encoding Symbol
010 0001
!
100 0001
A
010 0010
"
100
0010
B
010 0011
#
100
0011
C
010 0100
$
100
0100
D
010 0101
%
100
0101
E
010 0110
&
100
0110
F
010 0111
'
100 0111
G
010 1000
(
100
1000
H
010 1001
)
100
1001
I
010 1010
*
100
1010
J
010 1011
+
100
1011
K
010 1100
,
100
1100
L
010 1101
100
1101
M
010 1110
.
010 1111
/

Encoding Symbol
100 1110
N
100 1111
O
101 0000
P
101 0001
Q
101 0010
R
101 0011
S
101 0100
T
101 0101
U
101 0110
V
101 0111
W
101 1000
X
101 1001
Y
101 1010
Z

Encoding Symbol
110 0001
110 0010
...
111 1001
111 1010

a
b

011 0000
011 0001
011 0010
011 0011
011 0100
011 0101
011 0110
011 0111
011 1000
011 1001

0
1
2
3
4
5
6
7
8
9

y
z

Question:
What does this ASCII bit sequence represent?
1010010 1000101 1010011 1010100
a

REST
11

How to Encode Numbers: Binary Numbers


Each position represents a
quantity; symbol in position
means how many of that
quantity
Base ten (decimal)

104 103 102 101 100

Ten symbols: 0, 1, 2, ..., 8, and 9


More than 9 -- next position
So each position power of 10

Nothing special about base 10 -used because we have 10 fingers

Base two (binary)


Two symbols: 0 and 1
More than 1 -- next position
So each position power of 2
Digital Design 2e
Copyright 2010
Frank Vahid

24

23

22

21

20

Q: How much?
+

=
a

4+ 1= 5
12

Using Digital Data in a Digital System


A temperature sensor
outputs temperature in
binary
The system reads the
temperature, outputs
ASCII code:
F for freezing (0-32)
B for boiling (212 or more)
N for normal

A display converts its


ASCII input to the
corresponding letter
Digital Design 2e
Copyright 2010
Frank Vahid

temperature sensor
0

"33"

Digital System
if (input <= "00100000") // "32"
output = "1000110" // "F"
else if (input >= "11010100") // "212"

output = "1000010" // "B"


else
output = "1001110" // "N"
1

display

"N"

13

Converting from Binary to Decimal


Just add weights
12 is just 1*20, or 110.
1102 is 1*22 + 1*21 + 0*20, or 610. We might think of this using
base ten weights: 1*4 + 1*2 + 0*1, or 6.
100002 is 1*16 + 0*8 + 0*4 + 0*2 + 0*1, or 1610.
100001112 is 1*128 + 1*4 + 1*2 + 1*1 = 13510. Notice this time
that we didnt bother to write the weights having a 0 bit.
001102 is the same as 1102 above the leading 0s dont change
the value.
29

28

27

26

25

24

23

22

21

20

Useful to know powers of 2:


512 256 128 64 32

Practice counting up by powers of 2:


Digital Design 2e
Copyright 2010
Frank Vahid

16 8

512 256 128 64 32 16 8 4 2 1


14

Converting from Decimal to Binary


Put 1 in
leftmost
place without
sum
exceeding
number
Track sum

Digital Design 2e
Copyright 2010
Frank Vahid

Desired decimal
number: 12

Binary
number

Current
sum

(a)

16 > 12, too big;


Put 0 in 16s place

(b)

8 <= 12, so put


1 in 8s place,
current sum is 8

0
16 8

0 1
16 8

(c)

8+4=12 <= 12, so put


1 in 4s place,
current sum is 12

12

0 1
16 8

1
4 2

(d)

Reached desired 12,


so put 0s in remaining
places

done

0 1
16 8

1 0
4 2

0
1

15

Converting from Decimal to Binary


Example using
a more
compact
notation

Digital Design 2e
Copyright 2010
Frank Vahid

Desired decimal
number: 23

Binary
number
1 0

sum: 0 16 8 4 2 1
16
(a) 16
(b) 20
(c) 22
(d) 23
(e)

16

Example: DIP-Switch Controlled Channel


Ceiling fan
receiver
should be
set in
factory to
respond to
channel
73
Convert 73
to binary,
set DIP
switch
accordingly

Desired value: 73
a

0 1 0 0 1 0 0 1

Q:

(a)

128 64 32 16 8

sum:

64

72

(b)

73

DIP switch

channel receiver
"34" 0 0 1 0 0 0 1 0

1
0
"73" 0 1 0 0 1 0 0 1

InA

if (InA = InB)
Out = 1
else
Ceiling fan Out = 0
module
Out

InB

(c)

0
Digital Design 2e
Copyright 2010
Frank Vahid

17

Base Sixteen: Another Base Used by Designers


164

163

162

161

160

Nice because each position


represents four base-two positions
Compact way to write binary numbers

1000 1010 1111


hex

binary

hex

binary

0
1
2
3
4
5
6
7

0000
0001
0010
0011
0100
0101
0110
0111

8
9
A
B
C
D
E
F

1000
1001
1010
1011
1100
1101
1110
1111

Known as hexadecimal, or just hex

Q: Write 11110000 in hex


F0

Q: Convert hex A01 to binary


a

1010 0000 0001


Digital Design 2e
Copyright 2010
Frank Vahid

18

Decimal to Hex
Easy method: convert to binary first, then binary to hex
Convert 99 base 10 to hex
First convert to binary:

0 1 1 0 0 0 1 1
128 64 32 16 8

1
a

Then binary to hex:

(Quick check: 6*16 + 3*1 = 96+3 = 99)

Digital Design 2e
Copyright 2010
Frank Vahid

19

Hex Example: RFID Tag


Batteryless tag powered by radio field
Transmits unique identification number
Example: 32 bit id
8-bit province number, 8-bit country number, 16-bit animal number
Tag contents are in binary
But programmers use hex when writing/reading

(b)
Province #

(c) Province: 7 City: 160


(d) 00000111 10100000
(e)
07
A0

(a)
RFID
tag

Digital Design 2e
Copyright 2010
Frank Vahid

City #

(f)

Animal #
Animal: 513
00000010 00000001
02 01

Tag ID in hex: 07A00201

20

Converting To/From Binary by Hand: Summary


Decimal
1

26 10

16

Binary
1
0
1

To binary
To decimal
1

16

16

16+8
= 24

24

24+2
= 26

--

Digital Design 2e
Copyright 2010
Frank Vahid

To hex To octal
16 + 8 + 2
= 26 10
1 1010
= 1A16

11 010
= 32 8

21

Divide-By-2 Method Common in Automatic Conversion


Repeatedly divide decimal number by 2, place remainder
in current binary digit (starting from 1s column)
1. Divide decimal number by 2
Insert remainder into the binary number
Continue since quotient (6) is greater than 0

Decimal
6
2 12
12
0

0
1
(current value: 0)

2. Divide quotient by 2
Insert remainder into the binary number
Continue since quotient (3) is greater than 0

3
2 6
6
0

0 0
2 1
(current value: 0)

3. Divide quotient by 2
Insert remainder into the binary number
Continue since quotient (1) is greater than 0

1
2 3
2
1

1 0 0
4 2 1
(current value: 4)

4. Divide quotient by 2
Insert remainder into the binary number
Quotient is 0, done

0
2 1
0
1

1 1 0 0
8 4 2 1
(current value: 12)

Digital Design 2e
Copyright 2010
Frank Vahid

Binary

Note:
Works for
any base
Njust
divide by
N instead
22

Dibble-Dabble Algorithm
2|12
2|6
2|3
2|1

r = 0 least significant bit


r=0
r=1
r = 1 most significant bit

12 10 = 11002

23

Bytes, Kilobytes, Megabytes, and More


Byte: 8 bits
Common metric prefixes:
kilo (thousand, or 103), mega (million, or 106), giga (billion, or 109),
and tera (trillion, or 1012), e.g., kilobyte, or KByte

BUT, metric prefixes also commonly used inaccurately


216 = 65536 commonly written as 64 Kbyte
Typical when describing memory sizes

Also watch out for KB for kilobyte vs. Kb for kilobit

Digital Design 2e
Copyright 2010
Frank Vahid

24

Implementing Digital Systems: Programming

1.3

Microprocessors Vs. Designing Digital Circuits

Desired motion-at-night detector

Programmed Custom designed

microprocessor
digital circuit

Microprocessors a
common choice to
implement a digital
system

I0
I1
I2
I3
I4
I5
I6
I7

Digital Design 2e
Copyright 2010
Frank Vahid

P0
P1
P2
P3
P4
P5
P6
P7

Easy to program
Cheap (as low as
$1)
Readily available

void main()
1
a
{
0
while (1) {
1
b
P0 = I0 && !I1;
0
// F = a and !b,
1
F
}
0
}
6:00

7:057:06

9:009:01

time

25

Digital Design: When Microprocessors Arent Good


Enough
With microprocessors so easy,
cheap, and available, why
design a digital circuit?
Microprocessor may be too
slow
Or too big, power hungry, or
costly

Wing controller computation task:


50 ms on microprocessor
5 ms as custom digital circuit
If must execute 100 times per second:
100 * 50 ms = 5000 ms = 5 seconds
100 * 5 ms = 500 ms = 0.5 seconds
Microprocessor too slow, circuit OK.

Digital Design 2e
Copyright 2010
Frank Vahid

26

Digital Design: When Microprocessors Arent Good


Enough
Commonly, designers partition
a system among a
microprocessor and custom
digital circuits

Image Sensor

(a)
Memory

Image Sensor

Sample digital camera task execution times (in


seconds) on a microprocessor versus a digital
circuit:
Task

Microprocessor

Custom
Digital Circuit

Read

0.1

Compress

0.5

Digital Design 2e
Copyright 2010
Frank Vahid

0.8

(Read,
Compress,
and Store)

Read
circuit

5+8+1
=14 sec
Compress
circuit

(b)

Image Sensor

Memory

.1+.5+.8
=1.4 sec

Store
circuit

Memory

(c)

Store

Microprocessor

Q: How long for each


implementation option?

Read
circuit

Compress
circuit

Microprocessor
(Store)

.1+.5+1
=1.6 sec
Good
compromise
27

Chapter 1 Summary
Digital systems surround us
Inside computers
Inside many other electronic devices (embedded systems)

Digital systems use 0s and 1s


Encoding analog signals to digital can provide many benefits
e.g., audiohigher-quality storage/transmission, compression, etc.

Encoding integers as 0s and 1s: Binary numbers

Microprocessors (themselves digital) can implement many


digital systems easily and inexpensively
But often not good enoughneed custom digital circuits

28

2.1

Chapter 2 Introduction
Lets learn to design digital circuits, starting with a
simple form of circuit:
Combinational circuit
Outputs depend solely on the present combination of the circuit
inputs values
Vs. sequential circuit: Has memory that impacts outputs too

Motion
sensor

b=0 Digital F=0


System

b=0 Digital F=0


System

a
Digital
System F

b=1 Digital F=1


System

Lamp
Light
sensor

b=1 Digital F=1


System

(a)

if b=0, then F=0


if b=1, then F=1
a

Digital Design 2e
Copyright 2010
Frank Vahid

(b)

b
b=0 Digital F=1
System

if a=0 and b=0, then F=0


if a=0 and b=1, then F=0
if a=1 and b=0, then F=1
if a=1 and b=1, then F=0
a

Cannot determine value of


(c) F solely from present
input value

29
Note: Slides with animation are denoted with a small red "a" near the animated items

2.2

Switches
Electronic switches are the basis of
binary digital circuits

Analogous to water pressure

Resistance: Tendency of wire to resist


current flow (ohms, )

9V

4.5 A

Voltage: Difference in electric potential


between two points (volts, V)

4.5 A

Electrical terminology
+

2 ohms

Analogous to water pipe diameter

Current: Flow of charged particles (amps, A)

9V

0V

Analogous to water flow

V = I * R (Ohms Law)
9 V = I * 2 ohms
I = 4.5 A

Digital Design 2e
Copyright 2010
Frank Vahid

4.5 A
a

If a 9V potential difference is applied


across a 2 ohm resistor, then 4.5 A of
current will flow.
30

Switches
control
input

A switch has three parts

off

Source input, and output


Current tries to flow from source
input to output

source
input

Control input
Voltage that controls whether that
current can flow

1930s: Relays
1940s: Vacuum tubes
1950s: Discrete transistor
1960s: Integrated circuits (ICs)

control
input

on
output

(b)

Initially just a few transistors on IC


Then tens, hundreds, thousands...
relay

Digital Design 2e
Copyright 2010
Frank Vahid

source
input

The amazing shrinking switch

output

discrete
transistor
vacuum tube

IC

quarter
(to see the relative size)

31

Moores Law
IC capacity doubling about every 18 months
for several decades
Known as Moores Law after Gordon Moore,
co-founder of Intel
Predicted in 1965 predicted that components
per IC would double roughly every year or so

Book cover depicts related phenomena


For a particular number of transistors, the IC
area shrinks by half every 18 months
Consider how much shrinking occurs in just 10
years (try drawing it)
Enables incredibly powerful computation in
incredibly tiny devices

Todays ICs hold billions of transistors


The first Pentium processor (early 1990s)
needed only 3 million

Digital Design 2e
Copyright 2010
Frank Vahid

An Intel Pentium processor IC


having millions of transistors

32

2.3

The CMOS Transistor


CMOS transistor
Basic switch in modern ICs
A positive
voltage here...

...attracts electrons here,


turning the channel between
the source and drain into
a conductor

nMOS
gate

gate
oxide
source

IC package
drain

conducts

does not
conduct

pMOS

(a)

Silicon -- not quite a conductor or insulator:


Semiconductor
Digital Design 2e
Copyright 2010
Frank Vahid

IC

gate

does not
conduct

conducts

33

CMOS Transistor Analogy

source

gate

drain

Digital Design 2e
Copyright 2010
Frank Vahid

source

gate

drain

34

Boolean Logic Gates

2.4

Building Blocks for Digital Circuits


(Because Switches are Hard to Work With)

Logic gates are better digital circuit building blocks than switches (transistors)
Why?...
Digital Design 2e
Copyright 2010
Frank Vahid

35

Boolean Algebra and its Relation to Digital Circuits


To understand the benefits of logic gates vs. switches,
we should first understand Boolean algebra
Traditional algebra
Variables represent real numbers (x, y)
Operators operate on variables, return real numbers (2.5*x + y - 3)

Boolean Algebra
Variables represent 0 or 1 only
Operators return 0 or 1 only
Basic operators
AND: a AND b returns 1 only when both a=1 and b=1
OR: a OR b returns 1 if either (or both) a=1 or b=1
NOT: NOT a returns the opposite of a (1 if a=0, 0 if a=1)
Digital Design 2e
Copyright 2010
Frank Vahid

a
0
0
1
1

b
0
1
0
1

AND
0
0
0
1

a
0
1

NOT
1
0

a
0
0
1
1

b
0
1
0
1

36

OR
0
1
1
1

Boolean Algebra and its Relation to Digital Circuits


Developed mid-1800s by George Boole to formalize human thought
Ex: Ill go to lunch if Mary goes OR John goes, AND Sally does not go.
Let F represent my going to lunch (1 means I go, 0 I dont go)
Likewise, m for Mary going, j for John, and s for Sally
Then F = (m OR j) AND NOT(s)

Nice features

a
0
0
1
1

b
0
1
0
1

AND
0
0
0
1

a
0
0
1
1

b
0
1
0
1

OR
0
1
1
1

Formally evaluate
m=1, j=0, s=1 --> F = (1 OR 0) AND NOT(1) = 1 AND 0 = 0

Formally transform
F = (m and NOT(s)) OR (j and NOT(s))
Looks different, but same function
Well show transformation techniques soon

Formally prove

a
0
1

NOT
1
0

Prove that if Sally goes to lunch (s=1), then I dont go (F=0)


F = (m OR j) AND NOT(1) = (m OR j) AND 0 = 0

Digital Design 2e
Copyright 2010
Frank Vahid

37

Evaluating Boolean Equations


a

Evaluate the Boolean equation F = (a AND b) OR (c


AND d) for the given values of variables a, b, c, and d:
Q1: a=1, b=1, c=1, d=0.
Answer: F = (1 AND 1) OR (1 AND 0) = 1 OR 0 = 1.

Q2: a=0, b=1, c=0, d=1.


Answer: F = (0 AND 1) OR (0 AND 1) = 0 OR 0 = 0.

Q3: a=1, b=1, c=1, d=1.


Answer: F = (1 AND 1) OR (1 AND 1) = 1 OR 1 = 1.

a
0
0
1
1

b
0
1
0
1

AND
0
0
0
1

a
0
0
1
1

b
0
1
0
1

OR
0
1
1
1

a
0
1

Digital Design 2e
Copyright 2010
Frank Vahid

NOT
1
0

38

Converting to Boolean Equations


a

Convert the following English


statements to a Boolean equation
Q1. a is 1 and b is 1.
Answer: F = a AND b

Q2. either of a or b is 1.
Answer: F = a OR b

Q3. a is 1 and b is 0.
Answer: F = a AND NOT(b)

Q4. a is not 0.
Answer:
(a) Option 1: F = NOT(NOT(a))
(b) Option 2: F = a

Digital Design 2e
Copyright 2010
Frank Vahid

39

Homework
Chapter 1: 2,10,16,18, 21
Due date: Thursday, January 27

40

You might also like