11倪少平第二次作业.docx
- 文档编号:5452727
- 上传时间:2022-12-16
- 格式:DOCX
- 页数:10
- 大小:145.19KB
11倪少平第二次作业.docx
《11倪少平第二次作业.docx》由会员分享,可在线阅读,更多相关《11倪少平第二次作业.docx(10页珍藏版)》请在冰豆网上搜索。
11倪少平第二次作业
VHDL第2次作业
题目:
计数显示电路
姓名:
倪少平
学号:
1201120471
一、题目要求:
输出为3位BCD码的计数显示电路。
该计数显示电路由三个模块构成:
1、十进制计数器(BCD_CNT)
2、七段显示译码器电路(DEC_LED)
3、分时总线切换电路(SCAN)
根据逻辑图采用层次化的结构设计方法,系统的原理框图如下所示:
图1系统原理图
二、问题分析:
1、题目要求采用十进制加法计数器进行计数,显示在三个数码管上,那么这个计数器内部可由三个十进制计数器级联而成,输出有12位。
2、要使某个数码管点亮,则译码驱动器输出为高电平,七段译码输出为高电平。
3、要使三个数码管都点亮,则应当对其进行扫描,分时总线切换应该做一个3进制的计数器,再通过译码驱动器进行译码,扫描频率必须是计数频率的三倍以上。
通过以上分析可知,要设计这样的一个电路,应该具有四个电路模块:
十进制加法计数器、分时总线切换器、七段译码器、译码驱动器。
三、实验程序:
--十进制加法计数器
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitycount10is
port(clk,rrst:
instd_logic;
cout:
outstd_logic_vector(3downto0);
cc:
outstd_logic);
endcount10;
architecturecount10_1ofcount10is
begin
process(clk,rrst)
variablecoutnum:
std_logic_vector(3downto0);
variablec:
std_logic;
begin
ifclk'eventandclk='1'then
ifrrst='1'then
coutnum:
="0000";
c:
='0';
elsifcoutnum="1001"then
coutnum:
="0000";
c:
='1';
else
coutnum:
=coutnum+1;
endif;
endif;
cout<=coutnum;
cc<=c;
endprocess;
endcount10_1;
--把三个十进制加法计数器级联起来,形成长度为0-999的BCD码加法计数器
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitycountis
port(clk,rrst:
instd_logic;
ddout:
outstd_logic_vector(11downto0));
endcount;
architecturecount12ofcountis
componentcount10is
port(clk,rrst:
instd_logic;
cout:
outstd_logic_vector(3downto0);
cc:
outstd_logic);
endcomponentcount10;
signalc1,c2,c3:
std_logic;
begin
i1:
count10portmap(clk=>clk,rrst=>rrst,cout=>ddout(3downto0),cc=>c1);
i2:
count10portmap(clk=>c1,rrst=>rrst,cout=>ddout(7downto4),cc=>c2);
i3:
count10portmap(clk=>c2,rrst=>rrst,cout=>ddout(11downto8));
endcount12;
--分时总线切换器
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityscanis
port(clkd:
instd_logic;
d:
instd_logic_vector(11downto0);
q:
outstd_logic_vector(3downto0);
sel:
outstd_logic_vector(1downto0));
endscan;
architecturescan_1ofscanis
begin
process(clkd,d)
variablescannum:
std_logic_vector(1downto0);
begin
ifclkd'eventandclkd='1'then
ifscannum="10"then
scannum:
="00";
else
scannum:
=scannum+1;
endif;
casescannumis
when"00"=>q<=d(3downto0);
when"01"=>q<=d(7downto4);
when"10"=>q<=d(11downto8);
whenothers=>q<=null;
endcase;
endif;
sel<=scannum;
endprocess;
endscan_1;
--七段译码器的VHDL描述
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitydecode_ledis
port(num:
instd_logic_vector(3downto0);
led:
outstd_logic_vector(6downto0));
enddecode_led;
architecturedecodeofdecode_ledis
begin
process(num)
begin
casenumis
when"0000"=>led<="0111111";
when"0001"=>led<="0000110";
when"0010"=>led<="1011011";
when"0011"=>led<="1001111";
when"0100"=>led<="1100110";
when"0101"=>led<="1101101";
when"0110"=>led<="1111101";
when"0111"=>led<="0100111";
when"1000"=>led<="1111111";
when"1001"=>led<="1101111";
whenothers=>led<="0000000";
endcase;
endprocess;
enddecode;
--译码驱动电器
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitysel_ledis
port(selin:
instd_logic_vector(1downto0);
selout:
outstd_logic_vector(2downto0));
endsel_led;
architecturesel_led_1ofsel_ledis
begin
process(selin)
begin
caseselinis
when"00"=>selout<="001";
when"01"=>selout<="010";
when"10"=>selout<="100";
whenothers=>selout<="000";
endcase;
endprocess;
endsel_led_1;
--用元件例化的方式写顶层电路描述
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitybcd_counteris
port(clk,clkd:
instd_logic;
rrst:
instd_logic;
ddataout:
outstd_logic_vector(6downto0);
sdataout:
outstd_logic_vector(2downto0));
endbcd_counter;
architecturebcdcounterofbcd_counteris
signals1:
std_logic_vector(11downto0);
signals2:
std_logic_vector(3downto0);
signals3:
std_logic_vector(1downto0);
componentcountis
port(clk,rrst:
instd_logic;
ddout:
outstd_logic_vector(11downto0));
endcomponentcount;
componentscanis
port(clkd:
instd_logic;
d:
instd_logic_vector(11downto0);
q:
outstd_logic_vector(3downto0);
sel:
outstd_logic_vector(1downto0));
endcomponentscan;
componentdecode_ledis
port(num:
instd_logic_vector(3downto0);
led:
outstd_logic_vector(6downto0));
endcomponentdecode_led;
componentsel_ledis
port(selin:
instd_logic_vector(1downto0);
selout:
outstd_logic_vector(2downto0));
endcomponentsel_led;
begin
u1:
countportmap(clk=>clk,rrst=>rrst,ddout=>s1);
u2:
scanportmap(clkd=>clkd,d=>s1,q=>s2,sel=>s3);
u3:
decode_ledportmap(num=>s2,led=>ddataout);
u4:
sel_ledportmap(selin=>s3,selout=>sdataout);
endbcdcounter;
四、仿真结果及分析
4.1将程序的四个模块分别进行仿真,验证每个模块的正确性。
4.1.1十进制计数器的仿真结果如图所示
十进制计数器(BCD_CNT)完成计数长度为0-999的BCD码加法计数,输出数据总线的宽度为12位。
图2十进制加法计数器仿真结果
4.1.2分时总线切换电路的仿真结果
将12位二进制数据总线分时送到七段显示译码电路。
图3总线切换电路仿真结果
4.1.3七段显示译码电路仿真结果
图4七段译码显示电路仿真结果
4.1.4译码驱动器的仿真结果
图5驱动译码器仿真结果
从四个模块的仿真结果可以知道,十进制加法计数器、分时总线切换器、七段译码器、译码驱动器完全达到要求,说明了每个电路模块的正确性。
4.2将各个模块组合起来的仿真的结果
4.2.1用quartusII软件自动生成RTL级电路,从顶层电路可以看出,它的基本模块与题设要求或上面原理图输入方式输入的电路图完全相同,因此符合设计要求。
图6自动生成的RTL级电路
4.2.2输出三位BCD的计数显示电路的仿真结果
图7总程序的仿真结果
从上面的仿真结果可以看出,译码驱动器的输出信号sdataout输出为001、010、100、001、010、100……。
然而七段译码显示电路输出信号ddataout输出信号随着sdataout依次显示出个位、十位和百位数字,结果符合题目要求。
五、实验总结
这次实验的题目是一个综合性的课程设计,其中很多模块都是我们设计过的东西,因此我们的主要任务是将之前设计过的程序正确、有效地有机连接起来。
在计数器的设计上使用三个十进制的计数器级联的方式来分别实现个位、十位、百位,这样可以使设计的电路层次化清晰,便于调试。
考虑到组合电路的一些竞争冒险现象,计数器输出貌似有点毛刺,这可能会使输出结果不稳定,这可以通过修改设计,或者更改逻辑表达式等多种方法来消除。
扫描时钟频率clkd必须为十进制计数时钟clk三倍或三倍以上,否则扫描到的数值状态会发生变化,不能扫描到所有的值,即会出现如下图中的情况。
由下图可以看出,输出的个位从1直接跳到3,而到2的时候没有扫描到没有显示出来。
图8扫描频率是时钟频率的2倍是的仿真结果
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 11 倪少平 第二次 作业