1、 1 数字数字电子设计报告电子设计报告 课程题目:课程题目:简易简易定时器定时器 2 一一、 功能介绍:功能介绍: 定时器是一种生活中常见的时间计量工具.它的特点是结构简单小巧,精度较高,携带方 便.广泛运用于科技,经济,生活领域。此定时器基于 VHDL 语言,硬件相对较简单,且性能稳 定。 二二 、原理概述:原理概述: 本次实验主要采用了计数器和显示电路,其工作原理简单叙述如下:设计主要包括三大 模块:计数器(包含定时作用),扫描部分及译码输出电路.现分别对每一个模块的功能进行讨 论. (1) 计数器模块利用输入信号 set 的变化可实现计数器实现不同的功能,如 set=0 时,实现 加计数
2、的功能到预置数为止;set=1 时,则可实现减计数的功能, 开始从置数值递减.根据 set 信 号的跳变时刻可非常方便的置入计数初值.clr 用来整体复位清零, 可实现多次置数; clk 提供 秒信号,频率为 1Hz,为加计数提供时钟信号;clky 是用来扫描输出的,选用频率较高的方 波,则可方便将变化的数字显示输出。设计中将时钟信号 clk 进行分频,则可实现以秒的速 度从零增至所需定时的时间,然后在以分的速度(60 分频)递减,直到零。 计数器模块计数器模块 计数器的计数器的 VHDL 描述描述: library ieee; use ieee.std_logic_1164.all; use
3、 ieee.std_logic_unsigned.all; entity aaa is port(clk,clr,set:in std_logic; alm:out std_logic; q1,q0:out std_logic_vector(3 downto 0) ); 定义计数器模块的实体 end aaa; 3 architecture aaa_arc of aaa is begin process(clk) variable cnt1,cnt0:std_logic_vector(3 downto 0); variable cnt:integer range 0 to 59; begin i
4、f clr=0 then 整体复位 alm=0; cnt:=0; cnt1:=“0000“; cnt0:=“0000“; elsif clkevent and clk=1 then if set=0 then 设计数初值 cnt:=0; if cnt0“1001“then cnt0:=cnt0+1; else cnt0:=“0000“; if cnt1“1001“ then cnt1:=cnt1+1; else cnt1:=“0000“; end if; end if; else if cnt“0000“then cnt0:=cnt0-1; if cnt1=“0000“ and cnt0=“0000“then alm“0000“then 判断计数器是否结束 cnt1:=cnt1-1; else cnt1:=“1001“; end if ; end if ; end if ; end if ; 4 end if ; q0=cnt0; q1=cnt1; end proc