Counter synchronization across two clock-domains
Are you by any chance counting video frames in a frame buffer? I do this sort of thing all the time.

One way to pass a pulse from one clock domain to another is to turn it into an edge and then do edge detection on it. In domain A, use the pulse to toggle a FF. In domain B, synchronize the output through two FFs. Run the output of the synchronizer through an edge detector (FF and XOR gate).

You'll get a pulse in domain B for every pulse in domain A, as long as the pulses don't occur faster than either clock.



This is needed often enough that I've created a generic module to implement it. xd_ is short for "cross-domain" &mdash; I have other modules in this library that perform similar functions.

entity xd_pulse_xfer is
  generic (
    ACTIVE_RESET     : std_logic := '1';   -- active level of reset input
    ACTIVE_IN        : std_logic := '1';   -- active level of input pulse
    ACTIVE_OUT       : std_logic := '1'    -- active level of output pulse
  );
  port (
    reset            : in  std_logic;
    clk_a            : in  std_logic;
    pulse_in         : in  std_logic;
    clk_b            : in  std_logic;
    pulse_out        : out std_logic
  );
end xd_pulse_xfer;

architecture behavior of xd_pulse_xfer is
  signal toggle    : std_logic;
  signal toggle_a  : std_logic;
  signal toggle_b  : std_logic;
  signal toggle_c  : std_logic;
begin
  process (clk_a)
  begin
    if rising_edge(clk_a) then
      if reset = ACTIVE_RESET then
        toggle &lt;= '0';
      elsif pulse_in = ACTIVE_IN then
        toggle &lt;= not toggle;
      end if;
    end if;
  end process;

  process (clk_b)
  begin
    if rising_edge(clk_b) then
      toggle_a &lt;= toggle;        -- synchronizer
      toggle_b &lt;= toggle_a;      -- synchronizer
      toggle_c &lt;= toggle_b;      -- edge detector
    end if;
  end process;

  pulse_out &lt;= (not ACTIVE_OUT) xor (toggle_b xor toggle_c);

end behavior;