π© 1. 4x1 Multiplexer (MUX)
Function: Selects one input from 4 inputs and passes it to the output based on 2 selection lines.
Inputs:
-
Data Inputs:
I0, I1, I2, I3
-
Select Lines:
S0, S1
Output:
-
Y
Truth Table:
S1 | S0 | Output Y |
---|---|---|
0 | 0 | I0 |
0 | 1 | I1 |
1 | 0 | I2 |
1 | 1 | I3 |
π§ 2. 1x4 Demultiplexer (DEMUX)
Function: Takes 1 input and routes it to one of 4 outputs, based on select lines.
Inputs:
-
Data Input:
D
-
Select Lines:
S0, S1
Outputs:
-
Y0, Y1, Y2, Y3
Truth Table:
S1 | S0 | Y0 | Y1 | Y2 | Y3 |
---|---|---|---|---|---|
0 | 0 | D | 0 | 0 | 0 |
0 | 1 | 0 | D | 0 | 0 |
1 | 0 | 0 | 0 | D | 0 |
1 | 1 | 0 | 0 | 0 | D |
π¨ 3. 4-to-2 Priority Encoder
Function: Encodes the highest-priority active input (from I3 to I0) into binary.
Inputs: I0, I1, I2, I3
(I3 has the highest priority)
Outputs: A1, A0
(Binary code of highest-priority input), V
(Valid output)
Truth Table:
I3 | I2 | I1 | I0 | A1 | A0 | V |
---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | X | X | 0 |
0 | 0 | 0 | 1 | 0 | 0 | 1 |
0 | 0 | 1 | X | 0 | 1 | 1 |
0 | 1 | X | X | 1 | 0 | 1 |
1 | X | X | X | 1 | 1 | 1 |
X = Don't care
π¦ 4-to-16 Decoder (or 2-to-4 Decoder)
Function: Converts binary input into a single high output among many.
Letβs keep it to a 2-to-4 Decoder (to match the 2-bit output from the priority encoder or 4:1 MUX):
Inputs: A1, A0
Outputs: Y0, Y1, Y2, Y3
Truth Table:
A1 | A0 | Y0 | Y1 | Y2 | Y3 |
---|---|---|---|---|---|
0 | 0 | 1 | 0 | 0 | 0 |
0 | 1 | 0 | 1 | 0 | 0 |
1 | 0 | 0 | 0 | 1 | 0 |
1 | 1 | 0 | 0 | 0 | 1 |
π© 1. 4x1 Multiplexer (MUX)
πΈ Logic Expression:
πΈ Circuit Diagram (Conceptual):
I0 ββββ
β
I1 ββββΌββ> Logic AND with select lines
β
I2 ββββΌββ> OR gate ββ> Output Y
β
I3 ββββ
β
Select lines:
S1 βββ
ββ> Control logic
S0 βββ
π§ 2. 1x4 Demultiplexer (DEMUX)
πΈ Logic Expressions:
-
Y0 = D Β·
-
Y1 = D Β·
-
Y2 = D Β·
-
Y3 = D Β·
πΈ Circuit Diagram (Conceptual):
D
β
βββββΌββββ
β ANDs β
ββββ¬ββ¬ββ¬β
β β β
S0 S1 (Select lines)
β β
Y0 <βββ€ βββββ S1=0, S0=0
Y1 <βββ€ββββββ S1=0, S0=1
Y2 <βββ€ββββββ S1=1, S0=0
Y3 <βββββββββ S1=1, S0=1
π¨ 3. 4-to-2 Priority Encoder
πΈ Output Logic:
-
V = I0 + I1 + I2 + I3
-
A1 = I2 + I3
-
A0 = (I1 Β· Β¬I2 Β· Β¬I3) + I3
πΈ Circuit Diagram:
Inputs: I3 (highest priority) ... I0
β
Priority logic
β
ββββββββ
β ENCODER β
ββββββββ
β β
A1 A0 (binary output)
π¦ 4-to-1 Decoder (2-to-4 Decoder)
πΈ Logic Expressions:
-
Y0 =
-
Y1 =
-
Y2 =
-
Y3 =
πΈ Circuit Diagram:
A1 βββ
β
A0 βββ
β
ββββββββ
βDecoderβ
ββββββββ
β β β β
Y0 Y1 Y2 Y3
VERILOG CODE :
Perfect! Here's the Verilog code for each of the four components:
π© 1. 4x1 Multiplexer (MUX)
module mux4x1 (
input wire [3:0] I, // Inputs I0 to I3
input wire [1:0] S, // Select lines S1, S0
output wire Y // Output
);
assign Y = (S == 2'b00) ? I[0] :
(S == 2'b01) ? I[1] :
(S == 2'b10) ? I[2] :
I[3];
endmodule
π§ 2. 1x4 Demultiplexer (DEMUX)
module demux1x4 (
input wire D, // Single input
input wire [1:0] S, // Select lines S1, S0
output wire [3:0] Y // Outputs Y0 to Y3
);
assign Y[0] = (S == 2'b00) ? D : 1'b0;
assign Y[1] = (S == 2'b01) ? D : 1'b0;
assign Y[2] = (S == 2'b10) ? D : 1'b0;
assign Y[3] = (S == 2'b11) ? D : 1'b0;
endmodule
π¨ 3. 4-to-2 Priority Encoder
module priority_encoder_4to2 (
input wire [3:0] I, // I3 (highest) to I0
output reg [1:0] Y, // Encoded output
output reg V // Valid output
);
always @(*) begin
V = 1'b1;
casez (I)
4'b1???: Y = 2'b11; // I3
4'b01??: Y = 2'b10; // I2
4'b001?: Y = 2'b01; // I1
4'b0001: Y = 2'b00; // I0
default: begin
Y = 2'b00;
V = 1'b0; // No input is high
end
endcase
end
endmodule
π¦ 4-to-1 Decoder (2-to-4 Decoder)
module decoder2to4 (
input wire [1:0] A, // Inputs A1, A0
output wire [3:0] Y // Outputs Y0 to Y3
);
assign Y[0] = (~A[1]) & (~A[0]);
assign Y[1] = (~A[1]) & A[0];
assign Y[2] = A[1] & (~A[0]);
assign Y[3] = A[1] & A[0];
endmodule