In: Computer Science
Simulate a D-Flip Flop on Xilinx using Verilog HDL | Behavioral Modelling
PS: please include the simulation screenshot and output and the code
Find below the verilog code of D-flip Flop in behavioral style along with test bench and simulation results.
Code:
`timescale 1ns / 1ps
module D_FlipFlop_Bhev(D,Clk,Clear,Q,Q_bar);
input D,Clk,Clear;
output reg Q,Q_bar;
always @(posedge Clk)
begin
if(Clear == 1)
begin
Q<=0;
Q_bar<=1;
end
else
begin
Q<=D;
Q_bar<=!D;
end
end
endmodule
TestBench :
`timescale 1ns / 1ps
module D_FlipFlop_TestBench;
// Inputs
reg D;
reg Clk;
reg Clear;
// Outputs
wire Q;
wire Q_bar;
// Instantiate the Unit Under Test
(UUT)
D_FlipFlop_Bhev uut (
.D(D),
.Clk(Clk),
.Clear(Clear),
.Q(Q),
.Q_bar(Q_bar)
);
initial begin
Clk=0;
forever #20 Clk= ~Clk;
end
initial begin
$monitor("simtime = %g, CLK = %b, D = %b,reset = %b, Q
= %b, Q_bar = %b", $time, Clk, D, Clear, Q, Q_bar);
// Initialize Inputs
D = 0;
Clear = 1;
#100;
D = 0;
Clear = 0;
#100;
D = 1;
Clear = 0;
end
endmodule
Simulation Screenshot:
Output Screenshot: