Академический Документы
Профессиональный Документы
Культура Документы
Chapter 2
Register Transfer Level
Design with Verilog
Prepared by:
Homa Alemzadeh
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 1
Register Transfer Level Design
with Verilog
2.1 RT Level Design
2.1.1 Control/data partitioning
2.1.2 Data part
2.1.3 Control part
2.4 Testbenches
2.4.1 A simple tester
2.4.2 Tasks and functions
2.5 Summary
Partitioning
Control/data
Partitioning
Control/data
Control/data
Partitioning
Partitioning
RT Level Design
DataPath Control
Reg
Flags & status
Control
Data Inputs
Opcode Outputs
Data flow
Control signals
Control
Data Outputs
Inputs
Control/data
Partitioning
Data
Data Part
Part Control Part
DataPath
Reg
Flags & status
Data Inputs
Opcode
Data flow
Control signals
Data Outputs
Control/data
Partitioning
Outline of a Controller
Primitive Assign
Instantiations Statements
Condition Procedural
Expression Blocks
Module
Instantiations
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 16
Hardware Modules
Hardware
Modules
Modules
Primitive Assign
Instantiations Statements
Condition Procedural
Expression Blocks
Module
Instantiations
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 17
Hardware Modules
module :
The Main
Keyword
Component
module of Verilog
module module-name
Variables, wires, and
List of ports; module parameters
Declarations are declared.
...
Functional specification of module
...
Keyword
endmodule endmodule
Module Specifications
Primitive
Primitive Assign
Instantiations Statements
Condition Procedural
Expression Blocks
Module
Instantiations
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 20
Primitive Instantiations
Logic Gates
called
Primitives
a a_sel
s_bar w
s
b b_sel
A Multiplexer Using Basic Logic Gates
Primitive Instantiations
Primitive Assign
Instantiations Statements
Condition Procedural
Expression Blocks
Module
Instantiations
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 23
Assign Statements
Continuously
drives w with the
right hand side
expression
Primitive Assign
Instantiations Statements
Condition
Condition Procedural
Expression Blocks
Module
Instantiations
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 25
Condition Expression
Can be used when
the operation of a
unit is too complex
to be described by
Boolean expressions
Primitive Assign
Instantiations Statements
Condition Procedural
Expression Blocks
Module
Instantiations
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 27
Procedural Blocks
always
statement Sensitivity list
Primitive Assign
Instantiations Statements
Condition Procedural
Expression Blocks
Module
Module
Instantiations
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 29
Module Instantiations
a
ANDOR
i1
s i2 y w
i3
b i4
Data
Controllers
Components
Component
Description
Data
Data
Controllers
Components
Components
Multiplexer Flip-Flop
Counter Full-Adder
Shift-Register ALU
Interconnections
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 34
Multiplexer
Data
Components
Multiplexer Flip-Flop
Counter Full-Adder
Shift-Register ALU
Interconnections
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 35
Multiplexer
Defines a Time Unit of 1 ns
and Time Precision of 100 ps.
`timescale 1ns/100ps
Multiplexer Flip-Flop
Counter Full-Adder
Shift-Register ALU
Interconnections
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 37
Flip-Flop A
Flip-Flops are
Software-Like
used in data part
forProcedural
flags and data
Coding Style
storage
Synchronous
`timescale 1ns/100ps reset input
Flip-Flop The Body of
triggers
module Flop (reset, on the
din, always statement is
clk, qout);
falling edge of Aexecuted
Signal declared
at the as a
input reset, din, clk;
clk Input reg to beedge
negative capable
of of
output qout;
holding its values
the clk signal
reg qout;
between clock edges
always @(negedge clk) begin
if (reset) qout <= #8 1'b0;
else qout <= #8 din;
end
endmodule A Non-blocking
An 8-ns Assignment
Flip-Flop Description Delay
Multiplexer Flip-Flop
Counter Full-Adder
Shift-Register ALU
Interconnections
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 39
A 4-bit modulo-16
Counter Counters are used in data
part for registering data,
Counter accessing memory or
queues and register
stacks
4-bit
`timescale 1ns/100ps
Register
module Counter4 (input reset, clk,
output [3:0] count);
reg [3:0] count; Constant
always @(negedge clk) begin Definition
if (reset) count <= #3 4'b00_00;
else count <= #5 count + 1;
end When count
endmodule reaches 1111,
the next count
Counter Verilog Code taken is 10000
Multiplexer Flip-Flop
Counter Full-Adder
Shift-Register ALU
Interconnections
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 41
Full-Adder
Full-Adders are used
A combinational in data part for
circuit building
Carry-Chain adders
All Changes
Occur after 5 ns
`timescale 1ns/100ps
Multiplexer Flip-Flop
Counter Full-Adder
Shift-Register ALU
Interconnections
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 43
An 8-bit
2 Mode inputs Shift-Register Universal
Shift Register
m[1:0] form a
`timescale
2-bit number 1ns/100ps
module ShiftRegister8
(input sl, sr, clk, input [7:0] ParIn,
Case Statement
input [1:0] m, output
With 4 reg [7:0] ParOut);
case-alternatives
and default Value
always @(negedge clk) begin
case (m)
m=0 : Does Nothing
0: ParOut <= ParOut;
1: ParOut <= {sl, ParOut [7:1]};
2: ParOut <= {ParOut [6:0], sr}; m=1,2: Shifts Right
3: ParOut <= ParIn; and Left
default: ParOut <= 8'bX;
endcase m=3 : Loads its Parallel
end input into the register
endmodule
module ShiftRegister8
(input sl, sr, clk, input [7:0] ParIn,
input [1:0] m, output reg [7:0] ParOut);
Shift Right:
The SL input is
always @(negedge clk) begin
concatenated to
case (m) the left of
0: ParOut <= ParOut; ParOut
1: ParOut <= {sl, ParOut [7:1]};
2: ParOut <= {ParOut [6:0], sr};
3: ParOut <= ParIn;
default: ParOut <= 8'bX; Shifting the
endcase ParOut to the left
end
endmodule
Multiplexer Flip-Flop
Counter Full-Adder
Shift-Register ALU
Interconnections
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 46
ALU
`timescale 1ns/100ps
An 8-bit ALU
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 47
ALU (Continued) The Declaration of
ALUout both as
`timescale 1ns/100ps output and reg:
Because of
module ALU8 (input [7:0] left, right, assigning it within
input [1:0] mode, a Procedural Block
output reg [7:0] ALUout);
always @(left, right, mode) begin
case (mode) Blocking
0: ALUout = left + right; Assignments
1: ALUout = left - right;
2: ALUout = left & right;
3: ALUout = left | right;
default: ALUout = 8'bX; default alternative
endcase puts all Xs on ALUOut
end if mode contains
endmodule anything but 1s and 0s
An 8-bit ALU
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 48
Interconnections
Data
Components
Multiplexer Flip-Flop
Counter Full-Adder
Shift-Register ALU
Interconnections
Verilog Digital System Design
January 2006 Copyright Z. Navabi, 2006 49
Interconnections
Inbus Aside Bside
8 8
select_source
8
Outbus
Partial Hardware Using MUX8 and ALU
u1 Verilog
and u2 : Code of The Partial Hardware Example
Instance Names
Component
Description
Data
Controllers
Controllers
Components
Decisions
Based on :Inputs ,
Outputs ,State
Go to Next State
Controller Outline
Controller:
Is wired into data part to control its flow of data.
Monitors its inputs and makes decisions as to when and what output
signals to assert.
Keeps the history of circuit data by switching to appropriate states.
Sequence Detector
Controllers
Sequence
Synchronizer
Detector
Controllers
Sequence
Synchronizer
Synthesizer
Detector
Clk
adata
synched
Synchronizing adata
`timescale 1ns/100ps
Controllers
Sequence
Sequence
Synthesizer
Detector
Detector
clk
State Machine Description
endmodule
s1 s1:
0
a=1 if (a)
Testbenches
Tasks
A Simple
And
Tester
Functions
Testbenches
Tasks
A Simple
And
Tester
Tester
Functions
module Detector110Tester;
reg aa, clock, rst;
wire ww;
Detector110 UUT (aa, clock, rst, ww);
initial begin
aa = 0; clock = 0; rst = 1;
end
initial repeat (44) #7 clock = ~clock;
initial repeat (15) #23 aa = ~aa;
initial begin
#31 rst = 1;
#23 rst = 0;
end
always @(ww) if (ww == 1)
$display ("A 1 was detected on w at time = %t", $time);
endmodule
module Detector110Tester;
reg aa, clock,Outputs
rst; are Inputs are Declared as reg
wire ww; declared as wire
Detector110 UUT (aa, clock, rst, ww);
.........................
......................... The Instantiation of
Detector110 Module
Testbench for Detector110
Testbenches
Tasks
A Simple
And
And
Tester
Functions
Tasks:
Can represent a sub module within a Verilog module
Its body can only consist of sequential statements like if-else and
case
Functions:
Can be used for corresponding to hardware entities