簡單的Verilog測試模板結構

這裏記錄一下曾經用到的簡單的測試模板,以下所示:dom

//timescale
`timescale    1ns/1ns 
module  tb_module();
//the Internal motivation variable(register) and output wire 



//the  External motivation storage variable


//Sub module signal,example: wire [1:0] xxx == xxx_inst.xxx_inst.xxx;

// Global variable initialization ,such as 'clk'、'rst_n'
initial begin
    #0 rst_n = 0;
       clk = 0;
    #25 rst_n = 1 ;
end 

//Internal motivation variable initialization
//initial begin   
//end 

//cloclk signal generation
always #10 clk = ~clk ;

//Cases of sub module xxxx xxxx_inst(.(),.(), ... ,.());

// Internal motivation variable assignment  using task or random
/*  example                                                
task data_assign(xx);                               | task    rand_bit();        
    integer    xx,xx,...;                           |     integer i;
    begin                                           |     begin
        for( ; ; )begin                             |         for(i=0; i<255; i=i+1)begin
        @(posedge clock)                            |             @(posedge sclk);                  
        Internal motivation variable <= xxxxx;      |             Internal motivation variable <={$random} %2;
        end                                         |          end    
    end                                             |        end    
endtask                                             |     endtask                             
*/            

     
endmodule                                            

整個測試模塊(結構)很簡單,並無結果捕捉模塊,所以若是有錯的話,並不會打印出來,須要在波形中查看,僅限於簡單模塊使用。測試

另一個簡單的verilog測試模板結構以下所示:spa

module tb_module;
//drive the input port with reg type 

//sample the output with the wire type 


//task1 create the instance  







//task2 clock and reset generator
parameter CLK_PERIOD =   ;
reg clk ,rst_n;
initial begin
    clk = 0;
    forever begin
        #(CLK_PERIOD/2) clk = ~clk ;
    end 
end 

initial begin
    rst_n = 0;
    #
    rst_n = 1;
end 

//task3 drive the stimulus and capture the response 
//testcase 



//task4 check the result 


//task5 dump waveform with the compile option -debug_all,for the VCS
initial begin 
    $vcdpluson;
end 


endmodule 

 

這些結構都沒有給出具體的內容。有空補上一個簡單的例子。debug

相關文章
相關標籤/搜索