我是 VHDL 的新手,目前正在研究生成两种不同时钟速度的时钟发生器。一切正常,除了慢速和快速speed_status之间的切换。“速度按钮”似乎有问题,因为有时我必须多次按下它才能更改当前设置的速度。“重置按钮”始终按预期工作。我的 VHDL 代码有问题还是我需要添加某种软件去抖动?如果是这样,为什么重置按钮有效?您能否给我一些建议,我可以改进时钟发生器的哪些部分(代码/逻辑)?
entity clk_gen is
Port ( clk_in : in STD_LOGIC;
clk_btn_in : in STD_LOGIC_VECTOR (3 DOWNTO 0);
clk_out : out STD_LOGIC);
end clk_gen;
architecture Behavioral of clk_gen is
signal temp : STD_LOGIC := '0';
begin
clock: process(clk_in,clk_btn_in)
variable counter : integer range 0 to 49999999 := 0;
constant freq_cnt_slow : integer := 49999999;
constant freq_cnt_fast : integer := 4999999;
type speed is (slow, fast);
variable speed_status : speed := slow;
begin
if rising_edge(clk_in) then
-- RESET BUTTON PRESSED
if (clk_btn_in = "1000") then
temp <= '0';
counter := 0;
speed_status := slow;
-- SPEED BUTTON
elsif (clk_btn_in = "0100") then
if (speed_status = fast) then
speed_status:= slow;
elsif (speed_status = slow) then
speed_status := fast;
end if;
end if;
if ((counter = freq_cnt_fast) and (speed_status = fast)) then
temp <= NOT(temp);
counter := 0;
elsif ((counter = freq_cnt_slow) and (speed_status = slow)) then
temp <= NOT(temp);
counter := 0;
else
counter := counter + 1;
end if;
end if;
end process clock;
clk_out <= temp;
end Behavioral;
我使用 Xilinx ISE 13.4 和基于 Xilinx Virtex 5 的 XC5VLX110T。