Verilog ICPEP
Verilog ICPEP
A
H
T
P
I
R
C
S
E GE
D A
E
U
R
A NG
W LA
D
N
IO
IMPORTANCE OF VERILOG
Digital system are highly complex.
Verilog language provides the digital designer a
software platform.
Verilog allows user to express their design with
behavioral constructs.
A program tool can convert the Verilog program
to a description that was used to make chip,
like VLSI.
LEVELS OF ABSTRACTION-1
Switch Level: Module implemented with
switches and interconnects. Lowest
level of Abstraction
Gate Level: Module implemented in terms
of logic gates like (and ,or) and
interconnection between gates
LEVELS OF ABSTRACTION-2
Dataflow Level: Module designed by
specifying dataflow. The designer is
aware of how data flows between
hardware registers and how the data
is processed in the design
Behavioral Level :Module can be
implemented in terms of the desired
design algorithm without concern for
the hardware implementation
details. Very similar to C
programming
HIERARCHICAL DESIGN
E.g.
Top
TopLevel
Level
Module
Module
Sub-Module
Sub-Module
11
Basic
BasicModule
Module Basic
BasicModule
Module
11
22
Full
FullAdder
Adder
Sub-Module
Sub-Module
22
Basic
BasicModule
Module
33
Half
HalfAdder
Adder
Half
HalfAdder
Adder
HIERARCHY
MODULE
in1
my_module
out1
out2
in2
f
inN
outM
BASIC CONCEPTS
Number is specified as
<size>'<baseformat><number>
BASIC CONCEPTS
NETS
Nets represent internal connections
between hardware elements.
REGISTERS
Registers represent data storage
elements.
In Verilog, the term register is a
variable that can hold a value.
VECTORS
Arrays of Registers and Nets
PORTS
Ports provide interface for by which a
module can communicate with its
environment
MODULE
EXAMPLE :
EXAMPLE
CONNECTING PORTS
GATE GATE_NAME(OUT,IN1,IN2)
BUF/NOT GATES
Buf / not gates have one scalar input and one or more scalar
outputs.
M
I
S
G
N
I
T
A
L
U
VE
G
O
L
RI
Testbench
Result
checker
System Model
Response
WRITING TESTBENCHES
module test;
reg i0,i2,i3,i4,s1,s0;
initial begin
$monitor($time,, i0 = %b i2=%b
i2=%b i3=%b s1=%b s0=%b i0, i1, i2,
Stimulus generated by
i3, s1, s0, y);
sequence of assignments
i0 = 0; i1= 0; i2 = 0;
and delays
i3 = 0; s1= 0; s0 = 0;
#10 i0 = 1;
#10 i1 = 1;
#10 i2 = 1; #10 i3 = 1; #10 s1 = 1; #10
s0= 1;
STIMULUS
DECLARATION:
TEST BENCH
TEST BENCH
initial
begin
#0 A=4b0000; B=4b0000; C_IN=1b0;
#10 A=4b0100; B=4b0011; C_IN=1b1;
#20 A=4b0011; B=4b0111; C_IN=1b1;
#30 A=4b1000; B=4b0100; C_IN=1b0;
#40 A=4b0101; B=4b0101; C_IN=1b1;
end
$initial
begin
$monitor ($time A=%b B=%b C_IN=%b SUM=
%b C_OUT=%b, A,B,C_IN,SUM,C_OUT);
end
endmodule
TESTBENCHUSING $RANDOM
module tb_ripple_carry;
parameter N=4;
reg [N-1:0]A,B;
reg C_IN;
wire [N-1:0]SUM;
wire C_OUT;
fulladd4 RCA(.a(A),.b(B),.c_in(C_IN),.sum(SUM),.c_out(COUT));
initial begin
A= 4'b0000;
B= 4'b0000;
C_IN =1'b0;
repeat(10)
input_generate(A,B,C_IN);
#45 $finish;
end
TESTBENCHUSING $RANDOM
task input_generate;
output [N-1:0]A_t,B_t;
output CIN_t;
begin
#4;
A_t = $random % 4; //Above statement will generate
Random values from -3 to +3.
B_t = $random % 4;
CIN_t =$random;
end
endtask
TESTBENCHUSING $RANDOM
task display;
input [N-1:0] A_td,B_td,SUM_td;
input CIN_td,COUT_td;
$strobe("Time =%0t \t INPUT VALUES A=%b B=%b C_IN =
%b \t OUTPUT VALUES SUM =%b C_OUT =%b",
$time,A_td,B_td,CIN_td,SUM_td,COUT_td);
endtask
always@(SUM,A,C_OUT)
$display(A,B,SUM,C_IN,C_OUT);
endmodule
DATAFLOW MODELING
In complex designs the number of gates is
very large
Currently, automated tools are used to
create a gate-level circuit from a
dataflow design description. This
process is called logic synthesis
CONTINUOUS ASSIGNMENT
RULES:
The left hand side of an assignment must
always be a scalar or vector net
It cannot be a scalar or vector register.
Continuous assignments are always active.
The assignment expression is evaluated as
soon as one of the right-hand-side
operands changes and the value is
assigned to the left-hand-side net.
Rules
The operands on the right-hand side can
be registers or nets.
Delay values can be specified for
assignments in terms of time units.
Delay values are used to control the
time when a net is assigned the
evaluated value
B
C
wire S, C, A, B;
A
B
Half
Half
Adder
Adder
S
C
assign S = A ^ B;
assign C = A & B;
endmodule
in2
Half
Half
Adder
Adder11
ha1
ha1
I1
C I2
A
B
Half
Half
Adder
Adder
ha2
ha2
S
C
sum
I3
cin
module full_adder(sum, cout, in1, in2, cin);
output sum, cout;
input in1, in2, cin;
Module
name
Instance
name
cout
OPERATOR TYPES
CONDITIONAL OPERATOR
D-LATCH / FLIP-FLOP
module latch (G, D, Q);
input G, D;
output Q;
reg Q;
always @(G or D)
begin
if (G)
Q <= D;
end
endmodule
JK FLIP-FLOP
module jkff(J, K, clk, Q);
input J, K, clk;
output Q;
reg Q;
always @(posedge clk)
if(J == 1 && K == 0)
Q <= 1;
else if(J == 0 && K == 1)
Q <= 0;
else if(J == 1 && K == 1)
Q <= ~Q;
endmodule
Sequence counter
module CntSeq(clk, reset,
state);
parameter n = 4;
input clk, reset;
output [n-1:0]state;
reg [n-1:0]state;
//
always @(posedge clk)
if(reset)
state = 0;
else begin
case (state)
4'b0000:state = 4'b0001;
4'b0001:state = 4'b0010;
4'b0010:state = 4'b0100;
4'b0100:state = 4'b1001;
4'b1001:state = 4'b1010;
4'b1010:state = 4'b0101;
4'b0101:state = 4'b0110;
4'b0110:state = 4'b1000;
4'b1000:state = 4'b0111;
default:state = 4'b0000;
endcase
end
endmodule
//0 -> 1
//1 -> 2
//2 -> 4
//4 -> 9
//9 -> 10
//10-> 5
//5 -> 6
//6 -> 8
//8 -> 7
8 TO 1 MULTIPLEXER : SIMULATION
WAVEFORM
LAYOUT VS SCHEMATIC
THANK YOU.