简易时钟的设计EDA
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
摘要
本课程设计要紧介绍了运用EDA技术实现“电子时钟”的设计,以达到对EDA技术的熟练把握,提升对《EDA技术及应用》课程所学的内容的把握和应用,文介绍一种利用FPGA可编程逻辑器件设计数字电子时钟的方式及进程。
文中包括各部份程序及通过max-plusII仿真的波形。
通过对max-plusII的利用熟悉max-plusII仿真软件的工作方式及应用。
关键字:EDA FPGA 电子时钟 max-plusII
目录
摘要 ....................................................... Ι1.设计方案及原理 .. (2)
1.1设计方案 (2)
1.2设计原理 (2)
2. 设计进程 (4)
2.1顶层设计 (4)
2.2各个模块程序及波形 (4)
2.2.1小时模块 (4)
2.2.2分钟模块 (6)
2.2.3秒钟模块 (7)
2.2.4数码管译码模块 (9)
2.2.5数码管片选模块 (10)
2.2.6数码管扫描模块 (11)
2.2.7分频模块 (12)
2.3硬件电路图 (15)
总结 (16)
参考资料 (17)
附录Ⅰ简易时钟电路图 (18)
附录Ⅱ元件清单 (19)
依照电路特点,可用层次化结构化设计概念。
将此项设计任务分成假设干模块:
(1)时钟模块:由外部晶振提供;
(2)秒钟模块:对秒进行60循环计数,并向分钟产生进位,同时具有调分功能;
(3)分钟模块:对分进行60循环计数,并向小时产生进位,同时具有调时功能;
(4)小时模块:对小时进行24进制循环计;。
(5)10分频器和4分频器:将外部时钟分频为1Hz的时钟信号;
(6)6选1扫描显示:
(7)7段数码管译码器:译出数码管要显示的数字。
电子钟是一个将“时”“分”显示于人的视觉器官的计时装置。
它的计时周期为24小时;显示满刻度为23时59分59秒,秒由两个数码管显示,将标准秒信号送入“秒计数器”,每累加60秒发送一个“分脉冲”信号,该信号将被送到“时计数器”。
“时计数器”采纳24进制计数器,可实现对一天24小时的累计。
译码显示电路将“时”“分”“秒”计数器的输出状态六段显示译码器译码。
通过六位LED七段显示器显示出来。
数字钟结构组成框图如图1.2.1。
图 1.2.1 数字钟结构方框图
2. 设计进程
顶层文件是将各个模块连接在一路的模块。
其中,clk提供时钟信号,setmin用来调剂分钟,sethour用来调剂小时。
输出cout[2..0]是片选信号,输出a[6..0]连接7段数码管的7个引脚。
其顶层文件的电路图如图2.1.1。
图 2.1.1 顶层图
小时模块的电路图如图 2.2.1,其中,H1[3..0]是小时的高位,
H0[3..0]是小时的低位。
当H0[3..0]计到9时向高位进一。
当H1[3..0]与H0[3..0]别离计到0010和0011时,自动为0000。
图 2.2.1 小时模块
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity hour is
port(clk:in std_logic;
h1,h0:out std_logic_vector(3 downto 0));
end hour;
architecture art of hour is
signal cnt1,cnt0:std_logic_vector(3 downto 0);
begin
process(clk)
begin
if clk'event and clk='1' then
if cnt1="0010" then
if cnt0="0011" then
cnt0<="0000";
cnt1<="0000";
else
cnt0<=cnt0+1;
end if;
elsif cnt0="1001" then
cnt0<="0000";
cnt1<=cnt1+1;
else
cnt0<=cnt0+1;
end if;
end if;
h1<=cnt1;
h0<=cnt0;
end process;
end art;
小时模块的波形图如图2.2.2。
分钟模块的电路图如图 2.2.3,其中,MIN1[3..0]是分钟的高位,MIN0[3..0]是分钟的低位。
当MIN1[3..0]计到9时向高位进一。
当MIN1[3..0]与MIN0[3..0]别离计到0101和1001时,自动为0000。
SETHOUR是调时操纵。
其分钟模块的电路图如图2.2.3。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity minu is
port(sethour,clk:in std_logic;
min1,min0:out std_logic_vector(3 downto 0);
c0:out std_logic);
end minu;
architecture art of minu is
signal cnt1,cnt0:std_logic_vector(3 downto 0);
signal cc1,cc2:std_logic;
begin
cc2<=(sethour and clk);
c0<=(cc1 or cc2);
process(clk,sethour)
begin
if clk'event and clk='1' then
if cnt1="0101" then
if cnt0="1001" then
cc1<='1';
cnt0<="0000";
cnt1<="0000";
else
cnt0<=cnt0+1;
cc1<='0';
end if;
elsif cnt0="1001" then
cnt0<="0000";
cnt1<=cnt1+1;
cc1<='0';
else
cnt0<=cnt0+1;
cc1<='0';
end if;
end if;
min1<=cnt1;
min0<=cnt0;
end process;
end art;
分钟模块的波形图如图2.2.4。
秒钟模块的电路图如图 2.2.5,其中,SEC1[3..0]是秒钟的高位,SEC0[3..0]是秒钟的低位。
当SEC1[3..0]计到9时向高位进一。
当SEC1[3..0]与SEC0[3..0]别离计到0101和1001时,自动为0000。
SETMIN 是调时操纵。
秒钟模块的电路图如图2.2.2。
图2.2.5 秒钟模块
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity second is
port(clk,setmin:in std_logic;
sec1,sec0:out std_logic_vector(3 downto 0);
c0:out std_logic);
end second;
architecture art of second is
signal cnt1,cnt0:std_logic_vector(3 downto 0);
signal cc1,cc2:std_logic;
begin
cc2<=(setmin and clk);
c0<=(cc1 or cc2);
process(clk,setmin)
begin
if clk'event and clk='1' then
if cnt1="0101" and cnt0="1000" then
cc1<='1';
cnt0<="1001";
elsif cnt0<"1001" then
cnt0<=cnt0+1;
cc1<='0';
else
cnt0<="0000";
if cnt1<"0101" then
cnt1<=cnt1+1;
cc1<='0';
else
cnt1<="0000";
cc1<='1';
end if;
end if;
end if;
sec1<=cnt1;
sec0<=cnt0;
end process;
end art;
其秒钟模块的波形图如图2.2.6。
图2.2.6 秒钟模块波形
数码管译码模块用来译出数码管要显示的数字。
其电路图如图2.2.7。
library ieee;
use ieee.std_logic_1164.all;
entity disp is
port(d : in std_logic_vector(3 downto 0);
q : out std_logic_vector(6 downto 0));
end;
architecture one of disp is
begin
process(d)
begin
case d is
when "0000"=>q<="0111111";
when "0001"=>q<="0000110";
when "0010"=>q<="1011011";
when "0011"=>q<="1001111";
when "0100"=>q<="1100110";
when "0101"=>q<="1101101";
when"0110"=>q<="1111101";
when "0111"=>q<="0100111";
when"1000"=>q<="1111111";
when"1001"=>q<="1101111";
when others=>q<="0000000";
end case;
end process;
end one;
数码管片选模块用来选择数码管哪一时刻有效。
其电路图如图2.2.8。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cn6 is
port(clk : in std_logic;
cout : out std_logic_vector(2 downto 0));
end cn6;
architecture rtl of cn6 is
signal q : std_logic_vector(2 downto 0);
begin
process(clk)
begin
if(clk'event and clk='1') then
if(q=5) then
q<="000";
else
q<=q+1;
end if;
end if;
end process;
cout<=q;
end rtl;
数码管片选模块的波形图如图2.2.9。
数码管扫描模块用来显示输出的数字。
A[3..0]与B[3..0]别离接秒钟的高地位。
C[3..0]与D[3..0]别离接分钟模块的高地位。
E[3..0]与F[3..0]别离接小时模块的高低位。
其电路图如图2.2.10。
library ieee;
use ieee.std_logic_1164.all;
entity sel61 is
port(sel : in std_logic_vector(2 downto 0);
a,b,c,d,e,f : in std_logic_vector(3 downto 0);
q : out std_logic_vector(3 downto 0)); end;
architecture rtl of sel61 is
begin
process(a,b,c,d,e,f,sel)
variable cout : std_logic_vector(3 downto 0);
begin
case sel is
when "000"=>cout:=a;
when "001"=>cout:=b;
when "010"=>cout:=c;
when "011"=>cout:=d;
when "100"=>cout:=e;
when others=>cout:=f;
end case;
q <=cout;
end process;
end rtl;
10分频电路用来对时钟信号十分频。
10分频电路如图2.2.11。
图2.2.11 10分频电路
library ieee;
use ieee.std_logic_1164.all;
entity fen10 is
port(clk:in std_logic ;
q:out std_logic);
end fen10;
architecture fen_arc of fen10 is
begin
process(clk)
variable cnt:integer range 0 to 9; begin
if clk' event and clk='1'then
if cnt<9 then
cnt:=cnt+1;
q<='0';
else
cnt:=0;
q<='1';
end if;
end if;
end process;
end fen_arc;
十分频器波形图如图2.2.12。
图2.2.12 十分频器波形图四分频模块电路图如图2.2.13。
library ieee;
use ieee.std_logic_1164.all;
entity fen4 is
port(clk:in std_logic ;
q:out std_logic);
end fen4;
architecture fen_arc of fen4 is
begin
process(clk)
variable cnt:integer range 0 to 3; begin
if clk' event and clk='1'then
if cnt<3 then
cnt:=cnt+1;
q<='0';
else
cnt:=0;
q<='1';
end if;
end if;
end process;
end fen_arc;
本电路采纳FPGA芯片EP1K10TC144-1,外加有源晶振。
图 2.2.14 硬件电路图
总结
通过这次设计,进一步加深了对EDA的了解,让我对它有了加倍浓厚的爱好。
在编写顶层文件的程序时,碰到了很多问题,专门是各元件之间的连接,和信号的概念,老是有错误的存在,可是在我细心的检查下,终于找出了错误和警告的所在,排除困难后,程序编译就通过了。
在刚开始做实验的时,做起来感觉有点困难,很多的步骤都不记得,可是仍是试探着继续做完了实验,后来的实验就容易多了。
在这次实验中也碰到了很多问题,开始的时候我先是决定做数字钟那个实验,可是从我在图书馆查阅的资料来看,不是程序不完整确实是其中有错误,后来终于找到了一个比较完整的程序,可是其中又多出了有关七段共阴极扫描数码管的片选程序和七段译码程序因此就不用再编程序来完成这两个操作了。
我查了其他的有关资料然后对其程序进行了修改,把上述两个程序删除。
然后对顶层文件的各端口进行了修改,比如增添了三个输出端口SECOND[6..0]、MIN[6..0]、HOUR[6..0]等。
然后将各模块考虑后正确选择了硬件模式5,依照其功能要求选择了引脚,并查出了引脚号。
在对程序进行修改后,和正确选择硬件模块后,就对其进行了硬件测试,而且最后硬件测试结果与期望取得了功能要求一致。
总的来讲,这次设计的数字钟仍是比较成功的。
从这次实验中我学到了很多东西,不仅对EDA实验有所了解,而且还把实验和理论结合起来有效,对EDA有了较深切的了解。
不仅学到了很多知识,而且锻炼了自己的实际动手的能力,还提高了自己试探和独立的能力。
使自己对以后的学习道路有了个加倍清楚的熟悉,同时,对以后也有了更多的信心。
感激教师的指导!
参考资料
1.康华光主编,电子技术基础-数字部份[M].高等教育出版社,1998 2.谭会生等主编,EDA技术及应用[M].西安电子科技大学出版社,2001 3.潘松等主编,EDA技术有效教程[M].科学出版社,2006
4.雷伏容主编,VHDL电路设计[M].清华大学出版社,2006 5.Charles H.Roth等著,数字系统设计与VHDL[M].电子工业出版社,2020
6.王振红主编,数字电路设计与应用实践教程[M].机械工业出版社2004
附录Ⅰ简易时钟电路图
附录Ⅱ元件清单。