人人范文网 范文大全

FPGA可调数字时钟实验报告

发布时间:2020-03-02 08:34:51 来源:范文大全 收藏本文 下载本文 手机版

浙江大学城市学院

实验报告纸

一、实验要求

1、用vhdl编程,实现10进制计数器

2、用vhdl编程,实现60进制计数器

3、用vhdl编程,实现数字时钟,时、分、秒、毫秒分别显示在数码管上。

4、实现可调数字时钟的程序设计,用按键实现时、分、秒、毫秒的调整。

二、实验原理

用VHDL,行为级描述语言实现实验要求。思路如下:

1、分频部分:由50MHZ分频实现1ms的技术,需要对50MHZ采取500000分频。

2、计数部分:采用低级影响高级的想法,类似进位加1的思路。对8个寄存器进行计数,同步数码管输出。

3、数码管输出部分:用一个拨码开关控制显示,当sw0=0时,四位数码管显示秒、毫秒的计数。当sw0=1时,四位数码管显示时、分得计数。

4、调整部分:分别用四个按键控制时、分、秒、毫秒的数值。先由一个开关控制计数暂停,然后,当按键按下一次,对应的数码管相对之前的数值加1,,通过按键实现时间控制,最后开关控制恢复计数,完成时间调整。

5、整个实现过程由一个文件实现。

三、实验过程

各个引脚说明: Clk:50MHZ SW:数码管切换,SW=’0’时,数码管显示为秒,毫秒。SW=’1’时,数码管显示为时,分。

SW1:暂停与启动。SW1=’0’时,时钟启动,SW=’1’时,时钟暂停。

SW2:时钟调整接通按钮,当SW2=’0’时,不进行调整,当SW=’1’时,通过按键调整时间。

KEY0: 毫秒调整,按一次实现+1功能 KEY1:秒调整,按一次实现+1功能

浙江大学城市学院 实 验 报 告 纸

KEY2:分调整,按一次实现+1功能 KEY3:时调整,按一次实现+1功能 Q0;第一个数码管 Q1; 第二个数码管 Q2: 第三个数码管 Q3: 第四个数码管

1、源代码如下:

library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity paobiao is port(clk,sw,key0,key1,key2,key3,sw1,sw2:in std_logic;

q0:out std_logic_vector(6 downto 0);

q1:out std_logic_vector(6 downto 0);

q2:out std_logic_vector(6 downto 0);

q3:out std_logic_vector(6 downto 0)); end paobiao; architecture behave of paobiao is signal cntt1 :integer range 0 to 10; signal cntt2 :integer range 0 to 10; signal cntt3 :integer range 0 to 10; signal cntt4 :integer range 0 to 6; signal cntt5 :integer range 0 to 10; signal cntt6 :integer range 0 to 10; signal cntt7 :integer range 0 to 10; signal cntt8 :integer range 0 to 6; 浙江大学城市学院 实 验 报 告 纸

signal cntttt1 :integer range 0 to 10; signal cntttt2 :integer range 0 to 10; signal cntttt3 :integer range 0 to 10; signal cntttt4 :integer range 0 to 6; signal cntttt5 :integer range 0 to 10; signal cntttt6 :integer range 0 to 10; signal cntttt7 :integer range 0 to 10; signal cntttt8 :integer range 0 to 6;

begin

proce (clk)--,key0,key1,key2,key3)

variable cnt :integer range 0 to 500000;

--variable cnt9 :integer range 0 to 3000000000;

variable cnt1 :integer range 0 to 10;

variable cnt2 :integer range 0 to 10;

variable cnt3 :integer range 0 to 10;

variable cnt4 :integer range 0 to 6;

variable cnt5 :integer range 0 to 10;

variable cnt6 :integer range 0 to 10;

variable cnt7 :integer range 0 to 10;

variable cnt8:integer range 0 to 6;

