用户自定义源语UDP

本文详细介绍了如何使用UDP(无源门阵列)在VHDL中定义组合电路和时序电路,如D触发器。通过具体的D触发器和选择器的UDP实现,展示了UDP的工作原理及其在数字逻辑设计中的应用。同时,提供了测试模块来验证UDP的功能,并通过示例代码解释了如何在顶层模块中调用这些UDP。
摘要由CSDN通过智能技术生成

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

 输出:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值