基于FPGA的数字跑表的设计学士学位论文_第1页
基于FPGA的数字跑表的设计学士学位论文_第2页
基于FPGA的数字跑表的设计学士学位论文_第3页
基于FPGA的数字跑表的设计学士学位论文_第4页
基于FPGA的数字跑表的设计学士学位论文_第5页
已阅读5页,还剩27页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、基于FPGA的数字跑表的设计陈宝锋 17摘要:以硬件描述语言(Verilog或VHDL)所完成的电路设计,可以经过简单的综合与布局,快速的烧录至 FPGA 上进行测试,是现代 IC设计验证的技术主流。这些可编辑元件可以被用来实现一些基本的逻辑门电路(比如AND、OR、XOR、NOT)或者更复杂一些的组合功能比如解码器或数学方程式。在大多数的FPGA里面,这些可编辑的元件里也包含记忆元件例如触发器(Flipflop)或者其他更加完整的记忆块。第1章 引言本设计是基于FPGA利用VHDL语言实现硬件电路的描述实现一个智力抢答器的设计,完成6位选手在规定的时间内(10秒)按键抢答;抢中编号锁定显示,

2、其他无效;主持按键控制清零和开始选手抢中后在规定的时间内(30秒)答提;具有报警提示功能,分别提示抢答开始,有人抢答,抢答时间到,答题时间到。报警延时为1s;。设计使用的FPGA软件开发平台为Xilinx的ISE,它具有界面简单、简单易学、辅助功能强大等特点。在编写代码时可以使用编写向导生成头文件和模块框架,也可以使用语言模块帮助编写代码。实验使用的仿真软件为ModelSim,该软件具有代码分析能力可以看出不同代码段消耗资源的情况。其功能侧重于编译和仿真,不能制定编译的器件和不具有下载配置能力,所以需要和ISE等软件关联使用。第2章 实验项目方案设计2.1 项目系统设计原理系统主要要实现计数功

3、能、显示功能还有数据的锁存和读取。本设计采用了外部时钟为48Mhz的FPGA硬件开发平台。首先利用分频器将48Mhz的外部时钟分频产生100hz和1khz的始终信号,100hz的时钟用于实现精度为0.01s精度的计数器时钟,1kHz的时钟信号用于显示模块扫描显示的外部信号。计数器为两个六进制计数器和四个十进制计数器的同步级联,同时具有清零,暂停控制端口。显示模块6只数码管采用动态扫描的连接方式,硬件电路上的每个数码管abcdefg分别连在一起,作为段选信号,8个数码管数码管分别由8个选通信号控制(这里使用到了三八译码器),由于段选信号连在一起,所以数码管的显示采用的是动态扫描的显示方式。锁存模

4、块设计时采用了六进制的计数器输出端触发,有效地完成了锁存六个时间点的实验要求,同时加入了数据锁存和数据输出选择键,完美实现了锁存数据的输出。2.2 项目系统设计方案及模块组成图一为此次设计的基本构架和模块组成(不包含消抖模块)。系统的主要组成模块主要有消抖电路模块、分频器模块、计数器模块、锁存器模块、扫描显示模块、译码器模块、势能/选择模块。各模块的功能描述,将在第三章作介绍。具体的实现过程为:下载完成后按下get键,此时使能模块输出高电平,计数器开始计时,并在数码管上实时显示,锁存器模块进入锁存状态,start为系统的清零/复位键,sc为六进制计数器的时钟,每按一次sc键将会产生一个上升沿,

5、并计数一次,六进制的计数器的输出端触发锁存器,每记一次数锁存一组数。当再按一次get键的时候,势能/选择模块输出低电平,此时计数器停止计时,锁存器进入数据读取状态,显示模块显示读取的锁存的数据,按下start键为系统清零,当每按一次sc键,锁存器将会按锁存的顺序读取锁存的数据并显示该数据时第几次锁存下的。第3章 实验项目单元模块电路设计3.1 消抖模块设计3.1.1 模块描述分频器的功能是提供计数器的时钟信号以及数码管动态扫描部分的时钟信号。由于系统的外部时钟为48Mhz,而根据跑表的精度要求0.01s,计数器的时钟信号应为100hz,因此需要对48MHZ的时钟信号进行分频,得到100hz的信

6、号,作为时钟的计数时钟。根据显示部分的原理,需要1khz的扫描控制信号,因此在分频器部分还要产生1khz的信号。分频器的设计采用基于计数器的方法来实现。在本设计中,在程序的第一个进程中设计了一个24000进制的计数器,当计数24000个时钟,分频输出信号clk1kHz取反,这样就可以实现对输入时钟的48000次分频,从而得到1kHz的输出信号。在第二个进程中采用同样的方法对已经得到的1khz的信号进行10分频得到100hz的输出信号clk100hz。分频模块如图二所示:clkin为48Mhz的外部时钟输入端clk1khz为输出1khz的时钟输出端clk100hz为输出为100hz的时钟输出端该

