首页 > 其他 > 详细

双向端口

时间:2021-04-06 23:28:57      阅读:46      评论:0      收藏:0      [点我收藏+]

在总线设计中,常常要使用到双向端口。在芯片中,与单向端口相比,双向端口能够节约管脚资源,声明为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 : 1bz;
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 : 1bz;
20 
21 endmodule

fpga中综合得到电路为:

技术分享图片

 

 

技术分享图片

 

双向端口

原文:https://www.cnblogs.com/mr1victor/p/14622136.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!