EE577b: VLSI System Design Verilog Examples
EE577b: VLSI System Design Verilog Examples
EE577b: VLSI System Design Verilog Examples
Verilog Examples
January, 00 P. A. Beerel 2
1
Solutions to avoid inferred latch
January, 00 P. A. Beerel 3
January, 00 P. A. Beerel 4
2
Combinational Circuit Example I
January, 00 P. A. Beerel 5
January, 00 P. A. Beerel 6
3
Combinational Circuit Example II
always @(a or b)
begin
if (a == 1’b1)
q = b;
else // include “else statement”
q = 1’b0;
end
January, 00 P. A. Beerel 7
always @(d)
begin
case (d)
2’b00: z = 1’b1; // missing “s” assignment
2’b01: z = 1’b0; // missing “s” assignment
2’b10: z = 1’b1; s = 1’b1;
// missing condition “2’b11”.
endcase
end
January, 00 P. A. Beerel 8
4
Combinational Circuit Example III
January, 00 P. A. Beerel 9
always @(g, a, b)
begin
if (g == 1’b1)
q = 0;
else if (a == 1’b1)
q = b;
// missing case “g = 0” and “a = 0”.
end
January, 00 P. A. Beerel 10
5
Combinational Circuit Example IV
always @(g, a, b)
q = 0; // default assignment to avoid
begin // missing condition.
if (g == 1’b1)
q = 0;
else if (a == 1’b1)
q = b;
end
January, 00 P. A. Beerel 11
January, 00 P. A. Beerel 12
6
Sequential circuit with sync reset
January, 00 P. A. Beerel 13
January, 00 P. A. Beerel 14
7
Example of D-FF w/ asynch reset
January, 00 P. A. Beerel 15
January, 00 P. A. Beerel 16
8
FSM with async reset (Style I)
parameter IDLE = 2’b00;
RW_CYCLE = 2’b01;
INT_CYCLE = 2’b10;
DMA_CYCLE = 2’b11;
ADD1MUL1 = 3’b001;
ADD2MUL1 = 3’b011;
...
reg [1:0] STATE, NEXT_STATE;
January, 00 P. A. Beerel 17
January, 00 P. A. Beerel 18
9
FSM with async reset (Style I)
10
Synchronous RTL Coding Styles
General Requirements
y Register transfers on only clock edges.
y Combinational logic computes values to be depositid
before clock edge.
January, 00 P. A. Beerel 21
General Description
y One or more clocked process(es) to describe the
control unit (CU) and datapath (DPU)
x No distinct combinational logic blocks
Two Forms
y Separate CU and DPU (Recommended!)
x Helps ensure correctness and synthesizability
y Combined CU and DPU
x Not recommended!
x Disadvantage: data registers do not need to be reset but
they are coded under a process sensitive to reset (needed
because control registers must be reset).
January, 00 P. A. Beerel 22
11
Benefits of Behavioral RTL
Easy
y Do not have to visualize or explicitly specify...
x datapath component boundaries
x functional unit allocation and binding
x control signals such as mux_sel or op_codes
Helpful
y For ASIC Design: synthesis tools (e.g., design compiler)
can do function unit allocation and bining, mux and
op_code synthesis
y For full-custom design: helps guide and validate structural
RTL code
January, 00 P. A. Beerel 23
January, 00 P. A. Beerel 24
12
Separate CU and DPU Ex. (con’t)
// Separate DPU process.
// The OFL is implicitly treated as part of the DPU
// Muxes are not needed; they are implicit
// Registers are not needed; they are implicit
always@(posedge clk)
begin
case (state)
I_STATE:
x <= xin;
y <= yin;
C_STATE:
if (x >= y)
x <= x - y;
…
endcase
end
January, 00 P. A. Beerel 25
13
Structural RTL Coding
Create structural description of datapath unit
y Must visualize and specify functional units, muxes, mux_sel,
op_code_sel, registers etc…
y Must specify interface between control and datapath units
January, 00 P. A. Beerel 27
January, 00 P. A. Beerel 28
14
Structural RTL Example
z Example of circuit
z Top level circuit verilog example
z Datapath unit example
z Datapath unit components example
y 8-bit wide, 2 to 1 Multiplexor
y 8-bit positive edge flip-flop
y 8-bit ALU
zControl unit example
y Next state logic
y State memory
y Output functional logic
January, 00 P. A. Beerel 29
Example of circuit
Mux_1
...
Reg _1
Datapath Unit
...
ALU
Mux_2
Reg _2
alu_out
...
clk
January, 00 P. A. Beerel 30
15
Top level circuit verilog example
endmodule
January, 00 P. A. Beerel 31
‘include “mux.v”
‘include “alu.v”
‘include “reg.v”
endmodule
January, 00 P. A. Beerel 32
16
8-bit wide, 2 to 1 Multiplexor (mux.v)
January, 00 P. A. Beerel 33
January, 00 P. A. Beerel 34
17
8-bit ALU (alu.v)
January, 00 P. A. Beerel 35
reg CLK;
parameter PERIOD = 50; // clock period
initial CLK = 0; // initialize clock signal
// clock generator
always #(PERIOD/2) CLK = !CLK;
// reset generator
always begin
RESET = 1;
# (3 * PERIOD) RESET = 0;
end
January, 00 P. A. Beerel 36
18
Creating clock and reset signal (con’t)
parameter INITIAL_CLOCK= 1;
parameter MAX_CYCLES = 100;
parameter SIM_END = PERIOD * MAX_CYCLES;
always begin
while ($time < SIM_END) begin
CLK = INITIAL_CLOCK;
#(PERIOD/2);
CLK = !INITIAL_CLOCK;
#(PERIOD/2);
end
$finish
end
January, 00 P. A. Beerel 37
19
Simple delay model (con’t)
Other examples
wire #6.5 z = a & b;
or #10 u3(C, A, B);
Modeling rise and fall times
assign #(rise, fall) c = a ^ b;
or #(10, 25) u3(C, A, B);
buf #(10, 25, 35) zbuf(z, a, en);
Third delay parameter is the delay to high
impedance state.
January, 00 P. A. Beerel 39
System functions
initial begin
value1 = $random;
value2 = $random;
#delay1 $display(“%0d %b”, $time, value1);
end
endmodule
January, 00 P. A. Beerel 40
20
System functions (con’t)
always @(disk_full)
if (disk_full)
$stop; // interrupt simulation and enter interactive mode
January, 00 P. A. Beerel 41
Integers vs Registers
January, 00 P. A. Beerel 42
21
Integers vs Registers (con’t)
January, 00 P. A. Beerel 43
Testbench
Purpose
z To test your design you have to write a testbench
Description
z The testbench is a piece of verilog code that interacts
with your design.
z You can apply inputs and observe and store the
outputs.
January, 00 P. A. Beerel 44
22
Testbench Template
The Testbench
R e s e t
k lC
(DUT)
Design
Inputs Uhder Outputs
Test
January, 00 P. A. Beerel 45
Testbench Example
module TestBench;
reg Clk , Reset, ShiftReg ;
reg [9:0] DataIn, Packets[0:999];
Here the shift register is intantiated
wire [9:0] DataOut ; in the testbench to be tested
parameter L=10;
January, 00 P. A. Beerel 46
23