基于VHDL任意进制计数器(100以内)设计.doc
《基于VHDL任意进制计数器(100以内)设计.doc》由会员分享,可在线阅读,更多相关《基于VHDL任意进制计数器(100以内)设计.doc(12页珍藏版)》请在冰豆网上搜索。
VHDL课程设计
选题:
任意进制计数器(100以内)设计
班级:
学号:
11200134
姓名:
2014/5/23
12
目录
1、设计选题:
任意进制计数器(100以内)设计 3
2、设计要求 3
3、设计原理分析 3
4、程序编写、调试及仿真 4
4.1程序编写 4
4.11、n进制计数器顶层程序:
4
4.12、10进制计数器程序:
5
4.13、LED译码器程序:
6
4.14、50M分频器程序:
6
4.15、5分频程序:
7
4.16、10分频程序:
8
4.2功能仿真和芯片时序仿真 9
4.21、5分频仿真波形 9
4.22、50分频仿真波形() 9
4.23、10进制计数器仿真波形 9
4.24、LED译码器仿真波形 10
4.25、78进制计数器仿真波形 10
4.3、芯片引脚设定 10
4.4、适配下载结果 11
5、设计总结 11
1、设计选题:
任意进制计数器(100以内)设计
2、设计要求
(1)计数基数由输入确定,并采用按键所存,即按键每按下一次,存储计数基数(20—100之间),计数基数采用8421BCD码表示,否则改变开关输入无效。
(2)计数频率要求为每秒计数1次(仿真时可以调整为每10us计数1次);
(3)计数值用共阴数码管静态显示(实验板上自带);
(2)设计中系统时钟采用验证电路板上的50MHz晶振作为基准,且设计成同步电路;
(4)程序设计尽可能考虑模块化、参数化设计思想,并遵循基本的格式规范,添加适当的注释及文档说明;
(5)采用模块化设计方式,底层模块必须进行功能仿真;
(6)下载调试并编写设计总结报告。
3、设计原理分析
先对50MHz时钟信号分频得到1Hz,然后调用两个10进制计数器,计数到所输入的计数周期n后回到初始0的计数状态,每个10进制计数的计数结果通过显示译码送到两位数码管上显示。
判断计数器(20-100之间)是否计满计数周期的方式是:
将计数基数采用两个8421BCD码表示,分别为ge[3:
0]、shi[3:
0],将两个计数器计数产生的中间结果分别用“按位异或”(每位使用“(not(cont_tmp10(3)xorshi(3))”的方式实现)分别比对,当ge、shi每位都相同时,则说明计数完毕,重新载入初值”0000”,同时产生进位信号en_out,之后进入下一次计数周期,并以此循环。
结构框图如下:
4、程序编写、调试及仿真
(芯片型号:
MAXⅡ系列EPM1270T144C5)
4.1程序编写
4.11、n进制计数器顶层程序:
libraryieee;
useieee.std_logic_1164.all;
entitycount_nis
port(clk,rst,en:
instd_logic;
ge,shi:
instd_logic_vector(3downto0);
count_data10,count_data1:
outstd_logic_vector(6downto0);
en_out:
outstd_logic
);
endcount_n;
architecturertlofcount_nis
componentdivide_50Mport(clk,rst:
instd_logic;en_out:
outstd_logic);
endcomponent;
componentcount_10port(clk,rst,en_in,ld:
instd_logic;
data_in:
instd_logic_vector(3downto0);
data_out:
outstd_logic_vector(3downto0);
en_out:
outstd_logic);
endcomponent;
componentdecodeport(data_in:
instd_logic_vector(3downto0);
dis_num:
outstd_logic_vector(6downto0));
endcomponent;
signalcont_tmp10,cont_tmp1,data_in:
std_logic_vector(3downto0);
signalld,ks,sec_en,sec_en10,min_out,fuwei:
std_logic;
begin
data_in<="0000";
ks<=sec_enanden;
ld<=((not(cont_tmp10(3)xorshi(3)))and(not(cont_tmp10
(2)xorshi
(2)))and(not(cont_tmp10
(1)xorshi
(1)))and(not(cont_tmp10(0)xorshi(0)))and(not(cont_tmp1(3)xorge(3)))and(not(cont_tmp1
(2)xorge
(2)))and(not(cont_tmp1
(1)xorge
(1)))and(not(cont_tmp1(0)xorge(0))));
en_out<=ld;
U0:
divide_50Mportmap(clk,rst,sec_en);
U1:
count_10portmap(clk,rst,ks,ld,data_in,cont_tmp1,sec_en10);
U2:
count_10portmap(clk,rst,sec_en10,ld,data_in,cont_tmp10,min_out);
U3:
decodeportmap(cont_tmp1,count_data1);
U4:
decodeportmap(cont_tmp10,count_data10);
endrtl;
4.12、10进制计数器程序:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
useieee.std_logic_arith.all;
entitycount_10is
port(clk,rst,en_in,ld:
instd_logic;
data_in:
instd_logic_vector(3downto0);
data_out:
outstd_logic_vector(3downto0);
en_out:
outstd_logic
);
endcount_10;
architecturertlofcount_10is
signalcont_tmp:
std_logic_vector(3downto0);
begin
en_out<=en_inandcont_tmp(3)andcont_tmp(0);
data_out<=cont_tmp;
process(clk,rst)
begin
if(rst='0')then
cont_tmp<="0000";
elsif(clk'eventandclk='1')then
if(ld='1')then
cont_tmp<=data_in;
elsif(en_in='1')then
if(cont_tmp="1001")then
cont_tmp<="0000";
else
cont_tmp<=cont_tmp+'1';
endif;
endif;
endif;
endprocess;
endrtl;
4.13、LED译码器程序:
libraryieee;
useieee.std_logic_1164.all;
entitydecodeis
port(data_in:
instd_logic_vector(3downto0);
dis_num:
outstd_logic_vector(6downto0)
);
enddecode;
architecturertlofdecodeis
begin
withdata_inselect
dis_num<="0111111"WHEN"0000",
"0000110"WHEN"0001",
"1011011"WHEN"0010",
"1001111"WHEN"0011",
"1100110"WHEN"0100",
"1101101"WHEN"0101",
"1111101"WHEN"0110",
"0000111"WHEN"0111",
"1111111"WHEN"1000",
"1100111"WHEN"1001",
"0000000"WHENothers;
endrtl;
4.14、50M分频器程序:
libraryieee;
useieee.std_logic_1164.all;
entitydivide_50Mis
port(clk,rst:
instd_logic;
en_out:
outstd_logic
);
enddivide_50M;
architecturertlofdivide_50Mis
componentdivide_5port(clk,rst,en_in:
instd_logic;
en_out:
outstd_logic
);
endcomponent;
componentdivide_10port(clk,rst,en_in:
instd_logic;
en_out:
outstd_logic
);
endcomponent;
signalen0,en1,en2,en3,en4,en5,en6,en7:
std_logic;
begin
en_out<=en7;
U0:
divide_5portmap(clk,rst,'1',en0);
U1:
divide_10portmap(clk,rst,en0,en1);
U2:
divide_10portmap(clk,rst,en1,en2);
U3:
divide_10portmap(clk,rst,en2,en3);
U4:
divide_10portmap(clk,rst,en3,en4);
U5:
divide_10portmap(clk,rst,en4,en5);
U6:
divide_10portmap(clk,rst,en5,en6);
U7:
divide_1