实验四 VHDL层次化设计方法实验
实验性质:验证性 实验级别:必做 开课单位:信息与通信工程学院通信工程系 学时:2学时 一、实验目的:
1、掌握用VHDL语言层次化设计的基本方法。 2、掌握GENERATE语句的用法。 二、实验器材:
计算机、Quartus II软件或xilinx ISE 三、实验内容:
设计一8位异步计数器,它的上一位计数器的输出作为下一位计数器的时钟信号,一级一级串行连接构成一个异步计数器。
各个D触发器模块采用VHDL语言编写,分别用原理图和VHDL语言元件例化语句的方法实现8位异步计数器的设计。 四、实验步骤:
(一)、在原理图中调用VHDL生成的D触发器模块实现8位异步计数器的设计
1、在xilinx ISE环境中新建vhdl文本编辑文件,设计带清零端的D触发器并编译仿真。 2、将步骤1所设计的D触发器生成一个元件。
3、新建原理图文件,调用步骤2所生成的D触发器元件,在原理图中实现8位异步计数器。
(二)、用VHDL的COMPONENT语句调用VHDL生成的D触发器模块实现8位异步计数器设计。
1、在xilinx ISE环境中新建vhdl文本编辑文件,设计带清零端的D触发器并编译仿真。 2、在同一个程序中用COMPONENT语句实现8位异步计数器的设计。 library IEEE;
use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Uncomment the following lines to use the declarations that are -- provided for instantiating Xilinx primitive components.
31
--library UNISIM;
--use UNISIM.VComponents.all;
entity dff is port (
d,clk,clear: in std_logic; q,q_n: out std_logic ); end dff;
architecture Behavioral of dff is begin
process(clk,clear) begin
if (clear='0') then q<='0';
elsif(clk'event and clk='1') then q<=d; q_n<=not d; end if; end process; end Behavioral;
D触发器测试向量程序如下:
Test Bench Created from source file dff.vhd -- 21:40:17 03/24/2008 -- -- Notes:
-- This testbench has been automatically generated using types std_logic and -- std_logic_vector for the ports of the unit under test. Xilinx recommends -- that these types always be used for the top-level I/O of a design in order -- to guarantee that the testbench will bind correctly to the post-implementation -- simulation model. --
32
LIBRARY ieee;
USE ieee.std_logic_1164.ALL; USE ieee.numeric_std.ALL; ENTITY dff_dff_vhd_tb IS END dff_dff_vhd_tb;
ARCHITECTURE behavior OF dff_dff_vhd_tb IS COMPONENT dff PORT( d : IN std_logic; clear: in std_logic;
clk : IN std_logic; q : OUT std_logic; q_n: out std_logic
);
END COMPONENT; SIGNAL d : std_logic; signal clear: std_logic; SIGNAL clk : std_logic; SIGNAL q : std_logic; signal q_n: std_logic; BEGIN
uut: dff PORT MAP( d => d, clear=>clear, clk => clk, q => q,
q_n=> q_n
);u1: PROCESS BEGIN clk<='0'; wait for 10us;
33
clk<='1'; wait for 10us; clk<='0'; wait for 10us; clk<='1'; wait for 10us; clk<='0'; wait for 10us; clk<='1'; wait for 10us; clk<='0'; wait for 10us; clk<='1'; wait for 10us; clk<='0'; wait for 10us; clk<='1'; wait;
end process u1; u2: process begin d<='0'; wait for 30us; d<='1'; wait for 50us; d<='0'; wait ;
end process u2; u3: process begin clear<='1';
34
wait for 70us; clear<='0'; wait for 20us; clear<='1'; wait ;
end process u3;
-- *** End Test Bench - User Defined Section *** END behavior; 程序仿真如下图:
新建原理图文件,调用步骤1所生成的D触发器元件,在原理图中实现8位异步计数器: 原理图连接好如下图:
35