实现3-8译码器①
描述
下表是74HC138译码器的功能表.
E3 | E2_n | E1_n | A2 | A1 | A0 | Y0_n | Y1_n | Y2_n | Y3_n | Y4_n | Y5_n | Y6_n | Y7_n |
x | 1 | x | x | x | x | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
x | x | 1 | x | x | x | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
0 | x | x | x | x | x | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 |
1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 |
1 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 |
1 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 |
1 | 0 | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 |
1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 |
①请用基础门电路实现该译码器电路,用Verilog将电路描述出来。基础门电路包括:非门、多输入与门、多输入或门。
输入描述:
input E1_n ,
input E2_n ,
input E3 ,
input A0 ,
input A1 ,
input A2
输出描述:
output wire Y0_n ,
output wire Y1_n ,
output wire Y2_n ,
output wire Y3_n ,
output wire Y4_n ,
output wire Y5_n ,
output wire Y6_n ,
output wire Y7_n
解题思路:
由功能表可以看出,当且仅当E3 = 1、E2_n = 0、E1_n=0时,3-8译码器正常工作;
由于要求使用门电路实现,因此给出输出信号Y0_n~Y1_7的逻辑函数式:
代码如下所示:
使用行为级建模
`timescale 1ns/1nsmodule decoder_38(input E1_n ,input E2_n ,input E3 ,input A0 ,input A1 ,input A2 ,output wire Y0_n , output wire Y1_n , output wire Y2_n , output wire Y3_n , output wire Y4_n , output wire Y5_n , output wire Y6_n , output wire Y7_n
);reg [7:0] Y_t;
always @(*) beginY_t = 8'b1111_1111;if (E3 == 1'b1 && E2_n == 1'b0 && E1_n == 1'b0) beginY_t[0] = A2 | A1 | A0;Y_t[1] = A2 | A1 | ~A0;Y_t[2] = A2 | ~A1 | A0;Y_t[3] = A2 | ~A1 | ~A0;Y_t[4] = ~A2 | A1 | A0;Y_t[5] = ~A2 | A1 | ~A0;Y_t[6] = ~A2 | ~A1 | A0;Y_t[7] = ~A2 | ~A1 | ~A0;endelse beginY_t = 8'b1111_1111;end
endassign Y0_n = Y_t[0];
assign Y1_n = Y_t[1];
assign Y2_n = Y_t[2];
assign Y3_n = Y_t[3];
assign Y4_n = Y_t[4];
assign Y5_n = Y_t[5];
assign Y6_n = Y_t[6];
assign Y7_n = Y_t[7];endmodule
在使用门级建模时,出现以下问题:
代码如下:
`timescale 1ns/1nsmodule decoder_38(input E1_n ,input E2_n ,input E3 ,input A0 ,input A1 ,input A2 ,output wire Y0_n , output wire Y1_n , output wire Y2_n , output wire Y3_n , output wire Y4_n , output wire Y5_n , output wire Y6_n , output wire Y7_n
);//代码二wire work;and a1 (work, ~E1_n, ~E2_n, E3_n);or o0(Y0_n, A0, A1, A2, ~work);
or o1(Y1_n, ~A0, A1, A2, ~work);
or o2(Y2_n, A0, ~A1, A2, ~work);
or o3(Y3_n, ~A0, ~A1, A2, ~work);
or o4(Y4_n, A0, A1, ~A2, ~work);
or o5(Y5_n, ~A0, A1, ~A2, ~work);
or o6(Y6_n, A0, ~A1, ~A2, ~work);
or o7(Y7_n, ~A0, ~A1, ~A2, ~work);endmodule
但是其结果如下:
问题出现在哪里??