7、模块的VHDL源程序如下:library IEEE;use IEEE.STD_LOGIC_1164.ALL;entity div isport( clkin: in std_logic; clk1khz: out std_logic; clk100hz: out std_logic);end div;architecture Behavioral of div issignal cnter0: integer range 0 to 23999 :=0; signal cnter1: integer range 0 to 4 :=0; signal clk100hz_TMP,clk1khz_TM

8、P: std_logic:=0;beginprocess(clkin) is begin if clkinevent and clkin=1 then if cnter0 = 23999 then cnter0 =0; clk1khz_TMP =not clk1khz_TMP; else cnter0 =cnter0+1; end if; end if;end process; clk1khz=clk1khz_TMP;process(clk1khz_TMP) isbegin if clk1khz_TMPevent and clk1khz_TMP = 1 then if cnter1= 4 th

9、en cnter1=0; clk100hz_TMP= not clk100hz_TMP; else cnter1= cnter1 +1; end if; end if;end process;clk100hz clkin, clk1khz = clk1khz, clk100hz = clk100hz ); - Clock process definitions clkin_process :process beginclkin = 0;wait for clkin_period/2;clkin = 1;wait for clkin_period/2; end process; END;仿真波形

10、:波形分析:由仿真波形可以看出clk100hz波形的一个周期等于clk1khz的十倍,实现了分频器的分频功能。3.2计数器模块的设计3.2.1 模块描述由于要求秒表显示为六位,每一位可以视为一个一位计数器,则跑表的计数过程可由6个一位计数器级联完成,其中包括十进制的计数器4个,六进制的计数器2个。其中rst是清零端,clk100hz是计数器信号输入端,carryin是计数器的使能端,高电平时计数,低电平时停止计数且保持计数不变。Carryout是计数结果的输出,countout是进位端。下图为计数器的同步级联原理。十进制计数器的VHDL源程序如下:library IEEE;use IEEE.S

