카운터를 테스트 벤치에서 원하는 값에 더 가깝게 설정할 수 있습니다. 두 가지 스타일로 할 수 있습니다.
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
... 여기 결핵에 대한 전체 코드를 추가,하지만 난 방법이 구현하는 아무 생각이 없습니다.을 어떻게 대체해야합니까? 이것은 내가 전에 보지 못했던 표기법입니다. 그게 도움이된다면 Verilog 언어로 자일링스 ISE webpack을 사용하고 있습니다. 또한 정의 된 여러 변수로 count_up 작업을 읽지 않으며 코드 내에 정의 된 변수 unidad로 .unidad를 인식하지 못합니다. –
죄송합니다. RTL 코드가 있기 때문에 몇 가지 가정을했습니다. 나는 당신이 시뮬레이션에서 테스트 벤치를 원한다고 가정하고 테스트 벤치가 또한 합성 가능하기를 원하지 않는다. 또한 테스트 벤치는 cont 블록 주위에 래퍼로 빌드됩니다.나는 당신의 DUT (테스트중인 디자인) 이름을 알 수 없었기 때문에 거기에 자리 표시자를 넣었습니다. 그것은 cont_instance.unidad (cont_instance가 테스트 벤치에서 cont의 인스턴스라고 가정) –
테스트 벤치 구조/코드를 제공 할 수 있다면 위의 코드를 개선 할 수 있습니다. –