题目:使用8线-3线优先编码器Ⅰ实现16线-4线优先编码器_牛客题霸_牛客网
思路:4-16对于3-8逻辑是:3-8有一块有输入,4-16就有输入(GS为逻辑或),3-8两块都没输入,4-16才没输入(EO为逻辑与),Y的选择按照优先编码器的规则,先判断高位,再判断低位。
解法一
`timescale 1ns/1ns
module encoder_83(
input [7:0] I ,
input EI ,
output wire [2:0] Y ,
output wire GS ,
output wire EO
);
assign Y[2] = EI & (I[7] | I[6] | I[5] | I[4]);
assign Y[1] = EI & (I[7] | I[6] | ~I[5]&~I[4]&I[3] | ~I[5]&~I[4]&I[2]);
assign Y[0] = EI & (I[7] | ~I[6]&I[5] | ~I[6]&~I[4]&I[3] | ~I[6]&~I[4]&~I[2]&I[1]);
assign EO = EI&~I[7]&~I[6]&~I[5]&~I[4]&~I[3]&~I[2]&~I[1]&~I[0];
assign GS = EI&(I[7] | I[6] | I[5] | I[4] | I[3] | I[2] | I[1] | I[0]);
//assign GS = EI&(| I);
endmodule
module encoder_164(
input [15:0] A ,
input EI ,
output wire [3:0] L ,
output wire GS ,
output wire EO
);
wire [2 : 0] Y0;
wire [2 : 0] Y1;
wire GS0;
wire GS1;
wire EO0;
wire EO1;
encoder_83 en0(
.I(A[7 : 0]),
.EI(EI),
.Y(Y0),
.GS(GS0),
.EO(EO0)
);
encoder_83 en1(
.I(A[15 : 8]),
.EI(EI),
.Y(Y1),
.GS(GS1),
.EO(EO1)
);
assign L = GS1 ? {1'b1, Y1} : GS0 ? {1'b0, Y0} : 4'b0000;
assign GS = GS1 | GS0;
assign EO = EO0 & EO1;
endmodule
先画出简单的16-4真值表,整理一下需要的输入输出;思路为使用两片8-3,而第一片输出的时候,第二片不工作,所以可以使用第一片的EO作为第二片的EI;再画出使用两片8-3总体的输入输出,和之前画的16-4对比,即得结果
解法二:此题的一楼讲解的很详细,而且画有电路图
`timescale 1ns/1ns
module encoder_83(
input [7:0] I ,
input EI ,
output wire [2:0] Y ,
output wire GS ,
output wire EO
);
assign Y[2] = EI & (I[7] | I[6] | I[5] | I[4]);
assign Y[1] = EI & (I[7] | I[6] | ~I[5]&~I[4]&I[3] | ~I[5]&~I[4]&I[2]);
assign Y[0] = EI & (I[7] | ~I[6]&I[5] | ~I[6]&~I[4]&I[3] | ~I[6]&~I[4]&~I[2]&I[1]);
assign EO = EI&~I[7]&~I[6]&~I[5]&~I[4]&~I[3]&~I[2]&~I[1]&~I[0];
assign GS = EI&(I[7] | I[6] | I[5] | I[4] | I[3] | I[2] | I[1] | I[0]);
//assign GS = EI&(| I);
endmodule
module encoder_164(
input [15:0] A ,
input EI ,
output wire [3:0] L ,
output wire GS ,
output wire EO
);
wire EO1 ;
wire [2:0] Y0 ;
wire [2:0] Y1 ;
wire GS0 ;
encoder_83 U0(
.I (A[7:0]),
.EI (EO1 ),
.Y (Y0 ),
.GS (GS0 ),
.EO (EO )
);
encoder_83 U1(
.I (A[15:8]),
.EI (EI ),
.Y (Y1 ),
.GS (GS1 ),
.EO (EO1 )
);
assign L[3] = GS1;
assign L[2] = Y1[2] | Y0[2];
assign L[1] = Y1[1] | Y0[1];
assign L[0] = Y1[0] | Y0[0];
assign GS = GS1 | GS0;
endmodule