当前位置:网站首页>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在仿真测试中的使用方法
边栏推荐
- Struggle, programmer -- Chapter 44: eight hundred miles under one's command, fifty strings turning over the Great Wall
- Common real machine debugging plug-ins for unity commercial games
- Le modèle de diffusion est encore fou! Cette fois - ci, la zone occupée était...
- Thoroughly understand the builder mode (builder)
- C generic_ Generic class
- Fight, programmer chapter 43 kill one man in ten steps
- Sikulix select the picture of relative position (advanced version)
- Are there many unemployed people in 2022? Is it particularly difficult to find a job this year?
- Keil simulation and VSPD
- 一篇博客让你了解Material Design的使用
猜你喜欢

Database connection pool: stress testing

那些令人懵逼的用户态&内核态
![Dessert mall management system based on SSH framework [source code + database]](/img/6d/6d8ad081de9b0c0ab8c2f8aba1dcf0.png)
Dessert mall management system based on SSH framework [source code + database]

What is the value of a website? Why build an independent station

本周四晚19:00战码先锋第7期直播丨三方应用开发者如何为开源做贡献

visual studio开发过程中常见操作

Deadlock found when trying to get lock; Try restarting transaction

At 19:00 this Thursday evening, the 7th live broadcast of battle code Pioneer - how third-party application developers contribute to open source

我靠副业一年全款买房:那个你看不起的行业,未来十年很赚钱!

口令安全是什么意思?等保2.0政策中口令安全标准条款有哪些?
随机推荐
Groovy语法介绍
Perceptron of machine learning
【毕业设计】基于半监督学习和集成学习的情感分析研究
擴散模型又殺瘋了!這一次被攻占的領域是...
visual studio开发过程中常见操作
接了个私活项目,一下赚了15250,还有必要做主业吗?
大会倒计时 | 亚马逊云科技创新大会邀您一起构建AI新引擎 !
11 method reference and constructor application
PowerPoint 教程,如何在 PowerPoint 中添加水印?
Le modèle de diffusion est encore fou! Cette fois - ci, la zone occupée était...
先锋期货靠谱么?期货怎么开户安全些?
Closure of groovy
KEIL仿真和vspd
求求了,别被洗脑了,这才是90%中国人的生存实况
After 17 years, Liu Yifei became popular again: ordinary people don't want to be eliminated, but they also need to understand this
Are there many unemployed people in 2022? Is it particularly difficult to find a job this year?
"Forget to learn again" shell process control - 38. Introduction to while loop and until loop
Biden signe deux nouvelles lois visant à renforcer la cybersécurité du Gouvernement
FreeRtos 任务优先级和中断优先级
2022orace database installation and use