Professional Documents
Culture Documents
Purpose
• HDL’s were originally used to model and
simulate hardware before building it
Verilog HDL • In the past 20 years, synthesis tools were
developed that can essentially build the
hardware from the same description
Mark Redekopp
3 4
Software Hardware
Perform x+y and when that is This description models 2 gates
x module m1(x,y,z,f,g);
done assign d-c to tmp working at the same time
f
// circuit
var = x+y; f = a & b; y Module // description
g
tmp = d-c; g = a | b; z[2:0] endmodule
Event Driven Paradigm:
If a or b changes, f and g Software analogy: Modules are like functions, but also like classes in
will be re-evaluated that they are objects that you can instantiate multiple times.
5 6
7 8
Co module incrementer(a,z); • Supported Gates: and, or, not, nand, nor, xor, xnor
Structural input [3:0] a;
Half specification of output [3:0] z;
Adder a half adder module m1(c16,c8,c4,f);
wire [3:1] c; input c16,c8,c4;
S
ha ha0(a[0],1,z[0],c[1]); output f;
ha ha1(a[1],c[1],z[1],c[2]); wire n1;
ha ha2(a[2],c[2],z[2],c[3]); or i1(n1,c8,c4);
ha ha3(a[3],c[3],z[3], ); nand i2(f,c16,n1);
endmodule “i2” endmodule
“n1” instance name
net (wire)
Use HA’s to structurally describe incrementer Verilog Description
11 12
15 16
19 20
• If multiple statements as the body of if…else if…else then • Default statement is optional
enclose in begin…end construct • If multiple statements as the body of an option then enclose
in begin…end construct
23 24
27 28
31 32
testbench for the inputs and input x,y,z; as a component (just like you input x,y,z;
output f,g;
outputs of the design under output f,g; instantiate a gate in you design) ...
test ... • Pass the input and output endmodule
– inputs to your design should Unit Under Test
signals to the ports of the Unit Under Test
be declared type ‘reg’ in the design
module my_tb;
testbench (since you are module my_tb; • For designs with more than 4 or
driving them and their value reg x,y,z;
reg x,y,z;
5 ports, use named mapping wire f,g;
should be retained until you
change them) wire f,g; rather than positional mapping m1 uut(x,y,z,f,g);
/* m1 uut(.x(x), .y(y),
– outputs from your design endmodule .z(z), .f(f),
.g(g));
should be declared type ‘wire’ */
since your design is driving Testbench endmodule
them Testbench
35 36
39 40
variables
integer i; You can’t do assignments to {a,b} integer i;
“i++” as in
initial C/C++ or Java • Answer: 0 time…in fact if initial
• Verilog supports ‘for’ begin
you look at a waveform, begin
for(i=0;i<4;i=i+1) for(i=0;i<4;i=i+1)
loops to repeatedly begin {a,b} will just be equal to begin
a,b = 00,
execute a statement {a,b} = i; then 01, 1,1…you’ll never see any {a,b} = i;
end then 10, #10;
• Format: then 11 other combinations
end end
– for(initial_condition; endmodule • We must explicitly insert end
end_condition; increment Here, ‘i’ acts as a counter for a loop. time delays! endmodule
43