Professional Documents
Culture Documents
TECHNOLOGY, TAXILA
Lab Report 14
Digital Logic Design Lab
Name: Alina Gulzar
Section: Omega
LAB Tasks:
1. Write Verilog Code for D and T Flip Flop using behavioral modeling along with Test Bench
and simulate it on Icarus Verilog
2. Write Verilog Code for Counter using behavioral modeling along with Test Bench and
simulate it on Icarus Verilog
Design Methodology:
• First of all, we have to create a folder so that all the related files are in the same folder.
• Open Notepad, and write the Verilog code, save that notepad file in [module_name.v]
extension. The name of file and name of module must be same. As Verilog HDL is the case
sensitive Language so, a smallest mistake will cause an error.
• Again open notepad and write a test bench for the code file and save this file as syntax:
[module_nametb.v].
• Now, copy both files and open Local Disk: C → iverilog → bin → Paste the files.
• Click on the address bar.
output reg Q;
output Qbar;
input D, Clk, Reset;
assign Qbar = ~Q;
Test Bench:
`timescale 1ns / 1ps
module DFF1tb;
reg D, Clk, Reset;
wire Q, Qbar;
initial begin
D = 1'b0;
Clk = 1'b0;
Reset = 1'b1;
#100;
Reset = 1'b0;
#20;
forever #40 D = ~ D;
end
always #10 Clk = ~Clk;
initial
begin
$dumpfile ("DFF1tb.vcd");
$dumpvars (0, DFF1tb);
end
endmodule
Simulation:
• T - Flipflop
Verilog Code:
module TFF( Q, Qbar, T, Clk, Reset);
output reg Q;
output Qbar;
input T, Clk, Reset;
begin
if (!Reset )
Q <=0;
else
if (T)
Q <= ~Q;
else
Q <= Q;
end
endmodule
Test Bench:
`timescale 1ns / 1ps
module TFFtb;
initial begin
T = 1'b0;
Clk = 1'b0;
Reset = 1'b1;
#100;
Reset = 1'b0;
#20;
forever #40 T = ~ T;
end
initial
begin
$dumpfile ("TFFtb.vcd");
$dumpvars (0, TFFtb);
end
endmodule
Simulation:
• Counter
Verilog Code:
module udcounter(input clk, reset,up_down, output[3:0] counter );
reg [3:0] counter_up_down;
always @(posedge clk or posedge reset)
begin
if(reset)
counter_up_down <= 4'h0;
else if(~up_down)
counter_up_down <= counter_up_down + 4'd1;
else
counter_up_down <= counter_up_down - 4'd1;
end
assign counter = counter_up_down;
endmodule
Test Bench:
module udcountertb();
reg clk, reset,up_down;
wire [3:0] counter;
initial
begin
$dumpfile ("udcountertb.vcd");
$dumpvars (0, udcountertb);
end
endmodule
Simulation:
Results:
We have verified the truth table of D and T Flipflop and Counter. Their outputs are correct.
Conclusion:
The behavioral modeling describes how the circuit should behave. Due to these factors,
structural or data-flow models are regarded as having a lower abstraction level than behavioural
models. The actual implementation of the circuit is determined by the VHDL synthesiser tool.
Results are more accurate by using behavioral modeling. Instead of theories, it concentrates on
how a system behaves.