F
fogh
Guest
Hi All,
I found the random bitstream generator in ahdlLib (category telecom) to be not-so-random, and even obviously periodic with a big bad DC offset from eqiprobability. This is with spectre from IC446.100.92, and the verilogA in IC446 is the same as in IC5.
I came up with the following in an attempt to fix it, but I am new to verilogAMS, so please review it. I know that handling of zero rise time or fall time could be better, but I would rather the CDF callbacks deal with this. (BTW: when, oh when, will those ahdlLib symbol be deuglyfied ? )
//--------------------
// rand_bit_stream
//
// - Random bit steam generator
//
// vout: [V,A]
//
// INSTANCE parameters
// tperiod = period of stream
// seed = random number seed []
// vlogic_high = output voltage for high [V]
// vlogic_low = output voltage for low [V]
// tdel, trise, tfall = {usual}
//
// MODEL parameters
// {none}
//
// This model generates a random steam of bits.
//
module rand_bit_stream (vout);
output vout;
electrical vout;
parameter real tperiod = 1n from (0:inf);
parameter integer seed = 0;
parameter real vlogic_high = 2.2;
parameter real vlogic_low = 0 ;
parameter real tdel=0 from [0:inf);
parameter real trise=10p from (0:inf);
parameter real tfall=50p from (0:inf);
real next, vout_val, mintime,transition_accuracy;
integer bit;
analog begin
$bound_step(tperiod); //ensure the simulator will not step over
@ ( initial_step ) begin
next = $abstime + tperiod;
mintime=min(min(abs(trise),abs(tfall)),abs(tperiod));
//mintime=mintime+0.1f;
transition_accuracy=1m; //this is dimensionless.
bit = $random(seed) & 1;
vout_val = (vlogic_high - vlogic_low) * bit + vlogic_low;
end
//bit = abs($random) & 1;
bit = $random & 1;
@ ( timer( next )) begin
vout_val = (vlogic_high - vlogic_low) * bit + vlogic_low;
next = next + tperiod;
if(mintime>0) $bound_step(mintime);
$discontinuity (1); //announce discontinuity of first derivative
end
// V(vout) <+ transition(vout_val,tdel,trise,tfall,mintime*transition_accuracy); //not accepted yet by spectre446.
V(vout) <+ transition(vout_val,tdel,trise,tfall);
end //analog
endmodule
I found the random bitstream generator in ahdlLib (category telecom) to be not-so-random, and even obviously periodic with a big bad DC offset from eqiprobability. This is with spectre from IC446.100.92, and the verilogA in IC446 is the same as in IC5.
I came up with the following in an attempt to fix it, but I am new to verilogAMS, so please review it. I know that handling of zero rise time or fall time could be better, but I would rather the CDF callbacks deal with this. (BTW: when, oh when, will those ahdlLib symbol be deuglyfied ? )
//--------------------
// rand_bit_stream
//
// - Random bit steam generator
//
// vout: [V,A]
//
// INSTANCE parameters
// tperiod = period of stream
// seed = random number seed []
// vlogic_high = output voltage for high [V]
// vlogic_low = output voltage for low [V]
// tdel, trise, tfall = {usual}
//
// MODEL parameters
// {none}
//
// This model generates a random steam of bits.
//
module rand_bit_stream (vout);
output vout;
electrical vout;
parameter real tperiod = 1n from (0:inf);
parameter integer seed = 0;
parameter real vlogic_high = 2.2;
parameter real vlogic_low = 0 ;
parameter real tdel=0 from [0:inf);
parameter real trise=10p from (0:inf);
parameter real tfall=50p from (0:inf);
real next, vout_val, mintime,transition_accuracy;
integer bit;
analog begin
$bound_step(tperiod); //ensure the simulator will not step over
@ ( initial_step ) begin
next = $abstime + tperiod;
mintime=min(min(abs(trise),abs(tfall)),abs(tperiod));
//mintime=mintime+0.1f;
transition_accuracy=1m; //this is dimensionless.
bit = $random(seed) & 1;
vout_val = (vlogic_high - vlogic_low) * bit + vlogic_low;
end
//bit = abs($random) & 1;
bit = $random & 1;
@ ( timer( next )) begin
vout_val = (vlogic_high - vlogic_low) * bit + vlogic_low;
next = next + tperiod;
if(mintime>0) $bound_step(mintime);
$discontinuity (1); //announce discontinuity of first derivative
end
// V(vout) <+ transition(vout_val,tdel,trise,tfall,mintime*transition_accuracy); //not accepted yet by spectre446.
V(vout) <+ transition(vout_val,tdel,trise,tfall);
end //analog
endmodule