Lecture07 PDF
Lecture07 PDF
Lecture07 PDF
Lecture 7: 1
Announcements
• HW3 will be posted tonight
• Prelim 1
– Thursday March 1, in class
– Coverage: Lectures 1~7
• Binary number, Boolean algebra, CMOS, combinational logic,
sequential logic, and Verilog
– Closed book, closed notes, closed Internet
Lecture 7: 2
S-R Latch
(RESET)
R Q
(SET)
S
Lecture 7: 3
S-R Latch
• S-bar-R-bar latch
– Built from NAND gates
– Inputs are active low rather than active high
– When both inputs are active, Q = QN = 1 (avoid!)
S S R Q QN
Q
0 0 1 1 S Q
0 1 1 0 R
R
QN 1 0 0 1
Last Last
1 1
Q QN
Lecture 7: 4
D Latch and Flip-Flop
• Latch: level sensitive
– Captures the input when enable signal asserted
D Q
C
D Q
CLK
Lecture 7: 5
DFF Timing Example
CLK
A
B
A Y
B
Z
Y Z
CLK Waveform
(assuming Y & Z are
Circuit diagram initialized with 0s)
Lecture 7: 6
Another Example
CLK
A
B
A Y
B
Z
Y Z
CLK Waveform
(assuming Y & Z are
Circuit diagram initialized with 0s)
Lecture 7: 7
T (Toggle) Flip-Flop
• Output toggles only if T=1
• Output does not change if T=0
• Useful for building counters
Q: 0, 1, 0, 1, 0, 1, 0, ...
T Q
T ? D Q
CLK
CLK
Lecture 7: 8
T (Toggle) Flip-Flop
• Output toggles only if T=1
• Output does not change if T=0
• Useful for building counters
Q: 0, 1, 0, 1, 0, 1, 0, ...
T Q
D Q
CLK
T
CLK
Lecture 7: 9
Binary Counters
• Counts in binary in a particular sequence
• Advances at every tick of the clock
• Many types
Divide-
Up Down by-n n-to-m
000 111 000 n
001 110 001 n+1
010 101 010 n+2
..
011 100 011 .
100 011 100 m-1
..
101 010 . m
.. ..
. . n
n-1
000 n+1
..
001 .
Lecture 7: 10
Up Counter Sequence
000
001
010
011
100
101
110
111
Toggles every clock tick Toggles every clock tick
that two right bits = 11
Toggles every clock tick
that right bit = 1
Lecture 7: 11
Free Running Binary Up Counter
1 Q2 Q1 Q0
T Q Q0
000
CLK
001
T Q
010
Q1
011
100
T Q Q2 101
110
111
Q0 toggles at every rising edge
000
Q1 toggles at the rising edge when Q0=1
Q2 toggles at the rising edge when Q0=Q1=1 001
Lecture 7: 12
Up Counter Timing Diagram
CLK
Q0
Q1
Q2
Count 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0
Lecture 7: 13
Evolution of Design Abstractions
Results
?
(design productivity)
Gate-level entry
Transistor-level entry
McKinsey S-Curve
Effort
(CAD tool effort)
• Industry standards:
– Verilog: We will use it from Lab 3
– SystemVerilog: Successor to Verilog, gaining
popularity
– VHDL (Very High Speed Integrated Circuit HDL)
Lecture 7: 15
Verilog
• Developed in the early 1980s by Gateway
– Design Automation (later bought by Cadence)
Lecture 7: 17
Bit Vectors
• Multi-bit values are represented by bit vectors
(i.e., grouping of 1-bit signals)
– Right-most bit is always least significant
– Example
• input[7:0] byte1, byte2, byte3; /* three 8-bit inputs */
• Constants
• Binary Constants
4’b1001 – 8’b00000000
– 8’b0xx01xx1
• Decimal Constants
Base format (b,d,h,o) – 4’d10
Decimal number representing bit width – 32’d65536
Lecture 7: 18
Operators
• Bitwise Boolean operators
~ NOT
& AND
^ Exclusive OR
| OR
• Arithmetic operators
+ Addition / Division << Shift left
– Subtraction % Modulus >> Shift right
* Multiplication
Lecture 7: 19
Verilog Program Structure
module
• System is a collection of
modules
declarations
– Module corresponds to a
single piece of hardware
statements
• Declarations
– Describe names and types of inputs and outputs
– Describe local signals, variables, constants, etc.
Lecture 7: 20
Verilog Program Structure
module M_2_1 (x, y, select, out);
input x, y;
input select;
Declarations
output out;
wire tx, ty;
endmodule
Lecture 7: 21
module A
Verilog declarations
Hierarchy statements
module C module D
declarations declarations
statements statements
statements
Lecture 7: 22
Verilog Programming Styles
• Structural
– Shows how a module is built from other modules via
instance statements
– Textual equivalent of drawing a schematic
• Behavioral
– Specify what a module does in high-level description
– Use procedural code (e.g., in always block) and
continuous assignment (i.e., assign) constructs to
indicate what actions to take
y out
AND and0 (x, ~sel, tx);
AND and1 (y, sel, ty);
OR or0 (tx, ty, out); ty
endmodule sel
endmodule
endmodule
Lecture 7: 26
Sequential Logic in Always Blocks
reg Q;
• Sequential
always @( clk, D ) D Q logic can
begin C only be
if ( clk )
D latch modeled
Q <= D;
end using always
blocks
D Q
always @( posedge clk )
begin CLK
Q <= D;
• Q must be
end DFF declared as
a “reg”
Lecture 7: 27
Blocking Assignments
• Blocking assignments ( = )
– Simulation behavior: Right-hand side (RHS) evaluated
sequentially; assignment to LHS is immediate
reg Y, Z;
always @ (posedge clk)
begin
Y = A & B; Y and Z are flip-flops
Z = ~Y; in actual hardware
end
Blocking assignments
Simulator interpretation Resulting circuit (post synthesis)
Ynext = A & B A
B
Znext = ~(A & B)
Y Z
Lecture 7: 28
Nonblocking Assignments
• Nonblocking assignment ( <= )
– Simulation behavior: RHS evaluated in parallel (order doesn’t
matter); Assignment to LHS is delayed until end of always block
reg Y, Z;
always @ (posedge clk)
begin
Y <= A & B; Y and Z are flip-flops
Z <= ~Y; in actual hardware
end
Nonblocking assignments
Simulator interpretation Resulting circuit (post synthesis)
A
Znext = ~Y // reading the old Y
B
Ynext = A & B
Y Z
Lecture 7: 29
Assignments in Verilog
• Continuous assignments apply to
combinational logic only
Lecture 7: 30
Before Next Class
• H&H 3.4, 4.6
Next Time
Lecture 7: 31