您可以強制計數器接近您的測試平臺中感興趣的值。 你可以通過兩種風格。
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
或
// 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
在第一種方法
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
你也可以隨機數量的13位切換,你需要每個時鐘的24個被觸發和數量之間看到
那需要在櫃檯變化之間運行。
在方案2中
的13和24的計數值可通過測試寫入器來確定,或者也可以被隨機化。
count_24(10,10)
在選項1中,我們讓計數器機制完成大部分任務,因此是首選。
但最後它還更好地運行整個櫃檯看結果。大概你可以把它作爲週末迴歸來運行。
你也可以直接觀察TB中的信號。
wire [3:0] observe_unidad = <DUT>.unidad;
wire [3:0] observe_decena = <DUT>.decena;
添加完整的代碼在這裏一TB ...
// 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語言的Xilinx ISE webpack。此外,它不會讀取該任務的count_up,其中定義了多個變量,也不會將 .unidad識別爲代碼中定義的變量unidad以顯示它。 –
對不起,因爲只有RTL代碼我做了一些假設。我假設你只想在測試臺上進行仿真,而不希望測試臺也是可以合成的。此外,測試臺將作爲您的連續塊的包裝。我無法知道你的DUT(被測設計)名稱,所以我在那裏放置了一個位置。它可以cont_instance.unidad(假設cont_instance是您的測試平臺中的cont的實例) –
如果您可以提供您的測試平臺結構/代碼我可以改進上面的代碼 –