0% found this document useful (0 votes)
60 views

Lecture07 PDF

The document provides information about an upcoming lecture on sequential logic and Verilog. It includes the following: 1) Announcements about an upcoming homework assignment and prelim exam covering the material so far including sequential logic and Verilog. 2) Examples of sequential logic circuits like an S-R latch and timing diagrams. 3) Information about D latches, flip-flops and their usage in binary counters. 4) A brief introduction to Verilog as a hardware description language and its usage for modeling, simulation and synthesis of digital circuits.

Uploaded by

Timothy Eng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Lecture07 PDF

The document provides information about an upcoming lecture on sequential logic and Verilog. It includes the following: 1) Announcements about an upcoming homework assignment and prelim exam covering the material so far including sequential logic and Verilog. 2) Examples of sequential logic circuits like an S-R latch and timing diagrams. 3) Information about D latches, flip-flops and their usage in binary counters. 4) A brief introduction to Verilog as a hardware description language and its usage for modeling, simulation and synthesis of digital circuits.

Uploaded by

Timothy Eng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

ECE 2300

Digital Logic & Computer Organization


Spring 2018

More Sequential Logic


Verilog

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

– An old prelim exam will be posted early next week


– Review session(s) will be scheduled soon

Lecture 7: 2
S-R Latch
(RESET)
R Q
(SET)
S

• Suppose the S-R latch is initialized with Q=0,


write down the next state given the following
input sequence
– S=0, R=1 à Qnext = 0
– S=0, R=0 à Qnext = 0
– S=1, R=0 à Qnext = 1

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

• Flip-Flop (FF): edge sensitive


– Captures the input at the triggering clock edges
(e.g., LàH)
– A single FF is also called a one-bit register

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

Qnext = T•Q’ + T’•Q

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)

HDL (Verilog, VHDL)

Gate-level entry

Transistor-level entry

McKinsey S-Curve
Effort
(CAD tool effort)

[source: Keutzer] Lecture 7: 14


Hardware Description Languages
• Hardware Description Language (HDL):
a language for describing hardware
– Efficiently code large, complex designs
• Programming at a more abstract level than schematics
– CAD tools can automatically synthesize circuits

• 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)

• Supports modeling, simulation, and synthesis


– We will use a (synthesizable) subset of the language
features

• Major language features (in contrast to software


programming languages)
– Structure and instantiation
– Concurrency
– Bit-level behavior
Lecture 7: 16
Values
• Verilog signals can take 4 values
0 Logical 0, or false
1 Logical 1, or true
x Unknown logical value
z High impedance (Hi-Z), floating

x might be a 0, 1, z, or in transition, or don’t cares


Sometimes useful debugging and often exploited by CAD
tools during optimization

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.

• Statements specify what the module does

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;

AND and0 (x, ~select, tx);


AND and1 (y, select, ty); Statements
OR or0 (tx, ty, out);

endmodule

Lecture 7: 21
module A

Verilog declarations

Hierarchy statements

module C module D

declarations declarations

statements statements

A module can instantiate


other modules forming a
module F
module hierarchy
declarations

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

We can mix the structural and behavioral styles


in a Verilog design
Lecture 7: 23
Structural Style
module M_2_1 (x, y, sel, out);
input x, y;
input sel;
output out; tx
x
wire tx, ty;

y out
AND and0 (x, ~sel, tx);
AND and1 (y, sel, ty);
OR or0 (tx, ty, out); ty

endmodule sel

The order of the module instantiation does not matter


Essentially describing the schematic textually
Lecture 7: 24
Behavioral Style with
Continuous Assignments
• An assign statement represents continuously
executing combinational logic
module MUX2_1 (x, y, sel, out);
input x, y;
input sel;
output out;

assign out = (~sel & x) | (sel & y);

endmodule

• Multiple continuous assignments happen in


parallel; the order does not matter
Lecture 7: 25
(Behavioral Style) Combinational
Logic with Always Blocks
module MUX2_1 (x, y, select, out); • An always block is
input x, y; reevaluated whenever a
input select; signal in its sensitivity
output reg out; list changes

always @(x, y, select) • Formed by procedural


begin assignment statements
out <= (~select & x) | (select & y); – reg needed on the LHS of
end a procedural assignment

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

• Always blocks contain a set of procedural


assignments (blocking or nonblocking)
– Can be used to model either combinational or
sequential logic
– Always blocks execute concurrently with other
always blocks, instance statements, and
continuous assignment statements in a module

Lecture 7: 30
Before Next Class
• H&H 3.4, 4.6

Next Time

Finite State Machines

Lecture 7: 31

You might also like