一 设计要求
- 将EDA 板上的系统时钟50MHz 分频为1Hz 的时钟信号
- 占空比为50%
- 利用流水灯点亮程序,在EDA 板上观察效果
二 代码实现
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity clkdiv is
generic(n:integer:=50000000);
port(clk_50MHZ:in std_logic;
clk_1HZ:out std_logic);
end clkdiv;
architecture behavior of clkdiv is
signal count:integer range n-1 downto 0:=n-1;
begin
process(clk_50MHZ)
begin
if(clk_50MHZ'event and clk_50MHZ='1'and clk_50MHZ'last_value='0') then
count<=count-1;
if count>=n/2 then
clk_1HZ<='0';
else
clk_1HZ<='1';
end if;
if count<=0 then
count<=n-1;
end if;
end if;
end process;
end behavior;
三 整机电路
四 实验结果
状态1
状态2
状态3
状态4
状态5
状态6