begin if(clk\'event and clk=\'1\') then

if(sw1=\'0\') then if(cnt>=2) then

cnt:=0;

cnt1:=cnt1+1; 浙江大学城市学院 实 验 报 告 纸

if (cnt1=10) then

cnt1:=0;

cnt2:=cnt2+1;

if(cnt2=10) then

cnt1:=0;

cnt2:=0;

cnt3:=cnt3+1;

if(cnt3=10) then

cnt1:=0;

cnt2:=0;

cnt3:=0;

cnt4:=cnt4+1;

if(cnt4=6) then

cnt1:=0;

cnt2:=0;

cnt3:=0;

cnt4:=0;

cnt5:=cnt5+1;

if (cnt5=10) then

cnt5:=0;

cnt6:=cnt6+1;

if(cnt6=6) then

cnt5:=0;

cnt6:=0;

cnt7:=cnt7+1;

if(cnt7=4) then

cnt5:=0;

cnt6:=0;

cnt7:=0; 浙江大学城市学院 实 验 报 告 纸

cnt8:=cnt8+1;

if(cnt8=3) then

cnt5:=0;

cnt6:=0;

cnt7:=0;

cnt8:=0;

end if;

end if;

end if;

end if;

end if;

end if;

end if;

end if;

else cnt:=cnt+1;

end if;

if(sw2=\'0\') then

cntt1

cntt2

cntt3

cntt4

cntt5

cntt6

cntt7

cntt8

else

cnt1:=cntttt1;

cnt2:=cntttt2;

cnt3:=cntttt3; 浙江大学城市学院 实 验 报 告 纸

cnt4:=cntttt4;

cnt5:=cntttt5;

cnt6:=cntttt6;

cnt7:=cntttt7;

cnt8:=cntttt8;

cntt1

cntt2

cntt3

cntt4

cntt5

cntt6

cntt7

cntt8

end if;

end if; end if; end proce;

proce (key0) variable cnttt1 :integer range 0 to 10; variable cnttt2 :integer range 0 to 10; begin if(key0\'event and key0=\'0\') then

cnttt1:=cnttt1+1;

if(cnttt1=10) then

cnttt1:=0;

cnttt2:=cnttt2+1;

if(cnttt2=10) then 浙江大学城市学院 实 验 报 告 纸

cnttt2:=0;

end if;

end if;

cntttt1

cntttt2

end proce; proce (key1) variable cnttt3 :integer range 0 to 10; variable cnttt4 :integer range 0 to 10; begin if(key1\'event and key1=\'0\') then

cnttt3:=cnttt3+1;

if(cnttt3=10) then

cnttt3:=0;

cnttt4:=cnttt4+1;

if(cnttt4=6) then

cnttt4:=0;

end if;

end if;cntttt3

cntttt4

if(key2\'event and key2=\'0\') then 浙江大学城市学院 实 验 报 告 纸

cnttt5:=cnttt5+1;

if(cnttt5=10) then

cnttt5:=0;

cnttt6:=cnttt6+1;

if(cnttt6=6) then

cnttt6:=0;

end if;

end if;cntttt5

cntttt6

end if; end proce; proce(key3) variable cnttt7 :integer range 0 to 10; variable cnttt8 :integer range 0 to 10; begin

if (key3\'event and key3=\'0\') then

cnttt7:=cnttt7+1;

if(cnttt7=4) then

cnttt7:=0;

cnttt8:=cnttt8+1;

if(cnttt8=3) then

cnttt8:=0;

end if;

end if;

cntttt7

cntttt8

end if; 浙江大学城市学院 实 验 报 告 纸

end proce;

--end if; --end proce;

proce(cntt1,cntt5)

begin

if(sw=\'0\') then

case cntt1 is

when 0=>q0

when 1=>q0

when 2=>q0

when 3=>q0

when 4=>q0

when 5=>q0

when 6=>q0

when 7=>q0

when 8=>q0

when 9=>q0

when others=>q0

case cntt5 is

when 0=>q0

when 1=>q0

when 2=>q0

when 3=>q0

when 4=>q0

when 5=>q0

when 6=>q0

浙江大学城市学院 实 验 报 告 纸

when 7=>q0

when 8=>q0

when 9=>q0

when others=>q0

end if;

end proce;

proce(cntt2,cntt6)

begin if(sw=\'0\') then

case cntt2 is

when 0=>q1

when 1=>q1

when 2=>q1

when 3=>q1

when 4=>q1

when 5=>q1

when 6=>q1

when 7=>q1

when 8=>q1

when 9=>q1

when others=>q1

case cntt6 is

when 0=>q1

when 1=>q1

when 2=>q1

when 3=>q1

when 4=>q1

when 5=>q1

when 6=>q1

when 7=>q1

when 8=>q1

when 9=>q1

when others=>q1

end proce; proce(cntt3,cntt7)

begin

if(sw=\'0\') then

case cntt3 is

when 0=>q2

when 1=>q2

when 2=>q2

when 3=>q2

when 4=>q2

when 5=>q2

when 6=>q2

when 7=>q2

when 8=>q2

when 9=>q2

when others=>q2

case cntt7 is 浙江大学城市学院 实 验 报 告 纸

when 0=>q2

when 1=>q2

when 2=>q2

when 3=>q2

when 4=>q2

when 5=>q2

when 6=>q2

when 7=>q2

when 8=>q2

when 9=>q2

when others=>q2

end proce;

proce(cntt4,cntt8)

begin if(sw=\'0\') then

case cntt4 is

when 0=>q3

when 1=>q3

when 2=>q3

when 3=>q3

when 4=>q3

when 5=>q3

when others=>q3

case cntt8 is

when 0=>q3

when 1=>q3

when 2=>q3

when 3=>q3

when 4=>q3

when 5=>q3

when 6=>q3

-- when 7=>q3q3q3

when others=>q3

end proce; end behave;

2、原理图如下:

浙江大学城市学院 实 验 报 告 纸

3、功能仿真如下

1、秒、毫秒计数仿真

2、分、时计数仿真

注释:由于仿真时间限制,小时不能显示。注意SW由0变成1;

浙江大学城市学院 实 验 报 告 纸

3、

暂停的仿真,数码管显示用秒,毫秒。

4、按键调整的仿真,主要仿真毫秒的仿真

四、实验结果

实验结果均完成所有要求,但有一个bug,在实现调整功能的时候,不能实时调整数码管暂停下来的数字,只能从之前调整过的数值起开始调整,不过能实现调整之后,开启时钟,时钟即在设定的时间开始跑。当然找到解决的方法,当由于思路和已经 写好的程序冲突性较大,所以此处不再修改。

五、心得体会

本次实验在分频的基础上进行拓展,同时应用数码管显示,开关和按键的控制,比较系统的做了一个实验,对自身的提高还是很有帮助的。

说到心得,此次实验告诉我一下经验:

1、在开始写程序之前最好先评估好自己的思路,简易画出想象中的原理图,再进行编程,对之后的修改有很大的帮助。

2、程序写长了,发现错得时候,修改比较麻烦,所有注意编程习惯很重要,适当的加一些注释,提高程序的可读性。

3、程序最好分模块写,比较清晰。

浙江大学城市学院 实 验 报 告 纸

数字电子时钟实验报告

数字时钟的设计实验报告

FPGA实验报告

基于FPGA的数字电子时钟设计与实现

FPGA秒表实验报告

FPGA交通灯实验报告

数字时钟课程设计论文

数字电子时钟设计

EDA课程设计——数字时钟

EDA课程设计 数字时钟

FPGA可调数字时钟实验报告
《FPGA可调数字时钟实验报告.doc》
将本文的Word文档下载到电脑,方便编辑。
推荐度:
点击下载文档
点击下载本文文档