2020年2月27日 星期四

Verilog 多工器( Multiplexier )

Verilog 多工器( Multiplexier )

程式( 2 to 1 多工器 ):
module Mux2_1( In1, In2, Sel, Out );

    input   In1, In2, Sel;
    output  Out;

    wire    In1, In2, Sel;
    reg     Out;

    always @( In1, In2, Sel ) begin
        if( !Sel )
            Out <= In1;
        else
            Out <= In2;
    end

endmodule
//==================================
module mux_2x1( In1, In2, Sel, Out );

    input   In1, In2, Sel;
    output  Out;

    wire    In1, In2, Sel;
    reg     Out;

    always @( In1, In2, Sel ) begin
        if( !Sel )
            Out <= In1;
        else
            Out <= In2;
    end

endmodule

//==================================
// 時間單位 100ns, 時間精確度10 ps
`timescale 100ns/10ps
module Test_bench;
//    input   In1, In2, Sel;
//    output  Out;

    
wire Out; 
reg  In1=1'b0;
reg  In2=1'b0;
reg  Sel=1'b0;


mux_2x1 DUT ( .In1(In1), .In2(In2), .Sel(Sel), .Out(Out)  );

// initial程序結構區塊, 產生A、B輸入信號波形
initial begin

$monitor(In1, In2, Sel, Out );
 
 #100;    // 100ns
 In1=1'b0 ; In2=1'b0;Sel=1'b1 ; // “001”
 
 #100;    // 200ns
 In1=1'b0 ; In2=1'b1; Sel=1'b0 ; // “010”

 #100;    // 300ns
 In1=1'b0 ; In2=1'b1; Sel=1'b1 ; // “011"
 
 #100;    // 400ns
 In1=1'b1; In2=1'b0; Sel=1'b0 ; // “100"
 
 #100;    // 500ns
 In1=1'b1 ; In2=1'b0; Sel=1'b1 ; // “101"
 
 #100;    // 600ns
 In1=1'b1 ; In2=1'b1; Sel=1'b0 ; // “110"
 
 #100;    // 700ns
 In1=1'b1 ; In2=1'b1; Sel=1'b1; // “111"
 
 
 end

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

endmodule

Tools -> RTL Viewer





Tools -> Netlist Viewer ->Technology Map Viewer


沒有留言:

張貼留言

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

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