Is there a straightforward way to generate a signal that goes high at
random intervals ?
I have messed around with $random and tried some ideas with LFSRs, but
have not gotten anything useful to work .
Any hints, suggestions would be extremely helpful. Thanks in advance
for your help.
> A standard way to generate a clock pulse would be:
> always
> begin
> #5 clock = 1;
> #5 clock = 0;
> end
>
> Is there a straightforward way to generate a signal that goes high at
> random intervals ?
Of course there is, but you need to be a bit clearer about what
you mean by "random".
You can make a "random" clock signal easily, but let's think a
little about the characteristics you want it to have. Is it to
be a given frequency, with random jitter on the edges? Or
perhaps you want some jitter in the clock phase, or period?
Both those things can be done by computing a random time
error, and using it in a delay. Here's a 100MHz clock
generator with jitter in its edges:
`timescale 1ps/1ps;
...
parameter half_period = 5000; // 100 MHz nominal
parameter max_jitter = 500; // +/- 0.5ns jitter
reg clock;
reg clock_running = 1; // set to 0 to stop the clock
initial begin : jittery_clock_generator
integer seed; // needed for $dist_uniform
integer edge_error;
seed = 42; // change this to get different random values
clock = 0;
while (clock_running) begin
edge_error = $dist_uniform(seed, -max_jitter, +max_jitter);
#(half_period + edge_error) clock = ~clock;
end
end
If you don't like the uniform jitter distribution you could
try dist_gaussian instead, but beware of the (rather rare)
possibility of jitter being larger than a half-period.
Randomization of frequency I'll leave as an exercise :-)
Another useful thing to do is to generate a random possibility
of something happening. Suppose you have some synchronous
enable signal, and you want it to be asserted and deasserted
randomly on each clock edge. If you simply use randomization:
always @(posedge clock)
if ($random > 0)
enable <= 1;
else
enable <= 0;
you will get 50% probability of enable being active, but the
behaviour will probably not be very interesting; for example,
the chance of getting enable asserted for 4 successive clocks
is only 1/16. So it may be more interesting to say that
enable has a certain (small) probability of changing:
parameter typical_pulse_duration = 5;
initial begin : random_activity
integer seed;
seed = 42;
enable = 0;
forever @(posedge clock) begin
if ($dist_uniform(seed, 0, typical_pulse_duration) == 0)
enable <= ~enable;
end
end
Don't forget the other $dist_*** distribution functions:
for example, $dist_poisson is particularly useful for generating
things like the number of wait states introduced by a peripheral.
SystemVerilog adds a very sophisticated constraint language,
giving you access to all kinds of other randomization possibilities,
but that's another discussion. Good old Verilog $dist_*** will
get you a long way.
Hope this gives you some ideas. Be more precise about your needs
if you want more specific advice!
--
Jonathan Bromley
On Dec 11, 1:35 pm, Jonathan Bromley <s...@oxfordbromley.plus.com>
wrote:
If I may be permitted to quote myself:
> > Be more precise about your needs
"Fluctuates" is not a very lucid way to describe a probability
distribution!
--
Jonathan Bromley
On Dec 11, 9:36 pm, Jonathan Bromley <s...@oxfordbromley.plus.com>
wrote:
> If I may be permitted to quote myself:
snip ...