时分秒可校的定时器电路设计报告摘要本设计的目的是设计一时分秒可校的定时器电路,该电路由数据预置部分对核心部分定时器模块进行时间预置,输出接至显示模块并通过LED数码管显示时分秒信息,定时时间到通过声光报警模块进行报警。
设计采用可编程芯片和VHDL语言进行软硬件设计,不但可使硬件大为简化,而且稳定性也有明显提高。
本设计采用逐位设定预置时间,其最长时间设定可长达24小时59分59秒,并由六个共阴数码管进行时分秒的显示,定时时间到喇叭发出声响,同时两个LED灯亮。
关键字: VHDL语言定时器显示报警目录一、系统设计 (4)二、单元电路设计 (4)三、软件设计 (6)四、系统测试 (7)五、结论 (8)六、参考文献 (9)七、附录 (9)一、系统设计1、设计要求时分秒可校的定时器,定时范围为10秒—24时59分59秒,精度为1秒,能同时显示时分秒信息(LED数码管),定时时间到能发出声光警告信号。
2、系统设计方案 总体框图如图所示:图中定时模块由2个59进制、1个24进制的减计数器连接,实现定时器递减到零的倒计时功能;输出由七段数码显示译码器驱动数码管显示;报警模块由输出系列检测实现喇叭和LED 灯的时间报警;时间预置由六个输入端口分别对时分秒进行预置。
二、单元电路设计1、倒计时部分(以秒为例):该部分是整个电路的核心,clk 为时钟信号,当时钟上升沿到来,倒计时开始,cn 为使能端,高电平有效,res 为复位端,用来清零,采用异步复位方式,s1、s2端为别为十位、个位数据预置端;count 为数据溢出端,高电平有效,dlow 、high 为四位BCD 码输出端口,用于显示及报警。
当cn 有效时,clk 脉冲上升沿到来时,开始倒计时,每60秒为一个周期,溢出端count 输出一信号使分计数减1,直到计时完成。
2、七段数码管显示:该部分实现时分秒实时显示功能。
输入端为四位BCD 码,输入端为七段数码管。
定时部分输出的时分秒信号通过该部分电路译码驱动LED 数码管显示。
3、声光报警部分:该部分用于定时到发出声光信号报警。
输入端为23位数据总线,输出端speak 为声音报警信号,高电平有效,lamp 为LED 报警信号。
当输入检测定时部分输出都为0时,喇叭发出报警音,同时LED 灯亮。
三、软件设计1、主体部分:Res=1Res=0Cn=1Cn=0Cn=1计数以及预置数(秒和分的):beginif res='1' thendisplow<=0;disphigh<=0;elsif clk'event and clk = '1' thenif cn='1' then----计数部分if clk'event and clk = '1' thenif displow>0 thendisplow<=displow-1;elsif displow=0 thendisplow<=9;if disphigh>0 thendisphigh<=disphigh-1;elsif disphigh=0 thendisphigh<=5;end if;end if;end if;else ---预置数部分if s2 = '1' THENif displow<9 thendisplow<=displow+1;else displow<=0;end if;end if ;if s1 = '1' THENif disphigh<6 thendisphigh<=disphigh+1;else displow<=0;end if;end if ;end if ;end if;end process;process(disphigh,displow,clk)beginif disphigh=0 and displow=0 and clk='1' thencount<='1';elsecount<='0';end if;声音报警部分:process(din)beginif cn='1' anddin="001110010101100100000000" thenspeak<='1';lamp<="111";elsespeak<='0';lamp<="001";采用的是序列验证的方法获得报警信号,通过蜂鸣器发出以及LED显示。
四、系统测试1、综合分析如下:仿真分析(目标芯片型号EP2C5T144C8,资源使用:81个LCS,37个I/O)仿真波形如下:2、硬件验证(实验箱编号)引脚见附图(NO.3)验证结果:开始预置计时,当使能端为高电平时,倒计时开始,当完成倒计时,三个LED灯全亮,蜂鸣器发出声音。
五、结论分析:计数以及预置数部分当开始预置数时,h1是小时部分高位的递增按键h2是小时部分低位的递增按键m1是分钟部分高位的递增按键m2是分钟部分低位的递增按键s1是秒钟部分高位的递增按键s2是秒钟部分低位的递增按键;整个仿真的结果可以实现定时的功能,而且整个过程都清晰明了地显示在数码管,蜂鸣器以及LED灯上。
但是由于程序上的问题,定时时间到不能停止,这是一个小缺点,但是没有影响到报警的功能。
总得来说,各种要求都已经达到,存在的小缺点无伤整个设计,而且时间采用1HZ十分准确。
六、参考文献EDA技术与VHDL(第三版)清华大学出版社EDA技术与Verilog设计科学出版社七、电路原理图引脚图所有程序1)秒(分)计时以及预置数程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity second is port (clk:in std_logic;cn:in std_logic;res:in std_logic;s1:in std_logic;s2:in std_logic;count:out std_logic;dlow: OUT INTEGER RANGE 0 TO 15;dhigh:OUT INTEGER RANGE 0 TO 15 ) ;end second;architecture second_1 of second issignal displow: INTEGER RANGE 0 TO 15;signal disphigh: INTEGER RANGE 0 TO 15; beginprocess(clk,res,s1,s2)beginif res='1' thendisplow<=0;disphigh<=0;elsif clk'event and clk = '1' thenif cn='1' thenif clk'event and clk = '1' thenif displow>0 thendisplow<=displow-1;elsif displow=0 thendisplow<=9;if disphigh>0 thendisphigh<=disphigh-1;elsif disphigh=0 thendisphigh<=5;end if;end if;end if;elseif s2 = '1' THENif displow<9 thendisplow<=displow+1;else displow<=0;end if;end if ;if s1 = '1' THENif disphigh<6 thendisphigh<=disphigh+1;else displow<=0;end if;end if ;end if ;end if;end process;process(disphigh,displow,clk)beginif disphigh=0 and displow=0 and clk='1' thencount<='1';elsecount<='0';end if;end process;dhigh<=disphigh;dlow<=displow;end second_1;2)时计数以及预置程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity hour is port (clk:in std_logic;cn:in std_logic;res:in std_logic;s1:in std_logic;s2:in std_logic;count:out std_logic;dlow: OUT INTEGER RANGE 0 TO 15;dhigh:OUT INTEGER RANGE 0 TO 15) ;end hour;architecture hour_1 of hour issignal displow: INTEGER RANGE 0 TO 15;signal disphigh: INTEGER RANGE 0 TO 15; beginprocess(clk,res,s1,s2)beginif res='1' thendisplow<=0;disphigh<=0;elsif clk'event and clk = '1' thenif cn='1' thenif clk'event and clk = '1' thenif displow>0 thendisplow<=displow-1;elsif displow=0 thendisplow<=9;if disphigh>0 thendisphigh<=disphigh-1;elsif disphigh=0 thendisphigh<=3;end if;end if;end if;elseif s2 = '1' THENif displow<9 thendisplow<=displow+1;else displow<=0;end if;end if ;if s1 = '1' THENif disphigh<3 thendisphigh<=disphigh+1;else displow<=0;end if;end if ;end if ;end if;end process;process(disphigh)beginif disphigh=3 thencount<='1';elsecount<='0';end if;end process;dhigh<=disphigh;dlow<=displow;end hour_1;3)报警部分:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity alert isport(cn:in std_logic;din: in std_logic_vector(23 downto 0);speak:out std_logic;lamp: out std_logic_vector(2 downto 0)); end ;architecture alert_1 of alert isbeginprocess(din)beginif cn='1' anddin="001110010101100100000000" thenspeak<='1';lamp<="111";elsespeak<='0';lamp<="001";。