所以我有一个简单的 2 位计数器,可以在按下按钮时从一个状态移动到下一个状态。但是,我唯一可以访问的时钟运行在 125MHz,这对于按下按钮来说太快了,所以我需要将时钟分频到一个更合理的速度。我在这个网站上看到了一些时钟分频器的例子,但我不知道的是:
- 如何将时钟分频器添加到现有的 VHDL 代码中,我是否只需将分频时钟添加为新的输出或输入端口?以及如何设置它以使状态更改仅在分频时钟之后发生?
在约束文件中,如何包含分频时钟?我想我使用生成的时钟作为语句的一部分,但它是否必须分配给它自己的单独引脚?现在我将主时钟分配为:
set_property PACKAGE_PIN L16 [get_ports clk]
set_property IOSTANDARD LVCMOS33 [get_ports clk]
create_clock -period 10.000 -name clk -waveform {0.000 5.000} [get_ports clk]
这是VHDL代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity des_src is
Port ( clk : in STD_LOGIC;
BTN_0 : in STD_LOGIC;
LED_1 : out STD_LOGIC;
LED_0 : out STD_LOGIC);
end des_src;
architecture Behavioral of des_src is
TYPE statetype IS (Start, One, Two, Three);
SIGNAL currentstate, nextstate : statetype;
begin
fsm1: PROCESS (currentstate, BTN_0)
BEGIN
CASE currentstate IS
WHEN Start =>
LED_1 <= '0';
LED_0 <= '0';
CASE BTN_0 IS
WHEN '1' =>
nextstate <= One;
WHEN OTHERS =>
nextstate <= Start;
END CASE;
WHEN One =>
LED_1 <= '0';
LED_0 <= '1';
CASE BTN_0 IS
WHEN '1' =>
nextstate <= Two;
WHEN OTHERS =>
nextstate <= One;
END CASE;
WHEN Two =>
LED_1 <= '1';
LED_0 <= '0';
CASE BTN_0 IS
WHEN '1' =>
nextstate <= Three;
WHEN OTHERS =>
nextstate <= Two;
END CASE;
WHEN Three =>
LED_1 <= '1';
LED_0 <= '1';
CASE BTN_0 IS
WHEN '1' =>
nextstate <= Start;
WHEN OTHERS =>
nextstate <= Three;
END CASE;
END CASE;
END PROCESS;
fsm2: PROCESS (clk)
BEGIN
IF (clk'EVENT) AND (clk = '1') THEN
currentstate <= nextstate;
END IF;
END PROCESS;
end Behavioral;
我正在使用 Vivado 2015.2 为 ZYBO 编程,感谢任何和所有帮助,谢谢!