Search code examples
vhdlxilinx

Moving data between processes in Spartan 3


I have two processes A and B, each with its own clock input.

The clock frequencies are a little different, and therefore not synchronized.

Process A samples data from an IC, this data needs to be passed to process B, which then needs to write this data to another IC.

My current solution is using some simple handshake signals between process A and B. The memory has been declared as distributed RAM (128Bytes as an array of std_logic_vector(7 downto 0)) inside process A (not block memory).

I'm using a Spartan 3AN from Xilinx and the ISE Webpack.

But is this the right way to do it?

I read somewhere that the Spartan 3 has dual-port block memory supporting two clocks, so would this be more correct?

The reason I'm asking, is because my design behaves unpredictable, and in cases like this I just hate magic. :-)


Solution

  • Except for very specific exceptional cases, the only correct way to move data between two independent clock domains is to use an asynchronous FIFO (also more correctly called a multi-rate FIFO).

    In almost all FPGAs (including the Xilinx parts you are using), you can use FIFOs created by the vendor -- in Xilinx's case, you do this by generating yourself a FIFO using the CoreGen tool.

    You can also construct such a FIFO yourself using a dual-port RAM and appropriate handshaking logic, but like most things, this is not something you ought to go reinvent on your own unless you have a very good reason to do so.

    You also might consider whether your design really needs to have multiple clock domains. Sometimes it's absolutely necessary, but that's much, MUCH less often than most people just starting out believe. For instance, even if you need logic that runs at multiple rates, you can often handle this by using a single clock and appropriately generated synchronous clock enables.