how do I skip the first pos/neg edge?

  • Thread starter taebow@sbcglobal.net
  • Start date
T

taebow@sbcglobal.net

Guest
Hi All,

I have an incoming clock that I have to capture...
but the first pulse is short and can either be positive/negative.

in my testbench, i need to be able to skip this short pulse...
before i start to generate my 2x clock. how do I do this?

right now, my code looks something like this...

initial begin
CLOCK_2x = 0;
@(posedge CLOCK);
CLOCK_2x = 1;
@(negedge CLOCK);
CLOCK_2x = 0;
forever #(period/2) CLOCK_2x = ~CLOCK_2x;
end

Thanks,
-Tony
 
On Aug 28, 3:16 pm, "tae...@sbcglobal.net" <thai.t...@gmail.com>
wrote:
Hi All,

I have an incoming clock that I have to capture...
but the first pulse is short and can either be positive/negative.

in my testbench, i need to be able to skip this short pulse...
before i start to generate my 2x clock. how do I do this?

right now, my code looks something like this...

initial begin
CLOCK_2x = 0;
@(posedge CLOCK);
CLOCK_2x = 1;
@(negedge CLOCK);
CLOCK_2x = 0;
forever #(period/2) CLOCK_2x = ~CLOCK_2x;
end

Thanks,
-Tony

I guess I'm a bit confused why a testbench would have an
unknown clock coming into it. For one thing when you say
the first pulse is either positive or negative it implies
that at time 0 the initial state of the clock can be either
1 or 0.

Anyway it's easy enough to count clock edges the way
you do in your initial block. If you always wanted
to start on the 3rd edge regardless of direction, for
example just something like:

initial begin
CLOCK_2x = 0;
@(CLOCK); // first edge either pos or neg
@(CLOCK); // second edge
@(CLOCK); // third edge
CLOCK_2x = 1; // start 2x clock with 0 delay from third edge
forever #(period/2) CLOCK_2x = ~CLOCK_2x;
// assuming "period" is period of 2x clock, not input clock.
end

Of course if you need to start at a particular edge of CLOCK, e.g.
always on the rising edge, you'd need to modify the sequence. You
could for instance place an "if" statement after the first @(CLOCK)
and use a different starting point depending on the state of CLOCK
after its first edge. Something like:


initial begin
CLOCK_2x = 0;
@(CLOCK); // first edge either pos or neg
if (CLOCK) // clock started with rising edge?
@(CLOCK); // second edge if first was rising
@(CLOCK); // second or third edge, always rising
CLOCK_2x = 1; // start 2x clock with 0 delay from second or
third edge
forever #(period/2) CLOCK_2x = ~CLOCK_2x;
// assuming "period" is period of 2x clock, not input clock.
end

HTH,
Gabor
 

Welcome to EDABoard.com

Sponsor

Back
Top