2012年10月13日 星期六

Verilog HDL: Test Bench

源自http://asic-soc.blogspot.tw/2012/06/verilog-hdl-test-bench.html

Verilog HDL: Test Bench

Test Bench
Using Verilog we can write a test bench to apply stimulus to the design and verify the results of the design. Up-front verification becomes very important as design size increases in size and complexity. This ensures simulation results matches with post synthesis results. A test bench can have two parts, the one generates input signals for the model to be tested while the other part checks the output signals from the design under test.
assign à assign values to registers, wires ; synthesizable and hence used in designs.
force , release: assign and deassign values to wire, reg within procedural block; used in verification


reg x;
initial
begin
x=1’b0; //generate clock with 20 unit of duty cycle.
#20x=1’b1;
#20x=1’b0;
end
initial
#50 $stop; //stop the simulation at time unit 50
//same method is used to generate any inputs

//test bench for full adder
reg ta,tb,tc; //inputs should be held for 20 units; hence declare it as ‘reg’
wire tsum,tcr; //outputs are driven by input. hence ‘wire’
//instantiate the design under test
fulladder fa(.sum(tsum), .cr(tcr), .a(ta), .b(tb), .c(tc));
initial
begin
#0 ta=1’b0; tb=1’b0; tc=1’b0;
#10 ta=1’b0; tb=1’b0; tc=1’b1;
#20 ta=1’b0; tb=1’b1; tc=1’b0;
#30 ta=1’b0; tb=1’b1; tc=1’b1;
#40 ta=1’b1; tb=1’b0; tc=1’b0;
#50 ta=1’b1; tb=1’b0; tc=1’b1;
#60 ta=1’b1; tb=1’b1; tc=1’b0;
#70 ta=1’b1; tb=1’b1; tc=1’b1;
end
initial $monitor (“$time ta=%b tb=%b tc = %b tsum=%b tcr=%b”, ta,tb,tc,tsum, tcr);
//print the value to console whenener there is a change in the values.

沒有留言:

張貼留言

零成本學 ESP32!在 Wokwi 打造你的第一個微型氣象站 (ESP32 + DHT22 + 1602 LCD)

零成本學 ESP32!在 Wokwi 打造你的第一個微型氣象站(溫度 濕度) (ESP32 + DHT22 + 1602 LCD) 想學物聯網(IoT)與 ESP32 電子實作,卻擔心接線與電壓規範搞砸嗎?透過強大的線上模擬器 Wokwi ,我們不需要花費任何硬體費用,打開瀏覽器...