在总线设计中,常常要使用到双向端口。在芯片中,与单向端口相比,双向端口能够节约管脚资源,声明为inout,使用三态门实现。
描述这个三态门的verilog代码为:
1 module inout_test ( 2 input wire ctrl, 3 input wire din, 4 output wire dout, 5 inout wire dinout 6 ); 7 8 9 assign dinout = ctrl? din : 1‘bz; 10 assign dout = dinout; 11 12 endmodule
inout信号具有以下特征:
1.inout信号不能声明为reg型,因此不能用在always语句中;
2.给inout赋值需要一个印象寄存器,;
3.高阻态不能用于芯片内部,要将逻辑引到引脚处。
1 module inout_test ( 2 input wire clk, 3 input wire ctrl, 4 input wire din, 5 output reg dout, 6 inout wire dinout 7 ); 8 9 reg din_reg; 10 11 always @(posedge clk ) begin 12 if (ctrl) begin 13 din_reg <= din; 14 end 15 else 16 dout <= dinout; 17 end 18 19 assign dinout = ctrl? din_reg : 1‘bz; 20 21 endmodule
fpga中综合得到电路为:
原文:https://www.cnblogs.com/mr1victor/p/14622136.html