Testbench文件如下:
library IEEE;
use IEEE.std_logic_1164.all;
USE IEEE.STD_LOGIC_TEXTIO.ALL; USE STD.TEXTIO.ALL;
entity testbench is end entity testbench;
architecture test_reg of testbench is component tcomp1 is
port( DataA : in std_logic_vector(7 downto 0); DataB : in std_logic_vector(7 downto 0); AGEB : out std_logic) ; end component;
signal a,b:STD_LOGIC_VECTOR(7 DOWNTO 0); signal AGEB: STD_LOGIC;
begin
UUT : tcomp1 port map (DataA=>a, DataB=>b,AGEB=>AGEB);
file_io: PROCESS IS
FILE in_file : TEXT OPEN READ_MODE IS \
FILE out_file : TEXT OPEN WRITE_MODE IS \VARIABLE out_line : LINE; VARIABLE in_line : LINE;
VARIABLE a1,b1 : STD_LOGIC_VECTOR(7 DOWNTO 0); --VARIABLE result: STD_LOGIC;
BEGIN
WHILE NOT ENDFILE(in_file) LOOP --do this till out of data READLINE(in_file, in_line); --get line of input stimulus READ(in_line, a1); --get first operand READ(in_line, b1); --get second operand a<=a1;
b<=b1;
6
-- wait for 100 ns; wait for 1 ns;
--output the results to the file
write(out_line, string'(\
WRITE(out_line, AGEB); --save results to line WRITELINE(out_file, out_line); --write line to file --output the results to the screen
write(out_line, string'(\
WRITE(out_line, AGEB); --save results to line
WRITELINE(output, out_line); --write line to the screen END LOOP;
ASSERT FALSE REPORT \WAIT; --allows the simulation to halt!
END PROCESS;
end architecture test_reg;
(2)基本的仿真(自己编写testbench文件,采用catalog下的basic blocks):
采用component\\work\\tcomp\\tcomp.vhd作为被测试模块;仿真在tsim1文件夹下进行;
tcomp模块中包含tcomp1子模块、电源子模块等,因此,需要将smartgen\\tcomp1\\tcomp1.vhd文件加入到这个项目中,仿真结果如图所示。
(3)布局布线后仿真(自己编写testbench文件,采用catalog下的basic blocks): 所需文件在mysim\\designer\\impl1目录下: tcomp_ba.sdf布局布线后延时反标文件; tcomp_ba.vhd布局布线后的网表文件;
仿真在tsim2文件夹下进行,未反标时序文件sdf之前的运行结果如下:
反标时序文件sdf之后的仿真结果如下:
7
在Libero集成环境中输入testbench的步骤如下:
(a) Project Manager/SmartDesign/HDL Stimulus File/Name中输入testbench;
(b) 在出现的Project Manager的主窗口中输入自己编写的testbench的主体文件; (c) 点击Project Manager/Project/File organization/Stimulus,出现如下所示的对话框:
出现了项目文件中存在的所有testbench模块。如果Origin一栏中出现tcomp,那么这个测试模块为项目tcomp自动生成的testbench;如果Origin一栏中出现了User,那么这个测试模块为用户自己手工编制的testbench;将需要采用的testbench通过“Add”按钮移动到右边的“Associated files”栏中,那么这个testbench就成为被激活的有效测试模块; 注:采用如下的modelsim设置可消除仿真中的关于毛刺的一些警告: vsim -L proasic3 -L postlayout -noglitch -sdfmax /UUT=E:/Summary_Work/summary_100531/ipsim/mysim/designer/impl1/tcomp_ba.sdf -t 1ps postlayout.testbench;
在仿真时的如下对话框内选择“Disable glitch generation”,从而防止glitch的产生。
8
9