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 微控制器 採集的環境數據,經由 MQTT 協定 轉換並寫入工業標準的 Modbus 暫存器 中

  一個典型的 IoT(物聯網)與工業自動化系統整合(SCADA/機台連線) 的架構圖。它透過 Node-RED 作為核心資料網關,將前端 ESP32 微控制器 採集的環境數據,經由 MQTT 協定 轉換並寫入工業標準的 Modbus 暫存器 中。 1. 各模組功能拆解...