学校:
学院:
班级:
姓名:
学号:
指导教师:
模60倒计时器
一、实验目的
1.使用VHDL语言设计数字电路。
2.熟悉Quartus II开发环境,掌握基本操作。
3.学会使用FPGA开发板进行开发。
二、实验仪器
1.电脑一台。
2. FPGA开发板一块。
三、实验原理与设计
1.分频器设计
(1)原理设计
使用实验板上的50MHz时钟信号,因此需要对该时钟信号进行分频,以得到1Hz时钟信号,供计数器使用。
(2)VHDL语言描述
library ieee;
use ieee.std_logic_11.all;
use ieee.std_logic_unsigned.all;
entity divider is
port(
CLK:in std_logic;
OUT_CLK:out std_logic
);
end divider;
architecture one of divider is
signal count:std_logic_vector(31 downto 0):=x"00000000";
signal flag:std_logic:='0';
begin
process(CLK)
begin
if CLK'event and CLK='1' then
if count<24999999 then
count<=count+1;
else
count<=(others=>'0');
flag<=not flag;
end if;
end if;
end process;
OUT_CLK<=flag;
end one;
(3)RTL视图
(4)符号表示
2.计数器设计
(1)原理设计
计数器为模60倒计时计数器,分成十位与个位两部分。个位减到0后再减则十位减1,个位减完后为9。当两位数为“00”时输出借位,再减1则为“59”。另外,设计计数使能、异步清零功能。
(2)VHDL语言描述
library ieee;
use ieee.std_logic_11.all;
use ieee.std_logic_unsigned.all;
entity cnt60 is
port(
CLK:in std_logic;
OUT_H:out std_logic_vector(3 downto 0);
OUT_L:out std_logic_vector(3 downto 0);
EN:in std_logic;
CL:in std_logic;
OC:out std_logic
);
end cnt60;
architecture one of cnt60 is
signal s_h:std_logic_vector(3 downto 0):=(others=>'0');
signal s_l:std_logic_vector(3 downto 0):=(others=>'0');
signal s_oc:std_logic:='0';
begin
process(EN,CL,CLK)
begin
if CL='0' then
s_h<=(others=>'0');
s_l<=(others=>'0');
elsif EN='1' then
if CLK'event and CLK='1' then
if s_oc='1' then
s_oc<='0';
end if;
if s_l>0 then
s_l<=s_l-1;
if s_h="0000" and s_l="0001" then
s_oc<='1';
end if;
else
s_l<="1001";
if s_h>0 then
s_h<=s_h-1;
else
s_h<="0101";
end if;
end if;
end if;
end if;
end process;
OUT_L<=s_l;
OUT_H<=s_h;
OC<=s_oc;
end one;
(3)RTL视图
(4)符号表示
3. 7段数码管译码器
(1)原理设计
数码管原理如下图所示:
实验板上的数码管为共阳数码管,显示的数字与对应编码为
显示 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
编码 | 0xC0 | 0xF9 | 0xA4 | 0xB0 | 0x99 | 0x92 | 0x82 | 0xF8 | 0x80 | 0x90 |
library ieee;
use ieee.std_logic_11.all;
entity decoder is
port(
in_data:in std_logic_vector(3 downto 0);
out_code:out std_logic_vector(7 downto 0)
);
end decoder;
architecture one of decoder is
begin
out_code<="11000000" when in_data="0000" else
"11111001" when in_data="0001" else
"10100100" when in_data="0010" else
"10110000" when in_data="0011" else
"10011001" when in_data="0100" else
"10010010" when in_data="0101" else
"10000010" when in_data="0110" else
"11111000" when in_data="0111" else
"10000000" when in_data="1000" else
"10010000" when in_data="1001" else
"11111111";
end one;
(3)RTL视图
(4)符号表示
4.整机设计
(1)原理设计
将前述各模块用语句连接在一起即可得到整机电路。
(2)VHDL语言描述
library ieee;
use ieee.std_logic_11.all;
use ieee.std_logic_unsigned.all;
entity countdown is
port(
CLK,EN,CL:in std_logic;
OC:out std_logic;
CODE_H,CODE_L:out std_logic_vector(7 downto 0)
);
end countdown;
architecture one of countdown is
component divider
port(
CLK:in std_logic;
OUT_CLK:out std_logic
);
end component;
component cnt60
port(
CLK:in std_logic;
OUT_H:out std_logic_vector(3 downto 0);
OUT_L:out std_logic_vector(3 downto 0);
EN:in std_logic;
CL:in std_logic;
OC:out std_logic
);
end component;
component decoder
port(
in_data:in std_logic_vector(3 downto 0);
out_code:out std_logic_vector(7 downto 0)
);
end component;
signal s_clk:std_logic;
signal s_h,s_l:std_logic_vector(3 downto 0);
begin
u1:divider port map(CLK=>CLK,OUT_CLK=>s_clk);
u2:cnt60 port map(CLK=>s_clk,OUT_H=>s_h,OUT_L=>s_l,EN=>EN,CL=>CL,OC=>OC);
u3:decoder port map(in_data=>s_h,out_code=>CODE_H);
u4:decoder port map(in_data=>s_l,out_code=>CODE_L);
end one;
(3)RTL视图
(4)符号表示
四、实验内容与步骤
1.波形仿真
(1)分频器仿真
为了仿真观察方便,对时钟信号CLK进行了10分频。
(2)计数器仿真
(3)7段数码管译码器仿真
(4)整机仿真
为了仿真观察方便,对时钟信号CLK进行了4分频。
2.上板测试
将程序下载到开发板,运行效果如下图所示:
五、实验总结
通过本次数字电路EDA实验,学会了使用VHDL语言设计简单的数字电路;熟悉了Quartus II开发环境,掌握了基本操作;学会了使用FPGA开发板进行简单的开发。在自己写程序、调试过程中也遇到了一些问题,通过查资料,问老师等途径解决了问题,提高了自己应用知识与动手实践的能力。最后,感谢老师与学长的耐心指导!