Professional Documents
Culture Documents
Verilog Lab
Verilog Lab
• Describe hardware
– Functionality/behavior
– Delays and concurrency
• Why to model?
– Simulation and verification
• Before chip design: Functional & Timing
• After chip design: fault injection and diagnostic
– Synthesis
HDL - options
• Sum = A XOR B
• Carry = A AND B
Verilog example – structural model
Module Name
endmodule;
Verilog example – dataflow model
input A, B;
output Sum, Carry;
assign Sum = A ^ B;
A Sum
// Sum = A XOR B;
Half
assign Carry = A & B; Adder
// Carry = A AND B B Carry
endmodule;
Verilog Testbench Example
HA_TB
module HA_TB;
reg ra, rb;
wire wsum, wcarry; ra A Sum wsum
half_adder ha_inst(.A(ra), .B(rb), .Sum(wsum), .Carry(wcarry));
Half Adder
initial
begin rb B Carry wcarry
ra = 1’b0; rb = 1’b0;
#10
$display(“A: %b, B: %b, Sum: %b, Carry: %b”, ra, rb, wsum, wcarry)
ra = 1’b1; rb = 1’b0;
#10
Stimulus
$display(“A: %b, B: %b, Sum: %b, Carry: %b”, ra, rb, wsum, wcarry)
ra = 1’b0; rb = 1’b1;
#10
$display(“A: %b, B: %b, Sum: %b, Carry: %b”, ra, rb, wsum, wcarry)
ra = 1’b1; rb = 1’b1 ;
#10
$display(“A: %b, B: %b, Sum: %b, Carry: %b”, ra, rb, wsum, wcarry)
end
endmodule
How to compile/run/simulate
• Commercial tools
– Mentor’s Modelsim/Questa
– Cadence Incisive
– Synopsys – VCS
– Xilinx Vivado
• Free
– icarcus (both Verilog and VHDL)
– GHDL (only for VHDL)
• Online platform
– edaplayground
Viewing waveforms
• For example: F = AB + AC + BC
Delay = Max delay stage 1 + Max delay stage 2
T1
Assume all inputs change at same time
Delay
T2
Input
T3
T
Tp = 4a1 + 16a2 + a3
Critical Path
A n1
B n2
C
Y
D
Short Path
Delays in Verilog
• Structure modeling
– and #5 a1(out, i1, i2); //fixed delay
– and #(4, 6) a1(out, i1, i2); // (rise time, fall time)
– and #(4, 6, 8) a1(out, i1, i2); // (rise time, fall
time, switch off time)
– No delay means zero delay
• Dataflow modeling
– assign #10 out = in1 & in2;
– wire #10 out;