EmbDev.net

Forum: FPGA, VHDL & Verilog flop-flop simulation in ModelSim


von Dima P. (demsp)


Attached files:

Rate this post
0 useful
not useful
i try to simulate [1:0]flip-flop in ModelSim and i see one normal 
signal(out_inf[0]) and one blue signal(out_inf[1]). What is it?

von Lothar M. (lkmiller) (Moderator)


Rate this post
0 useful
not useful
Dima P. wrote:
> What is it?
Depends somewhat on your code...

But by default blue means high-Z.

von Dima P. (demsp)


Rate this post
0 useful
not useful
testbench tdff.v
module top; 
   reg clk; 
   reg [1:0] in_inf; 
   wire [1:0] out_inf;
dff D1 (clk, in_inf, out_inf); 

initial // Clock generator
  begin
    clk = 0;
    forever #10 clk = !clk;
  end

initial //in_inf[0]  
  begin
    in_inf[0] = 0;
    #28 in_inf[0] = 1;
    #5 in_inf[0] = 0;
  end
initial  //in_inf[1]  
  begin
    in_inf[1] = 0;
    #48 in_inf[1] = 1;
    #5 in_inf[1] = 0;
  end
endmodule 

whats the difference between in_inf[0] and in_inf[1]

von Lothar M. (lkmiller) (Moderator)


Rate this post
0 useful
not useful
Dima P. wrote:
> whats the difference between in_inf[0] and in_inf[1]
Thats remains the question.
What you posted is the test bench. That obvoiusly works properly...

von Dima P. (demsp)


Rate this post
0 useful
not useful
thanks, but why out_inf[1] is hi-z? how do i see normal(not blue) signal 
as out_inf[1]?

: Edited by User
von Lothar M. (lkmiller) (Moderator)


Rate this post
0 useful
not useful
Dima P. wrote:
> thanks, but why out_inf[1] is hi-z?
Thats in the up to now secret code of the flipflop itself. What you 
posted generates the clk and the in_inf signals. And they are fine.

von Dima P. (demsp)


Rate this post
0 useful
not useful
thanks, the bug in the "secret code" indeed ))

von Dima P. (demsp)


Rate this post
0 useful
not useful
And whats mean red signal 1'hx out_inf[0]?

von Dussel (Guest)


Rate this post
0 useful
not useful
Dima P. wrote:
> And whats mean red signal 1'hx out_inf[0]?
Behind the h is the value of the signal, in this case X. If you look up 
the definition of std_(u)logic you see, that this means 'unknown'. (Like 
Z means 'High Impedance')

von Dima P. (demsp)


Rate this post
0 useful
not useful
But the signal must be zero (not unknown)

: Edited by User
von Dussel (Guest)


Rate this post
0 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.

von Lothar M. (lkmiller) (Moderator)


Rate this post
0 useful
not useful
Dima P. wrote:
> But the signal must be zero (not unknown)
'U' does NOT mean "Unknown"! 'U' is "Uninitialized".

Why don't you show your code for better guessing?

von Dima P. (demsp)


Attached files:

Rate this post
0 useful
not useful
new dff.v
module dff(clk, din, dout); 
  input clk; 
  input [1:0] din; 
  output [1:0] dout; 
reg [1:0] dout; 
 always @ (posedge clk) 
  begin 
   dout <= din; 
end 
endmodule 

new tdff.v
module top; 
   reg clk; 
   reg [1:0] in_inf; 
   wire [1:0] out_inf;
dff D1 (clk, in_inf, out_inf); 
initial 
  begin
  in_inf[0] = 0;
  in_inf[1] = 0;
  clk = 0;
#28 in_inf[0] = 1;
#5 clk = 1;
#10 in_inf[0] = 0;
#5 clk = 0;
end
endmodule 

: Edited by User
von Lothar M. (lkmiller) (Moderator)


Rate this post
0 useful
not useful
That looks OK, what's the problem with it?

von Dima P. (demsp)


Rate this post
0 useful
not useful
the signal is red (before first clock). Why?

: Edited by User
von Dussel (Guest)


Rate this post
0 useful
not useful
Dima P. wrote:
> the signal is red (before first clock). Why?
I explained before.
Which value do you expect and why?

von Dima P. (demsp)


Rate this post
0 useful
not useful
can i initialize value before first clock?

: Edited by User
von Dima P. (demsp)


Rate this post
0 useful
not useful
i try to initialize value in dff.v
module dff(clk, dout); 
  input clk; 
  output reg [1:0] dout; 

reg [1:0] din;
initial
  begin
    din[0] = 1'b0;
    din[1] = 1'b0;
  end 

always @ (posedge clk) 
  begin 
   dout <= din; 
  end 
endmodule 

testbench doesnt work

: Edited by User
von Lothar M. (lkmiller) (Moderator)


Rate this post
0 useful
not useful
Dima P. wrote:
> testbench doesnt work
What message?

> i try to initialize value in dff.v
As you can easily see: dout is making trouble to you. And therefore you 
must initialize dout. That are your flipflops!

: Edited by Moderator
von Dima P. (demsp)


Rate this post
0 useful
not useful
ok, thank you

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.