FPGA课程设计
- 格式:doc
- 大小:8.84 MB
- 文档页数:10
河南机电高等专科学校《可编辑逻程器件原理与应用课程设计》题目:数字跑表班级:学号:姓名:2012年6月8日数字跑表设计一、设计题目设计一个以0.01s为基准计时信号的实用数字式跑表二、设计要求1)跑表计时显示范围0.01s—59min59.99s,计时精度为10ms。
2)具有清零、启动计时、暂停计时功能,操作按键(开关)不超过2个。
3)时钟源误差不超过0.01s。
三、总体设计思路数字秒表设计采用模块化思想,自顶向下设计。
总体上含有分频模块、计时控制器模块、计数模块、LED显示模块四个基本模块。
各模块功能如下:(1)分频模块分频器通过对256Hz时钟分频产生100Hz时钟,它同COUNT10中的十进制计数器要求的时钟频率一致。
(2)计时控制器模块计时控制器模块的作用是将按键信号转变为计时器的控制信号。
本设计中设置了2个按键,即启动/暂停键和清零键,由它们产生的计数允许保持和清零信号。
(3)计时模块计时器通过对10ms脉冲的计数,达到计时的目的。
由于数字跑表的计时范围为0到59分59.99秒,所以计时模块COUNT共需四个十进制计数器和两个六进制计时器。
(4)LED显示模块用于数字跑表的最后显示四、设计步骤如下:(1)分频模块由于试验箱没有100Hz的时钟源,所以应设计分频模块分频。
将输出256Hz 的时钟频率经过分频得到100Hz的时钟源,作为百分之一秒位的时钟输入,每产生一个时钟上升沿,计数器加1即为10ms。
新建Text Editor,以VHDL语言设计分频模块,程序源码如下:library ieee;use ieee.std_logic_1164.all;entity DIV isPort (clr:in std_logic;clk:in std_logic;clkout:out std_logic);end DIV;architecture a of DIV isbeginprocess (clk,clr)variable count: integer range 0 to 129;beginif(clr='0') thenclkout<='0';elseif(clk'event and clk='1') thencount:=count+1;if count=128 thenclkout<= not clkout;count:=0;end if;end if;end if;end process;end a;编译成功之后在执行菜单命令File—Create/Update—Create Symbol File for Current File计时控制器模块(2)计时控制器模块程序采用状态机的编程方式,其中s0是保持状态,s1是启动状态,s2是计数状态,s3是停止状态。
en为高电平有效的输出信号。
VHDL程序编写如下:library ieee;use ieee.std_logic_1164.all;entity key isport(clk,k:in std_logic;en:out std_logic);end;architecture one of key istype my_state is(s0,s1,s2,s3);signal state:my_state;beginprocess(clk)beginif (clk'event and clk='1') thencase state iswhen s0=>if k='1 'then state<=s0;else state<=s1;end if;when s1=>if k='0'then state<=s1;else state<=s2;end if;when s2=>if k='1'then state<=s2;else state<=s3;end if;when s3=>if k='0'then state<=s3;else state<=s0;end if;when others=>null;end case;end if;end process;process(clk)beginif clk'event and clk='1'thencase state iswhen s0=>en<='0';when s1=>en<='1';when s2=>en<='1';when s3=>en<='0';when others=>en<='0';end case;end if;end process;end;(三)、计时模块计时模块由四个十进制计数器和两个六进制计时器构成,这两种计数器除了时钟输入CLK和异步清零输入CLR外还设置了计数使能输入端EN.十进制计数器的VHDL程序如下:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnt10 isport(clk,clr,en:in std_logic;q:buffer std_logic_vector(3 downto 0);c10:out std_logic);end;architecture one of cnt10 isbeginprocess(clr,clk)if clr='1' then q<="0000";elsif (clk'event and clk='1') thenif en='1' thenif(q<9) then q<=q+1;else q<="0000";end if;end if;end if;end process;process(q)beginif q="1001"then c10<='1';else c10<='0';end if;end process;end;编译成功之后在执行菜单命令File—Create/Update—Create Symbol File for Current File六进制计数器的程序如下:library ieee;use ieee.std_logic_unsigned.all;entity cnt6 isport(clk,clr,en:in std_logic;q:buffer std_logic_vector(2 downto 0);c6:out std_logic);end;architecture one of cnt6 isbeginprocess(clr,clk)beginif clr='1'then q<="000";elsif (clk'event and clk='1') thenif en='1' thenif(q<5) then q<=q+1;else q<="000";end if;end if;end process;process(q)beginif q="101" then c6<='1';else c6<='0';end if;end process;end;编译成功之后在执行菜单命令File—Create/Update—Create Symbol File for Current File由上述两个程序可知:当clr为高电平时,计数器复位到0;当clr为低电平且en 为高电平时计数器开始计数。
当遇到en为低电平时,计数器停止计数,保持状态,一直到en为高电平时再进行0~9或0~ 6的加法。
(4)生成顶层文件如下图(a)所示:(5)锁引脚与编程下载采用由GW48-SOPC/EDA试验开发系统的工作模式7,验证设计结果。
有开发系统提供的硬件环境与EP1C12Q240C8芯片引脚间的对应关系选定:十进制输出msl[3..0]接数码管1,对应16~13号引脚;十进制输出msh[3..0]接数码管2,对应20~17号引脚; 十进制输出sl[3..0]接数码管4,对应引脚号由高分别为位到低位分别为132,128,41,21; 六进制输出sl[2..0]接数码管5,对应136~134引脚; 十进制输出ml[3..0]接数码管7,对应141~138引脚; 六进制输出mh[2..0]接数码管8,对应引脚号由高分别为位到低位分别为160,159,158,141;计数使能信号en 接按键5,对应237号引脚;清零信号接按键8,对应1号引脚;计数时钟信号clk接开发系统的主时钟Clock0, 对应28号引脚。
如图(b)所示:(b)锁引脚显示图形下载成功后,将系统的主时钟Clock0的跳线帽与频率256Hz的脉冲短接。
当设置en 为高电平且clr为低电平时,计数器开始计数;即可通过发光管显示出来;当clr为高电平时,计数器复位到0,也可通过发光管显示出来;当en为低电平时,计数器停止计数,保持状态。
实现了数字跑表的清零、启动计时、暂停计时及继续计时功能。
这一切都可以通过数码管显示出来。
如图:(c)是实现异步清零功能的图片;(d)是实现计数功能的图片;(e)是实现暂停功能的图片。
(c)实现异步清零(d)实现计数功能(e)实现暂停计数五、实验总结通过这一周的课程实习,我对可编程逻辑器件有了更深一步的认识,对VHDL语言有了更深一层的学习。
深刻明白了“眼高手低”的感觉,也明白了只有身体力行才能把事情做好。
不论这一次试验做的成败与否,我都收获了好多。
感谢老师给我们安排的这次课程设计的机会!。