verilog測試模塊


測試平台

格式

module module_tb
    //變量的聲明
    //產生相應的激勵信號
    //實例化被測試的模塊
    //監視輸入輸出信號
    //保存被監視信號的信息
endmodule

tb指testbench

模塊實例化

/*------- module --------*/
`timescale 1ns/1ns

module gate_construct
	(
		input i_a,
		input i_b,
		input i_c,
		input i_d,
		input i_e,

		output o_y
	);

	//定義門電路之間的連線信號
	wire w_and_o;
	wire w_or1_o;
	wire w_xor_o;


	//實例化門電路模塊
	and I_and(w_and_o, i_a, i_b);
	or I1_or(w_or1_o, i_c, i_d);
	xor I_xor(w_xor_o, w_and_o, w_or1_o );
	or I2_or(o_y, w_xor_o, i_e);

endmodule


/*------------  testbench   ---------*/
`timescale 1ns / 1ns

module gate_construct_simulation();
	reg r_a;
	reg r_b;
	reg r_c;
	reg r_d;
	reg r_e;

	reg[4:0] r_cnt;

	//定義輸出信號連線
	wire w_v;
	
	//實例化
	gate_construct I_gate_construct_tb
		(
			.i_a(r_a),
			.i_b(r_b),
			.i_c(r_c),
			.i_d(r_d),
			.i_e(r_e)
		);
	
	initial
	begin
		r_cnt = 5'd0;
		forever
			#2 r_cnt = r_cnt + 5'd1;
	end

	always@(r_cnt)
	begin
		r_a = r_cnt[0];
		r_b = r_cnt[1];
		r_c = r_cnt[2];
		r_d = r_cnt[3];
		r_e = r_cnt[4];
	end
endmodule

產生激勵信號

  1. 重復的信號,如時鍾信號

    initial
    begin
    	a = 0;
    #10 a = 1;
    end
    
  2. 一次特定的序列

    initial
    begin
        a = 0;
        forever
    		#10 a = ~a;
    end
            
    /*------*/
    initial 
        b = 0;
    
    always
        #4 b = ~b;
    


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM