EDA上机实验报告
班级:021211
姓名:张育东
学号:02121056
实验一:QUARTUS II软件使用及组合电路设计仿真
实验目的:
学习QUARTUS II软件的使用,掌握软件工程的建立、VHDL源文件的设计和波形仿真等基本内容;
实验内容:
1. 四选一多路选择器的设计
1.1实验内容
首先利用QuartusⅡ完成4选1多路选择器的文本编辑输入和仿真测试等步骤,给出仿真波形。
步骤:
(1) 建立工作库文件夹和编辑设计文件;
(2) 创建工程;
(3) 编译前设置;
(4) 全程编译;
(5) 时序仿真。
1.2程序设计:
library ieee;
use ieee.std_logic_1164.all;
entity mux41 is
port
(
s:IN STD_LOGIC_VECTOR(1 DOWNTO 0);
a,b,c,d:IN STD_LOGIC;
y : out std_logic
);
end mux41;
architecture behavior of mux41 is
begin
process(s)
begin
IF s="00" THEN
y<=a;
ELSIF s="01" THEN
y<=b;
ELSIF s="10" THEN
y<=c;
ELSIF s="11" THEN
y<=d;
END IF;
END PROCESS;
END BEHAVIOR;
1.3仿真波形
图 四选一多路选择器波形仿真结果
1.4结果分析
通过对实验结果的研究,可以发现该程序成功实现了4选1多路选择器的功能。当s=00时,y=a;s=01时,y=b;s=10时,y=c;s=11时,y=d.完全实现了4选1多路选择器的功能。
2. 七段译码器程序设计仿真
2.1 实验原理:
7段数码是纯组合电路,通常的小规模专用IC,如74或4000系列的器件只能作十进制BCD码译码,然而数字系统中的数据处理和运算都是2进制的,所以输出表达都是16进制的,为了满足16进制数的译码显示,最方便的方法就是利用VHDL译码程序在FPGA或CPLD中实现。本项实验很容易实现这一目的。例1作为7段BCD码译码器的设计,输出信号LED7S的7位分别接如实验图1数码管的7个段,高位在左,低位在右。例如当LED7S输出为 "0010010" 时,数码管的7个段:g、f、e、d、c、b、a分别接0、0、1、0、0、1、0,实验中的数码管为共阳极的,接有低电平的段发亮,于是数码管显示“5”。
2.2 实验内容:
参考后面的七段译码器程序,在QUARTUS II上对以下程序进行编辑、编译、综合、适配、仿真,给出其所有信号的时序仿真波形。
2.3 程序设计:
library ieee;
use ieee.std_logic_1164.all;
entity mu7 is
port( dat:in std_logic_vector(3 downto 0);
led:out std_logic_vector(6 downto 0));
end mu7;
architecture behave of mu7 is
signal tmp:std_logic_vector(6 downto 0);
begin
process(dat)
begin
case dat is
when "0000"=>tmp<="0000001";
when "0001"=>tmp<="1001111";
when "0010"=>tmp<="0010010";
when "0011"=>tmp<="0000110";
when "0100"=>tmp<="1001100";
when "0101"=>tmp<="0100100";
when "0110"=>tmp<="0100000";
when "0111"=>tmp<="0001111";
when "1000"=>tmp<="0000000";
when "1001"=>tmp<="0000100";
when "1010"=>tmp<="0001000";
when "1011"=>tmp<="1100000";
when "1100"=>tmp<="0110001";
when "1101"=>tmp<="1000010";
when "1110"=>tmp<="0110000";
when "1111"=>tmp<="0111000";
when others=>null;
end case;
end process;
led<=tmp;
end behave;
2.4仿真波形:
2.5结果分析:
通过波形仿真,得到该程序成功实现了七段译码器的功能,其中dat为四位二进制数的输入端,led为七段译码器的输出端。
实验二 计数器设计与显示
实验目的:
(1)熟悉利用QUARTUS II中的原理图输入法设计组合电路,掌握层次化设计的方法;
(2)学习计数器设计、多层次设计方法和总线数据输入方式的仿真,并进行电路板下载演示验证。
实验内容:
1. 完成计数器设计
1.1实验内容:
设计含有异步清零和计数使能的4位二进制加减可控计数器。
1.2程序设计:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
ENTITY cnt4 IS
PORT ( CLK ,enable,updown,reset: in std_logic ;
Oc:out std_logic;
Q : BUFFER INTEGER range 15 downto 0 ) ;
END ENTITY cnt4 ;
ARCHITECTURE bhv OF cnt4 IS
BEGIN
PROCESS (CLK,reset,enable,updown)
BEGIN
if reset='1' then
Q<=0;
else
if enable='1' then
IF CLK'EVENT AND CLK = '1' THEN
if updown='1'then
Q <= Q + 1 ;
else
Q<=Q-1;
end if;
if Q=15 then
Oc<='1';
end if;
if Q=0 then
Oc<='0';
end if;
END IF;
end if;
end if;
END PROCESS;
END bhv;
1.3仿真波形:
1.4结果分析:
通过波形仿真,可得该程序可以实现4位二进制加减可控计数器的功能。其中控制enable可以使计数器暂停或继续工作,控制reset可以使计数器复位,updown可以控制计数器是“加”还是“减”,可以看到Q在这次仿真过程中成功从0加到15,又从15减到0。可见实验结果是成功的。
2. 计数器显示译码设计与下载
2.1实验内容:
用原理图输入法按实验图2的方式,以前面设计的七段译码器DecL7S和计数器为底层元件,完成“计数器显示译码”的顶层文件设计。
2.2程序设计:
其他模块的代码与之前设计的实验代码一致,只有50M分频器的代码需要重新设计
50M分频器代码如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
ENTITY cnt50 IS
PORT ( CLK ,enable,updown,reset: in std_logic ;
Oc:out std_logic;
Q : BUFFER INTEGER range 49999999 downto 0 );
END ENTITY cnt50;
ARCHITECTURE bhv OF cnt50 IS
BEGIN
PROCESS (CLK,reset,updown,enable)
BEGIN
if reset='1' then
Q<=0;
else
if enable='1' then
IF CLK'EVENT AND CLK = '1' THEN
if updown='1'then
Q <= Q + 1 ;
else
Q<=Q-1;
end if;
if Q=49999999 then
Oc<='1';
end if;
if Q=0 then
Oc<='0';
end if;
END IF;
end if;
end if;
END PROCESS;
END bhv;
2.3波形仿真:
2.4各模块连接电路原理图:
实验图2 计数器和译码器连接电路的顶层文件原理图
2.5结果分析:
根据实验结果可知,各模块的功能都能成功实现,控制enable可以使计数器暂停或继续工作,控制reset可以使计数器复位,updown可以控制计数器是“加”还是“减”,而七段译码器则将计数器所记数通过数码管显示出来。成功实现了计数器显示译码的设计。
实验3:大作业设计 :2人抢答器
(一) 设计任务及要求
设计一个2人抢答器。要求如下:
1. 两人抢答,先抢为有效,用发光二极管显示是否抢到优先答题权;
2. 每人2位计分显示,答错了不加分,答对了可加10分、20分、30分;
3. 每题结束后,裁判按复位键,可重新抢答下一题;
4. 累计加分可由裁判随时清除;
(二) 设计总体框图:
(三) 程序功能:
1. 此程序主要由三部分组成,即抢答、加分、显示;
2. 当一人抢到优先答题权,发光二极管亮,另一人再按键无效。答题结束后,裁判按复位键,方可再次抢答;
3. 每人有2个数码管显示累加计分情况,分数分为3档,用按键来区别,数码管的末位始终显示0.
(四) 程序设计:
实体:
(实体器件图)
整个程序代码:
entity qd is
port(i1,i2 : in bit;
reset : in bit;
g10,g20,g30:in bit; --加分
light1,light2:out bit:='0'; --抢答标志灯
t11:out std_logic_vector(6 downto 0):= "1000000"; --第一人分数的十位数和个位数
t12:out std_logic_vector(6 downto 0):= "1000000";
t21:out std_logic_vector(6 downto 0):= "1000000"; --第二人分数的十位数和个位数
t22:out std_logic_vector(6 downto 0):= "1000000";
clk:in bit; --时钟
cong:in bit --清零
);
end qd;
architecture stru of qd is
signal cs1:integer range 0 to 9;
signal cs2:integer range 0 to 9;
signal a,b:bit:='0';
signal l1,l2:bit:='0';
begin
process(clk)
begin
if clk'event and clk='1' then
if(cong='1') then
if(reset='1') then
if (i1 ='0' and a='0') then l1<='1'; a<= '1' ; --抢答
elsif ( i2 ='0' and a='0') then l2<='1'; a<= '1' ;
end if;
if (g10 ='0' and l1='1' and b='0' ) then cs1<=cs1+1 ; b<='1' ;
elsif (g20 ='0' and l1='1' and b='0' ) then cs1<=cs1+2 ; b<='1' ;
elsif (g30 ='0' and l1='1' and b='0' ) then cs1<=cs1+3 ; b<='1' ;
end if; --完成第一人的加分
if(g10='0' and l2='1' and b='0') then cs2<=cs2+1;b<='1';
elsif(g20='0' and l2='1' and b='0') then cs2<=cs2+2;b<='1';
elsif(g30='0' and l2='1' and b='0') then cs2<=cs2+3;b<='1';
end if; --完成第二人的加分。
if (cs1=0) then t11<="1000000"; --数码管显示。
elsif (cs1=1) then t11<= "1111001";
elsif (cs1=2) then t11<= "0100100";
elsif (cs1=3) then t11<= "0110000";
elsif (cs1=4) then t11<= "0011001";
elsif (cs1=5) then t11<= "0010010";
elsif (cs1=6) then t11<= "0000010";
elsif (cs1=7) then t11<= "1111000";
elsif (cs1=8) then t11<= "0000000";
elsif (cs1=9) then t11<= "0010000";
else t11<= "0010000";
end if;
if (cs2=0) then t21<= "1000000" ;
elsif (cs2=1) then t21<= "1111001" ;
elsif (cs2=2) then t21<= "0100100" ;
elsif (cs2=3) then t21<= "0110000" ;
elsif (cs2=4) then t21<= "0011001" ;
elsif (cs2=5) then t21<= "0010010" ;
elsif (cs2=6) then t21<= "0000010" ;
elsif (cs2=7) then t21<= "1111000" ;
elsif (cs2=8) then t21<= "0000000" ;
elsif (cs2=9) then t21<= "0010000" ;
else t11<= "0010000";
end if;
else l1<='0';l2<='0';a<='0';b<='0';
end if;
else l1<='0';l2<='0';a<='0';b<='0';
cs1<=0 ; cs2<=0 ;
l1<='0' ; l2<='0' ;
end if;
light1<=l1;
light2<=l2;
t12<="1000000";
t22<="1000000";
end if;
end process;
end stru;
程序说明:
根据程序设计要求,该模块主要包含3部分功能,即抢答、加分、显示,各部分的实现如下:
a) 抢答部分
抢答部分主要由i1和i2两个输入端控制,其功能具体为:当i1或者i2中的一个有信号输入时,其所对应的抢答标志灯就将亮起,此时另一人再按键无效,则此时视为其抢答成功。
相关代码为:
if (i1 ='0' and a='0') then l1<='1'; a<= '1' ;
elsif ( i2 ='0' and a='0') then l2<='1'; a<= '1' ;
end if;
light1<=l1;
light2<=l2;
其中a为控制仅使其中一人抢答成功的标志信号,初始为0,抢答成功它就会变为1,此时不会再执行所有有关抢答部分的代码。当light1或light2为1时其所对应的抢答标志灯将亮起。
a) 加分部分
加分部分由三个输入端g10、g20、g30控制,分别代表加10分、20分、30分。当某位选手抢答成功时,通过这3个输入端可以为这位选手加分。
加分部分的代码为:
if (g10 ='0' and l1='1' and b='0' ) then cs1<=cs1+1 ; b<='1' ;
elsif (g20 ='0' and l1='1' and b='0' ) then cs1<=cs1+2 ; b<='1' ;
elsif (g30 ='0' and l1='1' and b='0' ) then cs1<=cs1+3 ; b<='1' ;
end if;
if(g10='0' and l2='1' and b='0') then cs2<=cs2+1;b<='1';
elsif(g20='0' and l2='1' and b='0') then cs2<=cs2+2;b<='1';
elsif(g30='0' and l2='1' and b='0') then cs2<=cs2+3;b<='1';
end if;
由于当每次某位选手抢答成功后,只能进行一次加分,这就由b来控制,每次加分完成后b变为1,此时将不再执行任何与加分有关的代码,cs1和cs2的值分别代表两位选手分数的十位数值。
b) 显示部分
抢答器需要靠七段数码管来显示两位选手的分数,设计的程序代码如下:
if (cs1=0) then t11<="1000000";
elsif (cs1=1) then t11<= "1111001";
elsif (cs1=2) then t11<= "0100100";
elsif (cs1=3) then t11<= "0110000";
elsif (cs1=4) then t11<= "0011001";
elsif (cs1=5) then t11<= "0010010";
elsif (cs1=6) then t11<= "0000010";
elsif (cs1=7) then t11<= "1111000";
elsif (cs1=8) then t11<= "0000000";
elsif (cs1=9) then t11<= "0010000";
else t11<= "0010000";
end if;
if (cs2=0) then t21<= "1000000" ;
elsif (cs2=1) then t21<= "1111001" ;
elsif (cs2=2) then t21<= "0100100" ;
elsif (cs2=3) then t21<= "0110000" ;
elsif (cs2=4) then t21<= "0011001" ;
elsif (cs2=5) then t21<= "0010010" ;
elsif (cs2=6) then t21<= "0000010" ;
elsif (cs2=7) then t21<= "1111000" ;
elsif (cs2=8) then t21<= "0000000" ;
elsif (cs2=9) then t21<= "0010000" ;
else t11<= "0010000";
end if;
两位选手通过前面抢答和加分两部分将改变cs1和cs2的数值,根据数值的不同,代表两位选手十位数值的数码管t11和t21将显示0~9中的某个数,个位t12和t22则始终显示为0。
c) 其他部分
该程序还具有clk,cong,reset这3个输入端,其中clk为时钟输入端,通过时钟上升沿的到来控制模块实现功能。cong则由裁判控制,通过这个输入端可以将抢答和加分两个部分的控制端初始化,而不会改变两位选手此时的分数,每当要进行下一轮抢答时,需要使用这个输入端。reset则可以使整个抢答器重置为初始状态。
d) 整体效果:
(五) 波形仿真:
图示为i1抢答成功并加10分的波形仿真。i1抢答成功后,抢答标志灯light1亮起,操作i2不会产生任何现象。裁判操作g10后led11显示为1,即加十分。再操作cong后,抢答标志灯不再亮,此时可以进行下一轮抢答和加分。
(六) 结果分析:
根据实验结果可知,2人抢答器的功能已经可以很好的实现。虽然在实验过程中由于种种原因出现了一些问题,但是都被一一排查,解决。这次实验也使我对VHDL语言和Quartus的使用有了比较深刻的了解。