当前位置:文档之家› FPGA可调数字时钟实验报告

FPGA可调数字时钟实验报告

一、实验要求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:50MHZSW:数码管切换,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 isport(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 issignal 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;beginprocess (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;beginif(clk'event and clk='1') thenif(sw1='0') thenif(cnt>=2) thencnt:=0;cnt1:=cnt1+1;if (cnt1=10) thencnt1:=0;cnt2:=cnt2+1;if(cnt2=10) thencnt1:=0;cnt2:=0;cnt3:=cnt3+1;if(cnt3=10) thencnt1:=0;cnt2:=0;cnt3:=0;cnt4:=cnt4+1;if(cnt4=6) thencnt1:=0;cnt2:=0;cnt3:=0;cnt4:=0;cnt5:=cnt5+1; if (cnt5=10) thencnt5:=0;cnt6:=cnt6+1;if(cnt6=6) thencnt5:=0;cnt6:=0;cnt7:=cnt7+1;if(cnt7=4) thencnt5:=0;cnt6:=0;cnt7:=0;cnt8:=cnt8+1;if(cnt8=3) thencnt5:=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') thencntt1<=cnt1;cntt2<=cnt2;cntt3<=cnt3;cntt4<=cnt4;cntt5<=cnt5;cntt6<=cnt6;cntt7<=cnt7;cntt8<=cnt8;elsecnt1:=cntttt1;cnt2:=cntttt2;cnt3:=cntttt3;cnt4:=cntttt4;cnt5:=cntttt5;cnt6:=cntttt6;cnt7:=cntttt7;cnt8:=cntttt8;cntt1<=cnt1;cntt2<=cnt2;cntt3<=cnt3;cntt4<=cnt4;cntt5<=cnt5;cntt6<=cnt6;cntt7<=cnt7;cntt8<=cnt8;end if;end if;end if;end process;process (key0)variable cnttt1 :integer range 0 to 10; variable cnttt2 :integer range 0 to 10; beginif(key0'event and key0='0') thencnttt1:=cnttt1+1;if(cnttt1=10) thencnttt1:=0;cnttt2:=cnttt2+1;if(cnttt2=10) thencnttt2:=0;end if;end if;cntttt1<=cnttt1;cntttt2<=cnttt2;end if;end process;process (key1)variable cnttt3 :integer range 0 to 10; variable cnttt4 :integer range 0 to 10; beginif(key1'event and key1='0') thencnttt3:=cnttt3+1;if(cnttt3=10) thencnttt3:=0;cnttt4:=cnttt4+1;if(cnttt4=6) thencnttt4:=0;end if;end if;cntttt3<=cnttt3;cntttt4<=cnttt4;end if;end process;process(key2)variable cnttt5 :integer range 0 to 10; variable cnttt6 :integer range 0 to 10; beginif(key2'event and key2='0') thencnttt5:=cnttt5+1;if(cnttt5=10) thencnttt5:=0;cnttt6:=cnttt6+1;if(cnttt6=6) thencnttt6:=0;end if;end if;cntttt5<=cnttt5;cntttt6<=cnttt6;end if;end process;process(key3)variable cnttt7 :integer range 0 to 10; variable cnttt8 :integer range 0 to 10; beginif (key3'event and key3='0') thencnttt7:=cnttt7+1;if(cnttt7=4) thencnttt7:=0;cnttt8:=cnttt8+1;if(cnttt8=3) thencnttt8:=0;end if;end if;cntttt7<=cnttt7;cntttt8<=cnttt8;end if;end process;--end if;--end process;process(cntt1,cntt5)beginif(sw='0') thencase cntt1 iswhen 0=>q0<="1000000";when 1=>q0<="1111001";when 2=>q0<="0100100";when 3=>q0<="0110000";when 4=>q0<="0011001";when 5=>q0<="0010010";when 6=>q0<="0000010";when 7=>q0<="1011000";when 8=>q0<="0000000";when 9=>q0<="0010000";when others=>q0<=NULL;end case;elsecase cntt5 iswhen 0=>q0<="1000000";when 1=>q0<="1111001";when 2=>q0<="0100100";when 3=>q0<="0110000";when 4=>q0<="0011001";when 5=>q0<="0010010";when 6=>q0<="0000010";when 7=>q0<="1011000";when 8=>q0<="0000000";when 9=>q0<="0010000";when others=>q0<=NULL;end case;end if;end process;process(cntt2,cntt6)beginif(sw='0') thencase cntt2 iswhen 0=>q1<="1000000";when 1=>q1<="1111001";when 2=>q1<="0100100";when 3=>q1<="0110000";when 4=>q1<="0011001";when 5=>q1<="0010010";when 6=>q1<="0000010";when 7=>q1<="1011000";when 8=>q1<="0000000";when 9=>q1<="0010000";when others=>q1<=NULL;end case;elsecase cntt6 iswhen 0=>q1<="1000000";when 1=>q1<="1111001";when 2=>q1<="0100100";when 3=>q1<="0110000";when 4=>q1<="0011001";when 5=>q1<="0010010";when 6=>q1<="0000010";when 7=>q1<="1011000";when 8=>q1<="0000000";when 9=>q1<="0010000";when others=>q1<=NULL;end case;end if;end process;process(cntt3,cntt7)beginif(sw='0') thencase cntt3 iswhen 0=>q2<="1000000";when 1=>q2<="1111001";when 2=>q2<="0100100";when 3=>q2<="0110000";when 4=>q2<="0011001";when 5=>q2<="0010010";when 6=>q2<="0000010";when 7=>q2<="1011000";when 8=>q2<="0000000";when 9=>q2<="0010000";when others=>q2<=NULL;end case;elsecase cntt7 iswhen 0=>q2<="1000000";when 1=>q2<="1111001";when 2=>q2<="0100100";when 3=>q2<="0110000";when 4=>q2<="0011001";when 5=>q2<="0010010";when 6=>q2<="0000010";when 7=>q2<="1011000";when 8=>q2<="0000000";when 9=>q2<="0010000";when others=>q2<=NULL;end case;end if;end process;process(cntt4,cntt8)beginif(sw='0') thencase cntt4 iswhen 0=>q3<="1000000";when 1=>q3<="1111001";when 2=>q3<="0100100";when 3=>q3<="0110000";when 4=>q3<="0011001";when 5=>q3<="0010010";when others=>q3<=NULL;end case;elsecase cntt8 iswhen 0=>q3<="1000000";when 1=>q3<="1111001";when 2=>q3<="0100100";when 3=>q3<="0110000";when 4=>q3<="0011001";when 5=>q3<="0010010";when 6=>q3<="0000010";-- when 7=>q3<="1011000";-- when 8=>q3<="0000000";--when 9=>q3<="0010000";when others=>q3<=NULL;end case;end if;end process;end behave;2、原理图如下:3、功能仿真如下1、秒、毫秒计数仿真2、分、时计数仿真注释:由于仿真时间限制,小时不能显示。

相关主题