0

私は VHDL を初めて使用し、現在 2 つの異なるクロック速度を生成するクロック ジェネレーターに取り組んでいます。低速と高速の 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 を使用しています。

4

1 に答える 1