资源描述
-目录1.秒表设计要求12.设计思路12.1功能模块12.1.1分频器12.1.2计数器12.1.3数据锁存器12.1.4控制器12.1.5扫描显示的控制电路22.1.6显示电路32.1.7按键消抖电路33.电路实现44.程序仿真104.1分频器104.1.1计数器电路综合114.1.2计数器电路仿真114.2同步计数器134.2.1计数器实现134.2.2计数器仿真154.2.3同步计数器电路综合174.3按键消抖电路184.3.1按键消抖电路实现184.3.2按键消抖电路仿真184.3.3按键消抖电路综合204.4八段译码器204.4.1八段译码器实现204.4.2八段译码器仿真214.4.3八段译码器电路综合224.5控制器234.5.1控制器234.5.1控制器仿真244.5.3控制器电路综合255.2View Technology Schematic :265.3管脚锁定:276.实验结论27. z-1.秒表设计要求(1) 秒表的计时围为00:00:00 59:59:99。(2) 两个按钮开关Start/Stop和Split/Reset,控制秒表的启动、停顿、分段和复位:在秒表已经被复位的情况下,按下“Start/Stop键,秒表开场计时。在秒表正常运行的情况下,如果按下“Start/Stop键,则秒表暂停计时;再次按下该键,秒表继续计时。在秒表正常运行的情况下,如果按下“Split/Reset键,显示停顿在按键时的时间,但秒表仍然在计时;再次按下该键,秒表恢复正常显示。在秒表暂停计时的情况下,按下“Split/Reset键,秒表复位归零。2.设计思路2.1功能模块2.1.1分频器对晶体振荡器产生的时钟信号进展分频,产生时间基准信号2.1.2计数器对时间基准脉冲进展计数,完成计时功能2.1.3数据锁存器锁存数据使显示保持暂停2.1.4控制器通过产生锁存器的使能信号来控制计数器的运行、停顿以及复位设计分析:2.1.5扫描显示的控制电路 包括扫描计数器、数据选择器和7段译码器,控制8个数码管以扫描方式显 示计时结果,原理图如下:实验电路板上的按键2.1.6显示电路2.1.7按键消抖电路消除按键输入信号抖动的影响,输出单脉冲实验板上的数码管为共阳LED数码管按键按下时,FPGA的输入为低电平;松开按键时,FPGA的输入为高电平但是在按下按键和松开按键的瞬间会出现抖动现象2.2电路框图3.电路实现- pany: - Engineer: - - Create Date: 09:08:39 03/12/2021 - Design Name: - Module Name: stopwatch_1 - Behavioral - Project Name: - Target Devices: - Tool versions: - Description: - Dependencies: - Revision: - Revision 0.01 - File Created- Additional ments: -library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;- Unment the following library declaration if instantiating- any *ilin* primitives in this code.-library UNISIM;-use UNISIM.Vponents.all;entity stopwatch_1 isPort (Clk : in STD_LOGIC;start_stop : in STD_LOGIC;split_reset : in STD_LOGIC;ncs : out STD_LOGIC;s : out STD_LOGIC_VECTOR(2 downto 0);seg : out STD_LOGIC_VECTOR (7 downto 0);end stopwatch_1;architecture Behavioral of stopwatch_1 issignal k1,k2,k3,k4: STD_LOGIC;signalt_1,t_2 : STD_LOGIC_VECTOR(1 downto 0);signal start_stop_out,split_reset_out: STD_LOGIC;signal count: STD_LOGIC_VECTOR(15 downto 0):=(others=0);signal clk_1k: STD_LOGIC;signal z0,z1,z2,z3,z4,z5,z6,q1,q2,q3,q4,q5,q6 : STD_LOGIC_VECTOR(3 downto 0):=(others=0);signal count_2: STD_LOGIC_VECTOR(2 downto 0 ):=(others=0);signal in_7: STD_LOGIC_VECTOR(3 downto 0);signal sreg: STD_LOGIC_VECTOR(2 downto 0):=111;signal sne*t: STD_LOGIC_VECTOR(2 downto 0);Begin-为三八译码器置入使能信号 ncs = 0;-分频电路process(clk)beginif rising_edge(clk) thenif count = 47999 thencount 0);elsecount = count+1;end if;end if;end process;clk_1k = count(15);-同步计数电路process(clk_1k,sreg(2)beginif rising_edge(clk_1k) thenif sreg(2) = 1 then z00);z10);z20);z30);z40);z50);z60);elsif sreg(1) = 1 thenz0 = z0+1;if z0 = 9 thenz0 0);z1 = z1+1;if z1 = 9 thenz1 0);z2 = z2+1;if z2 = 9 thenz2 0);z3 = z3+1;if z3 = 9 thenz3 0);z4 = z4+1;if z4 = 5 thenz4 0);z5 = z5+1;if z5 = 9 thenz5 0);z6 = z6+1;if z6 = 5 thenz6 0);end if;end if;end if;end if;end if;end if;end if;end if;end if;end process;-扫描计数器process(clk_1k)beginif rising_edge(clk_1k) thencount_2 = count_2+1;end if;end process;s = count_2;-锁存器process(sreg(0),z1,z2,z3,z4,z5,z6)beginif sreg(0) = 1 thenq1 = z1;q2 = z2;q3 = z3;q4 = z4;q5 = z5;q6 in_7 in_7 in_7 in_7 in_7 in_7 in_7 seg seg seg seg seg seg seg seg seg seg seg =11111101;end case;end process;-按键去抖电路process(clk_1k,start_stop)beginif clk_1kevent and clk_1k=0 thenift_1 = 3 thenk1 = 1;elsek1 = 0;t_1 =t_1+1;end if;k2 = k1;end if;if start_stop = 0 thent_1 = 00;end if;end process;start_stop_out = not k1 and k2; process(clk_1k,split_reset)beginif clk_1kevent and clk_1k=0 thenift_2 = 3 thenk3 = 1;elsek3 = 0;t_2 =t_2+1;end if;k4 = k3;end if;if split_reset = 0 thent_2 = 00;end if;end process;split_reset_out = not k3 and k4;-控制器process(clk_1k,start_stop_out,split_reset_out)beginif rising_edge(clk_1k) thensreg if start_stop_out = 1 and split_reset_out = 0 then sne*t = 011;else sne*t if start_stop_out = 1 and split_reset_out = 0 then sne*t = 001;elsif start_stop_out = 0 and split_reset_out = 1 then sne*t = 010;else sne*t if start_stop_out = 0 and split_reset_out = 1 then sne*t = 111;elsif start_stop_out = 1 and split_reset_out = 0 then sne*t = 011;else sne*t if start_stop_out = 0 and split_reset_out = 1 then sne*t = 011;else sne*t sne*t 0);beginprocess(clk_48M)beginif rising_edge(clk_48M) thenif count = 47999 thencount 0);elsecount = count+1;end if;end if;end process;clk_1k = count(15);end Behavioral;tb : PROCESSBEGINclk_48M = 1; wait for 10.4 ns;clk_48M 0);signal clr,en: STD_LOGIC;Beginclr = 0;-清零无效en = 1;-计数使能有效d1 = z1;d2 = z2;d3 = z3;d4 = z4;d5 = z5;d6 = z6;process(clk_1k,clr)beginif rising_edge(clk_1k) thenif clr = 1 then z00);z10);z20);z30);z40);z50);z60);elsif en = 1 thenz0 = z0+1;if z0 = 9 thenz0 0);z1 = z1+1;if z1 = 9 thenz1 0);z2 = z2+1;if z2 = 9 thenz2 0);z3 = z3+1;if z3 = 9 thenz3 0);z4 = z4+1;if z4 = 5 thenz4 0);z5 = z5+1;if z5 = 9 thenz5 0);z6 = z6+1;if z6 = 5 thenz6 0);end if;end if;end if;end if;end if;end if;end if;end if;end if;end process;end Behavioral;4.2.2计数器仿真tb: PROCESSBEGINclk_1k = 0;wait for 0.5 ms;clk_1k = 1;wait for 0.5 ms;END PROCESS;0.01s位由图可以看出为十进制0.1s位由图可以看出为十进制1s位由图可以看出为十进制10s位由图可以看出为六进制1min位由图可以看出为十进制10min位由图可以看出为六进制4.2.3同步计数器电路综合4.3按键消抖电路4.3.1按键消抖电路实现entity quedou is Port ( clk_1k : in STD_LOGIC; key_in : in STD_LOGIC; key_out : out STD_LOGIC);end quedou;architecture Behavioral of quedou issignal k1,k2: STD_LOGIC;signalt_1: STD_LOGIC_VECTOR(1 downto 0);beginprocess(clk_1k,key_in)beginif clk_1kevent and clk_1k=0 thenift_1 = 3 thenk1 = 1;elsek1 = 0;t_1 =t_1+1;end if;k2 = k1;end if;if key_in = 0 thent_1 = 00;end if;end process;key_out = not k1 and k2;end Behavioral;4.3.2按键消抖电路仿真tb: PROCESSBEGINclk_1k = 0;wait for 0.5 ms;clk_1k = 1;wait for 0.5 ms;END PROCESS;PROCESSBEGINkey_in = 1;wait for 10 ms;key_in = 0;wait for 0.1 ms;key_in = 1;wait for 0.09 ms;key_in = 0;wait for 0.1 ms;key_in = 1;wait for 0.11 ms;key_in = 0;wait for 0.12 ms;key_in = 1;wait for 0.11 ms;key_in = 0;wait for 0.12 ms;key_in = 1;wait for 0.1 ms;key_in = 0;wait for 0.11 ms;key_in = 1;wait for 0.12 ms;key_in = 0;wait for 0.1 ms;key_in = 1;wait for 0.1 ms;key_in = 0;wait for 10 ms;key_in = 1;wait for 0.09 ms;key_in = 0;wait for 0.08 ms;key_in = 1;wait for 0.1 ms;key_in = 0;wait for 0.11 ms;key_in = 1;wait for 0.09 ms;key_in = 0;wait for 0.1 ms;key_in = 1;wait for 0.11 ms;key_in = 0;wait for 0.12 ms;key_in = 1;wait for 0.1 ms;key_in = 0;wait for 0.11 ms;key_in = 1;wait for 0.12 ms;key_in = 0;wait for 0.1 ms;key_in seg seg seg seg seg seg seg seg seg seg seg =11111101;end case;end process;end Behavioral;4.4.2八段译码器仿真tb :PROCESSBEGINin_7 = 0000; wait for 1 ms;in_7 = 0001; wait for 1 ms;in_7 = 0010; wait for 1 ms;in_7 = 0011; wait for 1 ms;in_7 = 0100; wait for 1 ms;in_7 = 0101; wait for 1 ms;in_7 = 0110; wait for 1 ms;in_7 = 0111; wait for 1 ms;in_7 = 1000; wait for 1 ms;in_7 = 1001; wait for 1 ms;in_7 = 1010; wait for 1 ms;in_7 = 0000; wait for 1 ms;END PROCESS;由图可见仿真结果与程序完全符合4.4.3八段译码器电路综合View Technology Schematic :4.5控制器4.5.1控制器entity kongzhiqi is Port ( clk_1k : in STD_LOGIC; start_stop_out : in STD_LOGIC; split_reset_out : in STD_LOGIC; sreg_out : out STD_LOGIC_VECTOR (2 downto 0);end kongzhiqi;architecture Behavioral of kongzhiqi issignal sreg: STD_LOGIC_VECTOR(2 downto 0):=111;signal sne*t: STD_LOGIC_VECTOR(2 downto 0);beginprocess(clk_1k,start_stop_out,split_reset_out)beginif rising_edge(clk_1k) thensreg if start_stop_out = 1 and split_reset_out = 0 then sne*t = 011;else sne*t if start_stop_out = 1 and split_reset_out = 0 then sne*t = 001;elsif start_stop_out = 0 and split_reset_out = 1 then sne*t = 010;else sne*t if start_stop_out = 0 and split_reset_out = 1 then sne*t = 111;elsif start_stop_out = 1 and split_reset_out = 0 then sne*t = 011;else sne*t if start_stop_out = 0 and split_reset_out = 1 then sne*t = 011;else sne*t sne*t = 111;end case;end process;sreg_out = sreg ;end Behavioral;4.5.1控制器仿真tb: PROCESSBEGINclk_1k = 0;wait for 0.5 ms;clk_1k = 1;wait for 0.5 ms;END PROCESS;PROCESSBEGINstart_stop_out = 1 ;wait for 1 ms;start_stop_out = 1 ;wait for 1 ms;start_stop_out = 1 ;wait for 1 ms;start_stop_out = 0 ;wait for 1 ms;start_stop_out = 0 ;wait for 1 ms;start_stop_out = 1 ;wait for 1 ms;start_stop_out = 0 ;wait for 1 ms;END PROCESS;PROCESSBEGINsplit_reset_out = 0;wait for 1 ms;split_reset_out = 0;wait for 1 ms;split_reset_out = 0;wait for 1 ms;split_reset_out = 1;wait for 1 ms;split_reset_out = 1;wait for 1 ms;split_reset_out = 0;wait for 1 ms;split_reset_out = 1;wait for 1 ms;END PROCESS;注:为方便起见,此处 Test Bench是针对几个特定的状态间的转移来写的:复位状态111正常状态011暂停状态001正常状态011显示锁定状态010正常状态011暂停状态001复位状态1114.5.3控制器电路综合5. 电路综合5.1电路总体综合5.2View Technology Schematic :5.3管脚锁定:NET Clk LOC = T8;NET split_reset LOC = G5;NET start_stop LOC = F4;NET ncs LOC = D7;NET s LOC = F8;NET s LOC = D8;NET s LOC = E7;NET seg LOC = B14;NET seg LOC = A13;NET seg LOC = C13;NET seg LOC = C12;NET seg LOC = A12;NET seg LOC = B12;NET seg LOC = A11;NET seg LOC = C11;6.实验结论将程序下载到FPGA试验底板上后,演示结果已达任务要求。. z
展开阅读全文