Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

input - Can anyone help me to create a Verilog testbench?

Can anyone help me create a testbench or just the input code for my following code? I'm using XILINX.

module fsmb (input rst,clk,a,
             output reg x);

parameter sta = 2'b00, stb = 2'b01, stc = 2'b10,
          std = 2'b11;

reg[1:0] st, nst;

always @(posedge clk)
begin 
    if (rst)
        st <= 2'b00;
    else
        st <= nst;
end

always @*
begin
    st = nst; x =0'b0;
    case (st)
        sta: if(a) nst = stb;
             else nst = sta;
        stb: if(a) nst = stc;
             else nst = stb; 
        stc: begin 
             if(a) nst = stc;
             else nst = std; 
             x =1'b1;
             end
        std: begin
             if(a) nst = stc;
             else nst = sta;
             x = 1'b1;
             end
        default: nst = sta;
    endcase 
end
endmodule
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Testbench 101

  1. Create a new module (tb).
  2. Create a reg for each input of your DUT.
  3. Create a wire for each output of your DUT.
  4. Create an instance of your DUT.
  5. Connect your regs and wires to your DUT.
  6. Generate a clock
  7. Drive your other inputs
  8. Create checkers for your outputs (I'll leave this up to you).

Example:

module tb;

reg rst,clk,a;
wire x;

initial begin
    clk = 0;
    forever #5 clk = ~clk;
end

initial begin
    rst = 1;
    a = 0;
    #50 rst = 0;
    #50 $finish;
end

fsmb fsmb (
    .clk    (clk),
    .rst    (rst),
    .a      (a),
    .x      (x)
);

endmodule

Other simple testbench examples are provided on EDA playgound. You can sign up for a free account and look at samples such as: Published Playgounds -> D flip flop


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...