“LS74138”配置给了原理图文件“sch_ls74138”,其余电路仿真、管脚配置、编译、综合以及电路下载等过程与文本设计方式一致,在此不在重复说明。 五、预习与思考:
思考:比较VHDL语言和原理图的设计方法,这两种设计各有哪些优缺点。
11
实验二 组合逻辑电路的VHDL语言实现
实验性质:验证性 实验级别:必做 开课单位:信息与通信工程学院通信工程系 学时:2学时 一、实验目的:
1、掌握VHDL语言设计基本单元及其构成
2、掌握用VHDL语言设计基本的组合逻辑电路的方法。 3、掌握VHDL语言的主要描述语句。 二、实验器材:
计算机、Quartus II软件或Xilinx ISE 三、实验内容:
1、本实验以1位全加器为例,在Xilinx ISE软件平台上完成设计电路的VHDL文本输入,编辑,编
译,仿真,管脚分配和编程下载等操作。下载芯片选择Xilinx公司的CoolRunner II系列XC2C256-7PQ208作为目标仿真芯片。
2、用实验内容1所设计的全加器的VHDL文件生成一个adder的元件,在Xilinx ISE软件原理图设
计平台上完成adder元件的调用,用原理图的方法设计一个8位二进制加法器,实现编译,仿真,管脚分配和编程下载等操作。 3、或优先编码器、多路选择器等其它电路。 四、实验步骤:
(一)、用VHDL语言实现八位加法器的设计并实现功能仿真。
全加器是带进位位信号的加法器,起逻辑表达式为:Sum?dataA?dataB?carryin 。它的真值表如表1所示,其中dataA和dataB为加数与被加数,carryin是输入的进位位信号,而Sum是和数,carryout是输出进位位信号。参考真值表,实现八位全加器的功能。
表1
输入 输出 carryin 0 0 0
dataA 0 0 1 dataB 0 1 0 12
Sum 0 1 1 carryout 0 0 0
0 1 1 1 1 1 0 0 1 1 1 0 1 0 1 0 1 0 0 1 1 0 1 1 1 一)1位加法器的VHDL源程序参考如下:
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. --library UNISIM;
--use UNISIM.VComponents.all;
entity adder is
Port ( a : in std_logic; b : in std_logic; cin : in std_logic; sum : out std_logic; cout : out std_logic); end adder;
architecture Behavioral of adder is begin
sum <= (a xor b) xor cin;
cout <= (a and b) or (cin and a) or (cin and b); end Behavioral;
测试向量参考程序如下:
-- VHDL Test Bench Created from source file adder.vhd -- 21:00:50 03/18/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
13
-- simulation model. LIBRARY ieee;
USE ieee.std_logic_1164.ALL; USE ieee.numeric_std.ALL; ENTITY adder_adder_vhd_tb IS END adder_adder_vhd_tb;
ARCHITECTURE behavior OF adder_adder_vhd_tb IS
COMPONENT adder PORT(
a : IN std_logic; b : IN std_logic;
cin : IN std_logic; sum : OUT std_logic; cout : OUT std_logic );
END COMPONENT; SIGNAL a : std_logic; SIGNAL b : std_logic; SIGNAL cin : std_logic; SIGNAL sum : std_logic; SIGNAL cout : std_logic;
BEGIN
uut: adder PORT MAP( );
a => a, b => b, cin => cin, sum => sum, cout => cout
u1: PROCESS
14
BEGIN a<='0'; wait for 10 us; a<='1'; wait for 20 us; a<='0'; wait for 10 us; a<='1'; wait for 10 us; a<='0'; wait for 20 us; a<='1'; wait for 10 us; a<='0';
wait for 10 us;
a<='1';
wait;
END PROCESS u1; u2:process begin
b<='1'; wait for 10 us; b<='0'; wait for 10 us; b<='1'; wait for 10 us; b<='0'; wait for 10 us; b<='1'; wait for 20 us;
b<='0';
15