2020年2月6日 星期四

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

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


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

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

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

  endmodule
  

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

// Inputs
reg [7:0]in=0 ;

// Outputs
wire [2:0]out ;
wire valid;

// Instantiate the Unit Under Test (UUT)
//module ENCODER(in, out, valid);

ENCODER UUT (in, out, valid);

initial begin
 $monitor(in, out, valid);
    // Initialize Inputs
 #25 in=8'b1000_0000 ;
 #25 in=8'b0100_0000 ;
 #25 in=8'b0010_0000 ;
 #25 in=8'b0001_0000 ;
 #25 in=8'b0000_1000 ;
 #25 in=8'b0000_0100 ;
 #25 in=8'b0000_0010 ;
 #25 in=8'b0000_0001 ;

 #25 in=8'b0000_0000 ;
 #25 in=8'b0000_1100 ;
 #25 in=8'b0100_1000 ; 

end

initial
begin
  #300;   // 模擬終止時間  300 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...