课程设计说明书(本科)
题 目: 基于CPLD/FPDA数字秒表设计 姓 名: 赵 超 尚晓亮 王 浩 专 业: 电子信息工程 班 级: 08级2班
2011年 6 月 21 日
目录
摘要„„„„„„„„„„„„„„„„„„„„„„„„„„„„„„ 3 第一章 设计任务和目的„„„„„„„„„„„„„„„„„„„„„„ 3
1.1 设计任务„„„„„„„„„„„„„„„„„„„„„„„ 3 1.2 设计目的„„„„„„„„„„„„„„„„„„„„„„„ 3 1.3 设计中所用工具„„„„„„„„„„„„„„„„„„„„ 3
第二章 EDA、CPLD及VHDL语言概述„„„„„„„„„„„„„„„„„ 4
2.1 EDA概述及开发工具„„„„„„„„„„„„„„„„„„ 4
2.1.1 EDA技术概述„„„„„„„„„„„„„„„„„ 4 2.1.2 EDA技术工具„„„„„„„„„„„„„„„„„ 4 2.1.3 PCB设计软件 „„„„„„„„„„„„„„„„ 5
2.2 CPLD概述及开发工具„„„„„„„„„„„„„„„„„ 5
2.2.1 CPLD技术概述 „„„„„„„„„„„„„„„„ 5 2.2.2 CPLD开发工具 „„„„„„„„„„„„„„„„ 5
2.3 VHDL语言概述及特点„„„„„„„„„„„„„„„„„„ 6
2.3.1 语言概述„„„„„„„„„„„„„„„„„„„ 6 2.3.2 VHDL语言特点„„„„„„„„„„„„„„„„„ 7
第三章 总体设计的方案„„„„„„„„„„„„„„„„„„„„„„ 7
3.1 总体设计思想„„„„„„„„„„„„„„„„„„„„„ 7 3.2 总体硬件设计方案„„„„„„„„„„„„„„„„„„„ 8 3.3 总体软件设计方案„„„„„„„„„„„„„„„„„„„ 9
第四章 软件设计及仿真„„„„„„„„„„„„„„„„„„„„„„ 10
4.1 10分频模块程序设计及仿真„„„„„„„„„„„„„„„ 10 4.2 1000分频模块程序设计及仿真„„„„„„„„„„„„„„„ 11 4.3 七段数码译码程序及仿真„„„„„„„„„„„„„„„„„ 12 4.4 100分之1秒模块程序设计及仿真„„„„„„„„„„„„„„ 14 4.5 输出扫描模块程序设计及仿真„„„„„„„„„„„„„„„„ 16 4.6 分钟模块程序设计及仿真„„„„„„„„„„„„„„„„„„ 18 4.7 分钟模块程序设计及仿真„„„„„„„„„„„„„„„„„„ 19
第五章 基于AT89C51单片机的表设计„„„„„„„„„„„„„„„„„ 21
5.1 秒表硬件总电路 „„„„„„„„„„„„„„„„„„„„ 21 5.2 系统仿真及调试 „„„„„„„„„„„„„„„„„„„„„ 22
第六章总结„„„„„„„„„„„„„„„„„„„„„„„„„„„„ 24
6.1总结 „„„„„„„„„„„„„„„„„„„„„„„„„ 24 6.2收获 „„„„„„„„„„„„„„„„„„„„„„„„„ 24
参考文献„„„„„„„„„„„„„„„„„„„„„„„„„„„„„ 25 附录一: 单片机秒表汇编源程序„„„„„„„„„„„„„„„„„„„ 25
基于CPLD/FPDA数字秒表设计
摘要:
本次EDA课程设计硬件器件基于CPLD,软件程序基于VHDL语言,仿真采用Quartus Ⅱ 5.0,制作一个秒表。电路原理图的制作使用了Protel 99 se,软件设计思想从底层到顶层依次调试仿真。并写出了每一部分的源程序和时序仿真图。另外本设计中还基于Protues用AT89C51制作了一个秒表,将CPLD和单片机进行比较。
关键词: EDA CPLD VHDL Quartus Ⅱ 5.0 Protues AT89C51 秒表
第一章 设计任务的目的
1.1 设计任务
设计并实现数字秒表。下载芯片:Altera的MAX3000系列EPM3256ATC144-10。电子秒表具有以下基本功能:
1.具有秒表计时显示功能,最大计数99.9,分辨率0.1秒(基本功能); 2.具有计时启动与停止功能(基本功能);
3. 可以实现上次计时数据的调出显示功能(扩展功能);
1.2 设计目的 1.掌握可编程逻辑器件的基本原理及利用EDA开发工具QuartusII5.0(Max+plusII)进行可编程逻辑器件设计的方法;
2.熟练掌握可编程逻辑器件的原理图层次化设计方法;
3.掌握利用QuartusII5.0(Max+plusII10.2)进行软件仿真及对可编程逻辑器件进行硬件下载的方法。
4.熟悉实际工程项目开发的流程与设计思想;
1.3 设计中所用工具
本设计硬件是基于CPLD/FPGA芯片制作一个简单的数字秒表,具体实现是用CPLD/FPGA
开发硬件实验系统上的EPM3254ATC144-10芯片作主控模块,显示模块用8个七段数码管显示,实验开发板一有很多的时钟信号,本实验中所用的1MHz时钟可从开发板上很容易获得。开发软件是基于QuartusⅡ5.0,它继承了MAX-plusⅡ所有优点,是更加完善的PLD设计工具。它提供了完整的多平台设计环境,能够直接满足特定设计需要,为可编程芯片系统(SOPC)提供全面的设计环境,将为Altera的DSP模块进行系统模型设计提供了集成综合环境。它可以完成VHDL语言的编译、时序的仿真和程序的调试烧写工作等工作。本设计中所用语言为VHDL(Very-High-Speed Integrated Circuit HDL),设计思想是从底层到顶层依次调试、仿真。VHDL是以高级语言为甚而,能够以形式化方式描述电路的结构和行为并用于模拟和综合的高级描述方法。目的是用软件的方法实现硬件电路的设计,实现RTL级仿真,验证设计的正确性,而不必像在传统的手工设计过程中那样,必须等到完成后才能进行实测和调试。
第三章 总体设计方案
3.1 总体设计思想
要产生准确的时钟信号必须要一个很高频率的信号进行分频后得到想要的时钟信号才能确保时钟的精度,本设计中使用1MHz时钟信号先进行10分频得到100KHz的信号为数码管扫描信号,再将1KHz信号进行1000分频得到100Hz信号,此信号作为秒表的百分之一秒为,然后每100码元产生一个进为从后得到1秒钟的信号,再每60秒产生一个分钟信号作为分钟信号。总体设计方案如图3-1所示。
图3-1 秒表总体设计方案
3.2 总体硬件设计方案
硬件使用EPM3254ATC144-10(引脚如图3-2)作主控制,8个七段数码管作显示部分,三个开关分别起:开始、暂停、清零作用,总电路图如图3-4
图3-2 EPM3254ATC144-10引脚
图 3-3 总硬件电路图
3.3 总体软件设计方案
软件设计思想是从底层往顶层设计,将一个比较复杂的程序划分成7个小的模块,再通过一个顶层电路将七个子程序连接起来。本设计中分为七个子模块分别为:10分频、1000分频、一百分之一秒模块、秒钟模块、分钟模块、译码模块和显示模块。具体电路图如图 3-4所示,体仿真结果如图 3-5所示。
图 3-4 软件总电路图
图 3-5 软件总电路仿真结果
第四章 软件设计及仿真
4.1 10分频模块程序设计及仿真
library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity f10 is
port(clk:in std_logic; clk_out:out std_logic); end;
architecture art of f10 is
signal count:integer range 0 to 9;---改X值,
signal clk_data:std_logic; begin
process(clk,count) begin
if clk'event and clk='1' then
if count=9 then ---X值决定分频倍数 count
clk_data
clk_out
图 4-1
4.2 1000分频模块程序设计及仿真
library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity f1000 is port(clk:in std_logic; clk_out:out std_logic); end;
architecture art of f1000 is
signal count:integer range 0 to 999;---改X值, signal clk_data:std_logic; begin
process(clk,count) begin
if clk'event and clk='1' then
if count=999 then ---X值决定分频倍数 count
clk_data
clk_out
end art;
图 4-2
4.3 七段数码译码程序及仿真
说明:本程序适用于共阳极七段数码管。其硬件如下图所示:
硬件描述语言如下:
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; entity deled is
port( num: in std_logic_vector(3 downto 0 ); led: out std_logic_vector(6 downto 0) ); end deled;
architecture fun of deled is begin
led
图 4-3
注: 从图中可看出当num=”0000”时,led=“1000000”所以显示的是“0”,又如当num=”0111”时,led=”1111000”所以显示为“7”。
4.4 100分之1秒模块程序设计及仿真
百分之一秒硬件如下图所示,
clk为时钟脉冲输入端,实际中脉冲频率为100Hz, clr为清零端,当clr=‘1’时归“00” En为使能端,当En=‘1’时,芯片使能
Stop为停止计数端,当stop=‘1’时停止计数
Co 为分钟进位端,每100个clk产生一个进位信号 Sec1 百分之一秒的十位 Sec0 百分之一秒的个位
硬件描述语言: library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity miao100 is
port(clk,clr,En,STOP:in std_logic;----时钟/清零信号
sec1,sec0:out std_logic_vector(3 downto 0);----秒高位/低位 co:out std_logic);-------输出/进位信号 end miao100 ;
architecture SEC of miao100 is begin
process(clk,clr)
variable cnt1,cnt0:std_logic_vector(3 downto 0);---计数
begin
if clr='1' then----当ckr为1时,高低位均为0
cnt1:="0000"; cnt0:="0000";
elsif clk'event and clk='1' then
IF En='1'THEN
if stop='1' then
cnt0:=cnt0;
cnt1:=cnt1;
elsif cnt1="1001" and cnt0="1000" then
co
cnt0:="1001";----低位为9
elsif cnt0
cnt0:=cnt0+1;----计数
else
cnt0:="0000";
if cnt1
cnt1:=cnt1+1;
else
cnt1:="0000";
co
end if;end if;end if;end if;
sec1
sec0
end process;
end SEC;
图4-4
从图中可以看出如下:
① 在1个clk处sec0每1个clk自增1,当clk=100Hz时,每个sec0为一百分之一秒 ② 在10个clk处sec1 每10个clk自增1为100分之一秒的十位
③ 在100个clk处co产生一个进位,为1S信号
4.5 输出扫描模块程序设计及仿真
动态扫描显示程序硬件模拟图
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity seltime is
port(clk:in std_logic;
count1:in std_logic_vector(3 downto 0);
count2:in std_logic_vector(3 downto 0);
count3:in std_logic_vector(3 downto 0);
count4:in std_logic_vector(3 downto 0);
count5:in std_logic_vector(3 downto 0);
count6:in std_logic_vector(3 downto 0);
sel:out std_logic_vector(7 downto 0);
YIMA:out std_logic_vector(3 downto 0));
end entity seltime;
architecture art of seltime is
signal daout:std_logic_vector(3 downto 0);
signal sum:std_logic_vector(3 downto 0);
begin
YIMA
process(clk) is
begin
if clk'event and clk='1'then
if sum>="0111" then sum
else sum
END IF;
ELSE NULL;
END IF;
case sum is
when "0000"=>daout
when "0001"=>daout
when "0010"=>daout
when "0011"=>daout
when "0100"=>daout
when "0101"=>daout
when "0110"=>daout
when "0111"=>daout
WHEN OTHERS=>daout
end case;
end process;
end architecture;
图 4-5
4.6 秒模块程序设计及仿真
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity SECOND is
port(clk,clr:in std_logic;----时钟/清零信号
sec1,sec0:out std_logic_vector(3 downto 0);----秒高位/低位
co:out std_logic);-------输出/进位信号
end SECOND;
architecture SEC of SECOND is
begin
process(clk,clr)
variable cnt1,cnt0:std_logic_vector(3 downto 0);---计数
begin
if clr='1' then----当ckr为1时,高低位均为0
cnt1:="0000"; cnt0:="0000";
elsif clk'event and clk='1' then
if cnt1="0101" and cnt0="1000" then----当记数为58(实际是经过59个记时脉冲)
end process;
end SEC; cnt0:="1001";----低位为9 elsif cnt0
图 4-6
4.7 分钟模块程序设计及仿真
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity MINUTE is
port(clk,clr:in std_logic;
min1,min0:out std_logic_vector(3 downto 0);
co:out std_logic);
end MINUTE;
architecture MIN of MINUTE is
begin
process(clk,clr)
variable cnt1,cnt0:std_logic_vector(3 downto 0);
begin
if clr='1' then----当ckr为1时,高低位均为0
cnt1:="0000"; cnt0:="0000";
elsif clk'event and clk='1' then
if cnt1="0101" and cnt0="1000" then
min1
min0
co
end process;
end MIN;
图 4-7
第六章 总结
6.1 总结
本课题的目的是设计一种基于FPGA的秒表,它要具有较高的精度和稳定性。本次设计我采用EDA工具Quartus Ⅱ 5.0运用VHDL语言实现计时电路,采用电路设计工具Protel 99se软件实现系统外围电路的设计。本文首先介绍EDA的应用背景和发展趋势,说明设计一种较高精度的数字秒表的必要性,介绍它的应用及技术指标,然后详细介绍秒表系统组成和各部分的作用,其中各部分模块包括晶振、分频器、按键控制、计时模块、译码模块、数码显示部分及支持其工作的外围电路,还要包括编程下载所必需的接口部件等;提出基于FPGA的数字秒表的设计方案,详细介绍数字秒表的硬件电路,包括有源晶振、FPGA芯片及其外围电路、编程下载接口、数码管驱动电路及显示模块等,对数字秒表的软件设计作了详细介绍,包括计时模块的设计、系统电路设计等;描述软件程序的仿真和硬件电路调试,以及调试过程中遇到的问题及解决方法。数字秒表的硬件实现使用Protel 99se设计外围电路,最终完成整个秒表的硬件设计[7]。 通过以上的系统介绍,我们可以从中知道基于FPGA的秒表系统设计的过程为:先介绍各组成结构有晶振、输入键 START 键和RESET键、有显示输出部分;又介绍秒表的各部分的功能,通过功能的介绍我们可以知道这些组件是必不可少的,然后将这写组件总体安装在一起就可以得到秒表的整体系统结构[13]。最后又介绍输入输出端口的功能,从而完成了基于FPGA的秒表系统设计。
6.2 收获
1、系统工作原理的研究分析;
2、系统主要的VHDL程序设计与仿真;
3、系统实现的硬件原理图设计与PCB版图设计;(第2课堂中完成)
4、PCB板加工;
5、主要元件的焊接与测试;
6、实习综合报告撰写;
课程设计说明书(本科)
题 目: 基于CPLD/FPDA数字秒表设计 姓 名: 赵 超 尚晓亮 王 浩 专 业: 电子信息工程 班 级: 08级2班
2011年 6 月 21 日
目录
摘要„„„„„„„„„„„„„„„„„„„„„„„„„„„„„„ 3 第一章 设计任务和目的„„„„„„„„„„„„„„„„„„„„„„ 3
1.1 设计任务„„„„„„„„„„„„„„„„„„„„„„„ 3 1.2 设计目的„„„„„„„„„„„„„„„„„„„„„„„ 3 1.3 设计中所用工具„„„„„„„„„„„„„„„„„„„„ 3
第二章 EDA、CPLD及VHDL语言概述„„„„„„„„„„„„„„„„„ 4
2.1 EDA概述及开发工具„„„„„„„„„„„„„„„„„„ 4
2.1.1 EDA技术概述„„„„„„„„„„„„„„„„„ 4 2.1.2 EDA技术工具„„„„„„„„„„„„„„„„„ 4 2.1.3 PCB设计软件 „„„„„„„„„„„„„„„„ 5
2.2 CPLD概述及开发工具„„„„„„„„„„„„„„„„„ 5
2.2.1 CPLD技术概述 „„„„„„„„„„„„„„„„ 5 2.2.2 CPLD开发工具 „„„„„„„„„„„„„„„„ 5
2.3 VHDL语言概述及特点„„„„„„„„„„„„„„„„„„ 6
2.3.1 语言概述„„„„„„„„„„„„„„„„„„„ 6 2.3.2 VHDL语言特点„„„„„„„„„„„„„„„„„ 7
第三章 总体设计的方案„„„„„„„„„„„„„„„„„„„„„„ 7
3.1 总体设计思想„„„„„„„„„„„„„„„„„„„„„ 7 3.2 总体硬件设计方案„„„„„„„„„„„„„„„„„„„ 8 3.3 总体软件设计方案„„„„„„„„„„„„„„„„„„„ 9
第四章 软件设计及仿真„„„„„„„„„„„„„„„„„„„„„„ 10
4.1 10分频模块程序设计及仿真„„„„„„„„„„„„„„„ 10 4.2 1000分频模块程序设计及仿真„„„„„„„„„„„„„„„ 11 4.3 七段数码译码程序及仿真„„„„„„„„„„„„„„„„„ 12 4.4 100分之1秒模块程序设计及仿真„„„„„„„„„„„„„„ 14 4.5 输出扫描模块程序设计及仿真„„„„„„„„„„„„„„„„ 16 4.6 分钟模块程序设计及仿真„„„„„„„„„„„„„„„„„„ 18 4.7 分钟模块程序设计及仿真„„„„„„„„„„„„„„„„„„ 19
第五章 基于AT89C51单片机的表设计„„„„„„„„„„„„„„„„„ 21
5.1 秒表硬件总电路 „„„„„„„„„„„„„„„„„„„„ 21 5.2 系统仿真及调试 „„„„„„„„„„„„„„„„„„„„„ 22
第六章总结„„„„„„„„„„„„„„„„„„„„„„„„„„„„ 24
6.1总结 „„„„„„„„„„„„„„„„„„„„„„„„„ 24 6.2收获 „„„„„„„„„„„„„„„„„„„„„„„„„ 24
参考文献„„„„„„„„„„„„„„„„„„„„„„„„„„„„„ 25 附录一: 单片机秒表汇编源程序„„„„„„„„„„„„„„„„„„„ 25
基于CPLD/FPDA数字秒表设计
摘要:
本次EDA课程设计硬件器件基于CPLD,软件程序基于VHDL语言,仿真采用Quartus Ⅱ 5.0,制作一个秒表。电路原理图的制作使用了Protel 99 se,软件设计思想从底层到顶层依次调试仿真。并写出了每一部分的源程序和时序仿真图。另外本设计中还基于Protues用AT89C51制作了一个秒表,将CPLD和单片机进行比较。
关键词: EDA CPLD VHDL Quartus Ⅱ 5.0 Protues AT89C51 秒表
第一章 设计任务的目的
1.1 设计任务
设计并实现数字秒表。下载芯片:Altera的MAX3000系列EPM3256ATC144-10。电子秒表具有以下基本功能:
1.具有秒表计时显示功能,最大计数99.9,分辨率0.1秒(基本功能); 2.具有计时启动与停止功能(基本功能);
3. 可以实现上次计时数据的调出显示功能(扩展功能);
1.2 设计目的 1.掌握可编程逻辑器件的基本原理及利用EDA开发工具QuartusII5.0(Max+plusII)进行可编程逻辑器件设计的方法;
2.熟练掌握可编程逻辑器件的原理图层次化设计方法;
3.掌握利用QuartusII5.0(Max+plusII10.2)进行软件仿真及对可编程逻辑器件进行硬件下载的方法。
4.熟悉实际工程项目开发的流程与设计思想;
1.3 设计中所用工具
本设计硬件是基于CPLD/FPGA芯片制作一个简单的数字秒表,具体实现是用CPLD/FPGA
开发硬件实验系统上的EPM3254ATC144-10芯片作主控模块,显示模块用8个七段数码管显示,实验开发板一有很多的时钟信号,本实验中所用的1MHz时钟可从开发板上很容易获得。开发软件是基于QuartusⅡ5.0,它继承了MAX-plusⅡ所有优点,是更加完善的PLD设计工具。它提供了完整的多平台设计环境,能够直接满足特定设计需要,为可编程芯片系统(SOPC)提供全面的设计环境,将为Altera的DSP模块进行系统模型设计提供了集成综合环境。它可以完成VHDL语言的编译、时序的仿真和程序的调试烧写工作等工作。本设计中所用语言为VHDL(Very-High-Speed Integrated Circuit HDL),设计思想是从底层到顶层依次调试、仿真。VHDL是以高级语言为甚而,能够以形式化方式描述电路的结构和行为并用于模拟和综合的高级描述方法。目的是用软件的方法实现硬件电路的设计,实现RTL级仿真,验证设计的正确性,而不必像在传统的手工设计过程中那样,必须等到完成后才能进行实测和调试。
第三章 总体设计方案
3.1 总体设计思想
要产生准确的时钟信号必须要一个很高频率的信号进行分频后得到想要的时钟信号才能确保时钟的精度,本设计中使用1MHz时钟信号先进行10分频得到100KHz的信号为数码管扫描信号,再将1KHz信号进行1000分频得到100Hz信号,此信号作为秒表的百分之一秒为,然后每100码元产生一个进为从后得到1秒钟的信号,再每60秒产生一个分钟信号作为分钟信号。总体设计方案如图3-1所示。
图3-1 秒表总体设计方案
3.2 总体硬件设计方案
硬件使用EPM3254ATC144-10(引脚如图3-2)作主控制,8个七段数码管作显示部分,三个开关分别起:开始、暂停、清零作用,总电路图如图3-4
图3-2 EPM3254ATC144-10引脚
图 3-3 总硬件电路图
3.3 总体软件设计方案
软件设计思想是从底层往顶层设计,将一个比较复杂的程序划分成7个小的模块,再通过一个顶层电路将七个子程序连接起来。本设计中分为七个子模块分别为:10分频、1000分频、一百分之一秒模块、秒钟模块、分钟模块、译码模块和显示模块。具体电路图如图 3-4所示,体仿真结果如图 3-5所示。
图 3-4 软件总电路图
图 3-5 软件总电路仿真结果
第四章 软件设计及仿真
4.1 10分频模块程序设计及仿真
library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity f10 is
port(clk:in std_logic; clk_out:out std_logic); end;
architecture art of f10 is
signal count:integer range 0 to 9;---改X值,
signal clk_data:std_logic; begin
process(clk,count) begin
if clk'event and clk='1' then
if count=9 then ---X值决定分频倍数 count
clk_data
clk_out
图 4-1
4.2 1000分频模块程序设计及仿真
library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity f1000 is port(clk:in std_logic; clk_out:out std_logic); end;
architecture art of f1000 is
signal count:integer range 0 to 999;---改X值, signal clk_data:std_logic; begin
process(clk,count) begin
if clk'event and clk='1' then
if count=999 then ---X值决定分频倍数 count
clk_data
clk_out
end art;
图 4-2
4.3 七段数码译码程序及仿真
说明:本程序适用于共阳极七段数码管。其硬件如下图所示:
硬件描述语言如下:
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; entity deled is
port( num: in std_logic_vector(3 downto 0 ); led: out std_logic_vector(6 downto 0) ); end deled;
architecture fun of deled is begin
led
图 4-3
注: 从图中可看出当num=”0000”时,led=“1000000”所以显示的是“0”,又如当num=”0111”时,led=”1111000”所以显示为“7”。
4.4 100分之1秒模块程序设计及仿真
百分之一秒硬件如下图所示,
clk为时钟脉冲输入端,实际中脉冲频率为100Hz, clr为清零端,当clr=‘1’时归“00” En为使能端,当En=‘1’时,芯片使能
Stop为停止计数端,当stop=‘1’时停止计数
Co 为分钟进位端,每100个clk产生一个进位信号 Sec1 百分之一秒的十位 Sec0 百分之一秒的个位
硬件描述语言: library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity miao100 is
port(clk,clr,En,STOP:in std_logic;----时钟/清零信号
sec1,sec0:out std_logic_vector(3 downto 0);----秒高位/低位 co:out std_logic);-------输出/进位信号 end miao100 ;
architecture SEC of miao100 is begin
process(clk,clr)
variable cnt1,cnt0:std_logic_vector(3 downto 0);---计数
begin
if clr='1' then----当ckr为1时,高低位均为0
cnt1:="0000"; cnt0:="0000";
elsif clk'event and clk='1' then
IF En='1'THEN
if stop='1' then
cnt0:=cnt0;
cnt1:=cnt1;
elsif cnt1="1001" and cnt0="1000" then
co
cnt0:="1001";----低位为9
elsif cnt0
cnt0:=cnt0+1;----计数
else
cnt0:="0000";
if cnt1
cnt1:=cnt1+1;
else
cnt1:="0000";
co
end if;end if;end if;end if;
sec1
sec0
end process;
end SEC;
图4-4
从图中可以看出如下:
① 在1个clk处sec0每1个clk自增1,当clk=100Hz时,每个sec0为一百分之一秒 ② 在10个clk处sec1 每10个clk自增1为100分之一秒的十位
③ 在100个clk处co产生一个进位,为1S信号
4.5 输出扫描模块程序设计及仿真
动态扫描显示程序硬件模拟图
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity seltime is
port(clk:in std_logic;
count1:in std_logic_vector(3 downto 0);
count2:in std_logic_vector(3 downto 0);
count3:in std_logic_vector(3 downto 0);
count4:in std_logic_vector(3 downto 0);
count5:in std_logic_vector(3 downto 0);
count6:in std_logic_vector(3 downto 0);
sel:out std_logic_vector(7 downto 0);
YIMA:out std_logic_vector(3 downto 0));
end entity seltime;
architecture art of seltime is
signal daout:std_logic_vector(3 downto 0);
signal sum:std_logic_vector(3 downto 0);
begin
YIMA
process(clk) is
begin
if clk'event and clk='1'then
if sum>="0111" then sum
else sum
END IF;
ELSE NULL;
END IF;
case sum is
when "0000"=>daout
when "0001"=>daout
when "0010"=>daout
when "0011"=>daout
when "0100"=>daout
when "0101"=>daout
when "0110"=>daout
when "0111"=>daout
WHEN OTHERS=>daout
end case;
end process;
end architecture;
图 4-5
4.6 秒模块程序设计及仿真
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity SECOND is
port(clk,clr:in std_logic;----时钟/清零信号
sec1,sec0:out std_logic_vector(3 downto 0);----秒高位/低位
co:out std_logic);-------输出/进位信号
end SECOND;
architecture SEC of SECOND is
begin
process(clk,clr)
variable cnt1,cnt0:std_logic_vector(3 downto 0);---计数
begin
if clr='1' then----当ckr为1时,高低位均为0
cnt1:="0000"; cnt0:="0000";
elsif clk'event and clk='1' then
if cnt1="0101" and cnt0="1000" then----当记数为58(实际是经过59个记时脉冲)
end process;
end SEC; cnt0:="1001";----低位为9 elsif cnt0
图 4-6
4.7 分钟模块程序设计及仿真
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity MINUTE is
port(clk,clr:in std_logic;
min1,min0:out std_logic_vector(3 downto 0);
co:out std_logic);
end MINUTE;
architecture MIN of MINUTE is
begin
process(clk,clr)
variable cnt1,cnt0:std_logic_vector(3 downto 0);
begin
if clr='1' then----当ckr为1时,高低位均为0
cnt1:="0000"; cnt0:="0000";
elsif clk'event and clk='1' then
if cnt1="0101" and cnt0="1000" then
min1
min0
co
end process;
end MIN;
图 4-7
第六章 总结
6.1 总结
本课题的目的是设计一种基于FPGA的秒表,它要具有较高的精度和稳定性。本次设计我采用EDA工具Quartus Ⅱ 5.0运用VHDL语言实现计时电路,采用电路设计工具Protel 99se软件实现系统外围电路的设计。本文首先介绍EDA的应用背景和发展趋势,说明设计一种较高精度的数字秒表的必要性,介绍它的应用及技术指标,然后详细介绍秒表系统组成和各部分的作用,其中各部分模块包括晶振、分频器、按键控制、计时模块、译码模块、数码显示部分及支持其工作的外围电路,还要包括编程下载所必需的接口部件等;提出基于FPGA的数字秒表的设计方案,详细介绍数字秒表的硬件电路,包括有源晶振、FPGA芯片及其外围电路、编程下载接口、数码管驱动电路及显示模块等,对数字秒表的软件设计作了详细介绍,包括计时模块的设计、系统电路设计等;描述软件程序的仿真和硬件电路调试,以及调试过程中遇到的问题及解决方法。数字秒表的硬件实现使用Protel 99se设计外围电路,最终完成整个秒表的硬件设计[7]。 通过以上的系统介绍,我们可以从中知道基于FPGA的秒表系统设计的过程为:先介绍各组成结构有晶振、输入键 START 键和RESET键、有显示输出部分;又介绍秒表的各部分的功能,通过功能的介绍我们可以知道这些组件是必不可少的,然后将这写组件总体安装在一起就可以得到秒表的整体系统结构[13]。最后又介绍输入输出端口的功能,从而完成了基于FPGA的秒表系统设计。
6.2 收获
1、系统工作原理的研究分析;
2、系统主要的VHDL程序设计与仿真;
3、系统实现的硬件原理图设计与PCB版图设计;(第2课堂中完成)
4、PCB板加工;
5、主要元件的焊接与测试;
6、实习综合报告撰写;