11、TD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity COUNTER1 isport( res,clk100hz: in std_logic;carryin: in std_logic; carryout: out std_logic; counterout: out std_logic_vector(3 downto 0);end COUNTER1;architecture Behavioral of COUNTER1 issignal count:std_logic_vec

12、tor(3 downto 0):=0000;beginprocess(res,clk100hz)beginif res=1 then count=0000;elsif clk100hzevent and clk100hz=1 thenif carryin=1then if count 1001 thencount =count+1;else count=0000;end if; else null;end if;end if;end process;counterout=count;carryout=1when carryin=1and count=1001else0;end Behavior

13、al;六进制计数器的VHDL源程序如下:library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity COUNTER6 isport( res,clk100hz: in std_logic;carryin: in std_logic; carryout: out std_logic; counterout: out std_logic_vector(3 downto 0);end COUNTER6;architecture Behavior

14、al of COUNTER6 issignal count:std_logic_vector(3 downto 0):=0000;beginprocess(res,clk100hz)beginif res=1 then count=0000;elsif clk100hzevent and clk100hz=1 thenif carryin=1then if count 0101 thencount =count+1;else count=0000;end if; else null;end if;end if;end process;counterout=count;carryout res,

15、 clk100hz = clk100hz, carryin = carryin, carryout = carryout, counterout = counterout ); - Clock process definitions clk100hz_process :process beginclk100hz = 0;wait for clk100hz_period/2;clk100hz = 1;wait for clk100hz_period/2; end process; - Stimulus process stim_proc: process begin res=0; carryin

16、=1; - hold reset state for 100 ns. wait for 100 ns; wait for clk100hz_period*10; - insert stimulus here wait; end process;END;仿真波形:波形分析:由波形可以看出counterout每遇到一个适时钟的上升沿将会加一,carryout在遇到第十个上升沿是会出现一个上升沿,就会产生进位输出,仿真结果与预期结果一致。3.3显示模块设计3.3.1模块描述本设计中7只数码管采用动态扫描的连接方式。硬件电路上的每个数码管abcdefg分别连在一起作为段选信号。根据硬件电路的连接方式,

17、如果希望七个数码管显示计数器输出的数据,就必须是的7个选通信号分别被单独选通,所以我们设计了sel输出端作为位选信号的输出端。LED为7段数码管的段选信号的输出端。counterout1counterout7为计数器实时计数显示的输入端口,Countout1Countout7为锁存输出信号显示的输入端。e为选择输入端,当e为高电平时,显示模块的将显示counterout1counterout7的信号。当e为低电平时,显示模块将显示Countout1Countout7的信号。Clk1khz为时钟信号的输入端。高频率的时钟可以保证人眼很难分辨出数码管的独立显示。G为低电平有效,根据硬件电路,需设置

18、一个译码势能信号。模块的源程序:library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity DISPLAY isport( counterout1: in std_logic_vector(3 downto 0); counterout2: in std_logic_vector(3 downto 0); counterout3: in std_logic_vector(3 downto 0); counterout4: in std_l

19、ogic_vector(3 downto 0); counterout5: in std_logic_vector(3 downto 0); counterout6: in std_logic_vector(3 downto 0); counterout7: in std_logic_vector(3 downto 0); Countout1: in std_logic_vector(3 downto 0); Countout2: in std_logic_vector(3 downto 0); Countout3: in std_logic_vector(3 downto 0); Count

20、out4: in std_logic_vector(3 downto 0); Countout5: in std_logic_vector(3 downto 0); Countout6: in std_logic_vector(3 downto 0); Countout7: in std_logic_vector(3 downto 0); led: out std_logic_vector(6 downto 0); G: out std_logic; clk1khz: in std_logic; e : in std_logic; sel: out std_logic_vector(2 dow

21、nto 0);end DISPLAY;architecture Behavioral of DISPLAY issignal cnt : std_logic_vector(2 downto 0):=000; signal data : std_logic_vector(3 downto 0);begin scan : process(clk1khz) begin if rising_edge(clk1khz) then if cnt = 101 thencnt= 000;elsecnt data data data data data data data data data data data

22、 data data data= Countout7;end case;end if; end process;bcd2led :process(data) begin led led led led led led led led led led led null;end case;end process;G= 0;sel 0); signal counterout2 : std_logic_vector(3 downto 0) := (others = 0); signal counterout3 : std_logic_vector(3 downto 0) := (others = 0)

23、; signal counterout4 : std_logic_vector(3 downto 0) := (others = 0); signal counterout5 : std_logic_vector(3 downto 0) := (others = 0); signal counterout6 : std_logic_vector(3 downto 0) := (others = 0); signal Countout1 : std_logic_vector(3 downto 0) := (others = 0); signal Countout2 : std_logic_vec

24、tor(3 downto 0) := (others = 0); signal Countout3 : std_logic_vector(3 downto 0) := (others = 0); signal Countout4 : std_logic_vector(3 downto 0) := (others = 0); signal Countout5 : std_logic_vector(3 downto 0) := (others = 0); signal Countout6 : std_logic_vector(3 downto 0) := (others = 0); signal

25、clk1khz : std_logic := 0; signal e : std_logic := 0; -Outputs signal led : std_logic_vector(6 downto 0); signal G : std_logic; signal sel : std_logic_vector(2 downto 0); - Clock period definitions constant clk1khz_period : time := 10 ns;BEGIN- Instantiate the Unit Under Test (UUT) uut: DISPLAY PORT

26、MAP ( counterout1 = counterout1, counterout2 = counterout2, counterout3 = counterout3, counterout4 = counterout4, counterout5 = counterout5, counterout6 = counterout6, Countout1 = Countout1, Countout2 = Countout2, Countout3 = Countout3, Countout4 = Countout4, Countout5 = Countout5, Countout6 = Count

27、out6, led = led, G = G, clk1khz = clk1khz, e = e, sel = sel ); - Clock process definitions clk1khz_process :process beginclk1khz = 0;wait for clk1khz_period/2;clk1khz = 1;wait for clk1khz_period/2; end process; - Stimulus process stim_proc: process begin counterout1 = 0001; counterout2 = 0010; count

28、erout3 = 0011; counterout4 = 0001; counterout5 = 0010; counterout6 = 0011; e=1;wait for 100 ns; Countout1 = 0010; Countout2 = 0011; Countout3 = 0001; Countout4 = 0010; Countout5 = 0011; Countout6 = 0001; e led led led led led led led led led led data1= numin1; data2= numin2; data3= numin3; data4= nu

29、min4; data5= numin5; data6= numin6; data7 data1_1= numin1; data2_1= numin2; data3_1= numin3; data4_1= numin4; data5_1= numin5; data6_1= numin6; data7_1 data1_2= numin1; data2_2= numin2; data3_2= numin3; data4_2= numin4; data5_2= numin5; data6_2= numin6; data7_2 data1_3= numin1; data2_3= numin2; data

30、3_3= numin3; data4_3= numin4; data5_3= numin5; data6_3= numin6; data7_3 data1_4= numin1; data2_4= numin2; data3_4= numin3; data4_4= numin4; data5_4= numin5; data6_4= numin6; data7_4 data1_5= numin1; data2_5= numin2; data3_5= numin3; data4_5= numin4; data5_5= numin5; data6_5= numin6; data7_5data1_6= numin1; data2_6= numin2; data3_6= numin3; data4_6= numin4; data5_6= numin5; data6_6= numin6; data7_6numout1=data1; numout2=data2; numout3=data3; numout4=data4; numout5=data5; numout6=data6; numout7 numout1=data1_1; numout2=data2_1; numout3=data3_1; numout4=data4_1; nu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论