random delay for data

S

skyworld

Guest
Hi,
I would like to generage some data with random delay from rising edge
of clock, which simulates data jitter. I write code as this:

always @ (posedge clk or negedge rstn)
begin
if (!rstn)
data <= 4'b0;
else
data <= #($random%10*period/100) input_data;
end

period is defined as clock cycle time. My purpose is to generate data
which appears after clock rising edge with random delayed time (within
10% of clock period). But this doesn't work. Every time the data always
changes at the rising edge of clock. I am confused. Can anybody explain
why this happens? Thanks very much.



skyworld
 
I'm not 100% sure, but there are several things that could be going on
here.

One, $random returns a signed quantity. If it's negative, how should
the delay work? The simulator can't go back in time. You can use
{$random} to always get a positive value.

Two, what is your period? If $random%10*period is less than 100, then
the integer division will always return 0. I'll let you work out how to
get non-integer results.

Third, and this is just extra. You might want to pass a seed to $random
so that you can get different and repeatable results each time you
simulate.

integer seed = 5; // preferably, set via $value$plusargs
....
data <= #({$random(seed)}%10*period/100) input_data;

-cb
 
Hi CB,
I have tried your code, the question is that can I make the data ahead
of the clock, not always behind the clock? thanks.



Chris Briggs wrote:
I'm not 100% sure, but there are several things that could be going on
here.

One, $random returns a signed quantity. If it's negative, how should
the delay work? The simulator can't go back in time. You can use
{$random} to always get a positive value.

Two, what is your period? If $random%10*period is less than 100, then
the integer division will always return 0. I'll let you work out how to
get non-integer results.

Third, and this is just extra. You might want to pass a seed to $random
so that you can get different and repeatable results each time you
simulate.

integer seed = 5; // preferably, set via $value$plusargs
...
data <= #({$random(seed)}%10*period/100) input_data;

-cb
 
On 1 Nov 2006 17:51:28 -0800, "skyworld"
<chenyong20000@gmail.com> wrote:

I have tried your code, the question is that can I make the data ahead
of the clock, not always behind the clock? thanks.
Simulators cannot predict the future. If you use the clock to control
data generation, the data must change *after* the clock.

One possibility is to use a "phantom" or virtual clock to control
the data generation. Then create a delayed version of the clock,
which will be distributed to everything else in the system. That
way, you can have the data change before the delayed clock
occurs, and "users" (any modules that see these signals) get
data setup before the clock event.

Another obvious possibility is to use the *previous* clock
to control data generation.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 

Welcome to EDABoard.com

Sponsor

Back
Top