2016-06-29 6 views
0

다음 코드는 7 세그먼트 59 초 카운터인데 테스트 벤치를 구현하려고합니다. 저는 두 가지 문제가 있습니다 : 하나는 인턴 클럭으로 용어 q [24]를 사용하여 대략적인 초를 계산하지만, 테스트 벤치에서는 수천 개의 posedge 클럭을 구현하지 않고도 다른 출력을 볼 수 있어야합니다. 다른 문제는 testbench의 출력으로 7 세그먼트 패널의 각 숫자 인 레지스터 [3 : 0] unidad 및 [3 : 0] decena를보고 싶지만 사용되지 않는 코드입니다. 안으로 또는 출력으로, 그러나 인턴 변수로.클럭 분배기 및 다른 출력을 사용하여 Verilog에서 testbench 구현

합리적인 시간에 decena/unidad 출력을 보여주는 시뮬레이션을 어떻게 구현할 수 있습니까? 감사.

module cont(
    input clock, 
    input reset, 
    output reg [6:0]segm, 
    output [3:0]an 
    ); 

reg [3:0]unidad; 
reg [3:0]decena; 

reg [24:0] q; 

always @(posedge clock or posedge reset) 
    begin 
     if(reset == 1) 
     q <= 0; 
     else 
      q <= q + 1; 
    end 

always @ (posedge q[24] or posedge reset) 
begin 
    if (reset) begin 
    unidad <= 0; 
    decena <= 0; 
    end 
    else if (unidad==4'd9) 
    begin 
    unidad <= 0; 
    if (decena==4'd5) 
     decena <= 0; 
     else 
     decena <= decena + 1; 
    end 
    else 
    unidad <= unidad + 1; 
    end 

reg [6:0]sseg; 
reg [3:0]an_temp; 
always @ (*) 
begin 
    case(q[13]) 

    1'b0 : 
    begin 
    sseg = unidad; 
    an_temp = 4'b1110; 
    end 

    1'b1 : 
    begin 
    sseg = decena; 
    an_temp = 4'b1101; 
    end 

    endcase 
end 
assign an = an_temp; 

always @ (*) 
begin 
    case(sseg) 
    4'd0 : segm = 7'b1000000; //0 
    4'd1 : segm = 7'b1111001; //1 
    4'd2 : segm = 7'b0100100; //2 
    4'd3 : segm = 7'b0110000; //3 
    4'd4 : segm = 7'b0011001; //4 
    4'd5 : segm = 7'b0010010; //5 
    4'd6 : segm = 7'b0000010; //6 
    4'd7 : segm = 7'b1111000; //7 
    4'd8 : segm = 7'b0000000; //8 
    4'd9 : segm = 7'b0010000; //9 
    default : segm = 7'b1111111; 
    endcase 
end 

endmodule 

답변

0

카운터를 테스트 벤치에서 원하는 값에 더 가깝게 설정할 수 있습니다. 두 가지 스타일로 할 수 있습니다.

1) 카운터를 원하는 값에 가까운 값으로 설정하고 몇 가지 클록주기를 생성하십시오.

2) 관심있는 비트를 강제 실행하고 몇 가지 클럭 사이클을 기다리십시오.

'h1000 및'h1000000 값은 관심사 또는 비트 24 및 13입니다.

// function to set the register - replace <DUT> 
task load_counter (reg [24:0] val); 
#1 <DUT>.q = val ; //delay is to overwrite the main counter 
endtask 

또는 13 비트는 클럭의 각 24 비트 토글 및 번호 사이에 볼 필요가 전환의 또한 숫자를 랜덤 수

