1组合逻辑电路--基本门电路

1.1基本门电路

1.1.1结构化描述方式

代码如下

View Code
 1 module logics
2 (
3 input iA,
4 input iB,
5 output oAnd,
6 output oOr,
7 output oNot
8 );
9
10 and and_inst(oAnd,iA,iB);
11 or or_inst(oOr,iA,iB);
12 not not_inst(oNot,iA);
13
14 endmodule

最底层的是门级原语and or not

RTL级视图

testbench如下

View Code
 1 `timescale 1 ns/ 1 ns
2 module logics_tb();
3
4 reg ia;
5 reg ib;
6
7 wire oAnd;
8 wire oOr;
9 wire oNot;
10
11 initial
12 begin
13 ia=0;
14 #40 ia=1;
15 #40 ia=0;
16 #40 ia=1;
17 #40 ia=0;
18 end
19
20 initial
21 begin
22 ib=0;
23 #40 ib=0;
24 #40 ib=1;
25 #40 ib=1;
26 #40 ib=0;
27 end
28
29 logics logics_inst
30 (
31 .iA(ia),
32 .iB(ib),
33 .oAnd(oAnd),
34 .oOr(oOr),
35 .oNot(oNot)
36 );
37
38 endmodule

RTL级仿真图形如下

GATE级仿真图如下

可见RTL级仿真是理想的,GATE级仿真考虑了延迟和信号开始的不确定。

1.1.2采用流描述方法

代码如下

View Code
 1 module logics
2 (
3 input iA,
4 input iB,
5 output oAnd,
6 output oOr,
7 output oNot
8 );
9
10 assign oAnd=iA&iB;
11 assign oOr=iA|iB;
12 assign oNot=~iA;
13
14 endmodule

RTL级视图,仿真图形同上。

1.1.3 采用行为描述方式

代码如下

View Code
 1 module logics
2 (
3 input iA,
4 input iB,
5 output reg oAnd,
6 output reg oOr,
7 output reg oNot
8 );
9
10 always @(*)
11 begin
12 oAnd=iA&iB;
13 oOr=iA|iB;
14 oNot=~iA;
15 end
16
17 endmodule

always@()括号内的敏感信号填*,则综合器自动加上敏感信号。

由于always语句中左边信号都要是寄存器型,故输出信号定义为寄存器型。描述组合逻辑时,always中使用阻塞赋值方式。

RTL级视图及仿真图形同上。

posted on 2011-07-31 22:02  万好好  阅读(680)  评论(0编辑  收藏  举报

导航