You're going to have problems doing this no matter how you try.
Agreed.
Don't forget Nyquist theorem, you should sample a signal at least twice as
fast as it itself is expected to change. (i.e. 100MHz in your case)
I think we're OK - if the OP is sampling the *output* (count value)
of a counter clocked at 50MHz, then 77MHz is enough. Nyquist would
get in the way if he were trying to sample the 50MHz *clock*.
Presumably you don't need to see the counter's value on EVERY edge
of the 77MHz clock?
Think about the timing diagram, complete with the counter's
clock-to-output delays. Your 77MHz clock will sample at essentially
a random point in the 50MHz cycle. For some part of that 20ns 50MHz
cycle, the counter output will be changing as the result of a recent
clock pulse - let's guess that this will happen for up to 3ns after
the clock. Therefore, you have a 3 in 20 (15%) chance that the
77MHz clock will sample a value that's in transition, and therefore
completely unreliable.
It is not good enough simply to sample your counter into the 77MHz
clock domain before reading it, because that sampling process
suffers exactly the same problems that I've already mentioned.
You need either a handshaking mechanism, or else an asynchronous
FIFO. I guess that in your case the FIFO is probably overkill.
There are many possible handshake schemes. In any case you will
need a temporary holding register, clocked by the 50MHz clock.
When the 77MHz side wants a value, it sets a flag which causes
the 50MHz holding register to be enabled. As a result of this
flag, the 50MHz side must:
- wait for one 50MHz clock, to protect against the possibility
that the flag was set very close to a clock edge
- on the following 50MHz clock, copy the counter into the holding
register: note that this all happens in the 50MHz domain so it's OK
- on that same clock, clear the handshake flag
Meanwhile the 77MHz side, having set the flag, waits for it to clear;
as soon as the flag is cleared again, it can take a copy of the
holding register because that register is then known to be stable.
The big problem with this scheme is that the flag must be set by the
77MHz clock, but cleared by the 50MHz clock. Everything else is
purely synchronous logic in one or the other clock domain. For
a good idea on how to do this set/clear flag, do a Google search
for "Weinstein Flancter" and enjoy
Finally, the scheme I've suggested gives quite long latency,
and you may want to reduce that. This is possible by using a
FIFO, triple swinging buffer, or various other ideas. For a
good discussion of the problems you encounter when designing
such things, take a look at the paper on FIFO design by
Peter Alfke and Cliff Cummings:
www.sunburst-design.com/papers/CummingsSNUG2002SJ_FIFO2_rev1_1.pdf
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * Perl * Tcl/Tk * Verification * Project Services
Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail: (e-mail address removed)
Fax: +44 (0)1425 471573 Web:
http://www.doulos.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.