FPGA之IO信號類型深入理解


  在FPGA設計開發中,很多場合會遇到同一根信號既可以是輸入信號,又可以是輸出信號,即IO類型(Verilog定義成inout)。

  對於inout型的信號,我們既可以使用FPGA原語來實現,也可以使用Verilog代碼來實現。下面將介紹在Xilinx 7系列FPGA上兩種實現方式的差別和注意點。

  不管哪種方式實現IO功能,從編譯結果看都會調用IOBUF原語,為此,我們先來看一下IOBUF的結構,如下圖所示。

  1.FPGA原語實現

  首先,我們編寫的代碼如下:

 1`define PRIMITIVE 
 2 
 3 module io_buf(
 4     input    T    ,
 5     input    I    ,
 6     output    O    ,
 7     inout    IO
 8 );
 9 
10 `ifdef PRIMITIVE
11     IOBUF #(
12         .DRIVE            (12            ),    // Specify the output drive strength
13         .IBUF_LOW_PWR    ("TRUE"        ),    // Low Power - "TRUE", High Performance = "FALSE" 
14         .IOSTANDARD        ("DEFAULT"    ),    // Specify the I/O standard
15         .SLEW            ("SLOW"        )    // Specify the output slew rate
16     ) IOBUF_INST (
17         .O                (O            ),    // Buffer output
18         .IO                (IO            ),    // Buffer inout port (connect directly to top-level port)
19         .I                (I            ),    // Buffer input
20         .T                (T            )    // 3-state enable input, high=input, low=output
21     );
22 `else
23     assign IO = T? I:1'bz;
24     assign O  = IO;
25 `endif
26     
27 endmodule

  該代碼通過原語IOBUF實現IO功能,使用Vivado編譯后的原理圖如下圖所示。可以看到IOBUF內部由OBUFT和IBUF原語構成。

  2.使用Verilog實現

  把`define PRIMITIVE注釋掉,則為通過Verilog的實現方式,如下圖:

//`define PRIMITIVE 

module io_iobuf(
    input    T    ,
    input    I    ,
    output    O    ,
    inout    IO
);

`ifdef PRIMITIVE
    IOBUF #(
        .DRIVE            (12            ),    // Specify the output drive strength
        .IBUF_LOW_PWR    ("TRUE"        ),    // Low Power - "TRUE", High Performance = "FALSE" 
        .IOSTANDARD        ("DEFAULT"    ),    // Specify the I/O standard
        .SLEW            ("SLOW"        )    // Specify the output slew rate
    ) IOBUF_INST (
        .O                (O            ),    // Buffer output
        .IO                (IO            ),    // Buffer inout port (connect directly to top-level port)
        .I                (I            ),    // Buffer input
        .T                (T            )    // 3-state enable input, high=input, low=output
    );
`else
    assign IO = T? I:1'bz;
    assign O  = IO;
`endif
    
endmodule

  該代碼使用Vivado編譯后的原理圖如下圖所示。該實現方式也會調用IOBUF原語,但多消耗了一個LUT資源。

 

  通過Verilog實現時,我們在把IO信號當成輸入時給賦值高阻態(1‘bz)。假如我們把此時的IO信號賦值1‘b0或者1‘b1,會出現什么情況呢?我們把1‘bz寫成1‘b1,如下所示:

 1 //`define PRIMITIVE 
 2 
 3 module io_iobuf(
 4     input    T    ,
 5     input    I    ,
 6     output    O    ,
 7     inout    IO
 8 );
 9 
10 `ifdef PRIMITIVE
11     IOBUF #(
12         .DRIVE            (12            ),    // Specify the output drive strength
13         .IBUF_LOW_PWR    ("TRUE"        ),    // Low Power - "TRUE", High Performance = "FALSE" 
14         .IOSTANDARD        ("DEFAULT"    ),    // Specify the I/O standard
15         .SLEW            ("SLOW"        )    // Specify the output slew rate
16     ) IOBUF_INST (
17         .O                (O            ),    // Buffer output
18         .IO                (IO            ),    // Buffer inout port (connect directly to top-level port)
19         .I                (I            ),    // Buffer input
20         .T                (T            )    // 3-state enable input, high=input, low=output
21     );
22 `else
23     assign IO = T? I:1'b1;
24     assign O  = IO;
25 `endif
26     
27 endmodule

  編譯后的原理圖如下,可以看到並不會調用IOBUF原語,IO的不能實現輸入功能,這就是解釋了為什么在使用Verilog實現一根信號的IO功能時需要賦值1‘bz。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM