EDA技术课程大作业
设计题目: 秒表的设计 学生姓名: 学 号:
专业班级: 2009级通信工程
2012年5月5日
秒表的设计
1. 设计要求和设计方案
1.1设计要求
设计一块数字秒表,能够精确反映计时时间,并完成复位、计时功能。秒表计时的最大范围为1小时,精度为0.01秒。秒表可得到计时时间的分、秒、0.1秒、0.01秒等度量,各度量间可以正确进位。当复位清零有效时,秒表清零并做好计时准备。在任何情况下,只要按下复位开关,秒表都要无条件的进行复位操作,即使在计时过程中也要无条件的清零。设置秒表启动、停止开关,秒表即刻开始计时,并得到计时结果;放开该开关时,计时停止。
1.2设计方案
根据上述设计要求,可以预先设计若干个不同进制的计数器单元模块,然后将其进行例化组合来得到数字秒表系统。要满足数字秒表的精度,首先要获得精确的计时基准信号,这里的系统精度要求为0.01秒,因此必须设置周期为0.01秒的时钟脉冲。0.01秒、0.1秒、秒、分等计时单位之间的进位转换可以通过不同进制的计数器实现。
整个系统除了对每一计数器需设置清零信号输入外,还需在6个计数器设置时钟使能信号,即计时允许信号,以便作为秒表的计时启停控制开关。因此秒表可有1个分频器、4个十进制计数器(1/100秒、1/10秒、1秒、1分)以及2个六进制计数器(10秒、10分)组成。6个4位二进制计数输出的最小显示值分别是:1/ 100秒、1/10秒、1秒、10秒、1分、10分。
级联选择串行进位方式,即以低位片的进位输出信号作为高位片的时钟输入信号。秒表电路逻辑图如图1所示。
图1 秒表电路逻辑图
2. VHDL源程序
2.1分频器的源程序CLKGEN.VHD
library ieee;
use ieee.std_logic_11.all; entity clkgen is port(clk:in std_logic; newclk:out std_logic); end clkgen;
architecture art of clkgen is
signal cnter:integer range 0 to 10#29999#; begin process(clk) begin
if clk'event and clk='1' then
if cnter=10#29999# then cnter<=0; else cnter<=cnter+1; end if; end if; end process; process(cnter) begin
if cnter=10#29999# then newclk<='1'; else newclk<='0'; end if; end process; end art;
2.2六进制计数器的源程序CNT6.VHD
library ieee;
use ieee.std_logic_11.all; use ieee.std_logic_unsigned.all;
entity cnt6 is
port(clk:in std_logic; clr:in std_logic; ena:in std_logic;
cq:out std_logic_vector(3 downto 0 ); carry_out:out std_logic); end cnt6;
architecture art of cnt6 is
signal cqi:std_logic_vector(3 downto 0 ); begin
process(clk,clr,ena) begin
if clr='1' then cqi<=\"0000\"; elsif clk'event and clk='1' then if ena='1' then
if cqi=\"0101\" then cqi<=\"0000\"; else cqi<=cqi+'1';end if; end if; end if; end process; process(cqi) begin
if cqi=\"0000\" then carry_out<='1'; else carry_out<='0';end if; end process; cq<=cqi; end art;
2.3十进制计数器的源程序CNT10.VHD
library ieee;
use ieee.std_logic_11.all; use ieee.std_logic_unsigned.all;
entity cnt10 is port(clk:in std_logic; clr:in std_logic; ena:in std_logic;
cq:out std_logic_vector(3 downto 0 ); carry_out:out std_logic); end cnt10;
architecture art of cnt10 is
signal cqi:std_logic_vector(3 downto 0 ); begin
process(clk,clr,ena) begin
if clr='1' then cqi<=\"0000\"; elsif clk'event and clk='1' then if ena='1' then
if cqi=\"1001\" then cqi<=\"0000\"; else cqi<=cqi+'1';end if; end if; end if; end process; process(cqi) begin
if cqi=\"0000\" then carry_out<='1'; else carry_out<='0';end if; end process;
cq<=cqi; end art;
2.4秒表的源程序TIMES.VHD
library ieee;
use ieee.std_logic_11.all; entity times is
port(clk:in std_logic; clr:in std_logic; ena:in std_logic;
dout:out std_logic_vector(23 downto 0)); end times;
architecture art of times is component clkgen port(clk:in std_logic; newclk:out std_logic); end component; component cnt10
port(clk,clr,ena:in std_logic;
cq:out std_logic_vector(3 downto 0); carry_out: out std_logic); end component; component cnt6
port(clk,clr,ena:in std_logic;
cq:out std_logic_vector(3 downto 0); carry_out: out std_logic); end component; signal newclk:std_logic; signal carry1:std_logic; signal carry2:std_logic; signal carry3:std_logic; signal carry4:std_logic; signal carry5:std_logic; begin
U0:clkgen port map(clk=>clk,newclk=>newclk); U1:cnt10 port map(clk=>newclk,clr=>clr,ena=>ena, cq=>dout(3 downto 0),carry_out=>carry1); U2:cnt10 port map(clk=>carry1,clr=>clr,ena=>ena,
cq=>dout(7 downto 4),carry_out=>carry2); U3:cnt10 port map(clk=>carry2,clr=>clr,ena=>ena, cq=>dout(11 downto 8),carry_out=>carry3); U4:cnt6 port map(clk=>carry3,clr=>clr,ena=>ena, cq=>dout(15 downto 12),carry_out=>carry4); U5:cnt10 port map(clk=>carry4,clr=>clr,ena=>ena, cq=>dout(19 downto 16),carry_out=>carry5); U6:cnt6 port map(clk=>carry5,clr=>clr,ena=>ena, cq=>dout(23 downto 20)); end art;
3.源程序的仿真结果
3.1六进制计数器的仿真结果 六进制计数器的仿真结果如图2所示。
图2 六进制计数器的仿真结果
3.2十进制计数器的仿真结果
十进制计数器的仿真结果如图3所示。
图3 十进制计数器的仿真结果
3.3秒表的仿真结果
秒表的仿真结果如图4所示。
图4 秒表的仿真结果
4.附件
参考文献:
[1] 孙俊逸,EDA课程设计 2009年5月. [2] 潘松,EDA技术实用教程 2010年6月. [3] 计算机网络.