当前位置:网站首页>Verilog使用inout信号的方法
Verilog使用inout信号的方法
2022-06-22 13:50:00 【子木呀】
目录
一、inout在设计文件中的使用方法
在FPGA的设计过程中,有时候会遇到双向信号(既能作为输出,也能作为输入的信号叫双向信号)。比如,IIC总线中的SDA信号就是一个双向信号,QSPI Flash的四线操作的时候四根信号线均为双向信号。在Verilog中用关键字inout定义双向信号,这里总结一下双向信号的处理方法。
1.1、inout的第一种使用方法
实际上,双向信号的本质是由一个三态门组成的,三态门可以输出高电平,低电平和高阻态三种状态,在FPGA中,一个三态门的结构如下图所示:

描述这个逻辑的Verilog代码如下:
module inout_top
(
input I_data_in ,
inout IO_data ,
output O_data_out ,
input Control
);
assign IO_data = Control ? I_data_in : 1'bz ;
assign O_data_out = IO_data ;
endmodule当Control为1时,IO_data为输出,输出I_data_in的值
当Control为0时,IO_data为输入,把输入的信号赋值给O_data_out
这段代码在Vivado2015.4.2编译环境下的RTL图如下图所示

在ISE14.7的编译环境下的RTL图如下图所示
可以发现在Vivado2015.4.2环境的Control信号的IBUF后面居然还综合出了一个LUT,在ISE14.7环境下Control信号后面综合出了一个反向器,出现这个LUT和反向器的原因是Control为1才把IO_data设置成输出,而在Xilinx中一个IOBUF资源默认T端为0时IO端才为输出,T端为1时,IO端为输入,所以把
assign IO_data = Control ? I_data_in : 1'bz ;//Control=1时 作为输出改为
assign IO_data = (Control == 1’b0) ? I_data_in : 1'bz ;//Control=0时 作为输出在Vivado2015.4.2环境下综合出的RTL图为下图

在ISE14.7的环境下综合出的RTL图如下图所示
显然,Vivado环境中LUT和ISE环境中的反相器不见了,节省了1个Cell资源。
1.2、inout实现的第二种使用方法
以上是处理inout的第一种方法,第二种处理inout信号的方法是调用Xilinx的IOBUF原语,IOBUF的原语可以在Vivado2015.4.2的Language Templates中找到。

调用这个原语的Verilog代码如下:
module inout_top
(
input I_data_in,
inout IO_data ,
output O_data_out ,
input Control
);
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_data_out), // Buffer output
.IO(IO_data), // Buffer inout port (connect directly to top-level port)
.I(I_data_in), // Buffer input
.T(Control) // 3-state enable input, high=input, low=output
);
endmodule在Vivado2015.4.2环境下综合出的RTL图如下图所示

在ISE14.7环境下综合出的RTL图如下图所示
显然和 assign IO_data = (Control == 1’b0) ? I_data_in : 1'bz ;这种情况下综合出的RTL完全一样。
1.3、inout使用总结
利用Verilog处理双向信号有两种方式:
1、写代码
assign IO_data = (Control == 1’b0)? I_data_in : 1'bz ;
assign O_data_out = IO_data ;2、例化IOBUF原语
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_data_out), // Buffer output
.IO(IO_data), // Buffer inout port (connect directly to top-level port)
.I(I_data_in), // Buffer input
.T(Control) // 3-state enable input, high=input, low=output
);二、inout在仿真测试中的使用方法
边栏推荐
- U++ operator learning notes
- UE4 obtains local files through blueprints
- 扩散模型又杀疯了!这一次被攻占的领域是...
- [Software Engineering] planning and project management
- 数据资产管理:数据发现,发现什么,怎么发现?
- 全新混合架构iFormer!将卷积和最大池化灵活移植到Transformer
- FreeRtos 任务优先级和中断优先级
- U++ iterative Sorting Query learning notes
- Go all out to implement the flood control and disaster relief measures in detail and in place, and resolutely protect the safety of people's lives and property
- [live broadcast review] battle code pioneer phase VI: build a test subsystem and empower developers to provide
猜你喜欢

PHP内置协议(支持的协议和封装协议)

Verification code is the natural enemy of automation? See how the great God solved it

拜登签署两项旨在加强政府网络安全的新法案

那些令人懵逼的用户态&内核态

【Pr】基础流程
![[live broadcast review] battle code pioneer phase VI: build a test subsystem and empower developers to provide](/img/46/d36ae47c3d44565d695e8ca7f34980.jpg)
[live broadcast review] battle code pioneer phase VI: build a test subsystem and empower developers to provide

phpStudy 2016搭建-pikachu靶场

Show me my personal work list for the past two years. I earn 6K a month in my spare time. It's so delicious to have a sideline

嵌入式中的强符号和弱符号是什么?

封装api时候token的处理
随机推荐
[Software Engineering] design module
我靠副业一年全款买房:那个你看不起的行业,未来十年很赚钱!
U++编程 移动 学习笔记
网络安全的五大特点有哪些?五大属性是什么?
Unity sub thread calls UI of main thread
数据库连接池:代码目录
A thorough understanding of singleton
MySQL learning notes 2022
U++ 迭代 排序 查询 学习笔记
C # define and implement interface interface
求求了,别被洗脑了,这才是90%中国人的生存实况
【直播回顾】战码先锋第六期:共建测试子系统,赋能开发者提
What is the value of a website? Why build an independent station
"Forget to learn again" shell process control - 38. Introduction to while loop and until loop
Thoroughly understand the factory mode
U++ iterative Sorting Query learning notes
Phpstudy 2016 build Pikachu range
What are the five characteristics of network security? What are the five attributes?
Biden signe deux nouvelles lois visant à renforcer la cybersécurité du Gouvernement
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