B
Břrge Strand
Guest
Do you guys have any good thoughts about polling an async clock?
I have a feeling I'm missing something about buffering of signals because I
keep missing the edges I poll for when I try go get the speed up.
I run my FPGA on 100MHz and have to cope with an asynchronous 11 or 16MHz
clock to dump some serial bits. Data bits are read by an external unit on
the positive edge of this clock. What I want to do is detect the positive
edge and then set up the new data bit out of the FPGA. This means the FPGA
outputs new data right after the previous bit was read.
I poll by doing the following:
always @(posedge clk_100MHz)
begin
prev <= clock_11MHz;
prevprev <= prev;
if ({prevprev, prev} == 2'b01) // we detect a positive edge a little
while after it happens ...
begin
// do whatever happens on the positive edge
end
end
This works just fine when I compare {prevprev,prev} to a rise. If I compare
{prev,clock_11MHz} to a rise, quite a few of them are missed. However, I
want to spend as few clock ticks as possible on this, so I thought about
doing something like this instead:
if ({clock_11MHz,edge_detected} == 2'b10) // clock is high, but the edge
hasn't been detected
begin
edge_detected <= 1; // clock has gone up
// do what ever happens on the positive edge
end
if (clock_11MHz == 0)
edge_detected <= 0; // clock has gone down, start looking for positive
edge.
But this method too misses a lot of edges. Is there some kind of buffering
(Xilinx) that would make this code work?
Greetings,
Břrge Strand
I have a feeling I'm missing something about buffering of signals because I
keep missing the edges I poll for when I try go get the speed up.
I run my FPGA on 100MHz and have to cope with an asynchronous 11 or 16MHz
clock to dump some serial bits. Data bits are read by an external unit on
the positive edge of this clock. What I want to do is detect the positive
edge and then set up the new data bit out of the FPGA. This means the FPGA
outputs new data right after the previous bit was read.
I poll by doing the following:
always @(posedge clk_100MHz)
begin
prev <= clock_11MHz;
prevprev <= prev;
if ({prevprev, prev} == 2'b01) // we detect a positive edge a little
while after it happens ...
begin
// do whatever happens on the positive edge
end
end
This works just fine when I compare {prevprev,prev} to a rise. If I compare
{prev,clock_11MHz} to a rise, quite a few of them are missed. However, I
want to spend as few clock ticks as possible on this, so I thought about
doing something like this instead:
if ({clock_11MHz,edge_detected} == 2'b10) // clock is high, but the edge
hasn't been detected
begin
edge_detected <= 1; // clock has gone up
// do what ever happens on the positive edge
end
if (clock_11MHz == 0)
edge_detected <= 0; // clock has gone down, start looking for positive
edge.
But this method too misses a lot of edges. Is there some kind of buffering
(Xilinx) that would make this code work?
Greetings,
Břrge Strand