flop-flop simulation in ModelSim

OP #5424929
Rate this post
useful
not useful
testbench tdff.v
1
module top; 
2
   reg clk; 
3
   reg [1:0] in_inf; 
4
   wire [1:0] out_inf;
5
dff D1 (clk, in_inf, out_inf); 
6

7
initial // Clock generator
8
  begin
9
    clk = 0;
10
    forever #10 clk = !clk;
11
  end
12

13
initial //in_inf[0]  
14
  begin
15
    in_inf[0] = 0;
16
    #28 in_inf[0] = 1;
17
    #5 in_inf[0] = 0;
18
  end
19
initial  //in_inf[1]  
20
  begin
21
    in_inf[1] = 0;
22
    #48 in_inf[1] = 1;
23
    #5 in_inf[1] = 0;
24
  end
25
endmodule

whats the difference between in_inf[0] and in_inf[1]
Guest #5426340
Rate this post
useful
not useful
Probably the signal is not initialised. The signal is assigned a value 
on the rising edge of the clock. So before the first rising edge, there 
is no assignment, so the signal value is unknown.
But I'd expect U instead of X.
OP #5426527
Rate this post
useful
not useful
new dff.v
1
module dff(clk, din, dout); 
2
  input clk; 
3
  input [1:0] din; 
4
  output [1:0] dout; 
5
reg [1:0] dout; 
6
 always @ (posedge clk) 
7
  begin 
8
   dout <= din; 
9
end 
10
endmodule

new tdff.v
1
module top; 
2
   reg clk; 
3
   reg [1:0] in_inf; 
4
   wire [1:0] out_inf;
5
dff D1 (clk, in_inf, out_inf); 
6
initial 
7
  begin
8
  in_inf[0] = 0;
9
  in_inf[1] = 0;
10
  clk = 0;
11
#28 in_inf[0] = 1;
12
#5 clk = 1;
13
#10 in_inf[0] = 0;
14
#5 clk = 0;
15
end
16
endmodule
Attached files:
OP #5426638
Rate this post
useful
not useful
i try to initialize value in dff.v
1
module dff(clk, dout); 
2
  input clk; 
3
  output reg [1:0] dout; 
4

5
reg [1:0] din;
6
initial
7
  begin
8
    din[0] = 1'b0;
9
    din[1] = 1'b0;
10
  end 
11

12
always @ (posedge clk) 
13
  begin 
14
   dout <= din; 
15
  end 
16
endmodule

testbench doesnt work

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now