Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Chapter 5:
Register-Transfer Level
(RTL) Design
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
Introduction
Chpt 2
Higher levels
Register-
Capture Comb. behavior: Equations, truth tables transfer
Convert to circuit: AND + OR + NOT Comb. logic level (RTL)
0 1 0 processor 50
25
Digital Design 2e
Copyright 2010 3
Frank Vahid
HLSMs s
8
a
8
m m' m
? // Increment Preg
m S_Inc Preg := Preg + 1
(a) (b) (c)
Digital Design 2e Note: Could have designed directly using an up-counter. But, that methodology
Copyright 2010
is ad hoc, and won't work for more complex examples, like the next one. a 5
Frank Vahid
Example: Laser-Based Distance Measurer
T (in seconds)
laser
D
Object of
a
interest
sensor
2D = T sec * 3*108 m/sec
Digital Design 2e
Copyright 2010 6
Frank Vahid
Example: Laser-Based Distance Measurer
T (in seconds)
B L
laser from button to laser
Laser-based
distance
sensor D 16 measurer S
to display from sensor
Inputs/outputs
B: bit input, from button, to begin measurement
L: bit output, activates laser
S: bit input, senses laser reflection
D: 16-bit output, to display computed distance
Digital Design 2e
Copyright 2010 7
Frank Vahid
Example: Laser-Based Distance Measurer
DistanceMeasurer from button B Laser-
L
to laser
Inputs: B (bit), S (bit) based
Outputs: L (bit), D (16 bits) distance
D 16 measurer S
Local storage: Dreg(16) to display from sensor
(required)
a
S0 ?
(first state usually
L := '0' // laser off initializes the system)
Dreg := 0 // distance is 0
Digital Design 2e
Copyright 2010 8
Frank Vahid
Example: Laser-Based Distance Measurer
from button B Laser-
L
to laser
DistanceMeasurer based
... B' // button not pressed distance
D 16 measurer S
to display from sensor
S0 S1 ?
B
L := '0' // button
Dreg := 0 pressed
S0 S1 S2 S3
B
L := '0' L := '1' L := '0'
Dreg := 0 // laser on // laser off
Digital Design 2e
Copyright 2010 10
Frank Vahid
Example: Laser-Based Distance Measurer
B L
from button to laser
DistanceMeasurer Inputs: B (bit), S (bit) Outputs: L (bit), D (16 bits) Laser-based
Local storage: Dreg, Dctr (16 bits) 16
distance
D measurer S
B' to display from sensor
S' // no reflection
S // reflection
S0 S1 S2 S3 ?
B
L := '0' Dctr := 0 L := '1' L := '0'
Dreg := 0 // reset cycle Dctr := Dctr + 1
count // count cycles
a
S0 S1 S2 S3 S4
B S
L := '0' Dctr := 0 L := '1' L := '0' Dreg := Dctr/2
Dreg := 0 Dctr := Dctr+1 // calculate D
B' B
!(Jreg<2) Jreg<2
1 2 3
S0 S1 Jreg ? 1 2 3
B
P := '0' P := '1'
Jreg := 1 Jreg := Jreg + 1 P
Digital Design 2e
Copyright 2010
(a) (b) 13
Frank Vahid
5.3
Digital Design 2e
Copyright 2010 14
Frank Vahid
Ctrl/DP Example for Earlier CountHigh a
A B
Create DP
add1
CountHigh
S
Connect
First clear Preg to 0s
m
Preg ? 32 with
Then increment Preg for each Preg_clr controller
clr I
clock cycle that m is 1 ld Preg
(a) Preg_ld Q
P
(c) DP
32 Derive
CountHigh Inputs: m (bit) P
controller
Outputs: P (32 bits)
LocStr: Preg (32 bits) CountHigh
//Clear Preg to 0s
S_Clr Preg := 0 m 000...00001
We //Preg := 0
S_Clr Preg_clr = 1 A B
created
Preg_ld = 0 add1
this S
m' //Wait for m=='1'
HLSM S_Wt 32
//Wait for m=1 Preg_clr
earlier m' S_Wt Preg_clr = 0 clr I
m' m ld Preg
Preg_ld = 0
Preg_ld Q
//Increment Preg m' m
m S_Inc Preg := Preg + 1 DP
//Preg:=Preg+1
a
m S_Inc Preg_clr = 0
(b) Preg_ld = 1 a
Digital Design 2e
Controller
Copyright 2010 15
Frank Vahid (d) 32
P
RTL Design Process
Digital Design 2e
Copyright 2010 16
Frank Vahid
Example: Soda Dispenser from Earlier
s a
Quick overview example.
More details of each step to come.
tot_ld ld
tot
tot_clr clr
a
8
Inputs: c (bit), a (8 bits), s (8 bits) 8 8
Outputs: d (bit) // '1' dispenses soda
Local storage: tot (8 bits) 8-bit
tot_lt_s 8-bit
c < adder
Datapath 8
Init Wait
tot:=tot+a
Step 2A
d:='0' c'*(tot<s) s a
c*(tot<s)
tot:=0 8 8
Disp
c
SodaDispenser d:='1' tot_ld
d a
tot_clr
Step 1 Controller Datapath
tot_lt_s
Digital Design 2e
Copyright 2010
Step 2B 17
Frank Vahid
Example: Soda Dispenser
Quick overview example. s
8
a
8
More details of each step to come.
c
tot_ld
d
tot_clr
Inputs: c (bit), a (8 bits), s (8 bits)
Controller Datapath
Outputs: d (bit) // '1' dispenses soda tot_lt_s
Local storage: tot (8 bits)
Step 2B
c
Inputs: c, tot_lt_s (bit)
Init Wait Outputs: d, tot_ld, tot_clr (bit)
tot:=tot+a c tot_ld
c
d:='0' c'*(tot<s) d
Add tot_clr
c*(tot<s)
tot:=0 Init Wait
tot_ld=1 tot_lt_s
Disp
d=0 c' *
tot_lt_s
c*tot_lt_s
tot_clr=1
SodaDispenser d:='1'
Disp
Digital Design 2e
Copyright 2010 Step 2C 18
Frank Vahid
Example: Soda Dispenser
Quick overview example.
Inputs: c, tot_lt_s (bit)
More details of each step to come. Outputs: d, tot_ld , tot_clr (bit)
c tot_ld
c
Add tot_clr
d
tot_lt_s
tot_clr
tot_ld
Init Wait
tot_ld=1 tot_lt_s
c*tot_lt_s
s1 s0 c n1 n0 d c *
d=0 tot_lt_s
0 0 0 0 0 1 0 0 1 tot_clr=1
0 0 0 1 0 1 0 0 1 Disp
Init
0 0 1 0 0 1 0 0 1
Controller d=1
0 0 1 1 0 1 0 0 1
0 1 0 0 1 1 0 0 0
0 1 0 1 0 1 0 0 0 Step 2C
Wait
0 1 1 0 1 0 0 0 0
0 1 1 1 1 0 0 0 0 Use controller design process
1 0 0 0 0 1 0 1 0
Add
Digital Design 2e
Copyright 2010 19
Frank Vahid
RTL Design ProcessStep 2A: Create a datapath
Sub-steps
HLSM data inputs/outputs Datapath inputs/outputs.
HLSM local storage item Instantiated register
"Instantiate": Add new component ("instance") to design
Each HLSM state action and transition condition data computation
Datapath components and connections
Also instantiate multiplexors as needed
Need component library from which to choose
clr I A B A B I I1 I0
ld reg add cmp shift<L/R> mux2x1
Q S lt eq gt Q s0 Q
clk^ and clr=1: Q=0 S = A+B (unsigned) shiftL1: <<1 s0=0: Q=I0
clk^ and ld=1: Q=I A<B: lt=1 shiftL2: <<2 s0=1: Q=I1
else Q stays same A=B: eq=1 shiftR1: >>1
A>B: gt=1 ...
Digital Design 2e
Copyright 2010 20
Frank Vahid
Step 2A: Create a DatapathSimple Examples
X Y Z X X Y Z X Y Z
k k=0: Preg = Y + Z
Preg = X + Y + Z Preg = Preg + X Preg=X+Y; regQ=Y+Z
k=1: Preg = X + Y
Preg Preg Preg regQ Preg
P P P Q P
(a) (b) (c) (d)
X Y Z X X Y Z X Y Z
DP DP
A B
add1 A B A B A B
S add1 A B A B add1 add2
S add1 add2 S S
X+Y S S
A B 0 clr I I1 I0
add2 1 ld Preg 0 clr I 0 clr I mux2x1
S Q 1 ld Preg 1 ld regQ k s0 Q
X+Y+Z Q Q a
0 clr I 0 clr I
1 ld Preg P P Q 1 ld Preg
Q Q
DP DP
P P
Digital Design 2e
Copyright 2010 21
Frank Vahid
Laser-Based Distance MeasurerStep 2A: Create a
Datapath
DistanceMeasurer Inputs: B (bit), S (bit) Outputs: L (bit), D (16 bits)
Local storage: Dreg, Dctr (16 bits)
B' S'
S0 S1 S2 S3 S4
B S
L := '0' Dctr := 0 L := '1' L := '0' Dreg := Dctr/2
Dreg := 0 Dctr := Dctr+1 // calculate D
1 Datapath
16
a
A B
HLSM data I/O DP I/O Add1: add(16) 16 I
S Shr1: shiftR1(16)
HLSM local storage reg Dreg_clr 16 Q
HLSM state action and Dreg_ld 16
Dreg_ld
Dctr_clr Datapath
Dctr_ld
D
to display
16
a
300 MHz Clock
Digital Design 2e
Copyright 2010 23
Frank Vahid
Laser-Based Distance MeasurerStep 2C: Derive the
HLSM
Controller FSM 1
16
Datapath
A B
DistanceMeasurer Inputs: B (bit), S (bit) Outputs: L (bit), D (16 bits) Add1: add(16) 16 I
S Shr1: shiftR1(16)
Local storage: Dreg, Dctr (16 bits) Q
Dreg_clr 16
Dreg_ld 16
B' S'
Dctr_clr clr I clr I
Dctr_ld ld Dctr: reg(16) ld Dreg: reg(16)
S0 S1 S2 S3 S4 Q Q
B S
16
L := '0' Dctr := 0 L := '1' L := '0' Dreg := Dctr/2 D
Dreg := 0 Dctr := Dctr+1 // calculate D
B S
B S
S0 S1 S2 S3 S4
(signed)
W_d
A B A B A clr W_a
sub mul abs inc upcnt W_e
clk^ and W_e=1:
S P Q Q RF[W_a]= W_d
RF R_e=1:
R_a
R_e R_d = RF[R_a]
S = A-B P = A*B Q = |A| clk^ and clr=1: Q=0 R_d
(signed) (unsigned) (unsigned) clk^ and inc=1: Q=Q+1
else Q stays same
Digital Design 2e
Copyright 2010 26
Frank Vahid
RTL Design Involving Register File or Memory
HLSM array: Ordered list of items
Ex: Local storage: A[4](8-bit) 4 8-bit items
Accessed using notation "A[i]", i is index
A[0] := 9; A[1] := 8; A[2] := 7; A[3] := 22
Array contents now: <9, 8, 7, 22>
X := A[1] will set X to 8
Note: First element's index is 0
Array can be mapped to instantiated register file or memory
Digital Design 2e
Copyright 2010 27
Frank Vahid
ArrayEx Inputs: (none)
(A[0] == 8)' a
Init2 A[1] := 12
12 9
11 11
A[0] == 8
I1 I0
A_s Amux
Out1 Preg := A[1] s0 Q
8
(a) A_Wa0 W_d
A_Wa1 W_a
ArrayEx Inputs: A_eq_8 A_We W_e A B
A_Ra0 A
Outputs: A_s, A_Wa0, ... Acmp
A_Ra1 R_a RF[4](11)
lt eq gt
Preg_clr = 1 A_Re R_e
A_s = 0 R_d
Init1 A_Wa1=0, A_Wa1=0
A_We = 1 A_eq_8
(A_eq_8)'
Preg_clr
A_s = 1 clr I
Init2 ld Preg
A_Wa1=0, A_Wa0=1 Preg_ld Q
A_We = 1 DP
A_Ra1=0, A_Ra0=0
A_eq_8 A_Re = 1 (b) 11
P
Out1 Preg_ld = 1
Digital Design 2e Controller
Copyright 2010 28
Frank Vahid (c)
a
RTL Example: Video Compression Sum of Absolute
Only difference: ball moving
Differences
Frame 1 Frame 2 Frame 1 Frame 2
a
S2
S0: wait for go
(i<256)
i<256
S1: initialize sum and index sum:=sum+abs(A[i]-B[i])
S3
i := i + 1
S2: check if done ( (i<256) )
S3: add difference to sum, S4 sadreg := sum
increment index
(b)
S4: done, write to output sad_reg
Digital Design 2e
Copyright 2010 31
Frank Vahid
Array Example: Video
Inputs: A, B [256](8 bits); go (bit)
Outputs: sad (32 bits)
Local storage: sum, sadreg (32 bits); i (9 bits)
S0 !go CompressionSum-of-
Absolute Differences
go
sum := 0
S1
i := 0
S2
!(i<256) i<256
sum:=sum+abs(A[i]-B[i])
S3
i := i + 1
S4 sadreg := sum
i_lt_256 A
lt
S0 go cmp B 8 8
256 9 a
go i_inc
A B
S1
sum=0 sum_clr=1
i_clr
i
i=0 i_clr=1
8
S2 sum_ld
(i<256) (i_lt_256)
(i<256)
S2
i<256
sum:=sum+abs(A[i]-B[i])
S3
i:=i+1
Digital Design 2e
Copyright 2010 33
Frank Vahid
Common RTL Design Pitfall Involving Storage Updates
Questions Local storage: R, Q (8 bits)
Value of Q after state A?
R<100 C
Final state is C or D?
A B
Answers (R<100)'
irrelevant
A's actions same if: Q ? ? ?
Q:=R R:=99 or
R:=99 Q:=R
Digital Design 2e
Copyright 2010 34
Frank Vahid
Common RTL Design Pitfall Involving Storage Updates
R<100 (R<100)'
clk A B B2 D
99 100
R ? 99 100 100
Q ? ? 99 99
Digital Design 2e
Copyright 2010 35
Frank Vahid
RTL Design Involving a Timer
Commonly need explicit time intervals L
Ex: Repeatedly blink LED on 1 second, off 1 second
Pre-instantiate timer that HLSM can then use
Digital Design 2e
Copyright 2010 38
Frank Vahid
Data Dominated RTL Design Example: FIR Filter
FIR filter X Y
Init FC
Step 2B: Connect Ctrlr/DP (as
Yreg := 0 Yreg :=
earlier examples)
xt0 := 0 c0*xt0 +
xt1 := 0 c1*xt1 + Step 2C: Derive FSM
xt2 := 0 c2*xt2
c0 := 3
c1 := 2
xt0 := X
xt1 := xt0
Set clr and ld lines appropriately
FIR filter c2 := 2 xt2 := xt1
3 2 2
...
...
xt0_ld
xt0 xt1 xt2
X
12
clk
x(t)
* x(t-1)
* x(t-2)
*
Yreg_clr
+ + Yreg_ld
Y
Yreg
12
Datapath for 3-tap FIR filter
Digital Design 2e
Copyright 2010 40
Frank Vahid
Circuit vs. Microprocessor y(t) = c0*x(t) + c1*x(t-1) + c2*x(t-2)
Digital Design 2e
Copyright 2010 41
Frank Vahid
5.5
Digital Design 2e
Copyright 2010 42
Frank Vahid
Critical Path
Example shows four paths
a to c through +: 2 ns
a to d through + and *: 7 ns a b
b to d through + and *: 7 ns
b to d through *: 5 ns
Longest path is thus 7 ns
2 ns
delay
+ * 5 ns
delay
Fastest frequency
2 ns
2 ns
7 ns
7 ns
Max
1 / 7 ns = 142 MHz (2,7,7,5)
= 7 ns c d
a
Digital Design 2e
Copyright 2010 43
Frank Vahid
Critical Path Considering Wire Delays
Real wires have delay too
Must include in critical path
Example shows two paths clk a b
Each is 0.5 + 2 + 0.5 = 3 ns
0.5 ns
Trend 0.5 ns
1980s/1990s: Wire delays were tiny
compared to logic delays + 2 ns
But wire delays not shrinking as fast as a
logic delays 0.5 ns
3 ns
3 ns
Wire delays may even be greater than
logic delays! c
Must also consider register setup and
hold times, also add to path
Then add some time to the computed
path, just to be safe
e.g., if path is 3 ns, say 4 ns instead
Digital Design 2e
Copyright 2010 44
Frank Vahid
A Circuit May Have Numerous Paths
Paths can exist s a
automatically very
helpful
Digital Design 2e
Copyright 2010 45
Frank Vahid
5.6
i<256 i = i + 1;
S3 sum:=sum+abs(A[i]-B[i]) }
i := i + 1 return sum;
}
a
S4 sadreg := sum
Digital Design 2e
Copyright 2010 47
Frank Vahid
Converting from C to High-Level State Machine
If-then-else
cond
Becomes state with condition if (cond) { cond
check, transitioning to then // then stmts
(then stmts) (else stmts)
statements if condition true, or }
a
else {
to else statements if condition // else stmts (end)
false }
X>Y X>Y
if (X > Y) {
Max = X; (then stmts) (else stmts) Max:=X Max:=Y
}
else {
Max = Y;
(end) (end)
}
a a
code to HLSM
(go')'
bit go;
Output: int sad
go' go' go go' go
main()
{
uint sum; short uint i; sum:=0 sum:=0
Convert each construct while (1) { i:=0
(g)
Digital Design 2e a
sadreg :=
Copyright 2010 sum 50
Frank Vahid (e)
(f)
5.7
Memory Components
RTL design instantiates
datapath components to
create datapath, controlled
by a controller
Some components are used
M words
outside the controller and DP
MxN memory
M words, N bits wide each
Several varieties of memory,
N-bits
which we now introduce wide each
MN memory
Digital Design 2e
Copyright 2010 51
Frank Vahid
Random Access Memory (RAM)
RAM Readable and writable memory 32 32
W_data R_data
Random access memory 4 4
Strange nameCreated several decades ago to W_addr R_addr
contrast with sequentially-accessed storage like W_en R_en
tape drives 1632
register file
Logically same as register fileMemory with
address inputs, data inputs/outputs, and control Register file from Chpt. 4
RAM usually one port; RF usually two or more
RAM vs. RF
32
RAM typically larger than about 512 or 1024 words data
10
RAM typically stores bits using a bit storage addr
approach that is more efficient than a flip-flop 1024 32
rw RAM
RAM typically implemented on a chip in a square
rather than rectangular shapekeeps longest en
wires (hence delay) short
RAM block symbol
Digital Design 2e
Copyright 2010 52
Frank Vahid
RAM Internal Structure
Let A = log2M wdata(N-1) wdata(N-2) wdata0
32
data
10 word bit storage
addr block
1024x32 enable
rw RAM d0 (aka cell)
en
addr0 a0 word
addr1 a1 AxM
d1
decoder
addr(A-1) a(A-1) data cell
word word
e d(M-1) enable enable
clk
Combining rd and wr rw data
en
data lines rw to all cells
wdata
rdata0
wdata0
(N-1)
rdata
(N-1)
SRAM cell
data data
Static RAM cell 1 0
6 transistors (recall inverter is 2 transistors) d
a
Writing this cell 1 0
word enable input comes from decoder
When 0, value d loops around inverters word 1
That loop is where a bit stays stored enable
When 1, the data bit value enters the loop
data data
data is the bit to be stored in this cell cell
data enters on other side d d
1 0 a
Example shows a 1 being written into cell
word 0
Digital Design 2e
enable
Copyright 2010 54
Frank Vahid
Static RAM (SRAM)
32
data
10
addr
1024x32
rw RAM
en
SRAM cell
Static RAM cell
data data
Reading this cell 1 1
Somewhat trickier d
When rw set to read, the RAM logic sets
both data and data to 1 1 0
DRAM cell
Dynamic RAM cell data
cell
1 transistor (rather than 6)
word
Relies on large capacitor to store bit enable
d
capacitor
Write: Transistor conducts, data voltage slowly
level gets stored on top plate of capacitor discharging
addr
data
en
rw
wire 16
analog-to- digital-to-
digital 12 analog
ad_buf Ra RrwRen wire
microphone converter converter
ad_ld processor da_ld
speaker
Behavior
Record: Digitize sound, store as series of 4096 12-bit digital values in RAM
Well use a 4096x16 RAM (12-bit wide RAM not common)
Play back later
Common behavior in telephone answering machine, toys, voice recorders
To record, processor should read a-to-d, store read values into
successive RAM words
To play, processor should read successive RAM words and enable d-to-a
Digital Design 2e
Copyright 2010 59
Frank Vahid
RAM Example: Digital Sound Recorder
4096x16
RTL design of processor RAM
Create HLSM
16
Begin with the record behavior analog-to-
12
digital-to-
digital ad_buf Ra Rw Ren analog
Create local storage a converter converter
ad_ld processor da_ld
Stores current address,
ranges from 0 to 4095 (thus
need 12 bits) Record behavior
Local register: a, Rareg (12 bits)
Create state machine that
a<4095
counts from 0 to 4095 using a S T
For each a a:=0 ad_ld:=1 a
ad_buf:=1
Read analog-to-digital conv. Rareg:=a U
ad_ld:=1, ad_buf:=1 Rrw:=1 a:=a+1
Ren:=1
Write to RAM at address a
(a<4095)
Rareg:=a, Rrw:=1,
Ren:=1
Digital Design 2e
Copyright 2010 60
Frank Vahid
RAM Example: Digital Sound Recorder
4096x16
Now create play behavior RAM data bus
Use local register a again,
create state machine that 16
counts from 0 to 4095 again analog-to-
digital 12
digital-to-
analog
ad_buf Ra Rw Ren
For each a converter converter
ad_ld processor da_ld
Read RAM
Write to digital-to-analog conv.
Note: Must write d-to-a one Play behavior
cycle after reading RAM, when
Local register: a,Rareg (12 bits)
the read data is available on
the data bus a<4095
V W
The record and play state a:=0
a
ad_buf:=0
machines would be parts of a Rareg:=a
larger state machine controlled Rrw=0 X
Ren=1
by signals that determine when da_ld:=1
a:=a+1
to record or play
(a<4095)
Digital Design 2e
Copyright 2010 61
Frank Vahid
Read-Only Memory ROM
Memory that can only be read from, not 32
data
written to 10
addr
Data lines are output only rw
1024 32
RAM
No need for rw input en
Choose ROM over RAM if stored data wont ROM block symbol
change (or wont change often)
For example, a table of Celsius to Fahrenheit
conversions in a digital thermometer
Digital Design 2e
Copyright 2010 62
Frank Vahid
Read-Only Memory ROM
32
data
10 1024x32
addr Let A = log2M
ROM
en bit storage
word
enable block
ROM block symbol d0 (aka cell)
addr0 a0 word
addr1 a1 AxM
d1
decoder
data
addr
addr(A-1) a(A-1)
word word
e d(M-1) enable enable
clk
en data
Digital Design 2e
Copyright 2010 63
Frank Vahid
ROM Types
If a ROM can only be read, how
are the stored bits stored in the
first place?
Storing bits in a ROM known as
programming
Several methods
Mask-programmed ROM 1 data line 0 data line
as 1s enable
Digital Design 2e
Copyright 2010 65
Frank Vahid
ROM Types
Erasable Programmable ROM
(EPROM)
Uses floating-gate transistor in each cell
Special programmer device uses higher-
than-normal voltage to cause electrons to
tunnel into the gate
floating-gate
Electrons become trapped in the gate data line data line
transistor
Only done for cells that should store 0 cell cell
Other cells (without electrons trapped in 1 1
0 a
Digital Design 2e
Copyright 2010 66
Frank Vahid
ROM Types
Electronically-Erasable Programmable ROM
(EEPROM)
Similar to EPROM
Uses floating-gate transistor, electronic programming to
trap electrons in certain cells
But erasing done electronically, not using UV light
Erasing done one word at a time
Flash memory
Like EEPROM, but all words (or large blocks of
words) can be erased simultaneously 32
data
Became very common starting in late 1990s 10
Both types are in-system programmable addr
en 1024x32
Can be programmed with new stored bits while in the EEPROM
system in which the ROM operates write
Requires bi-directional data lines, and write control input busy
Also need busy output to indicate that erasing is in
progress erasing takes some time
Digital Design 2e
Copyright 2010 67
Frank Vahid
ROM Example: Talking Doll
Hello there! audio
divided into 4096 speaker
Hello there!
4096x16 ROM
samples, stored
in ROM Hello there!
16 a
digital-to-
analog vibration
Ra Ren converter sensor
da_ld
processor
v
Doll plays prerecorded message, triggered by vibration
Message must be stored without power supply Use a ROM, not a RAM,
because ROM is nonvolatile
And because message will never change, may use a mask-programmed ROM or
OTP ROM
Processor should wait for vibration (v=1), then read words 0 to 4095 from
the ROM, writing each to the d-to-a
Digital Design 2e
Copyright 2010 68
Frank Vahid
ROM Example: Talking Doll
Local register: a, Rareg (12 bits)
4096x16 ROM
v a<4095
a:=0 S T
16 Rareg:=a
digital-to- Ren:=1
analog U a
Ra Ren converter v
da_ld:=1
da_ld (a<4095) a:=a+1
processor
v
HLSM
Create state machine that waits for v=1, and then counts from 0 to
4095 using a local storage a
For each a, read ROM, write to digital-to-analog converter
Digital Design 2e
Copyright 2010 69
Frank Vahid
ROM Example: Digital Telephone Answering Machine
Using a Flash Memory
Want to record the outgoing
announcement 4096x16 Flash
Were not home.
erase
When rec=1, record digitized
busy
addr
data
en
rw
sound in locations 0 to 4095
When play=1, play those
stored sounds to digital-to- 16
analog converter analog-to-
digital 12 digital-to-
ad_buf Ra Rrw Ren er bu
What type of memory? converter analog
Should store without power ad_ld processor converter
da_ld
supply ROM, not RAM
Should be in-system rec
programmable EEPROM record play
or Flash, not EPROM, OTP
microphone speaker
ROM, or mask-programmed
ROM
Will always erase entire
memory when
reprogramming Flash
better than EEPROM
Digital Design 2e
Copyright 2010 70
Frank Vahid
ROM Example: Digital Telephone Answering Machine
Using a Flash Memory
HLSM 4096x16 Flash
Digital Design 2e
Copyright 2010 71
Frank Vahid
Blurring of Distinction Between ROM and RAM
We said that
RAM is readable and writable ROM Flash RAM
a
EEPROM NVRAM
ROM is read-only
But some ROMs act almost like RAMs
EEPROM and Flash are in-system programmable
Essentially means that writes are slow
Also, number of writes may be limited (perhaps a few million times)
And, some RAMs act almost like ROMs
Non-volatile RAMs: Can save their data without the power supply
One type: Built-in battery, may work for up to 10 years
Another type: Includes ROM backup for RAM controller writes RAM contents to
ROM before turning off
New memory technologies evolving that merge RAM and ROM benefits
e.g., MRAM
Bottom line
Lot of choices available to designer, must find best fit with design goals
Digital Design 2e
Copyright 2010 72
Frank Vahid
5.8
Queues (FIFOs)
A queue is another component
sometimes used during RTL
back front
design
Queue: A list written to at the
back, from read from the front
Like a list of waiting restaurant
customers write items read (and
Writing called a push, reading to the back
of the queue
remove) items
from front of
called a pop the queue
Digital Design 2e
Copyright 2010 73
Frank Vahid
Queues
7 6 5 4 3 2 1 0
Queue has addresses, and two
pointers: rear and front
Initially both point to 0
Push (write) rf
7 6 5 4 3 2 1 0
Item written to address pointed to
by rear A
A a
rear incremented
Pop (read) r f
Item read from address pointed 7 6 5 4 3 2 1 0
to by front
front incremented B B A a
7) B A
r f
Digital Design 2e
Copyright 2010 74
Frank Vahid
Queues
Treat memory as a circle 7 6 5 4 3 2 1 0
If front or rear reaches 7, next (incremented)
value should be 0 rather than 8 (for a queue B A
with addresses 0 to 7)
Two conditions of interest r f
Causes front=rear B
Empty queue no items
f
No pops allowed until a push occurs
2 6
Causes front=rear r
r
Digital Design 2e
Copyright 2010 75
Frank Vahid
Queue Implementation
Can use register file for 8x16 register file
item storage wdata 16
wdata rdata
16 rdata
Controller
up counter up counter
set control lines for rear front
reset
pushes and pops, and
also detect full and empty eq
=
full
situations
FSM for controller not empty
8-word 16-bit queue
shown
Digital Design 2e
Copyright 2010 76
Frank Vahid
Common Uses of a Queue
Computer keyboard
Pushes pressed keys onto queue, meanwhile pops and sends to
computer
Digital video recorder
Pushes captured frames, meanwhile pops frames, compresses
them, and stores them
Computer network routers
Pushes incoming packets onto queue, meanwhile pops packets,
processes destination information, and forwards each packet out
over appropriate port
Digital Design 2e
Copyright 2010 77
Frank Vahid
Queue Usage Example
7 6 5 4 3 2 1 0
rf
Note how rear and front 7 6 5 4 3 2 1 0
pointers move 1. After pushing 3 2 7 5 8 5 9
Note that popping doesnt 9, 5, 8, 5, 7, 2, 3
rf
Digital Design 2e
5. After pushing 4 ERROR! Pushing a full queue
Copyright 2010 78
Frank Vahid results in unknown state.
5.9
Multiple Processors
Using multiple processors
can ease design from ButtonDebouncer
Keeps distinct behaviors button
Bin Bout
B
L
separate to laser
Laser-based
Ex: Laser-based distance distance
D 16 measurer S
measurer with button
debounce to display from sensor
Digital Design 2e
Copyright 2010 79
Frank Vahid
Interfacing Multiple Processors
Use signal, register, or other component outside processors
Known as global
Common methods use global...
control signal, data signal, register, register file, queue
Typically all multiple processors and clocked globals use
same clock
Synchronized
Digital Design 2e
Copyright 2010 80
Frank Vahid
Ex: Temperature Statistics with Multiple Processors
16-bit unsigned input T from temperature sensor, 16-bit output A. Sample T
every 1 second. Compute output A every minute, should equal average of most
recent 64 samples.
Single HLSM: Complicated
Instead, two HLSMs (and hence two processors) and shared register file
Tsample HLSM: Store T into successive RF address, once per sec.
Avg HLSM: Compute and output average of all 64 RF words, once per min.
Note that each uses distinct timer
T W_d TempStats
Keeping the T
W_d
sampling and W_a W_a R_a R_a A
a
A
averaging W_e W_e R_e R_e
behaviors Tsample TRF
RF[64](16)
separate leads to R_d
Avg
simple design R_d
Digital Design 2e
Copyright 2010 81
Frank Vahid
Ex: Digital Camera with Mult. Processors and Queue
Read and Compress processors (Ch 1)
Compress may take longer, depends on picture
Use queue, read can push additional pics (up to 8)
Likewise, use queue between Compress and Store
Image sensor
8 8
wdata rdata
Read wr Compress Queue Store
circuit rd Memory
full Queue empty circuit [8](8) circuit
[8](8)
a
Digital Design 2e
Copyright 2010 82
Frank Vahid
5.10
Province 2
Province 3
Province 1
CityF
a
Organization with few items at the top, with CityB
each item decomposed into other items CityE
Common example: Country CityC
CityG
1 item at top (the country) Country A
Province 2
Province 3
Province 1
Hierarchy helps us manage complexity
To go from transistors to gates, muxes,
decoders, registers, ALUs, controllers,
datapaths, memories, queues, etc. Country A
Imagine trying to comprehend a controller
and datapath at the level of gates Map showing just top two levels
of hierarchy
Digital Design 2e
Copyright 2010 83
Frank Vahid
Hierarchy and Abstraction
Abstraction
Hierarchy often involves not just
grouping items into a new item, but also
associating higher-level behavior with
the new item, known as abstraction a7.. a0 b7.. b0
Ex: 8-bit adder has understandable high-
level behavioradds two 8-bit binary 8-bit adder ci
numbers
co s7.. s0
Frees designer from having to
remember, or even understand, the
lower-level details
Digital Design 2e
Copyright 2010 84
Frank Vahid
Hierarchy and Composing Larger Components
from Smaller Versions
A common task is to compose smaller components 4x1
into a larger one i0 i0 a
Gates: Suppose you have plenty of 3-input AND gates, i1 i1
but need a 9-input AND gate i2 i2 d
Can simple compose the 9-input gate from several 3-input
gates i3 i3
Muxes: Suppose you have 4x1 and 2x1 muxes, but 2x1
s1 s0 i0
need an 8x1 mux
d
s2 selects either top or bottom 4x1
4x1 i1
s1s0 select particular 4x1 input
i4 i0 s0
Implements 8x1 mux 8 data inputs, 3 selects, one output
i5 i1
i6 i2 d
i3
P
ro
vin
c s1 s0
e1
0
s1 s0 s2 1
Digital Design 2e
Copyright 2010 85
Frank Vahid
Hierarchy and Composing Larger Components
from Smaller Versions
Composing memory very common
Making memory words wider
Easy just place memories side-by-side until desired width obtained
Share address/control lines, concatenate data lines
Example: Compose 1024x8 ROMs into 1024x32 ROM
10
addr
en en en en
data data data data
8 8 8 8
data(31..0)
10
1024x32
ROM
data
Digital Design 2e 32
Copyright 2010 86
Frank Vahid
Hierarchy and Composing Larger Components
from Smaller Versions
11
a9..a0
addr
Creating memory with more words addr
Put memories on top of one another until the a10 1x2 d0 1024x8
number of desired words is achieved i0 dcd ROM
Use decoder to select among the memories e d1 en data
Can use highest order address input(s) as 8
en
decoder input
Although actually, any address line could be addr
used 1024x8
11
Example: Compose 1024x8 memories into ROM
addr
2048x8 memory 2048x8 en data
ROM
en
a10a9a8 a0 8
data
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 addr 8 a
a 0 0 0 0 0 0 0 0 0 1 0 1024x8
P P
r1 1
ROM
0 1 ro1 1 1 1 1ovin 1 0 en data
a10 just chooses vin a
0 1 1 1 1 1 1 c1 1 1 1
which memory To create memory with more
to access 1 0 0 0 0 0 0 0 0 0 0 words and wider words, can first
1 0 0 0 0 0 0 0 0 0 1 addr
compose to enough words, then
1 0 0 0 0 0 0 0 0 1 0 1024x8
ROM
widen.
Digital Design 2e
Copyright 2010 1 1 1 1 1 1 1 1 1 1 0 en data 87
Frank Vahid 1 1 1 1 1 1 1 1 1 1 1
Chapter Summary
Modern digital design involves creating processor-level components
High-level state machines
RTL design process
1. Capture behavior: Use HLSM
2. Convert to circuit
A. Create datapath B. Connect DP to controller C. Derive controller FSM
More RTL design
More components, arrays, timers, control vs. data dominated
Determining fastest clock frequency
By finding critical path
Behavioral-level design C to gates
By using method to convert C (subset) to high-level state machine
Memory components (RAM, ROM)
Queues
Multiple processors
Hierarchy: A key concept used throughout Chapters 2-5
Digital Design 2e
Copyright 2010 88
Frank Vahid