数电课程设计(推荐)由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“数电课程设计题目选”。
数电课程设计
基于vhdl数字电子时钟
华侨大学 2009级电子信息工程A班 学生:刘飞 学号:0916103045 1实验目的及要求.A:锻炼自己的实际动手能力,学习如何编写相关程序,加强实践。B:设计一个24进制电子时钟,并实现其基本校时功能。
2.时钟的功能
A、按键消抖,整点报时,音乐闹钟,秒表,时分秒校时,秒的清零,达到23时59分59秒
3.设计方案
A它由分频器、计数器、译码器显示器和校时扫描,使能等电路组成。B秒计数器满60后向分计数器进位,分计数器满60后向小时计数器进位,小时计数器按照24进制规律计数。计数器的输出分别经译码器送显示器按键切换显示。计时出现误差时,可以用校时电路校时、校分。
C可设置闹钟,当达到闹钟时间,蜂鸣器就会播放音乐。当到达整点时蜂鸣器会发出5秒钟的叫声,完成其整点报时功能。
D秒表部分由其单独模块构成。其 设置与时钟类似,构成相对简单,可仿照时钟完成。
E总体讲它是由各模块分块构成,(自我感觉来说首先确定其功能想象出原理图,最后一步一步地添加各个功能,这对于我们初学者来说十分重要)。
F将各个模块首先一部分一部分进行仿真,不断改正,连接起来,想成一个整体。如果需要相关的门及触发器,可以通过软件平台中查找,尤其是消抖需要的触发器。
G最后进行硬件测试,并反复调时,观察其计时是否准确,各个模块的功能是否正确。如果出现错误,要进行自顶向下的查找,同时更要结合其功能模块,查错,最后完成时钟
4.原理图为
5.模块(各个模块仿真结果正常)
A.时分秒模块都相对简单,其介绍就不做多说 B.校时功能是在分秒模块内添加一个控制键,让其进行调时分时,完成其功能。C.闹钟模块设置,利用一个切换键让闹钟与其他显示进行切换显示,其设定功能与时分共用。即设置多功能按键 D.秒表模块是单独设置的,它也利用相关的多功能按键。E.切换显示模块稍微简单,只需添加控制开关即可,但要开关要与相关的功能键对应。F.译码显示模块是对前面需要译码的信息进行译码显示,此模块设置为最后连接的模块,可节约资源,减少成本。G.扫描模块主要是应对我们硬件不能同时显示而设置的,相对难度大一点,因为它要考虑到输出的数码显示使能端,和扫描频率大小的设定这这都需要自己亲自测试,毕竟自己第一次使用这种类型的fpga开发板.H.分频模块,由于开发板里面只有一个时钟源50M,我们若要得到相关频率就必须对其进行分频,输出。I.消抖主要通过D触发器完成其功能,并且接上一定的时钟信号。5.具体程序如下
1. 秒模块
进位信号正常,为60进制,较分信号也正常,实现60进制带有进位和清零功能的秒计数模块SECOND,输入为1Hz脉冲和高电平有效的清零信号CLR,输出秒个位、十位及进位信号CO。
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity second is port(mode1 :in std_logic;clk,reset,semin:in std_logic;sec1,sec0:out std_logic_vector(3 downto 0);enmin:out std_logic);end second;architecture art of second is signal enmin_2:std_logic;signal co:std_logic;begin proce(clk,semin,mode1)variable cnt1,cnt0:std_logic_vector(3 downto 0);begin if mode1='0'then enmin_2
elsif clk'event and clk='1' then if cnt1=“0101” and cnt0=“1001”then
co
cnt1:=“0000”;
cnt0:=“0000”;
elsif cnt0
cnt0:=cnt0+1;
co
cnt0:=“0000”;
if cnt1
cnt1:=cnt1+1;
co
else
cnt1:=“0000”;
co
end if;end if;end if;sec1
仿真结果正常
2.分模块
进位信号正常,为60进制,较时信号也正常
LIBRARY ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;ENTITY minute10 IS
PORT(en1 : IN STD_LOGIC;
min1,min0
:out std_logic_vector(3 downto 0);
enhour: OUT STD_LOGIC);END minute10;ARCHITECTURE art OF minute10 IS signal enmin_2:std_logic;signal bco:std_logic;BEGIN
Proce(en1)variable cnt1,cnt0:std_logic_vector(3 downto 0);begin
if en1'event and en1='1' then
if cnt1=“0101”and cnt0=“1001” then
bco
cnt1:=“0000”;
cnt0:=“0000”;
elsif cnt0
cnt0:=cnt0+1;
bco
else
cnt0:=“0000”;
if cnt1
cnt1:=cnt1+1;
bco
else
cnt1:=“0000”;
bco
end if;
end if;
end if;
min1
min0
enhour
end proce;end art;
仿真结果正常
3.时模块
进位信号正常,为24进制。
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity hour is port(mode3 :in std_logic;
en2
:in std_logic;
h1,h0
:out std_logic_vector(3 downto 0));end hour;architecture hour_arc of hour is begin proce(en2)variable cnt1,cnt0:std_logic_vector(3 downto 0);begin
if en2'event and en2='1' then if cnt1=“0010”and cnt0=“0011” then cnt0:=“0000”;cnt1:=“0000”;elsif cnt0
仿真结果正常
4.第一个切换模块(不同于第二个)此模块主要用于闹钟显示与时间显示的切换
LIBRARY ieee;use ieee.std_logic_1164.all;ENTITY alarm IS
PORT(amin1,amin0,ah1,ah0,min1,min0,h1,h0
:in std_logic_vector(3 downto 0);
clk:in std_logic;
mode6
:IN STD_LOGIC;
a1,a0,b1,b0
:OUT std_logic_vector(3 downto 0));END alarm;ARCHITECTURE art OF alarm IS BEGIN
Proce(mode6,min1,min0,h1,h0,amin1,amin0,ah1,ah0)begin
if mode6='0' then
a1
a0
b1
b0
else
a1
a0
b1
b0
end if;end proce;end art;仿真结果正常
5第二个切换显示模块
此模块主要用于切换秒表模块与其他模块的显示
LIBRARY ieee;use ieee.std_logic_1164.all;ENTITY alarm2 IS
PORT(tmin1,tmin0,tsec0,tsec1,a1,a0,b0,b1,c1,c0,tsecp0,tsecp1
:in std_logic_vector(3 downto 0);
mode6
:IN STD_LOGIC;
ta1,ta0,tb1,tb0,tc0,tc1
:OUT std_logic_vector(3 downto 0));END alarm2;ARCHITECTURE art OF alarm2 IS BEGIN
Proce(mode6,tmin1,tmin0,tsec0,tsec1,a1,a0,b0,b1,c1,c0,tsecp0,tsecp1)begin
if mode6='0' then
ta1
ta0
tb1
tb0
tc1
tc0
else
ta1
ta0
tb1
tb0
tc0
tc1
end if;end proce;end art;6闹钟模块 library ieee;use ieee.std_logic_1164.all;entity ts_zdbs is port(m1,m0,s6,s7
:in std_logic_vector(3 downto 0);
clk :in std_logic;
q512
:out std_logic);end ts_zdbs;architecture art of ts_zdbs is begin
proce(m1,clk,m0,s7,s6)begin if m1=“0101”and m0=“1001”and s7=“0101” then if s6=“1001” or s6=“1000” or s6=“0111” or s6=“0110” then q512
q512
用于设置分钟的的定时
LIBRARY ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;ENTITY aminute0 IS
PORT(mode4 :in std_logic;
s4: IN STD_LOGIC;
amin1,amin0
:out std_logic_vector(3 downto 0));end aminute0;ARCHITECTURE art OF aminute0 IS BEGIN
Proce(mode4,s4)variable cnt1,cnt0:std_logic_vector(3 downto 0);begin
if mode4='1' then
if s4'event and s4='1' then
if cnt1=“0101”and cnt0=“1001” then
cnt1:=“0000”;
cnt0:=“0000”;
elsif cnt0
cnt0:=cnt0+1;
else
cnt0:=“0000”;
if cnt1
cnt1:=cnt1+1;
else
cnt1:=“0000”;
end if;
end if;
end if;
amin1
amin0
end if;
end proce;end art;
仿真结果正常
8闹钟的时模块 设置时的大小
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity bahour is port(mode5
:in std_logic;
t5
:in std_logic;
ah1,ah0
:out std_logic_vector(3 downto 0));end bahour;architecture bahour_arc of bahour is begin proce(mode5,t5)variable cnt1,cnt0:std_logic_vector(3 downto 0);begin
if mode5='1' then
if t5'event and t5='1' then
if cnt1=“0010”and cnt0=“0011”then cnt0:=“0000”;cnt1:=“0000”;elsif cnt0
仿真结果正常
至于外加音乐模块十分复杂,可要可不要(这个模块是通过抄写得到的)9.分频模块1 产生1HZ的时钟信号
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fasheng1 is port(clk_in:in std_logic;
clk_out:out std_logic);end fasheng1;architecture arc of fasheng1 is signal number:integer range 0 to 25000000;signal current_clk: std_logic;begin
clk_out
if clk_in'event and clk_in='0' then if number
number
这个模块不好仿真,因为数字太大,利用改小测试之后,正常
10.分频模块2 产生10kHZ的数码管扫描信号,以及用作消抖时钟信号
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fasheng2 is port(clk_in:in std_logic;
clk_out:out std_logic);end fasheng2;architecture arc of fasheng2 is signal number:integer range 0 to 2500;signal current_clk: std_logic;begin
clk_out
if clk_in'event and clk_in='0' then if number
number
current_clk
11整点报时模块
其中报时时间为5秒,clk为10kHZ library ieee;use ieee.std_logic_1164.all;entity ts_zdbs is port(m1,m0,s6,s7
:in std_logic_vector(3 downto 0);
clk :in std_logic;
q
:out std_logic);end ts_zdbs;architecture art of ts_zdbs is begin
proce(m1,clk,m0,s7,s6)begin if m1=“0101”and m0=“1001”and s7=“0101” then if s6=“1001” or s6=“1000” or s6=“0111” or s6=“0110” then q
q
其输出作为数码管使能,library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity coutn8 is port(sel:in std_logic_vector(2 downto 0);
dp: out std_logic;
enf:out std_logic_vector(7 downto 0));end coutn8;architecture
arc of coutn8 is signal en :std_logic_vector(7 downto 0);
begin
enf
dp
begin
case sel is
when “000”=>en
when “001”=>en
when “010”=>en
when “011”=>en
when “100”=>en
when “101”=>en
when “110”=>en
when “111”=>en
end case;
end proce;end arc;13译码模块 library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity decoderceshi is Port(din:in std_logic_vector(3 downto 0);
--四位二进制码输入 dout:out std_logic_vector(6 downto 0));--输出LED七段码 end decoderceshi;architecture Behavioral of decoderceshi is signal ddout:std_logic_vector(6 downto 0);begin dout(6 downto 0)ddout ddout ddout ddout ddout ddout ddout ddout ddout ddout ddout
14.扫描模块
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity SELTIMEceshi is
port(clk:in std_logic;------扫描时钟
sec1,sec0,min1,min0,h1,h0:in std_logic_vector(3 downto 0);-----分别为秒个位/时位;分个位/
daout:out std_logic_vector(3 downto 0);----------------输出
sel:out std_logic_vector(2 downto 0));-----位选信号 end SELTIMEceshi;architecture fun of SELTIMEceshi is
signal count:std_logic_vector(2 downto 0);----计数信号 begin
sel
proce(clk)
begin
if(clk'event and clk='0')then
if(count>=“111”)then
count
else
count
end if;
end if;
case count is
when“111”=>daout
when“110”=>daout
when“101”=>daout
when“100”=>daout
when“011”=>daout
----时个位
when“010”=>daout
when“001”=>daout
when others =>daout
end case;
end proce;end fun;15秒表模块 1.分频模块
产生100HZ的时钟信号
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fasheng100 is port(clk_in:in std_logic;
clk_out:out std_logic);end fasheng100;architecture arc of fasheng100 is signal number:integer range 0 to 250000;signal current_clk: std_logic;begin
clk_out
if clk_in'event and clk_in='0' then if number
number
LIBRARY ieee;(顶层文件)use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity miao is port(clknew,cclr:in std_logic;
tsec0,tsec1,tmin0,tmin1,tsecp0,tsecp1:out std_logic_vector(3 downto 0));end miao;architecture arc of miao is component count100 port(clk0,clr:in std_logic;
secp0,secp1 :out std_logic_vector(3 downto 0);
dout1:out std_logic);end component;component tsecond port(enx1,clr:in std_logic;sec1,sec0:out std_logic_vector(3 downto 0);dout2:out std_logic);end component;component tminute0
PORT(enx2,clr
: IN STD_LOGIC;
min1,min0
:out std_logic_vector(3 downto 0));END component;signal kdout1,kdout2:std_logic;begin u1: count100 port map(clk0=>clknew,clr=>cclr,secp0=>tsecp0,secp1=>tsecp1,dout1=>kdout1);u2: tsecond port map(enx1=>kdout1,clr=>cclr,sec1=>tsec1,sec0=>tsec0,dout2=>kdout2);u3: tminute0 port map(enx2=>kdout2,clr=>cclr,min1=>tmin1,min0=>tmin0);end arc;
100进制模块 LIBRARY ieee;
use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity count100 is port(clk0,clr:in std_logic;
secp0,secp1 :out std_logic_vector(3 downto 0);
dout1:out std_logic);end count100;architecture arc of count100 is begin proce(clk0,clr)variable cnt0,cnt1:std_logic_vector(3 downto 0);begin
if clr='1' then cnt0:=“0000”;cnt1:=“0000”;elsif clk0'event and clk0='1' then
if cnt0=“1001” and cnt1=“1001” then cnt0:=“0000”;cnt1:=“0000”;dout1
cnt0
cnt0:=cnt0+1;
dout1
cnt0:=“0000”;
if cnt1
cnt1:=cnt1+1;
dout1
else
cnt1:=“0000”;
dout1
end if;end if;end if;secp1
dout2
cnt1:=“0000”;
cnt0:=“0000”;
elsif cnt0
cnt0:=cnt0+1;
dout2
cnt0:=“0000”;
if cnt1
cnt1:=cnt1+1;
dout2
else
cnt1:=“0000”;
dout2
end if;end if;end if;sec1
PORT(enx2,clr
: IN STD_LOGIC;
min1,min0
:out std_logic_vector(3 downto 0));END tminute0;ARCHITECTURE art OF tminute0 IS BEGIN
Proce(enx2,clr)variable cnt1,cnt0:std_logic_vector(3 downto 0);begin
if clr='1' then
cnt1:=“0000”;
cnt0:=“0000”;
elsif enx2'event and enx2='1' then
if cnt1=“0101”and cnt0=“1001”then
cnt1:=“0000”;
cnt0:=“0000”;
elsif cnt0
cnt0:=cnt0+1;
else
cnt0:=“0000”;
if cnt1
cnt1:=cnt1+1;
else
cnt1:=“0000”;
end if;
end if;
end if;
min1
min0
end proce;end art;各个仿真结果正常 其整个仿真结果图为
6.感悟:做完这个实验是我由完全不懂到懂了很多的vhdl编程,确实了解了很多的知识与技能,同时这其中也有我的同学的帮忙与指点以及网上的参考,才让我能够顺利完成这个实验。
相信只要动手做就有可能做成,倘若连不动手,不去思考,连做成想法都没有,甚至连抄写的想法也没有,结果注定会做不成。