您的位置:技术中心首页 > 设计杂项 >> 双向端口仿真及实例

双向端口仿真及实例

作者:deve   时间:2006-02-27 04:53:20  来自:EDACN  浏览次数:526  文字大小:【】【】【
很多读者反映仿真双向端口的时候遇到困难,这里介绍一下双向端口的仿真方法。一个典型的双向端口如图1所示。

其中inner_port与芯片内部其他逻辑相连,outer_port为芯片外部管脚,out_en用于控制双向端口的方向,out_en为1时,端口为输出方向,out_en为0时,端口为输入方向。

用Verilog语言描述如下:
module bidirection_io(inner_port,out_en,outer_port);
input out_en;
inout[7:0] inner_port;
inout[7:0] outer_port;
assign outer_port=(out_en==1)?inner_port:8'hzz;
assign inner_port=(out_en==0)?outer_port:8'hzz;
endmodule

用VHDL语言描述双向端口如下:
library ieee;
use IEEE.STD_LOGIC_1164.ALL;
entity bidirection_io is
port ( inner_port : inout std_logic_vector(7 downto 0);
out_en : in std_logic;
outer_port : inout std_logic_vector(7 downto 0) );
end bidirection_io;
architecture behavioral of bidirection_io is
begin
outer_port<=inner_port when out_en='1' else (OTHERS=>'Z');
inner_port<=outer_port when out_en='0' else (OTHERS=>'Z');
end behavioral;

仿真时需要验证双向端口能正确输出数据,以及正确读入数据,因此需要驱动out_en端口,当out_en端口为1时,testbench驱动inner_port端口,然后检查outer_port端口输出的数据是否正确;当out_en端口为0时,testbench驱动outer_port端口,然后检查inner_port端口读入的数据是否正确。由于inner_port和outer_port端口都是双向端口(在VHDL和Verilog语言中都用inout定义),因此驱动方法与单向端口有所不同。
验证该双向端口的testbench结构如图2所示。

这是一个self-checking testbench,可以自动检查仿真结果是否正确,并在Modelsim控制台上打印出提示信息。图中Monitor完成信号采样、结果自动比较的功能。
testbench的工作过程为
1)out_en=1时,双向端口处于输出状态,testbench给inner_port_tb_reg信号赋值,然后读取outer_port_tb_wire的值,如果两者一致,双向端口工作正常。
2)out_en=0时,双向端口处于输如状态,testbench给outer_port_tb_reg信号赋值,然后读取inner_port_tb_wire的值,如果两者一致,双向端口工作正常。

用Verilog代码编写的testbench如下,其中使用了自动结果比较,随机化激励产生等技术。

`timescale 1ns/10ps
module tb();
reg[7:0] inner_port_tb_reg;
wire[7:0] inner_port_tb_wire;
reg[7:0] outer_port_tb_reg;
wire[7:0] outer_port_tb_wire;
reg out_en_tb;
integer i;

initial
begin
out_en_tb=0;
inner_port_tb_reg=0;
outer_port_tb_reg=0;
i=0;
repeat(20)
begin
#50
i=$random;
out_en_tb=i[0]; //randomize out_en_tb
inner_port_tb_reg=$random; //randomize data
outer_port_tb_reg=$random;
end
end

//**** drive the ports connecting to bidirction_io
assign inner_port_tb_wire=(out_en_tb==1)?inner_port_tb_reg:8'hzz;
assign outer_port_tb_wire=(out_en_tb==0)?outer_port_tb_reg:8'hzz;

//instatiate the bidirction_io module
bidirection_io bidirection_io_inst(.inner_port(inner_port_tb_wire),
.out_en(out_en_tb),
.outer_port(outer_port_tb_wire));

//***** monitor ******
always@(out_en_tb,inner_port_tb_wire,outer_port_tb_wire)
begin
#1;
if(outer_port_tb_wire===inner_port_tb_wire)
begin
$display("\n **** time=%t ****",$time);
$display("OK! out_en=%d",out_en_tb);
$display("OK! outer_port_tb_wire=%d,inner_port_tb_wire=%d",
outer_port_tb_wire,inner_port_tb_wire);
end
else
begin
$display("\n **** time=%t ****",$time);
$display("ERROR! out_en=%d",out_en_tb);
$display("ERROR! outer_port_tb_wire != inner_port_tb_wire" );
$display("ERROR! outer_port_tb_wire=%d, inner_port_tb_wire=%d",
outer_port_tb_wire,inner_port_tb_wire);
end
end
endmodule

本实例在modelsim仿真通过。



 
责任编辑:5life

更多相关 Dual port verilog simulation 的文章

仿真工作流程(Verilog/Modelsim+Debussy) [2007-05-14]
Verilog 的些许经验 [2006-09-05]
Verilog学习笔记(More) [2006-02-27]
Verilog PLI教程 --- 第七部分 VPI 函数 [2006-02-19]
Verilog PLI教程 --- 第三部分 PLI 程序 [2006-02-19]
Verilog PLI教程 --- 第五部分 PLI例子 [2006-02-19]
Verilog PLI教程 --- 第二部分 编写PLI应用程序 [2006-02-18]
Verilog PLI教程 --- 第一部分 介绍 [2006-02-18]
Verilog Pli的基本使用方法(modelsim) [2006-02-18]
提高NC-Verilog仿真效率的技巧 [2006-01-25]
Verilog HDL的基础知识 [2006-01-07]
本文共有0条评论,现在显示最新的5条。

栏目导航

电路基础
硬件语言
逻辑验证
电路综合
后端设计
可测设计
基本逻辑
制造工艺
书籍精选
说文解字
工具学习
数字滤波
趣闻逸事
数字锁相
设计杂项
低耗设计

站点最新

更多相关链接

  LVDS技术原理和设计简介
  I2C总线性能介绍
  NAND闪存深入解析
  终极内存技术指南
  深入介绍一下CPU的原理
  双向端口仿真及实例
  三种常用SoC片上总线的分...
  存储器类型综述及DDR接口...
  SoC片上总线综述
  片上系统的总线结构发展...

栏目最新

更多相关链接

  LVDS技术原理和设计简介
  I2C总线性能介绍
  NAND闪存深入解析
  终极内存技术指南
  深入介绍一下CPU的原理
  双向端口仿真及实例
  三种常用SoC片上总线的分...
  存储器类型综述及DDR接口...
  SoC片上总线综述
  片上系统的总线结构发展...

热点文章

更多相关链接