登录站点

用户名

密码

VHDL测试平台设计_4位计数器

已有 1423 次阅读  2010-11-02 20:56   标签VHDL  计数器  平台  设计 

VHDL测试平台设计_4位计数器

VHDL设计实体,它是一个带低有效复位的4位计数器:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity counter is

port(rst_n : in std_logic;

clk : in std_logic;

cnt_dout : out std_logic_vector(3 downto 0));

end counter;

architecture behave of counter is

signal cnt : std_logic_vector(3 downto 0) := "0000";

begin

cnt_dout <= cnt;

process(clk, rst_n)

begin

if(rst_n = '0') then

cnt <= "0000";

elsif clk'event and clk = '1' then

cnt <= cnt + 1;

end if;

end process;

cnt_dout <= cnt;

end behave;

测试平台:

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity counter_tb is

end counter_tb;

architecture behave of counter_tb is

component counter is

port(rst_n : in std_logic;

clk : in std_logic;

cnt_dout : out std_logic_vector(3 downto 0));

end component counter;

signal rst_n : std_logic;

signal clk : std_logic;

signal cnt_dout : std_logic_vector(3 downto 0);

begin

i1: counter port map(rst_n => rst_n,

clk => clk,

cnt_dout => cnt_dout);

--重复信号可以用PROCESS语句生成

generate_clk: process

begin

clk <= '1';

wait for 10ns;

clk <= '0';

wait for 10ns;

end process;

--非重复信号可以直接用AFTER语句生成

rst_n <= '0', '1' after 80ns;

end behave;

由测试平台可以看看出,VHDL的测试平台有以下几个部分组成:

1. 库的引用。

2. 实体声明,这是个空实体,即没有输入输出端口声明。

3. 被测实体的声明。

4. 内部信号的声明。

5. 被测实体的引用。

6. 测试信号的生成。

MODELSIM中仿真如图1所示。

图1

由图1可以看出,实现了4位计数器的测试。


上一篇: AD/DA的分类与主要技术指标 下一篇: VHDL测试平台设计_文件的操作

分享 举报