This should be the simplest issue to sort out but for some reason I just can't figure it out. I'm currently teaching myself Verilog and as an exercise have been developing very basic modules and test benches for these modules. One of these modules is the D Flip Flop (DFF). Here is the DFF module (no reset):
module DFF( clk, D, Q );
parameter n = 1; // DFF width
input clk;
input [n-1:0] D;
output [n-1:0] Q;
reg [n-1:0] Q;
always @( posedge clk ) begin
Q <= D;
end
endmodule
And here is the test bench:
module DFF_tb;
reg clk, D;
reg Q;
DFF #(1) DUT ( clk, D, Q );
initial begin
clk = 1'b0;
forever #10 clk = ~clk; // Generate clock
end
initial begin
D = 0; // Check D = 0
if ( Q !== 0 ) $display( "[FAIL] Q = 0" );
#40 D = 1; // Check D = 1
#40
if ( Q !== 1 ) $display( "[FAIL] Q = 1" );
$finish; // Complete test
end
endmodule
And here is the simulation:
The test bench reg Q stays x for the duration of the simulation (thought Q[0] doesn't...).
Any idea why? Thanks!