2013-03-20 2 views
0

누구나 다음 코드에 대한 verilog 테스트 벤치 코드를 작성하는 데 도움을 줄 수 있습니까? 시도했지만 작동하지 않습니다!Verilog 테스트 벤치 코드

module top(clock_in, Reset, Hold, up_down, Led_Out, f);  
    input clock_in, Reset, Hold, up_down; 
    output  [6:0] Led_Out;   
    output wire [3:0] f; 

    wire pulse; 

    clock_design temp0(clock_in, pulse); 
    up_down_counter temp1(pulse, Reset, Hold, up_down, f); 
    led7 temp2(Led_Out, f); 
endmodule 

LED7 :

module led7(iOut, iQ); 
    output reg [6:0] iOut; 
    input  [3:0] iQ; 

    always @(iQ) 
    case (iQ) 
     4'b0000: iOut = 7'b0000001; //0 
     4'b0001: iOut = 7'b1001111; //1 
     4'b0010: iOut = 7'b0010010; //2 
     4'b0011: iOut = 7'b0000110; //3 
     4'b0100: iOut = 7'b1001100; //4 
     4'b0101: iOut = 7'b0100100; //5 
     4'b0110: iOut = 7'b0100000; //6 
     4'b0111: iOut = 7'b0001111; //7 
     4'b1000: iOut = 7'b0000000; //8 
     4'b1001: iOut = 7'b0000100; //9 
     default: iOut = 7'b0000000; //default 
    endcase 
    endmodule 

up_down_counter :

module up_down_counter (Clock,Reset,Hold,up_down,Q); 
    input Clock,Reset,Hold,up_down; 
    output reg [3:0] Q; 
    integer direction; 


    always @(posedge Clock) 
    begin 
     if(up_down) 
     direction = 1; 
     else 
     direction = -1; 

    if (!Reset && direction == 1) 
     Q <= 0; 
     else if(!Reset && direction == -1) 
     Q <= 1001; 
     else if (!Hold)   
     Q <= Q + direction; 

     if (direction==1 && Q[0]==1 && Q[1]==0 &&Q[1]==0 && Q[3]==1) 
     Q <= 0; 
     else if (direction==-1 && Q[0]==0 && Q[1]==0 &&Q[2]==0 && Q[3]==0) 
     Q <= 1001; 
     end 
    endmodule 

clock_design :

module clock_design (clock_in,clock_out); 
    input clock_in; 
    output clock_out; 
    parameter which_clock=1; 
    reg [31:0] divided_clocks=0; 

    always @(posedge clock_in) 
    divided_clocks = divided_clocks +1; 

    assign clock_out = divided_clocks[which_clock]; 
endmodule 

내 테스트 벤치 코드

module counter_tb; 
    reg [6:0] Led_Out_tb; 
    wire [3:0] f_tb; 
    reg clock_in_tb, Reset_tb, Hold_tb, up_down_tb; 

    top dut(clock_in_tb, Reset_tb,Hold_tb, up_down_tb, Led_Out_tb, f_tb); 

    initial begin 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 1; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 1;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    #10 clock_in_tb = 0;Hold_tb = 0;Reset_tb = 1; up_down_tb = 0; 
    end 
endmodule 
+3

"작동하지 않음"은 문제에 대한 유용한 설명이 아닙니다. – toolic

+0

'divided_clocks'에 대해 비 차단 할당을 사용합니다. – toolic

답변

6

테스트 벤치 현명한 나는 시계를 설정하고 다음과 같이 다시 것입니다 : 코드

당신에 대해

//The actual test 
initial begin 
    Hold_tb = 0; 
    up_down_tb = 1; 
    repeat (50) begin 
    @(posedge clk); 
    end 
    up_down_tb = 1; 
    repeat (50) begin 
    @(posedge clk); 
    end 
    $finish(); 
end 

:

reg clk ; //Rising edge every 10 timesteps initial begin clk = 0; #5; forever begin #5 clk = ~clk; end end // TB Reset_tb reg Reset_tb initial begin Reset_tb = 0; @(posedge clk); @(posedge clk); Reset_tb = 1; end 

과 같은 실제 시험 뭔가

always @(posedge clk) 블록에서 결합 논리가되어야하는 것처럼 보이는 섹션을 가지고 있습니다.
always @(posedge Clock) 
begin 
    if(up_down) 
    direction = 1; 
    else 
    direction = -1; 

나는이 있어야한다고 생각 : 문은 다음 라인에 적용 할 경우

always @* begin 
    if(up_down)begin 
    direction = 1; 
    end 
    else begin 
    direction = -1; 
    end 
end 

것은 당신이 begin end을 포함하지 않는 경우. 시작 부분을 훨씬 더 자주 사용하므로 코드에 명시 적으로 의도가 표시됩니다.

당신은 다음 코드 섹션이있다 :

if (!Reset && direction == 1) 
    Q <= 0; 
    else if(!Reset && direction == -1) 
    Q <= 1001; 
    else if (!Hold)   
    Q <= Q + direction; 

    if (direction==1 && Q[0]==1 && Q[1]==0 &&Q[1]==0 && Q[3]==1) 
    Q <= 0; 
    else if (direction==-1 && Q[0]==0 && Q[1]==0 &&Q[2]==0 && Q[3]==0) 
    Q <= 1001; 

인가 거기 경우 4 일에 다른 실종? if (direction==1 && Q[0]==1 && Q[1]==0 &&Q[1]==0 && Q[3]==1)

RTL에서 정수 유형을 사용하지 않으려합니다. 특히 지나치게 많이 사용하는 경우가 있습니다. 특히 여기에 1 또는 -1을 저장하면 실제로는 1 비트 값만 필요합니다. 사무 처리 규정 및 전선에 서명 할 수 있습니다

reg signed signed_reg ; 
reg signed [7:0] signed_reg8; 

또한 일정하게 선언 할 수 있습니다 서명과 같이

reg_signed = 1'sd-1 ; //1Bit Signed Decimal value -1 

내가 나쁜 관행 혼합 된 경우 신호 이름을 사용하는 발견, 난 항상 소문자를 사용합니다. 매개 변수 및 localparams와 같은 상수는 모두 대문자입니다. 이것은 오타를 조금 덜 일으키고, 운동을 시도하는 데 많은 시간을 소비 할 수 있습니다. 왜 무언가가 작동하지 않는 경우 연결 중 하나가 대문자의 첫 문자 대신 소문자를 사용하고 있다는 것을 깨닫게됩니다.