Presentation is loading. Please wait.

Presentation is loading. Please wait.

数字时钟设计及实现 何宾 2011.09.

Similar presentations


Presentation on theme: "数字时钟设计及实现 何宾 2011.09."— Presentation transcript:

1 数字时钟设计及实现 何宾

2 数字时钟设计-本章概要 本章给出了PLD器件在复杂数字系统的典型应用实例- 数字时钟的设计。数字时钟的设计也是PLD在复杂数字系
统的经典应用。 该章首先介绍了数字时钟的功能要求和整体结构;随后 具体介绍了数字时钟的模块设计,其中包括数字时钟控制 信号和控制模块的具体结构。本章最后详细描述了设计的 具体实现过程,具体包括数字时钟的计数模块设计、计数 时钟及扫描时钟设计和显示控制模块设计。

3 数字时钟设计-数字时钟的功能要求 数字钟时常见的一种计数装置,数字钟以1Hz的频率工 作。该设计完成数字钟的运行和显示。其主要功能有:
1、数字钟以1Hz的频率工作,其输入频率为1MHz。 2、数字钟显示时、分、秒信息。这些显示信息在6个7 段数码管上完成。 3、通过按键设置时、分信息。并且具有对数字钟的复 位功能。 4、复位键将时、分、秒清零,并做好重新计数的准备。 5、按键具有预置时、分的功能。分别对当前的时和分 信息做递增设置和递减设置。

4 数字时钟设计-数字时钟的结构

5 数字时钟设计-数字时钟的结构 该数字钟的控制部分由PLD芯片完成。该芯片的输入 和输出接口由下面信号组成: 输入信号:
复位信号(reset) 时钟输入信号(clk) 小时递增信号(inc_hour) 小时递减信号(sub_hour) 分钟递增信号(inc_min) 分钟递减信号(sub_min) 输出信号: 7段数码管选信号(sel) 7段数码管段选信号(q)

6 数字时钟设计-控制模块结构 该设计分成下面四个模块:定时时钟模块、扫描时钟模 块、按键处理模块、定时计数模块和显示控制模块。图
11.2给出了这几个模块之间的信号连接关系。

7 数字时钟设计-控制模块结构 1、按键处理模块 由于VHDL语言的规则,将按键的处理和定时模块设计
在一起。为了描述清楚,将对按键的处理进行说明。在该 设计中,采用异步复位电路方式。当复位信号低有效时, 计数器停止计数,时、分、秒清零。 对于小时的递增、递减按键操作,通过一个1Hz的计数 时钟采样。图11.3给出了递增、递减的操作时序。

8 数字时钟设计-控制模块结构

9 数字时钟设计-控制模块结构 当1Hz的div_clk信号的上升沿到来时,检测hour_inc
和hour_dec按键,图中的虚线表示在时钟的上升沿对 按键信号进行采样。当hour_inc或hour_dec按键低有效 时,对小时进行递加或递减操作。 对于分钟的递加、递减按键操作,也是通过一个 1Hz的计数时钟采样。原理同图11.4。

10 定时时钟模块其作用就是将外部提供的1MHz的时钟, 通过分频器后向模块内的定时计数模块提供1Hz的定时计
数字时钟设计-控制模块结构 2、定时时钟模块 定时时钟模块其作用就是将外部提供的1MHz的时钟, 通过分频器后向模块内的定时计数模块提供1Hz的定时计 数时钟。在设计定时时钟模块时,采用同步计数电路。

11 扫描时钟模块的作用就是通过对1MHz的分频处理后, 向显示控制模块提供合适的显示扫描时钟,该时钟必须经
数字时钟设计-控制模块结构 3、扫描时钟模块 扫描时钟模块的作用就是通过对1MHz的分频处理后, 向显示控制模块提供合适的显示扫描时钟,该时钟必须经 过合理的设计,才能保证7段数码显示的稳定。在设计扫 描时钟模块时,采用同步计数电路。

12 数字时钟设计-控制模块结构 4、定时计数模块 定时计数模块是该设计中最重要的一部分,在设计该模
块时,为了便于后续显示控制模块的设计,将时、分、秒 进行分离,即小时分成了小时的十位和个位分别处理,分 钟分成了分钟的十位和个位分别处理。秒分成了秒的十位 和个位分别处理。在该设计中,采用24小时计数模式。 例如:13:28:57。13为小时的表示,1为小时的十 位,3为小时的个位;28为分钟的表示,2为分钟的十位, 8为分钟的个位;57为秒的表示,5为秒的十位,7为秒的 个位。

