如何将时钟分频器集成到现有的VHDL代码和约束文件中

时间:2015-08-26 18:09:34

标签: vhdl clock divider vivado

所以我有一个简单的2位计数器,在按下按钮时从一个状态移动到另一个状态。但是,我可以访问的唯一时钟以125MHz运行,这对于按下按钮来说太快了,所以我需要将时钟分频到更合理的速度。我在这个网站上看到了一些时钟分频器的例子,但我无法弄清楚:

  1. 如何将时钟分频器添加到现有的VHDL代码,我只需添加 分频时钟作为新输出或输入端口?以及如何设置它 这样状态变化只会在分频时钟之后发生?
  2. 在约束文件中,如何包含分频时钟?我认为 我使用生成的时钟作为语句的一部分,但它必须这样做 被分配到自己的单独销钉?现在我有主时钟 分配为:

    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]

  3. 这是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编程 任何和所有帮助表示赞赏,谢谢!

0 个答案:

没有答案