Verilog 4bits 4x1 MUX (Data flow level)
module MUX_4x1_4bit(A,B,C,D,s0,s1,Y) ;
input [3:0]A,B,C,D;
input s0,s1 ;
output [3:0]Y;
wire [3:0]w1,w2,w3,w4;
assign w1[0]=A[0] & (~s1) & (~s0);
assign w1[1]=A[1] & (~s1) & (~s0);
assign w1[2]=A[2] & (~s1) & (~s0);
assign w1[3]=A[3] & (~s1) & (~s0);
assign w2[0]=B[0] & (~s1) & (s0);
assign w2[1]=B[1] & (~s1) & (s0);
assign w2[2]=B[2] & (~s1) & (s0);
assign w2[3]=B[3] & (~s1) & (s0);
assign w3[0]=C[0] & (s1) & (~s0);
assign w3[1]=C[1] & (s1) & (~s0);
assign w3[2]=C[2] & (s1) & (~s0);
assign w3[3]=C[3] & (s1) & (~s0);
assign w4[0]=D[0] & (s1) & (s0);
assign w4[1]=D[1] & (s1) & (s0);
assign w4[2]=D[2] & (s1) & (s0);
assign w4[3]=D[3] & (s1) & (s0);
assign Y= w1 | w2 | w3 | w4;
endmodule
/*
module mux_4to1_assign ( input [3:0] a, // 4-bit input called a
input [3:0] b, // 4-bit input called b
input [3:0] c, // 4-bit input called c
input [3:0] d, // 4-bit input called d
input [1:0] sel, // input sel used to select between a,b,c,d
output [3:0] out); // 4-bit output based on input sel
// When sel[1] is 0, (sel[0]? b:a) is selected and when sel[1] is 1, (sel[0] ? d:c) is taken
// When sel[0] is 0, a is sent to output, else b and when sel[0] is 0, c is sent to output, else d
assign out = sel[1] ? (sel[0] ? d : c) : (sel[0] ? b : a);
endmodule
*/
`timescale 10ns/10ps
module Test_bench;
reg [3:0] A = 4'b0101;
reg [3:0] B = 4'b0101;
reg [3:0] C = 4'b0101;
reg [3:0] D = 4'b0101;
reg s0 = 1'b0;
reg s1 = 1'b0;
wire [3:0] Y;
//mux_4x1(S0,S1,A,B,C,D,Y);
MUX_4x1_4bit UUT (
.s0(s0),
.s1(s1),
.A(A),
.B(B),
.C(C),
.D(D),
.Y(Y));
initial
begin
#800; // Final time: 1000 ns
$stop;
end
initial
begin
// ------------- Current Time: 100ns
#100;
s1=1'b0; s0=1'b0; A = 4'b1010;B = 4'b0101; C = 4'b0101;D = 4'b0101;
// -------------------------------------
// ------------- Current Time: 200ns
#100;
s1=1'b0; s0=1'b1; A = 4'b0101;B = 4'b0101; C = 4'b0101;D = 4'b0101;
// -------------------------------------
// ------------- Current Time: 300ns
#100;
s1=1'b0; s0=1'b1; A = 4'b0101;B = 4'b1010; C = 4'b0101;D = 4'b0101;
// -------------------------------------
// ------------- Current Time: 400ns
#100;
s1=1'b1; s0=1'b0; A = 4'b0101;B = 4'b0101; C = 4'b0101;D = 4'b0101;
// -------------------------------------
// ------------- Current Time: 500ns
#100;
s1=1'b1; s0=1'b0; A = 4'b0101;B = 4'b0101; C = 4'b1010;D = 4'b0101;
// -------------------------------------
// ------------- Current Time: 600ns
#100;
s1=1'b1; s0=1'b1; A = 4'b0101;B = 4'b0101; C = 4'b0101;D = 4'b0101;
// -------------------------------------
// ------------- Current Time: 700ns
#100;
s1=1'b1; s0=1'b1; A = 4'b0101;B = 4'b0101; C = 4'b0101;D = 4'b1010;
// -------------------------------------
// ------------- Current Time: 1000ns
end
endmodule
訂閱:
張貼留言 (Atom)
113 學年度第 1 學期 RFID應用課程 Arduino程式
113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...
-
python pip 不是内部或外部命令 -- 解決方法 要安裝 Pyqt5 1. 首先,開啟命令提示字元。 2. 輸入 pip3 install pyqt5 好像不能執行 ! ! 錯誤顯示 : ‘ pip3 ’ 不是內部或外部命令、可執行的程式或批...
-
課程講義 下載 11/20 1) PPT 下載 + 程式下載 http://www.mediafire.com/file/cru4py7e8pptfda/106%E5%8B%A4%E7%9B%8A2-1.rar 11/27 2) PPT 下載...
-
• 認 識 PreFix、InFix、PostFix PreFix(前序式):* + 1 2 + 3 4 InFix(中序式): (1+2)*(3+4) PostFix(後序式):1 2 + 3 4 + * 後 序式的運算 例如: 運算時由 後序式的...
沒有留言:
張貼留言