VHDL: creating a very slow clock pulse based on a very fast clock

前端 未结 4 1512
悲哀的现实
悲哀的现实 2021-01-02 22:35

(I\'d post this in EE but it seems there are far more VHDL questions here...)

Background: I\'m using the Xilinx Spartan-6LX9 FPGA with the

4条回答
  •  一个人的身影
    2021-01-02 23:01

    If you just need a clock to drive another part of your logic in the FPGA, the easy answer is to use a clock enable.

    That is, run your slow logic on the same (fast) clock as everything else, but us a slow enable for it. Example:

    signal clk_enable_200kHz  : std_logic;
    signal clk_enable_counter : std_logic_vector(9 downto 0);
    
    --Create the clock enable:
    process(clk_200MHz)
    begin
      if(rising_edge(clk_200MHz)) then
        clk_enable_counter <= clk_enable_counter + 1;
        if(clk_enable_counter = 0) then
          clk_enable_200kHz <= '1';
        else
          clk_enable_200kHz <= '0';
        end if;
      end if;
    end process;
    
    
    --Slow process:
    process(clk_200MHz)
    begin
      if(rising_edge(clk_200MHz)) then
        if(reset = '1') then
          --Do reset
        elsif(clk_enable_200kHz = '1') then
          --Do stuff
        end if;
      end if;
    end process;
    

    The 200kHz is approximate though, but the above can be extended to basically any clock enable frequency you need. Also, it should be supported directly by the FPGA hardware in most FPGAs (it is in Xilinx parts at least).

    Gated clocks are almost always a bad idea, as people often forget that they are creating new clock-domains, and thus do not take the necessary precautions when interfacing signals between these. It also uses more clock-lines inside the FPGA, so you might quickly use up all your available lines if you have a lot of gated clocks.

    Clock enables have none of these drawbacks. Everything runs in the same clock domain (although at different speeds), so you can easily use the same signals without any synchronizers or similar.

提交回复
热议问题