院系:物理与电子工程学院专业:电子信息工程班级:2008级3班指导老师:****名:**学号:************ 实验时间:2010年12月10日前言本设计为一个多功能的数字钟,具有时、分、秒计数显示功能,以24小时循环计数;具有校对功能及整点报时功能。
本设计采用EDA技术,以硬件描述语言VHDL为系统逻辑描述手段设计文件,在MAXPLUSⅡ工具软件环境下,采用自顶向下的设计方法,由各个基本模块共同构建了一个基于FPGA的数字钟。
系统主芯片采用EP1K3QC208-3,由时钟模块、控制模块、计时模块、数据译码模块、显示及报时模块组成。
经编译和仿真所设计的程序,在可编程逻辑器件上下载验证,本系统能够完成时、分、秒的分别显示,由按键输入进行数字钟的校对、清零、启停功能。
数字时钟实验设计一、实验目的1.掌握十进制,六进制,二十四进制计数器以及译码器的设计方法。
2.掌握多位计数器相连的设计方法。
3. 掌握多位数码管扫描显示驱动的设计方法。
4. 掌握EDA技术的层次化设计方法。
5、了解数字时钟的组成及工作原理。
6、熟悉数字时钟的设计与制作。
二、实验内容1. 设计具有时,分,秒,计数显示功能,以24小时循环计时的电子钟。
2. 设计电子钟复位清零功能。
3. 设计调节小时、分钟、秒功能。
三、实验仪器1. EDA实验箱2. 导线若干3.max+plu2软件四、设计思路1.要完成秒/分/时的各阶段的正确进位,就要设计两个60进制和一个24进制,为了更加给数字钟一个完善的功能,还设置了一个清零功能和校时、校分。
2. 要依次显示秒/分/时,就要连接数码管,共六个数码管一个数码管要七根输入线,故六个数码管共要42根输出线,不紧接线复杂而且浪费本钱,故我们采用动态扫描驱动显示秒/分/时。
3.总体结构图如图所示(1-1)。
五.数字钟的工作原理振荡器产生稳定的高频脉冲信号,作为数字钟的时间基准,然后经过分频器输出标准秒脉冲。
秒计数器满60后向分计数器进位,分计数器满60后向小时计数器进位,小时计数器按照“24翻1”规律计数。
计数满后各计数器清零,重新计数。
计数器的输出分别经译码器送数码管显示。
计时出现误差时,可以用校时电路校时、校分。
控制信号由1×5矩形键盘输入。
时基电路可以由石英晶体振荡电路构成,假设晶振频率1MHz,经过6次十分频就可以得到秒脉冲信号。
译码显示电路由八段译码器完成。
用counter6无进位六进制计数器选择数码管的亮灭以及对应的数,循环扫描显示,用dout六选一选择器选择给定的信号输出对应的数送到七段码译码器。
由按键输入清零/校时、分信号经按键消抖动模块,再输入到秒计时器、时计时器,最后输入到显示译码控制模块。
六.单元模块设计部分单元模块分别由五个模块组成。
译码器的设计、六进制的设计、十进制的设计、二十四进制的设计和时钟扫描控制端的输出共五个模块组成。
1.译码器模块的设计显示译码控制器的输入均为8421BCD码,分别是秒计数器的输出秒十位、秒个位;分计数器的输出分十位、分个位;时计数器的输出时十位、时个位;还有一个分频器输出的512Hz的时钟信号作为扫描的时钟,显示译码控制器的输出为8位段码信号及6位的数码管选择信号。
具体实现的程序如下:library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity decoder isPort (din:in std_logic_vector(3 downto 0 ); --四位二进制码输入dout:out std_logic_vector(6 downto 0) ); --输出LED七段码end decoder;architecture Behavioral of decoder isbeginprocess(din)begincase din iswhen "0000" => dout<="0111111";--0when "0001" => dout<="0000110";--1when "0010" => dout<="1011011";--2when "0011" => dout<="1001111";--3when "0100" => dout<="1100110"; --4when "0101" => dout<="1101101";--5when "0110" => dout<="1111101";--6when "0111" => dout<="0000111";--7when "1000" => dout<="1111111";--8when "1001" => dout<="1101111";--9when others => dout<="1110111";end case;end process;end Behavioral;2.六进制模块的设计library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity counter6 isPort ( clk : in std_logic;reset : in std_logic;dout : out std_logic_vector(3 downto 0);c:out std_logic);end counter6;architecture Behavioral of counter6 issignal count : std_logic_vector(3 downto 0);begindout <= count;process(clk,reset)beginif reset= '0' thencount <= "0000";c<='0';elsif rising_edge(clk) thenif count="0101" thencount<="0000";c<='1';elsecount<=count+1;c<='0';end if;end if;end process;end Behavioral;3.十进制模块的设计library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity counter10 isPort ( clk : in std_logic;reset : in std_logic;dout : out std_logic_vector(3 downto 0);c:out std_logic);end counter10;architecture Behavioral of counter10 is signal count : std_logic_vector(3 downto 0); begindout <= count;process(clk,reset)beginif reset='0'thencount <= "0000" ;c<='0';elsif rising_edge(clk) thenif count = "1001" thencount <= "0000";c<='1';elsecount <= count+1;c<='0';end if;end if;end process;end Behavioral;4.二十四进制模块的设计library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity counter24 isPort ( clk : in std_logic;reset : in std_logic;dout : out std_logic_vector(7 downto 0));end counter24;architecture Behavioral of counter24 issignal count : std_logic_vector(7 downto 0);begindout <= count;process(clk,reset)beginif reset= '0' thencount <= "00000000";elsif rising_edge(clk) thenif count(3 downto 0)="1001" thencount(3 downto 0)<="0000";count(7 downto 4)<=count(7 downto 4) +1;elsecount(3 downto 0)<=count(3 downto 0)+1;end if;if count="00100011" thencount<="00000000";end if;end if;end process;end Behavioral;5.时钟扫描控制端的输出设计library ieee;use ieee.std_logic_1164.all;entity clk1hz isport (clk : in std_logic;clk1hz :out std_logic);end clk1hz;architecture one of clk1hz isbeginPROCESS(clk)variable cnt : INTEGER RANGE 0 TO 49999999;BEGINIF clk='1' AND clk'event THENIF cnt=49999999 THEN cnt:=0;ELSEIF cnt<25000000 THEN clk1hz<='1'; ELSE clk1hz<='0';END IF;cnt:=cnt+1;END IF;END IF;end process;end one;七.实验总体电路顶层设计library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity clock isPort ( clk : in std_logic; --1hz时钟信号clk1:in std_logic; --jishi hz xinhaoreset : in std_logic; --初始化BT : out std_logic_vector(2 downto 0);--位SG : out std_logic_vector(6 downto 0)); --段end clock;architecture Behavioral of clock is component counter10 isPort ( clk : in std_logic;reset : in std_logic;dout : out std_logic_vector(3 downto 0);c:out std_logic);end component;component counter6 isPort ( clk : in std_logic;reset : in std_logic;dout : out std_logic_vector(3 downto 0);c:out std_logic);end component;component counter24 isPort ( clk : in std_logic;reset : in std_logic;dout : out std_logic_vector(7 downto 0));end component;component decoder isPort (din:in std_logic_vector(3 downto 0 );dout:out std_logic_vector(6 downto 0));end component;signal c1,c2,c3,c4:std_logic;signal doutsl,doutml:std_logic_vector(3 downto 0);signal doutsh,doutmh:std_logic_vector(3 downto 0);signal douth:std_logic_vector(7 downto 0);signal cnt : integer range 0 to 6;--计数signal secondl: std_logic_vector(6 downto 0);--秒钟低位输出signal secondh: std_logic_vector(6 downto 0); --秒钟高位输出signal minutel: std_logic_vector(6 downto 0); --分钟低位输出signal minuteh: std_logic_vector(6 downto 0); --分钟高位输出signal hourl: std_logic_vector(6 downto 0); --小时低位输出signal hourh: std_logic_vector(6 downto 0); --小时高位输出beginu2: counter10 port map( clk=>clk,reset=>reset,dout=>doutsl,c=>c1);u3: counter6 port map( clk=>c1,reset=>reset,dout=>doutsh,c=>c2);u4: counter10 port map( clk=>c2,reset=>reset,dout=>doutml,c=>c3);u5: counter6 port map( clk=>c3,reset=>reset,dout=>doutmh,c=>c4);u6: counter24 port map( clk=>c4,reset=>reset,dout=>douth);u7: decoder port map( din => doutsl,dout => secondl);u8: decoder port map( din => doutsh,dout => secondh);u9: decoder port map( din => doutml,dout => minutel);u10: decoder port map( din => doutmh,dout => minuteh);u11: decoder port map( din => douth(7 downto 4),dout => hourh); u12: decoder port map( din => douth(3 downto 0),dout => hourl);process(clk1)beginif clk1'event and clk1='1' thenif cnt = 5 then cnt <= 0; else cnt <= cnt+1;end if;end if;case cnt iswhen 0 => BT <="000" ; SG <=secondl;when 1 => BT <="001" ; SG <=secondh;when 2 => BT <="010" ; SG <=minutel;when 3 => BT <="011" ; SG <=minuteh;when 4 => BT <="100" ; SG <=hourl;when 5 => BT <="101" ; SG <=hourh;when others => BT <="111";end case ;end process;end Behavioral;八.仿真过程及结果1、输入完文本之后,对该文本进行功能仿真,然后在没有出现错误的情况下,对文本进行时序仿真,观察其波形如下:7段显示译码器六进制十进制二十四进制时钟扫描控制端的输出顶层设计2、在对该文本进行编辑下载,在这之前,先要设置其器件,选择目标芯片。