load_counter(25'hff0);// load and wait for bit 13 to be set 
repeat(50) @(posedge clock) ; 
load_counter(25'h1ff0); // load and wait for bit 13 to be re-set. 
repeat(50) @(posedge clock) ; 
load_counter(25'hf0ff0); //load and wait for bit 13 set (while other bits > 13 are on) 
repeat(50) @(posedge clock) ; 
load_counter(25'hfffff0); // bit 24 set 
repeat(50) @(posedge clock) ; 
// if needed add set/reset for bit 13 code here 
load_counter(25'h1fffff0); // load and wait till bit 24 rolls over 
repeat(50) @(posedge clock) ; 
// repeat the whole process above in a loop to get desired behavior 

첫 번째 방법에서

// function to set the counter bit - replace <DUT> 
task count_up (int count,int loc , bit val); 
repeat(count) @(posedge clock) ; 
#1 <DUT>.q[loc] = val; //delay is to overwrite the main counter 
endtask 

// toggle bit 24 and in between toggle bit 13 based on counts. 
// 100 clock is just a value it can be changes. 
task count_24(int count_24,int count_13); 
repeat (count_24) 
     begin 
     repeat(count_13) 
     begin 
       count_up (100,13,1); 
       count_up (100,13,0); 
     end 
     count_up (1,24,1); 
     repeat(count_13) 
     begin 
       count_up (100,13,1); 
       count_up (100,13,0); 
     end 
     count_up (1,24,0); 
end 
endtask 

그 카운터 변경 사이에 실행해야합니다. 반응식 2

(13) 및 (24)의 카운트는 시험 라이터에 의해 결정될 수도 있고 또한 랜덤 수에

.

count_24(10,10) 

옵션 1에서는 카운터 메커니즘이 대부분의 작업을 수행하므로 선호됩니다.

하지만 결국은 전체 카운터를 실행하여 결과를 확인하는 것이 좋습니다. 아마 당신은 주말 회귀로 그것을 실행할 수 있습니다.

또한 TB의 신호를 직접 볼 수 있습니다.

wire [3:0] observe_unidad = <DUT>.unidad; 
wire [3:0] observe_decena = <DUT>.decena; 

죄송합니다

// this code will not synthesize 
module tb_cont ; 


reg clock_gen ; // To generate a clock 
reg reset_gen ; // to generate reset 

// Main counter instance 
cont cont_instance (
       .clock(clock_gen), 
       .reset (reset_gen) 
       ) ; 

// Clock generation block 
initial 
begin 
clock_gen = 0 ; 

forever 
begin 
     #10 clock_gen = 0 ; 
     #10 clock_gen = 1 ; 
end 
end 

// Task to write data in the cont- block 
task count_up (int count,int loc , bit val); 
repeat(count) @(posedge clock_gen) ; 
#1 cont_instance.q[loc] = val; //delay is to overwrite themain counter 
endtask 

/toggle bit 24 and in between toggle bit 13 based on counts. 
// 100 clock is just a value it can be changed. 
task count_24(int count_24,int count_13); 
repeat (count_24) 
     begin 
     repeat(count_13) 
     begin 
       count_up (100,13,1); 
       count_up (100,13,0); 
     end 
     count_up (1,24,1); 
     repeat(count_13) 
     begin 
       count_up (100,13,1); 
       count_up (100,13,0); 
     end 
     count_up (1,24,0); 
end 
endtask 

// task to load the counter 
task load_counter (reg [24:0] val); 
#1 cont_instance.q = val ; //delay is to overwrite themain counter 
endtask 


initial 
begin 
// dump waveform to observe signals 
$dumpvars; 

// generate a reset first 
reset_gen = 0 ; 
#100 reset_gen = 0 ; 
#100 reset_gen = 1 ; 
#100 ; 
@(posedge clock_gen) ; 
reset_gen = 0 ; 
end 

// value for the count 
int count13 = 100; 
int count24=100; 

// generate test vector 
initial 
begin 

repeat(100) @ (posedge clock_gen) ; // wait for counter 
load_counter(25'hff0); 
repeat(100) @ (posedge clock_gen) ; // wait for counter 
load_counter(25'hfffff0); 
repeat(100) @ (posedge clock_gen) ; // wait for counter 
load_counter(25'h1fffff0); 
repeat(100) @ (posedge clock_gen) ; // wait for counter 

// scheme 2 
count_24(10,10); 

$finish ; 
end 

// both the signal can eb observed 
wire [3:0] observe_unidad = cont_instance.unidad; 
wire [3:0] observe_decena = cont_instance.decena; 

endmodule 
+0

... 여기 결핵에 대한 전체 코드를 추가,하지만 난 방법이 구현하는 아무 생각이 없습니다. 을 어떻게 대체해야합니까? 이것은 내가 전에 보지 못했던 표기법입니다. 그게 도움이된다면 Verilog 언어로 자일링스 ISE webpack을 사용하고 있습니다. 또한 정의 된 여러 변수로 count_up 작업을 읽지 않으며 코드 내에 정의 된 변수 unidad로 .unidad를 인식하지 못합니다. –

+0

죄송합니다. RTL 코드가 있기 때문에 몇 가지 가정을했습니다. 나는 당신이 시뮬레이션에서 테스트 벤치를 원한다고 가정하고 테스트 벤치가 또한 합성 가능하기를 원하지 않는다. 또한 테스트 벤치는 cont 블록 주위에 래퍼로 ​​빌드됩니다.나는 당신의 DUT (테스트중인 디자인) 이름을 알 수 없었기 때문에 거기에 자리 표시자를 넣었습니다. 그것은 cont_instance.unidad (cont_instance가 테스트 벤치에서 cont의 인스턴스라고 가정) –

+0

테스트 벤치 구조/코드를 제공 할 수 있다면 위의 코드를 개선 할 수 있습니다. –