2020年4月22日 星期三

4-bit 2 to 1 multiplexer in Verilog

4-bit 2 to 1 multiplexer in Verilog



//--------------------------------
//4-bit 2 to 1 multiplexer
//--------------------------------
module Mux2x1_4bit( s, a, b, y);

input s;           //Select signal
input [3:0] a, b;  //Input data

output reg [3:0] y;


always @ (s or a or b)
 if (s)
   y = b;
 else
   y = a;

endmodule


// 時間單位 1ns, 時間精確度10 ps
`timescale 10ns/10ps 
module TB;
/*
module Mux2x1_4bit( s, a, b, y);
input s;           //Select signal
input [3:0] a, b;  //Input data
output reg [3:0] y;
*/
// Inputs
    reg s;
    reg [3:0] a;
    reg [3:0] b;

// Outputs
    wire [3:0] y;

// Instantiate the UUT
Mux2x1_4bit UUT (
        .y(y), 
        .s(s), 
        .a(a), 
        .b(b)
        );

// Initialize Inputs

integer i;
initial begin
    b = 4'b1010; s=1'b0;
    for (i=0; i<16; i=i+1) begin
          a = i;
         #35;
    end
    a = 4'b0101; s=1'b1;
    for (i=0; i<16; i=i+1) begin
          b = i;
         #35;
    end
        
    
    #25
     $stop;
end
endmodule



沒有留言:

張貼留言

MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構

MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 這張圖片展示了一個 結合 MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 (主要透過 Node-RED 進行資料整合)。 系統包含三個核心部分,其運作功能說明如下: 1. ESP32 終端設備(硬體控制層...