FPGA数字跑表程序设计与防仿真_fpga数字跑表课程设计
FPGA数字跑表程序设计与防仿真由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“fpga数字跑表课程设计”。
一、设计名称:基于FPGA的数字系统设计(数字跑表)
二、设计指标:
1、跑表精度为0.01秒
2、跑表计时范围为:1小时
3、设置开始计时/停止计时、复位两个按钮
4、显示工作方式:用六位BCD七段数码管显示读数。显示格式为xx分xx秒xx0.01秒
三、设计要求:
1、设计出符合设计要求的解决方案
2、设计出单元电路
3、利用EDA软件对各单元电路及整体电路进行仿真
4、利用EDA软件在实验板上实现设计
四、方案设计:
1、由石英振荡器产生正弦信号,然后通过分频器分频产生需要的分频信号
2、由开关通过使能控制对计数器的工作状态进行控制
3、分频信号控制计数器计数
4、将计数器结果输入显示模块,完成在七段数码管上的显示
五、系统设计框图:
六、单元电路划分分频器
(1)设计思路:由于显示最末位为0.01秒故需给计数器提供100Hz的时钟信号;显示部分由于一次只能显示单只数码管,为满足设计要求一次显示六位则需提高显示模块时钟信号频率,利用视觉效应使人一次看到六位显示,故分频器需要提供100Hz和1KHz两个输出信号。分频器通过计数的方法实现分频功能。
(2)元件符号:
(3)源程序:
library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity clock is
Port(clk : in STD_LOGIC;
clk1 : out STD_LOGIC;
clk2 : out STD_LOGIC);end clock;
architecture Behavioral of clock is signal fcount1:integer range 1 to 24000:=1;signal fcount2:integer range 1 to 5:=1;signal clk1_tmp:STD_LOGIC:='0';signal clk2_tmp:STD_LOGIC:='0';begin
proce(clk,fcount1,clk1_tmp)
begin
if clk'event and clk = '1' then
if fcount1= 24000 then
fcount1
clk1_tmp
fcount1
end if;
end if;
end proce;clk1
begin
if clk1_tmp'event and clk1_tmp = '1' then
if fcount2= 5 then
end proce;clk2
fcount2
clk2_tmp
fcount2
end if;
end if;
(4)仿真结果:
(5)结果分析:
仿真结果显示分频程序正确的产出了实验所需频率信号.十进制计数器
(1)源程序:
library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity counter10 is
Port(rst : in STD_LOGIC;
clk : in STD_LOGIC;
carry_in : in STD_LOGIC;
carry_out : out STD_LOGIC;
count_out : out STD_LOGIC_VECTOR(3 downto 0));end counter10;
architecture Behavioral of counter10 is
signal count_tmp:STD_LOGIC_VECTOR(3 downto 0):=“0000”;signal pause : STD_LOGIC:='1';begin proce(clk,rst,carry_in,count_tmp)begin if rising_edge(carry_in)then pause
if rst='0' then count_tmp
carry_out
elsif clk'event and clk='1' then
if pause='1' then
if count_tmp=“1001” then
count_tmp
carry_out
ELSE
count_tmp
carry_out
end if;
end if;end if;count_out
end Behavioral;
(2)仿真结果:
(3)结果分析:
仿真结果显示当无reset信号输入时计数器正常计数并在记满时自动清零并产生进位信号,当有reset输入时会清零,程序符合设计要求.六进制计数器
(1)源程序:library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity counter6 is
Port(rst : in STD_LOGIC;
clk : in STD_LOGIC;
carry_in : in STD_LOGIC;
carry_out : out STD_LOGIC;
count_out : out STD_LOGIC_VECTOR(3 downto 0));end counter6;
architecture Behavioral of counter6 is
signal count_tmp:STD_LOGIC_VECTOR(3 downto 0):=“0000”;
begin
proce(clk,rst,carry_in,count_tmp)begin if rst='0' then count_tmp
carry_out
elsif clk'event and clk='1' then
if carry_in='1' then
if count_tmp=“0101” then
count_tmp
carry_out
ELSE
count_tmp
carry_out
end if;
end if;end if;count_out
end Behavioral;
(2)仿真结果: 显示模块
(1)设计思路:数码管显示需要对应位置显示对应位数的时间,故需要一个信号同时选择六个地址输入的一个和其所对应的数码管,因此需要一个六位计数器产生这个选择信号。前级计数器的地址输入为4位地址输入而数码管段选信号为7位信号,因而需要对输入的地址信号进行七段译码。由于硬件要求还需输出一低电平信号使数码管能正常工作。
(2)元件符号:
(3)源程序: library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;
----Uncomment the following library declaration if instantiating----any Xilinx primitives in this code.--library UNISIM;--use UNISIM.VComponents.all;
entity xiansi is
PORT(count_out1 : in STD_LOGIC_VECTOR(3 downto 0);
count_out2 : in STD_LOGIC_VECTOR(3 downto 0);
count_out3 : in STD_LOGIC_VECTOR(3 downto 0);
count_out4 : in STD_LOGIC_VECTOR(3 downto 0);
count_out5 : in STD_LOGIC_VECTOR(3 downto 0);
count_out6 : in STD_LOGIC_VECTOR(3 downto 0);
clk
: in STD_LOGIC;
led
: out STD_LOGIC_VECTOR(6 downto 0);
sel:out STD_LOGIC_VECTOR(2 downto 0);
led_en: out STD_LOGIC);
end xiansi;
architecture Behavioral of xiansi is
signal sel_tmp: STD_LOGIC_VECTOR(2 downto 0);signal y_tmp : STD_LOGIC_VECTOR(3 downto 0);
begin proce(clk)begin if clk'event and clk = '1' then
if sel_tmp=“101” then
sel_tmp
else
sel_tmp
end proce;
proce(sel_tmp,count_out1,count_out2,count_out3,count_out4,count_out5,count_out6)begin
case sel_tmp is
when “000”=>y_tmpy_tmpy_tmpy_tmpy_tmpy_tmpy_tmp
end case;end proce;
proce(y_tmp)begin case y_tmp is
when “0000”=>led
when “0001”=>ledledledledledledledledledled
(5)结果分析:
仿真结果显示显示模块程序符合设计要求
七、设计实现
(1)
通过元件调用将上述做好的各个模块电路连接起来。
程序如下: library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;
----Uncomment the following library declaration if instantiating----any Xilinx primitives in this code.--library UNISIM;--use UNISIM.VComponents.all;
entity top_mod is
port(clk:in std_logic;
rst:in std_logic;
enable:in std_logic;
led:out STD_LOGIC_VECTOR(6 downto 0);
sel:out STD_LOGIC_VECTOR(2 downto 0);
led_en:out std_logic);
end top_mod;
architecture Behavioral of top_mod is
component clock
Port(clk : in STD_LOGIC;
clk1 : out STD_LOGIC;
clk2 : out STD_LOGIC);end component;
component diaoyong
PORT(reset : in STD_LOGIC;
clk : in STD_LOGIC;
en : in STD_LOGIC;
count_out1 : out STD_LOGIC_VECTOR(3 downto 0);
count_out2 : out STD_LOGIC_VECTOR(3 downto 0);
count_out3 : out STD_LOGIC_VECTOR(3 downto 0);
count_out4 : out STD_LOGIC_VECTOR(3 downto 0);
count_out5 : out STD_LOGIC_VECTOR(3 downto 0);
count_out6 : out STD_LOGIC_VECTOR(3 downto 0));end component;
component xiansi
PORT(count_out1 : in STD_LOGIC_VECTOR(3 downto 0);
count_out2 : in STD_LOGIC_VECTOR(3 downto 0);
count_out3 : in STD_LOGIC_VECTOR(3 downto 0);
count_out4 : in STD_LOGIC_VECTOR(3 downto 0);
count_out5 : in STD_LOGIC_VECTOR(3 downto 0);
count_out6 : in STD_LOGIC_VECTOR(3 downto 0);
clk
: in STD_LOGIC;
led
: out STD_LOGIC_VECTOR(6 downto 0);
sel:out STD_LOGIC_VECTOR(2 downto 0);
led_en:out std_logic);end component;
signal clk_1,clk_2:std_logic;
signal count_out1 :
STD_LOGIC_VECTOR(3 downto 0);
signal count_out2 :
STD_LOGIC_VECTOR(3 downto 0);signal count_out3 :
STD_LOGIC_VECTOR(3 downto 0);signal count_out4 :
STD_LOGIC_VECTOR(3 downto 0);signal count_out5 :
STD_LOGIC_VECTOR(3 downto 0);signal count_out6 :
STD_LOGIC_VECTOR(3 downto 0);
begin
s1:clock
PORT MAP(clk,clk_1,clk_2);
s2:diaoyong
PORT MAP(rst,clk_2,enable,count_out1,count_out2,count_out3,count_out4,count_out5,count_out6);
s3:xiansi
port MAP(count_out1,count_out2,count_out3,count_out4,count_out5,count_out6,clk_1,led,sel,led_en);end Behavioral;
(2)管脚配置:
clk=>T8;reset=>E4;ignal=>G6;G=>D7;sel0=>F8;sel1=>D8;sel2=>E7;led0=>A11;led1=>B12;led2=>A12;led3=>C12;led4=>C13;led5=>A13;led6=>B14
(3)下载过程:
①双击【 Generate Programing File】 ②关闭弹出的窗口
③双击【 Generate Prom, ACE,or JTAG File】
④双击【 Finish】,选择后缀为bit的文件,单击【 Open】,最后单击【 Bypa 】 ⑤光标移至该图标,单击右键,然后单击【Program】,点击【OK】,下载成功
八、测试结果
七段数码管可以正确显示时间,从00:00:00到了59:59:99(59分59秒99*0.01s)再自动转到00:00:00,按下开始、暂停键计时暂停、开始,按下清零后计时从00:00:00重新开始。
九、心得体会
通过本次试验课程,使我对FPGA开发板有了一定的了解,对使用VHDL语言设计简单数字系统的大致步骤也有了一定的认识,对编写程序中时一些基本结构和细节有了一定的掌握。加深了我对使用软件让硬件电路实现某些功能的认识与联系。