Digital Design
Chapter 1: Introduction
Digital Design, with RTL Design, VHDL, and Verilog, 2nd Edition,
by Frank Vahid, John Wiley and Sons Publishers, 2010.
1.1
Why Study Digital Design?
Look under the hood of computers
S
Solid
lid understanding
d t di -->
> confidence,
fid
iinsight,
i ht
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 g
games, PDAs, ...
Known as embedded systems
Thousands of new devices every year
Designers needed: Potential career direction
Satellites
Portable
music players
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
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
di
i l
signal
analog
signal
Possible values:
1.00, 1.01, 2.0000009,
... infinite p
possibilities
a
time
i
vaalue
vaalue
which creates
current in the nearby wire
4
3
2
1
0
Possible values:
0, 1, 2, 3, or 4.
Thatss it
That
it.
time
3
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
y is popular
p p
because
value
Binary digital signal -- only two
possible
ibl values
l
1
0
time
Transistors, the basic digital electric
component, operate using two voltages
((more
o e in C
Chpt.
pt 2))
Storing/transmitting one of two values is
easier than three or more (e.g., loud beep
or quiet beep, reflection or no reflection)
Digitized version enables
near-perfect save/cpy/tran.
Sample voltage at
particular rate, save
sample using bit encoding
Voltage levels still not kept
perfectly
But we can distinguish 0s
from 1s
time
3
2
i d signal
i l
1 received
0
time
How fix -- higher,
g , 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
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
Higher sampling
rate and more bits per
encoding improves re-creation
Volts
original
i i l signal
i l
lengthy tran
nsmission
(e.g, cell phone)
Voltage levels not
saved/copied/transmitted
perfectly
3
2
1
0
lengthy trransmission
(e.g, celll phone)
Analog signal (e.g., audio,
video) may lose quality
Volts
V
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
3
V
Volts
digital-todi
it l t
analog
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
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
7
How Do We Encode Data as Binary for Our Digital
S t ?
System?
analog
phenomena
sensors and
other inputs
electric
di it l
digital
signal
data
A2D
digital
d t
data
Some inputs inherently
digital
Just need encoding in
binary
e.g., multi-button input:
encode red=001
red 001, blue=010
blue 010,
...
digital
data
D2A
electric
signal
actuators and
other outputs
Some inputs inherently
binary
Button: not pressed (0),
pressed (1)
Digital System
digital
data
button
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
How to Encode Text: ASCII, Unicode
ASCII: 7- (or 8-)
bit encoding
di off
each letter,
number or
number,
symbol
Unicode:
Increasingly
popular 16-bit
encoding
Encodes
characters from
various world
languages
Encoding Symbol
010 0000 <space>
010 0001
!
010 0010
"
010 0011
#
010 0100
$
010 0101
%
010 0110
&
010 0111
'
010 1000
(
010 1001
)
010 1010
*
010 1011
+
010 1100
,
010 1101
010 1110
.
010 1111
/
Sample ASCII encodings
Encoding
cod g Symbol
Sy bo
100 0001
A
100 0010
B
100 0011
C
100 0100
D
100 0101
E
100 0110
F
100 0111
G
100 1000
H
100 1001
I
100 1010
J
100 1011
K
100 1100
L
100 1101
M
Encoding
cod g Symbol
Sy bo
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
9
How to Encode Numbers: Binary Numbers
Each position represents a
quantity;
tit symbol
b l iin position
iti
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)
T
Two symbols:
b l 0 and
d1
More than 1 -- next position
So each position power of 2
24
23
22
21
20
Q: How much?
+
=
a
4+ 1= 5
10
Using Digital Data in a Digital System
A temperature sensor
outputs
t t temperature
t
t
in
i
binary
The system
s stem 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
SC input to the
corresponding letter
temperature sensor
0
"33"
Digital System
if (input <= "00100000") // "32"
output = "1000110"
1000110 // "F"
F
else if (input >= "11010100") // "212"
output = "1000010" // "B"
else
output = "1001110" // "N"
1
display
"N"
11
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 4 + 1*2
1 2 + 0*1
0 1, or 6
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
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:
16 8
512 256 128 64 32 16 8 4 2 1
12
Converting from Decimal to Binary
Put 1 in
leftmost
place without
sum
exceeding
number
Track sum
Desired decimal
number: 12
Binary
number
Current
sum
0
(a)
16 > 12, too big;
P t 0 in
Put
i 16
16s place
l
(b)
8 <= 12, so put
1 in 8s
8 s place,
current sum is 8
((c))
8+4=12 <= 12, so put
1 in 4s
4 s place,
current sum is 12
12
0 1
16 8
1
4 2
((d))
Reached desired 12,
so put 0s in remaining
places
done
do
e
0 1
16 8
1 0
4 2
0
1
16 8
0 1
16 8
1
a
13
Converting from Decimal to Binary
Example using
a more
compact
notation
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)
14
Example: DIP
DIP-Switch
Switch Controlled Channel
Ceiling fan
receiver
should be
set in
f t
factory
to
t
respond to
channel
73
Convert 73
to binary
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)
15
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
bina ry
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
16
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)
17
Hex Example: RFID Tag
Batteryless tag powered by radio field
Transmits unique identification number
Example: 32 bit id
8-bit province number
number, 8-bit country number,
number 16-bit animal number
Tag contents are in binary
But programmers use hex when writing/reading
(b)
Province #
(c) Province: 7
(a)
(d)
(e)
RFID
tag
(f)
00000111
07
City #
Animal #
City: 160
Animal: 513
10100000
00000010 00000001
A0
02 01
Tag ID in hex: 07A00201
18
Converting To/From Binary by Hand: Summary
Decimal
1
26 10
16
Binary
1
0
1
To binary
T decimal
To
d i l
1
16
16
16+8
= 24
24
24+2
= 26
--
To hex To octal
16 + 8 + 2
= 26 10
1 1010
= 1A16
11 010
= 32 8
19
Divide-By-2
Divide
By 2 Method Common in Automatic Conversion
Repeatedly divide decimal number by 2, place remainder
i currentt binary
in
bi
digit
di it ((starting
t ti ffrom 1
1s column)
l
)
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
Binary
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,
0 done
0
2 1
0
1
1 1 0 0
8 4 2 1
((current value: 12))
Note:
Works ffor
any base
Njust
divide by
N instead
20
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
(trillion, or 1012),
) e.g.,
e g kilobyte
kilobyte, or KByte
BUT, metric prefixes also commonly used inaccurately
216 = 65536 commonly written as 64
64 Kbyte
Kbyte
Typical when describing memory sizes
Also watch out for KB for kilobyte
y vs. Kb for kilobit
21
Implementing Digital Systems: Programming
1.3
Microprocessors Vs. Designing Digital Circuits
Desired motion-at-night
g detector
Programmed Custom designed
microprocessor
digital circuit
Microprocessors a
common choice to
implement a digital
system
I0
I1
I2
I3
I4
I5
I6
I7
P0
P1
P2
P3
P4
P5
P6
P7
Easy
y to p
program
g
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
22
Digital Design: When Microprocessors Arent Good
E
Enough
h
With microprocessors so easy,
cheap and available
cheap,
available, why
design a digital circuit?
Microprocessor may be too
slow
Or too big, power hungry, or
costly
Wing
g controller computation
p
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
Mi
Microprocessor
ttoo slow,
l
circuit
i it OK.
OK
23
Digital Design: When Microprocessors Arent Good
E
Enough
h
Commonly, designers partition
a system among a
microprocessor and custom
digital circuits
Image
g 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
Store
0.8
Microprocessor
Q: How long for each
implementation option?
(Read,
Compress,
and Store)
Read
circuit
5+8+1
=14
14 sec
Compress
circuit
(b)
Store
circuit
Memory
Image Sensor
(c)
Memory
.1+.5+.8
=1.4 sec
Read
circuit
Compress
circuit
Microprocessor
(Store)
.1+.5+1
1+ 5+1
=1.6 sec
Good
compromise
24
Chapter Summary
Digital systems surround us
Inside computers
Inside many other electronic devices (embedded systems)
Digital ssystems
stems use
se 0s and 1s
Encoding analog signals to digital can provide many benefits
e.g., audio
audiohigher-quality
higher quality storage/transmission, compression, etc.
Encoding integers as 0s and 1s: Binary numbers
Microprocessors
p
((themselves digital)
g ) can implement
p
many
y
digital systems easily and inexpensively
But often not good enoughneed custom digital circuits
25