2020年2月5日 星期三

數位IC設計入門-Verilog combinational logic 全加器 Behavioral Modeling (Test Bench)

數位IC設計入門-Verilog combinational logic 全加器 Behavioral Modeling (Test Bench)


  module FA (a, b, c, sum, cy);
  input a, b, c;
  output sum, cy;
  reg sum, cy;

  always@(a or b or c)
  begin
        {cy, sum} = a + b + c;
  end

  endmodule

// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps    
module Test_bench;
  //module FA (a, b, c, sum, cy);
  //input a, b, c;
  //output sum, cy;

// Inputs
reg a=0,b=0,c=0;

// Outputs
wire sum,cy;

// Instantiate the Unit Under Test (UUT)
//module FA (a, b, c, sum, cy);

FA UUT(a, b,c, sum, cy);

initial begin
 $monitor(a, b,c, sum, cy);
    // Initialize Inputs
 #25 a=0;b=0;c=1;    //001
 #25 a=0;b=1;c=0;    //010
 #25 a=0;b=1;c=1;    //011
 #25 a=1;b=0;c=0;    //100
 #25 a=1;b=0;c=1;   //101
 #25 a=1;b=1;c=0;   //110
 #25 a=1;b=1;c=1;   //111

end

initial
begin
  #200;   // 模擬終止時間  200 ns
  $stop;
end


endmodule

   

沒有留言:

張貼留言

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

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