Re: hi
here is the code..i did this for the two cases.
"SQUARE WAVE WITH JITTER"
// VerilogA for SSS, sqarJ2, veriloga
`include "constants.vams"
`include "disciplines.vams"
module squrJ2 (out);
output out; voltage out; // output terminal
parameter real vl=-1; //low output voltage
parameter real vh=1; //high output voltage
parameter real freqT=1 from (0:inf); // output frequency
parameter real tt=0.01/freqT from (0:inf); //output transition time
parameter real ttol=1u/freqT from (0:1/freqT); // time tolerance
parameter real jitter=0 from [0:0.25/freqT); // period jitter (produces white accumulating jitter), variance of random normal distribution.
real freq, phase, dT ;
integer n, seed;
analog begin
@(initial_step) seed = -561;
// freq to freq2
freq = freqT;
// add the phase noise
freq = freq/(1 + dT*freq);
// bound the time step to assure no cycles are skipped
$bound_step(0.6/freqT);
// phase is the integral of the freq modulo 2p
phase = 2*`M_PI*idtmod(freq, 0.0, 1.0, -0.5);
// update jitter twice per period
// `M_SQRT2=sqrt(K), K=2 jitter updates/period
@(cross(phase + `M_PI/2, +1, ttol) or cross(phase - `M_PI/2, +1, ttol)) begin
dT = `M_SQRT2*jitter*$rdist_normal(seed,0, 1);
n = (phase >= -`M_PI/2) && (phase < `M_PI/2);
end
// generate the output
V(out) <+ transition(n ? vh : vl,330p ,tt);
end
endmodule\
================================================================================================================
"SINE WAVE WITH JITTER" ( modified the above one to get this.)
// VerilogA for SSS, sineJ2, veriloga
`include "constants.vams"
`include "disciplines.vams"
module sineJ2 (out);
output out; voltage out; // output terminal
parameter real freqT=1 from (0:inf); // output frequency
parameter real ttol=1u/freqT from (0:1/freqT); // time tolerance
parameter real jitter=0 from [0:0.25/freqT); // period jitter (produces white accumulating jitter), variance of random normal distribution.
real freq, phase, dT ;
integer seed;
analog begin
@(initial_step) seed = -561;
// freq to freq2
freq = freqT;
// add the phase noise
freq = freq/(1 + dT*freq);
// bound the time step to assure no cycles are skipped
// $bound_step(0.6/freqT);
// phase is the integral of the freq modulo 2p
phase = 2*`M_PI*idtmod(freq, 0.0, 1.0, -0.5);
// update jitter twice per period
// `M_SQRT2=sqrt(K), K=2 jitter updates/period
@(cross(phase + `M_PI/2, +1, ttol) or cross(phase - `M_PI/2, +1, ttol)) begin
dT = `M_SQRT2*jitter*$rdist_normal(seed,0, 1);
end
// generate the output
V(out) <+ 1.2*sin(`M_TWO_PI*freqT*$realtime + phase) ;
$bound_step(0.06/freqT);
end
endmodule