modelsim仿真测试实验三.doc
文本预览下载声明
实验3.1. modelsim仿真测试
一、实验目的
1、分析分频器的VHDL代码,了解信号和变量的差别。
2、学习modelsim软件环境下,采用测试向量进行测试的方法。包括:激励文件的建立和测试实现。
二、实验步骤
1.1. modelsim的批处理操作流程
建立一个工程File-New Project Wizard,
信号描述
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; entity div_Signal is
generic (div_nx2:positive:=4);
port ( clk: in std_logic;
q: out std_logic);
end div_Signal; architecture behav of div_Signal is
SIGNAL fre_N : integer range 0 to div_nx2:=0;
SIGNAL clk_tmp: std_logic:=’0’;
BEGIN
q = clk_tmp;
process(clk)
begin
if clkevent and clk = 1 then
if fre_N = div_nx2 - 1 then fre_N = 0; clk_tmp = not clk_tmp;
else fre_N = fre_N + 1;
end if;
end if;
end process;
end behav; 变量描述:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL; entity div_var is
generic (div_nx2:positive:=4);
Port ( CLK : in std_logic;
clkout: out std_logic);
end div_var; architecture Behavioral of div_var is
signal Clk_Out : std_logic:=0;
begin
process(CLK)
variable fre_N:integer range 0 to div_nx2:=0;
begin
if rising_edge(CLK) then
if fre_N=div_nx2-1 then fre_N := 0; Clk_Out = not Clk_Out;
else fre_N:=fre_N+1; end if;
end if;
end process;
clkout = Clk_Out;
end Behavioral;
方法1:
方法2:
存为:div_signal_do.do
vsim work.div_signal
add wave sim:/div_signal/*
force -freeze sim:/div_signal/clk 1 0, 0 {10 ns} -r 20
run 400ns 在编译后,获得了逻辑网表,但未开始仿真。可以直接运行DO文件。
点击Next,我们将其工程存储在D:\Temp\ex1下(注意:存储路径中一定不能有空格或中文,否则找不到相关文件),工程命名为ex1,如下所示
1.2. 使用测试向量testbench
新建项目,添加新文件:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; entity cntx is
port(clk,rst,en: in std_logic;
q: out std_logic_vector(3 downto 0));
end cntx; architecture behave of cntx is
signal q_n: std_logic_vector(3 downto 0);
begin
process(clk, rst, en, q_n)
begin
if (rst = 1) then q_n = (others = 0);
elsif rising_edge
显示全部