13 秒的个位计数从0-9,即十进制计数。当秒的个位计 数到9后,准备向秒的十位进位。秒的十位计数从0-5,即
数字时钟设计-控制模块结构 秒的个位计数从0-9,即十进制计数。当秒的个位计 数到9后,准备向秒的十位进位。秒的十位计数从0-5,即 六进制计数。当秒的十位计数到5后,准备向分的个位进 位。 分钟的个位计数从0-9,即十进制计数。当分钟的个位 计数到9后,准备向分钟的十位进位。分钟的十位计数从 0-5,即六进制计数。当分钟的十位计数到5后,准备向小 时的个位进位。

14 数字时钟设计-控制模块结构 对于小时的处理比较复杂,小时的十位和个位之 间存在下面的关系: 当小时的十位为0或1时,小时的个位可以计数范
围为0-9,即十进制计数; 当小时的十位为2时,小时的各位可以计数的范围 为0-3,即四进制计数;

15 数字时钟设计-控制模块结构

16 数字时钟设计-控制模块结构 5、显示控制模块 显示控制模块主要作用是在7段数码管上正确的显示0-
9的数字。sel三位选择线和3-8译码器相连

17 数字时钟设计-主程序 library IEEE; use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; --实体定义部分 entity clock is port( clk : in std_logic; rst : in std_logic; inc_min : in std_logic; sub_min : in std_logic; inc_hour : in std_logic; sub_hour : in std_logic; sel : out std_logic_vector(2 downto 0); q : out std_logic_vector(7 downto 0)); end clock;

18 数字时钟设计-主程序 --信号定义: architecture Behavioral of clock is
signal sec_counter1:std_logic_vector(3 downto 0); signal sec_counter2:std_logic_vector(3 downto 0); signal min_counter1:std_logic_vector(3 downto 0); signal min_counter2:std_logic_vector(3 downto 0); signal hour_counter1:std_logic_vector(3 downto 0); signal hour_counter2:std_logic_vector(3 downto 0); signal divcounter : std_logic_vector(3 downto 0); signal div_clk : std_logic; signal scancounter : std_logic_vector(1 downto 0); signal scan_clk : std_logic; signal scan_out : std_logic_vector(2 downto 0); signal secseg1,secseg2,minseg1,minseg2,hourseg1,hourseg2:std_logic_vector(7 downto 0); begin

19 数字时钟设计-主程序 --计数时钟,对外部输入时钟分频,此处只适用于仿真,实际进行时间计数时,分频后时钟应该满足1HZ。
process(rst,clk) begin if(rst='0')then divcounter<="0000"; div_clk<='0'; elsif(rising_edge(clk)) then if(divcounter="1111") then div_clk<=not div_clk; else divcounter<=divcounter+'1'; end if; end process;

20 第11章 数字时钟设计-主程序 --仿真时数码管扫描时钟,实际中需根据具体情况进行调解时钟频率 process(rst,clk) begin
if(rst='0')then scancounter<="00"; scan_clk<='0'; elsif(rising_edge(clk)) then if(scancounter="11") then scan_clk<=not scan_clk; else scancounter<=scancounter+'1'; end if; end process;

21 数字时钟设计-主程序 --时钟计数部分主进程 --时钟复位 clock:process(div_clk,rst) begin
if(rst='0')then sec_counter1<=X"0"; sec_counter2<=X"0"; min_counter1<=X"0"; min_counter2<=X"0"; hour_counter1<=X"0"; hour_counter2<=X"0";

22 数字时钟设计-主程序 --手动调分,递增 elsif(rising_edge(div_clk))then
if(inc_min='0') then if(min_counter1=X"9") then min_counter1<=X"0"; if(min_counter2>=X"5") then min_counter2<=X"0"; else min_counter2<=min_counter2+1; end if; min_counter1<=min_counter1+1;

23 数字时钟设计-主程序 --手动调分,递减 elsif(sub_min='0') then
if(min_counter1=X"0") then min_counter1<=X"9"; if(min_counter2=X"0")then min_counter2<=X"5"; else min_counter2<=min_counter2-1; end if; min_counter1<=min_counter1-1;

24 第11章 数字时钟设计-主程序 --手动调时,增时 elsif(inc_hour='0') then
if(hour_counter2=X"2")then if(hour_counter1=X"3")then hour_counter1<=X"0"; hour_counter2<=X"0"; else hour_counter1<=hour_counter1+1; end if; if(hour_counter1=X"9") then hour_counter2<=hour_counter2+1;

25 数字时钟设计-主程序 --手动调时,减时 elsif(sub_hour='0') then
if(hour_counter1=X"0")then if(hour_counter2=X"0")then hour_counter1<=X"3"; hour_counter2<=X"2"; else hour_counter2<=hour_counter2-1; hour_counter1<=X"9"; end if; else hour_counter1<=hour_counter1-1;

