常用建模方式
- 门级建模:门电路描述
- 数据流建模:assign语句
- 行为级建模:always结构
示例
构建一个2线输入,4线输出电路;真值表如下:
{A1,A0} | Y |
---|---|
0 0 | 0001 |
0 1 | 0010 |
1 0 | 0100 |
1 1 | 1000 |
门级建模
module _2to4decodeer(
input A1,
input A0,
output[3:0] Y);
wire A0_n,A1_n;//节点信号
not n1(A1_n, A1);
not n2(A0_n, A0);
and n3(Y[0],A1_n,A0_n);
and n4(Y[1],A1_n,A0);
and n5(Y[2],A1,A0_n);
and n6(Y[3],A1,A0);
endmodule
为A0、A1添加适当的输入信号,观察输出结果:
数据流建模
module _2to4decodeer(
input A1,
input A0,
output[3:0] Y);
assign Y[0] = ~A1&~A0;
assign Y[1] = ~A1&A0;
assign Y[2] = A1&~A0;
assign Y[3] = A1&A0;
endmodule
行为级建模
module _2to4decodeer(A1, A0, Y);
input A1;
input A0;
output[3:0] Y;
reg [3:0] Y;
always @(A0 or A1)
begin
Y = {A1&A0,A1&~A0,~A1&A0,~A1&~A0};
end
endmodule
为A0、A1添加适当的输入信号,观察输出结果: