UDP类似于一张真值表
注意点:
1.U D P
的定义不依赖于模块定义,因此出现在模块定义以外。也可以在单独的文本文件中
定义
U D P
。
2.U D P
只能有一个输出和一个或多个输入(wire)。第一个端口必须是输出端口。此外,输出可以
取值
0
、
1
或
x
(
不允许取
z
值
)
。输入中出现值
z
以
x
处理。
U D P
的行为以表的形式描述。
3.Table中描述顺序与定义顺序相同":"后面为输出。
3.在
U D P
中可以描述下面两类行为:
1)
组合电路
2)
时序电路
(
边沿触发和电平触发
)
定义一个UDP的D触发器(边沿触发时序电路):
primitive D_i(Q,CLK,D);
output Q;
reg Q;
input CLK,D;
table
(01) 0 : ? : 0 ;//(01)表示clk 0到1的转换,同理(0x),(?0)
(01) 1 : ? : 1 ;//第一个冒号表示当前时刻Q值,第二表示下一时刻Q值
(0x) 1 : 1 : 1 ;
(0x) 0 : 0 : 0 ;
(?0) ? : ? : - ;//-表示不变
? (??): ? : - ;
endtable
endprimitive
module top_module ();
reg clk=0;
always #5 clk = ~clk; // Create clock with period=10
initial `probe_start; // Start the timing diagram
`probe(clk); // Probe signal "clk"
// A testbench
reg D=0;
wire Q=0;
initial begin
#5 D <= 1;
#10 D <= 0;
#10 D <= 1;
#10 D <= 0;
$display ("Hello world! The current time is (%0d ps)", $time);
#50 $finish; // Quit the simulation
end
D_FF D_FF1(.D(D),.CLK(clk),.Q(Q)); // Sub-modules work too.
endmodule
module D_FF(input D, CLK,output Q);
`probe(D);
`probe(CLK);
`probe(Q);
D_i D_index1(Q,CLK,D);
endmodule
结果:
UDP定义个选择器(组合电路):
primitive sel(z,i1,i2,sel);
output z;
input i1,i2,sel;
table
1 ? 1 : 1;
0 ? 1 : 0;
? 1 0 : 1;
? 0 0 : 0;
endtable
endprimitive
module top_module ();
reg sel=0;
always #5 sel = ~sel; // Create clock with period=10
initial `probe_start; // Start the timing diagram
`probe(sel); // Probe signal "clk"
// A testbench
reg i1=0,i2=0;
initial begin
#5 i1 <= 1;
i2 <= 0;
#5 i1 <= 0;
i2 <= 1;
#10 i1 <= 1;
#10 i2 <= 0;
$display ("Hello world! The current time is (%0d ps)", $time);
#50 $finish; // Quit the simulation
end
Sel Sel1(.i1(i1),.i2(i2),.sel(sel)); // Sub-modules work too.
endmodule
module Sel(input i1, i2, sel, output z);
`probe(z);
`probe(i1);
`probe(i2);
`probe(sel);
sel sel1(z,i1,i2,sel);
endmodule
输出: