2020年2月6日 星期四

數位IC設計入門-Verilog combinational logic 3 to 8 Decoder 解碼器 Behavioral Modeling (& Test Bench)

數位IC設計入門-Verilog combinational logic 
3 to 8 Decoder  解碼器 Behavioral Modeling (& Test Bench)



//數位IC設計入門-Verilog combinational logic 
//3 to 8 Decoder  解碼器 Behavioral Modeling (& Test Bench)



 module DECODER3X8(enable, in, out);
  input enable;
  input [2:0] in;
  output [7:0] out;
  reg [7:0] out;

  always@(in or enable)
  begin
        if(enable)
        begin
              case(in)
              3'b000 : out = 8'b00000001;
              3'b001 : out = 8'b00000010;
              3'b010 : out = 8'b00000100;
              3'b011 : out = 8'b00001000;
              3'b100 : out = 8'b00010000;
              3'b101 : out = 8'b00100000;
              3'b110 : out = 8'b01000000;
              3'b111 : out = 8'b10000000;
              endcase
        end

        else
        begin
              out = 8'b00000000;
        end
  end
 endmodule

// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps    
module Test_bench;
  //module DECODER3X8(enable, in, out);
  //input enable;
  //input [2:0] in;
  //output [7:0] out;

// Inputs
reg [2:0]in=0 ;
reg enable=0;

// Outputs
wire [7:0] out;


// Instantiate the Unit Under Test (UUT)
//DECODER3X8(enable, in, out);

DECODER3X8 UUT(enable, in, out);

initial begin
 $monitor(enable, in, out);
    // Initialize Inputs
 #25 in[2:0]=3'b000 ; enable=1 ;
 #25 in[2:0]=3'b001 ; enable=1 ;
 #25 in[2:0]=3'b010 ; enable=1 ;
 #25 in[2:0]=3'b011 ; enable=1 ;
 #25 in[2:0]=3'b100 ; enable=1 ;
 #25 in[2:0]=3'b101 ; enable=1 ;
 #25 in[2:0]=3'b110 ; enable=1 ;
 #25 in[2:0]=3'b111 ; enable=1 ;
 #25 in[2:0]=3'b101 ; enable=0 ;
 #25 in[2:0]=3'b111 ; enable=0 ;
  
end

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


endmodule


 

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...