26 第11章 数字时钟设计-主程序 --时分秒正常计数 else if(sec_counter1>=X"9") then
if(min_counter1>=X"9") then min_counter1<=X"0"; if(min_counter2>=X"5") then min_counter2<=X"0"; if(hour_counter2=X"2") then if(hour_counter1=X"3") then hour_counter1<=X"0"; hour_counter2<=X"0";

27 数字时钟设计-主程序 else hour_counter1<=hour_counter1+1; end if;
if(hour_counter1=X"9") then hour_counter1<=X"0"; hour_counter2<=hour_counter2+1; min_counter2<=min_counter2+1;

28 数字时钟设计-主程序 else min_counter1<=min_counter1+1; end if;
sec_counter2<=sec_counter2+1; sec_counter1<=sec_counter1+1; end process clock;

29 第11章 数字时钟设计-主程序 --生成扫描时钟 process(rst,scan_clk) begin if (rst='0') then
scan_out<="000"; elsif(rising_edge(scan_clk)) then if(scan_out="101")then else scan_out<=scan_out+1; end if; end process;

30 数字时钟设计-主程序 --扫描输出进程 process(scan_out) begin case scan_out is
when "000" => q<=secseg1; sel<="000"; when "001" => q<=secseg2; sel<="001"; when "010" => q<=minseg1; sel<="010"; when "011" => q<=minseg2; sel<="011"; when "100" => q<=hourseg1; sel<="100"; when "101" => q<=hourseg2; sel<="101"; when others => q<=" ";sel<="111"; end case; end process;

31 数字时钟设计-主程序 --秒低位显示 second_counter1:process(sec_counter1) begin
case sec_counter1 is when "0000" => secseg1<=" "; when "0001" => secseg1<=" "; when "0010" => secseg1<=" "; when "0011" => secseg1<=" "; when "0100" => secseg1<=" "; when "0101" => secseg1<=" "; when "0110" => secseg1<=" "; when "0111" => secseg1<=" "; when "1000" => secseg1<=" "; when "1001" => secseg1<=" "; when others => secseg1<=" "; end case; end process second_counter1;

32 第11章 数字时钟设计-主程序 --秒高位显示 second_counter2:process(sec_counter2) begin
case sec_counter2 is when "0000" => secseg2<=" "; when "0001" => secseg2<=" "; when "0010" => secseg2<=" "; when "0011" => secseg2<=" "; when "0100" => secseg2<=" "; when "0101" => secseg2<=" "; when others => secseg2<=" "; end case; end process second_counter2;

33 数字时钟设计-主程序 --分低位显示 minute_counter1:process(min_counter1) begin
case min_counter1 is when "0000" => minseg1<=" "; when "0001" => minseg1<=" "; when "0010" => minseg1<=" "; when "0011" => minseg1<=" "; when "0100" => minseg1<=" "; when "0101" => minseg1<=" "; when "0110" => minseg1<=" "; when "0111" => minseg1<=" "; when "1000" => minseg1<=" "; when "1001" => minseg1<=" "; when others => minseg1<=" "; end case; end process minute_counter1;

34 第11章 数字时钟设计-主程序 --分高位显示 minute_counter2:process(min_counter2) begin
case min_counter2 is when "0000" => minseg2<=" "; when "0001" => minseg2<=" "; when "0010" => minseg2<=" "; when "0011" => minseg2<=" "; when "0100" => minseg2<=" "; when "0101" => minseg2<=" "; when others => minseg2<=" "; end case; end process minute_counter2;

35 数字时钟设计-主程序 --小时低位显示 hor_counter1:process(hour_counter1) begin
case hour_counter1 is when "0000" => hourseg1<=" "; when "0001" => hourseg1<=" "; when "0010" => hourseg1<=" "; when "0011" => hourseg1<=" "; when "0100" => hourseg1<=" "; when "0101" => hourseg1<=" "; when "0110" => hourseg1<=" "; when "0111" => hourseg1<=" "; when "1000" => hourseg1<=" "; when "1001" => hourseg1<=" "; when others => hourseg1<=" "; end case; end process;

36 数字时钟设计-主程序 --小时高位显示 hor_counter2:process(hour_counter2) begin
case hour_counter2 is when "0000" => hourseg2<=" "; when "0001" => hourseg2<=" "; when "0010" => hourseg2<=" "; when others => hourseg2<=" "; end case; end process; end Behavioral;


Download ppt "数字时钟设计及实现 何宾 2011.09."

Similar presentations


Ads by Google