Verilog 組合邏輯UDP

2022-05-20 14:43 更新

與非門實(shí)例

組合邏輯 UDP 中,狀態(tài)表規(guī)定了不同的輸入組合和相對(duì)應(yīng)的輸出值,沒(méi)有指定的任意組合輸出值為 x。

一個(gè)簡(jiǎn)單的與非門 UDP 可以表示如下:

primitive nand_my(out, a, b);
   output       out ;
   input        a, b ;

   table
    //a         b       :       out ;
      0         0       :       1 ;
      0         1       :       1 ;
      1         0       :       1 ;
      1         1       :       0 ;
   endtable
endprimitive

如上一節(jié)所闡述,端口列表和聲明部分可以改為:

primitive nand_my(
  output       out,
  input        a, b);
  ......
endprimitive

狀態(tài)表項(xiàng)

表示組合邏輯的狀態(tài)表中的每一行的語(yǔ)法格式如下:

<input1>  <input2>  ...  <inputN>  :  <output> ;

  • 狀態(tài)表中的 input 信號(hào)順序要與 UDP 端口列表的順序一致。
  • 輸入和輸出用冒號(hào) ?:? 隔開。
  • 狀態(tài)表的每一行以分號(hào) ?;? 結(jié)束。
  • 能夠產(chǎn)生確定輸出值的所有輸入項(xiàng)的組合都必須在狀態(tài)表中列出,否則會(huì)輸出 x 值。

例如在上述 UDP nand_my 中,如果 a=0, b=x,則輸出 out = x ,因?yàn)樵摻M合選項(xiàng)在 table 中無(wú)法找到。所以在編寫 UDP 時(shí),要完整的考慮輸入的所有組合情況。

UDP nand_my 的狀態(tài)表可以修改為:

   table
    //a         b       :       out ;
      0         0       :       1 ;
      0         1       :       1 ;
      1         0       :       1 ;
      1         1       :       0 ;

      0         x       :       1 ;
      x         0       :       1 ;
   endtable

無(wú)關(guān)項(xiàng)

UDP nand_my 中,當(dāng) a 或 b 兩個(gè)輸入只要有一個(gè)為 0 時(shí),則輸出為 1。

不影響輸出結(jié)果的輸入信號(hào)為無(wú)關(guān)項(xiàng),可以用問(wèn)號(hào)"?"來(lái)表示。狀態(tài)表中的"?"項(xiàng)將自動(dòng)展開為 0, 1 或 x。

因此 UDP nand_my 的狀態(tài)表可以改為:

   table
    //a         b       :       out ;
      0         ?       :       1 ;
      ?         0       :       1 ;
      1         1       :       0 ;

      //下面組合將輸出 x,所以也可以省略,Verilog 默認(rèn)會(huì)輸出 x
      1         x       :       x ;
      x         1       :       x ;
   endtable

UDP 例化

UDP 調(diào)用格式與內(nèi)置門級(jí)原語(yǔ)完全一致。

利用上述 UDP nand_my 完成《Verilog 門延遲》中 D 觸發(fā)器的仿真。

去除延遲信息,D 觸發(fā)器模型如下。

module D_TRI(
            input       D, CP,
            output      Q, QR);

   //part1, not gate
   wire         CPN, DN ;
   not          (CPN, CP);
   not          (DN, D);

   //part2, master trigger
   wire         G3O, G4O ;
   nand_my      (G3O, D, CP);
   nand_my      (G4O, DN, CP);
   wire         G1O, G2O ;
   nand_my      (G1O, G3O, G2O);
   nand_my      (G2O, G4O, G1O);

   //part3, slave trigger
   wire         G7O, G8O ;
   nand_my      (G7O, G1O, CPN);
   nand_my      (G8O, G2O, CPN);
   wire         G5O, G6O ;
   nand_my      (G5O, G7O, G6O);
   nand_my      (G6O, G8O, G5O);

   assign       Q = G5O ;
   assign       QR = G6O ;

endmodule

testbench 保持不變,仿真結(jié)果如下。

由圖可知,觸發(fā)器在時(shí)鐘 CP 下降沿采集到了 D 端信號(hào),并傳遞給 Q/QR ,在單周期內(nèi)保持不變。

UDP 完成的與非門功能正確。


點(diǎn)擊這里下載源碼


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)